├── DATESTAMP ├── Makefile.in ├── arch ├── amd64 │ ├── code.c │ ├── local.c │ ├── local2.c │ ├── macdefs.h │ ├── order.c │ └── table.c ├── arm │ ├── code.c │ ├── local.c │ ├── local2.c │ ├── macdefs.h │ ├── order.c │ └── table.c ├── hppa │ ├── code.c │ ├── local.c │ ├── local2.c │ ├── macdefs.h │ ├── order.c │ └── table.c ├── i386 │ ├── code.c │ ├── flocal.c │ ├── local.c │ ├── local2.c │ ├── macdefs.h │ ├── order.c │ └── table.c ├── m16c │ ├── TODO │ ├── code.c │ ├── local.c │ ├── local2.c │ ├── macdefs.h │ ├── order.c │ └── table.c ├── mips │ ├── TODO │ ├── code.c │ ├── local.c │ ├── local2.c │ ├── macdefs.h │ ├── order.c │ └── table.c ├── nova │ ├── README │ ├── code.c │ ├── local.c │ ├── local2.c │ ├── macdefs.h │ ├── order.c │ └── table.c ├── pdp10 │ ├── README │ ├── code.c │ ├── local.c │ ├── local2.c │ ├── macdefs.h │ ├── order.c │ └── table.c ├── pdp11 │ ├── code.c │ ├── local.c │ ├── local2.c │ ├── macdefs.h │ ├── order.c │ └── table.c ├── powerpc │ ├── README │ ├── code.c │ ├── local.c │ ├── local2.c │ ├── macdefs.h │ ├── order.c │ └── table.c ├── sparc64 │ ├── code.c │ ├── local.c │ ├── local2.c │ ├── macdefs.h │ ├── order.c │ └── table.c └── vax │ ├── code.c │ ├── local.c │ ├── local2.c │ ├── macdefs.h │ ├── order.c │ └── table.c ├── cc ├── Makefile.in ├── cc │ ├── Makefile.in │ ├── cc.1 │ └── cc.c ├── ccom │ ├── Makefile.in │ ├── builtins.c │ ├── ccom.1 │ ├── cgram.y │ ├── gcc_compat.c │ ├── init.c │ ├── inline.c │ ├── main.c │ ├── optim.c │ ├── pass1.h │ ├── pftn.c │ ├── scan.l │ ├── softfloat.c │ ├── stabs.c │ ├── symtabs.c │ └── trees.c ├── cpp │ ├── Makefile.in │ ├── cpp.1 │ ├── cpp.c │ ├── cpp.h │ ├── cpy.y │ ├── scanner.l │ ├── tests │ │ ├── res1 │ │ ├── res10 │ │ ├── res11 │ │ ├── res12 │ │ ├── res13 │ │ ├── res2 │ │ ├── res3 │ │ ├── res4 │ │ ├── res5 │ │ ├── res6 │ │ ├── res7 │ │ ├── res8 │ │ ├── res9 │ │ ├── test1 │ │ ├── test10 │ │ ├── test11 │ │ ├── test12 │ │ ├── test13 │ │ ├── test2 │ │ ├── test3 │ │ ├── test4 │ │ ├── test5 │ │ ├── test6 │ │ ├── test7 │ │ ├── test8 │ │ └── test9 │ └── token.c ├── cxxcom │ ├── Makefile.in │ ├── builtins.c │ ├── cgram.y │ ├── cxxcode.c │ ├── cxxdefs.h │ ├── gcc_compat.c │ ├── init.c │ ├── inline.c │ ├── main.c │ ├── optim.c │ ├── pass1.h │ ├── pftn.c │ ├── scan.l │ ├── softfloat.c │ ├── stabs.c │ ├── symtabs.c │ └── trees.c └── driver │ ├── Makefile.in │ ├── driver.c │ ├── driver.h │ ├── platform.c │ ├── strlist.c │ ├── strlist.h │ ├── xalloc.c │ └── xalloc.h ├── config.guess ├── config.h.in ├── config.sub ├── configure ├── configure.ac ├── f77 ├── Makefile.in ├── f77 │ ├── Makefile.in │ ├── f77.1 │ └── f77.c └── fcom │ ├── Makefile.in │ ├── data.c │ ├── defines.h │ ├── defs.h │ ├── equiv.c │ ├── error.c │ ├── exec.c │ ├── expr.c │ ├── ftypes.h │ ├── gram.dcl │ ├── gram.exec │ ├── gram.expr │ ├── gram.head │ ├── gram.io │ ├── init.c │ ├── intr.c │ ├── io.c │ ├── lex.c │ ├── main.c │ ├── misc.c │ ├── proc.c │ ├── put.c │ ├── putscj.c │ ├── scjdefs.h │ └── tokens ├── install-sh ├── mip ├── common.c ├── compat.c ├── compat.h ├── manifest.h ├── match.c ├── mkext.c ├── node.h ├── optim2.c ├── pass2.h ├── reader.c └── regs.c └── os ├── bsd └── ccconfig.h ├── darwin └── ccconfig.h ├── dragonfly └── ccconfig.h ├── freebsd └── ccconfig.h ├── linux └── ccconfig.h ├── midnightbsd └── ccconfig.h ├── minix └── ccconfig.h ├── mirbsd └── ccconfig.h ├── netbsd └── ccconfig.h ├── nextstep └── ccconfig.h ├── none └── ccconfig.h ├── openbsd ├── ccconfig.h └── f77config.h ├── sunos └── ccconfig.h └── win32 ├── build.bat ├── build_installer.bat ├── ccconfig.h ├── config.h └── pcc.iss /DATESTAMP: -------------------------------------------------------------------------------- 1 | 20120401 2 | -------------------------------------------------------------------------------- /Makefile.in: -------------------------------------------------------------------------------- 1 | # $Id: Makefile.in,v 1.9 2011/06/07 13:56:05 plunky Exp $ 2 | # 3 | # Makefile.in for top-level of pcc. 4 | # 5 | 6 | @SET_MAKE@ 7 | 8 | ALL_SUBDIRS= cc 9 | DIST_SUBDIRS= $(ALL_SUBDIRS) f77 10 | 11 | all install clean: 12 | @for subdir in $(ALL_SUBDIRS); do \ 13 | _nextdir_=$${_thisdir_+$$_thisdir_/}$$subdir; \ 14 | echo "===> $$_nextdir_"; \ 15 | (_thisdir_=$$_nextdir_; export _thisdir_; cd $$subdir && \ 16 | exec $(MAKE) $(MFLAGS) $@) || exit $$?; \ 17 | echo "<=== $$_nextdir_"; \ 18 | done 19 | 20 | distclean: 21 | @for subdir in $(DIST_SUBDIRS); do \ 22 | _nextdir_=$${_thisdir_+$$_thisdir_/}$$subdir; \ 23 | echo "===> $$_nextdir_"; \ 24 | (_thisdir_=$$_nextdir_; export _thisdir_; cd $$subdir && \ 25 | exec $(MAKE) $(MFLAGS) $@) || exit $$?; \ 26 | echo "<=== $$_nextdir_"; \ 27 | done 28 | rm -rf Makefile config.log stamp-h1 config.status \ 29 | configure.lineno config.h autom4te.cache 30 | -------------------------------------------------------------------------------- /arch/hppa/order.c: -------------------------------------------------------------------------------- 1 | /* $Id: order.c,v 1.10 2011/06/05 08:54:42 plunky Exp $ */ 2 | 3 | /* 4 | * Copyright (c) 2007 Michael Shalayeff 5 | * Copyright (c) 2003 Anders Magnusson (ragge@ludd.luth.se). 6 | * All rights reserved. 7 | * 8 | * Redistribution and use in source and binary forms, with or without 9 | * modification, are permitted provided that the following conditions 10 | * are met: 11 | * 1. Redistributions of source code must retain the above copyright 12 | * notice, this list of conditions and the following disclaimer. 13 | * 2. Redistributions in binary form must reproduce the above copyright 14 | * notice, this list of conditions and the following disclaimer in the 15 | * documentation and/or other materials provided with the distribution. 16 | * 3. The name of the author may not be used to endorse or promote products 17 | * derived from this software without specific prior written permission 18 | * 19 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 20 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 21 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 22 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 23 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 24 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 25 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 26 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 28 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | */ 30 | 31 | 32 | # include "pass2.h" 33 | 34 | #include 35 | 36 | int canaddr(NODE *); 37 | 38 | /* is it legal to make an OREG or NAME entry which has an 39 | * offset of off, (from a register of r), if the 40 | * resulting thing had type t */ 41 | int 42 | notoff(TWORD t, int r, CONSZ off, char *cp) 43 | { 44 | return(0); /* YES */ 45 | } 46 | 47 | /* 48 | * Turn a UMUL-referenced node into OREG. 49 | * Be careful about register classes, this is a place where classes change. 50 | */ 51 | void 52 | offstar(NODE *p, int shape) 53 | { 54 | NODE *r; 55 | 56 | if (x2debug) 57 | printf("offstar(%p)\n", p); 58 | 59 | if (isreg(p)) 60 | return; /* Is already OREG */ 61 | 62 | r = p->n_right; 63 | if (p->n_op == PLUS || p->n_op == MINUS) { 64 | if (r->n_op == ICON) { 65 | if (isreg(p->n_left) == 0) 66 | (void)geninsn(p->n_left, INAREG); 67 | /* Converted in ormake() */ 68 | return; 69 | } 70 | } 71 | (void)geninsn(p, INAREG); 72 | } 73 | 74 | /* 75 | * Do the actual conversion of offstar-found OREGs into real OREGs. 76 | */ 77 | void 78 | myormake(NODE *q) 79 | { 80 | NODE *p, *r; 81 | 82 | if (x2debug) 83 | printf("myormake(%p)\n", q); 84 | 85 | p = q->n_left; 86 | if (p->n_op == PLUS && (r = p->n_right)->n_op == LS && 87 | r->n_right->n_op == ICON && r->n_right->n_lval == 2 && 88 | p->n_left->n_op == REG && r->n_left->n_op == REG) { 89 | q->n_op = OREG; 90 | q->n_lval = 0; 91 | q->n_rval = R2PACK(p->n_left->n_rval, r->n_left->n_rval, 0); 92 | tfree(p); 93 | } 94 | } 95 | 96 | /* 97 | * Shape matches for UMUL. Cooperates with offstar(). 98 | */ 99 | int 100 | shumul(NODE *p, int shape) 101 | { 102 | 103 | if (x2debug) 104 | printf("shumul(%p)\n", p); 105 | 106 | /* Turns currently anything into OREG on hppa */ 107 | if (shape & SOREG) 108 | return SOREG; 109 | return SRNOPE; 110 | } 111 | 112 | /* 113 | * Rewrite operations on binary operators (like +, -, etc...). 114 | * Called as a result of table lookup. 115 | */ 116 | int 117 | setbin(NODE *p) 118 | { 119 | if (x2debug) 120 | printf("setbin(%p)\n", p); 121 | 122 | return 0; 123 | } 124 | 125 | /* setup for assignment operator */ 126 | int 127 | setasg(NODE *p, int cookie) 128 | { 129 | if (x2debug) 130 | printf("setasg(%p,%s)\n", p, prcook(cookie)); 131 | 132 | if (p->n_left->n_op == FLD && !isreg(p->n_left->n_left)) { 133 | NODE *l, *r; 134 | int reg; 135 | 136 | geninsn(p->n_left->n_left, INAREG); 137 | 138 | reg = DECRA(p->n_left->n_left->n_reg, 0); 139 | l = tcopy(p->n_left->n_left); 140 | p->n_left->n_left->n_op = REG; 141 | p->n_left->n_left->n_rval = reg; 142 | p->n_left->n_left->n_lval = 0; 143 | r = tcopy(p->n_left->n_left); 144 | 145 | geninsn(p->n_left, INAREG); 146 | l = mkbinode(ASSIGN, l, r, l->n_type); 147 | geninsn(l, INAREG); 148 | return (1); 149 | } 150 | 151 | return (0); 152 | } 153 | 154 | /* setup for unary operator */ 155 | int 156 | setuni(NODE *p, int cookie) 157 | { 158 | if (x2debug) 159 | printf("setuni(%p,%s)\n", p, prcook(cookie)); 160 | 161 | return 0; 162 | } 163 | 164 | /* 165 | * Special handling of some instruction register allocation. 166 | */ 167 | struct rspecial * 168 | nspecial(struct optab *q) 169 | { 170 | comperr("nspecial entry %d", q - table); 171 | return 0; /* XXX gcc */ 172 | } 173 | 174 | /* 175 | * Set evaluation order of a binary node if it differs from default. 176 | */ 177 | int 178 | setorder(NODE *p) 179 | { 180 | return 0; /* nothing differs on hppa */ 181 | } 182 | 183 | /* 184 | * Set registers "live" at function calls (like arguments in registers). 185 | * This is for liveness analysis of registers. 186 | */ 187 | int * 188 | livecall(NODE *p) 189 | { 190 | static int r[5], *s = &r[4]; 191 | 192 | *s = -1; 193 | if (p->n_op == UCALL || p->n_op == UFORTCALL || p->n_op == USTCALL || 194 | p->n_op == FORTCALL) 195 | return s; 196 | 197 | for (p = p->n_right; p->n_op == CM; p = p->n_left) 198 | if (p->n_right->n_op == ASSIGN && 199 | p->n_right->n_left->n_op == REG) 200 | *--s = p->n_right->n_left->n_rval; 201 | 202 | if (p->n_op == ASSIGN && 203 | p->n_left->n_op == REG) 204 | *--s = p->n_left->n_rval; 205 | 206 | return s; 207 | } 208 | 209 | /* 210 | * Signal whether the instruction is acceptable for this target. 211 | */ 212 | int 213 | acceptable(struct optab *op) 214 | { 215 | return 1; 216 | } 217 | -------------------------------------------------------------------------------- /arch/i386/flocal.c: -------------------------------------------------------------------------------- 1 | /* $Id: flocal.c,v 1.16 2008/12/19 20:26:50 ragge Exp $ */ 2 | /* 3 | * Copyright(C) Caldera International Inc. 2001-2002. All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions 7 | * are met: 8 | * 9 | * Redistributions of source code and documentation must retain the above 10 | * copyright notice, this list of conditions and the following disclaimer. 11 | * Redistributions in binary form must reproduce the above copyright 12 | * notice, this list of conditionsand the following disclaimer in the 13 | * documentation and/or other materials provided with the distribution. 14 | * All advertising materials mentioning features or use of this software 15 | * must display the following acknowledgement: 16 | * This product includes software developed or owned by Caldera 17 | * International, Inc. 18 | * Neither the name of Caldera International, Inc. nor the names of other 19 | * contributors may be used to endorse or promote products derived from 20 | * this software without specific prior written permission. 21 | * 22 | * USE OF THE SOFTWARE PROVIDED FOR UNDER THIS LICENSE BY CALDERA 23 | * INTERNATIONAL, INC. AND CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR 24 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 25 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 26 | * DISCLAIMED. IN NO EVENT SHALL CALDERA INTERNATIONAL, INC. BE LIABLE 27 | * FOR ANY DIRECT, INDIRECT INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 28 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 29 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 30 | * HOWEVER CAUSED AND ON ANY THEORY OFLIABILITY, WHETHER IN CONTRACT, 31 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING 32 | * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 33 | * POSSIBILITY OF SUCH DAMAGE. 34 | */ 35 | #include 36 | 37 | #include "defines.h" 38 | #include "defs.h" 39 | 40 | void 41 | prchars(int *s) 42 | { 43 | printf("\t.byte 0%o,0%o\n", s[0], s[1]); 44 | } 45 | 46 | 47 | void 48 | setloc(int l) 49 | { 50 | static int lastloc = -1; 51 | static char *loctbl[] = 52 | { "text", "data", "section .rodata", "section .rodata", "bss" }; 53 | if (l == lastloc) 54 | return; 55 | printf("\t.%s\n", loctbl[l]); 56 | lastloc = l; 57 | } 58 | 59 | #ifdef FCOM 60 | 61 | 62 | /* 63 | PDP11-780/VAX - SPECIFIC PRINTING ROUTINES 64 | */ 65 | 66 | /* 67 | * Called just before return from a subroutine. 68 | */ 69 | void 70 | goret(int type) 71 | { 72 | } 73 | 74 | /* 75 | * Print out a label. 76 | */ 77 | void 78 | prlabel(int k) 79 | { 80 | printf(LABFMT ":\n", k); 81 | } 82 | 83 | /* 84 | * Print naming for location. 85 | * name[0] is location type. 86 | */ 87 | void 88 | prnloc(char *name) 89 | { 90 | if (*name == '0') 91 | setloc(DATA); 92 | else 93 | fatal("unhandled prnloc %c", *name); 94 | printf("%s:\n", name+1); 95 | } 96 | 97 | /* 98 | * Print integer constant. 99 | */ 100 | void 101 | prconi(FILE *fp, int type, ftnint n) 102 | { 103 | fprintf(fp, "\t%s\t%ld\n", (type==TYSHORT ? ".word" : ".long"), n); 104 | } 105 | 106 | /* 107 | * Print address constant, given as a label number. 108 | */ 109 | void 110 | prcona(ftnint a) 111 | { 112 | printf("\t.long\t" LABFMT "\n", (int)a); 113 | } 114 | 115 | /* 116 | * Print out a floating constant. 117 | */ 118 | void 119 | prconr(FILE *fp, int type, double x) 120 | { 121 | fprintf(fp, "\t%s\t0f%e\n", (type==TYREAL ? ".float" : ".double"), x); 122 | } 123 | 124 | void 125 | preven(int k) 126 | { 127 | if (k > 1) 128 | printf("\t.align\t%d\n", k); 129 | } 130 | 131 | /* 132 | * Convert a tag and offset into the symtab table to a string. 133 | * An external string is never longer than XL bytes. 134 | */ 135 | char * 136 | memname(int stg, int mem) 137 | { 138 | #define MLEN (XL + 10) 139 | char *s = malloc(MLEN); 140 | 141 | switch(stg) { 142 | case STGCOMMON: 143 | case STGEXT: 144 | snprintf(s, MLEN, "%s", varstr(XL, extsymtab[mem].extname)); 145 | break; 146 | 147 | case STGBSS: 148 | case STGINIT: 149 | snprintf(s, MLEN, "v.%d", mem); 150 | break; 151 | 152 | case STGCONST: 153 | snprintf(s, MLEN, ".L%d", mem); 154 | break; 155 | 156 | case STGEQUIV: 157 | snprintf(s, MLEN, "q.%d", mem); 158 | break; 159 | 160 | default: 161 | fatal1("memname: invalid vstg %d", stg); 162 | } 163 | return(s); 164 | } 165 | 166 | void 167 | prlocvar(char *s, ftnint len) 168 | { 169 | printf("\t.lcomm\t%s,%ld\n", s, len); 170 | } 171 | 172 | 173 | void 174 | prext(char *name, ftnint leng, int init) 175 | { 176 | if(leng == 0) 177 | printf("\t.globl\t%s\n", name); 178 | else 179 | printf("\t.comm\t%s,%ld\n", name, leng); 180 | } 181 | 182 | void 183 | prendproc() 184 | { 185 | } 186 | 187 | void 188 | prtail() 189 | { 190 | } 191 | 192 | void 193 | prolog(struct entrypoint *ep, struct bigblock *argvec) 194 | { 195 | /* Ignore for now. ENTRY is not supported */ 196 | } 197 | 198 | 199 | 200 | void 201 | prdbginfo() 202 | { 203 | } 204 | 205 | static void 206 | fcheck(NODE *p, void *arg) 207 | { 208 | NODE *r, *l; 209 | 210 | switch (p->n_op) { 211 | case CALL: /* fix arguments */ 212 | for (r = p->n_right; r->n_op == CM; r = r->n_left) { 213 | r->n_right = mkunode(FUNARG, r->n_right, 0, 214 | r->n_right->n_type); 215 | } 216 | l = talloc(); 217 | *l = *r; 218 | r->n_op = FUNARG; 219 | r->n_left = l; 220 | r->n_type = l->n_type; 221 | break; 222 | } 223 | } 224 | 225 | /* 226 | * Called just before the tree is written out to pass2. 227 | */ 228 | void p2tree(NODE *p); 229 | void 230 | p2tree(NODE *p) 231 | { 232 | walkf(p, fcheck, 0); 233 | } 234 | #endif /* FCOM */ 235 | -------------------------------------------------------------------------------- /arch/m16c/TODO: -------------------------------------------------------------------------------- 1 | * Mul/Div does not work. -------------------------------------------------------------------------------- /arch/m16c/macdefs.h: -------------------------------------------------------------------------------- 1 | /* $Id: macdefs.h,v 1.24 2011/06/05 10:19:24 ragge Exp $ */ 2 | /* 3 | * Copyright (c) 2003 Anders Magnusson (ragge@ludd.luth.se). 4 | * All rights reserved. 5 | * 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions 8 | * are met: 9 | * 1. Redistributions of source code must retain the above copyright 10 | * notice, this list of conditions and the following disclaimer. 11 | * 2. Redistributions in binary form must reproduce the above copyright 12 | * notice, this list of conditions and the following disclaimer in the 13 | * documentation and/or other materials provided with the distribution. 14 | * 3. The name of the author may not be used to endorse or promote products 15 | * derived from this software without specific prior written permission 16 | * 17 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 18 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 19 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 20 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 21 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 22 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 23 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 24 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 25 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 26 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 | */ 28 | 29 | /* 30 | * Machine-dependent defines for both passes. 31 | */ 32 | #define makecc(val,i) lastcon = (lastcon<<8)|((val<<8)>>8); 33 | 34 | #define ARGINIT 40 /* # bits above fp where arguments start */ 35 | #define AUTOINIT 0 /* # bits below fp where automatics start */ 36 | 37 | /* 38 | * Convert (multi-)character constant to integer. 39 | * Assume: If only one value; store at left side (char size), otherwise 40 | * treat it as an integer. 41 | */ 42 | 43 | /* 44 | * Storage space requirements 45 | */ 46 | #define SZCHAR 8 47 | #define SZINT 16 48 | #define SZFLOAT 16 49 | #define SZDOUBLE 16 50 | #define SZLDOUBLE 16 51 | #define SZLONG 32 52 | #define SZSHORT 16 53 | #define SZLONGLONG 32 54 | /* pointers are of different sizes on m16c */ 55 | #define SZPOINT(t) (ISFTN(DECREF(t)) ? 32 : 16) 56 | 57 | /* 58 | * Alignment constraints 59 | */ 60 | #define ALCHAR 8 61 | #define ALINT 16 62 | #define ALFLOAT 16 63 | #define ALDOUBLE 16 64 | #define ALLDOUBLE 16 65 | #define ALLONG 16 66 | #define ALLONGLONG 16 67 | #define ALSHORT 16 68 | #define ALPOINT 16 69 | #define ALSTRUCT 16 70 | #define ALSTACK 16 71 | 72 | /* 73 | * Min/max values. 74 | */ 75 | #define MIN_CHAR -128 76 | #define MAX_CHAR 127 77 | #define MAX_UCHAR 255 78 | #define MIN_SHORT -32768 79 | #define MAX_SHORT 32767 80 | #define MAX_USHORT 65535 81 | #define MIN_INT -32768 82 | #define MAX_INT 32767 83 | #define MAX_UNSIGNED 65535 84 | #define MIN_LONG -2147483648 85 | #define MAX_LONG 2147483647 86 | #define MAX_ULONG 4294967295UL 87 | #define MIN_LONGLONG -2147483648 88 | #define MAX_LONGLONG 2147483647 89 | #define MAX_ULONGLONG 4294967295UL 90 | 91 | /* Default char is unsigned */ 92 | #undef CHAR_UNSIGNED 93 | 94 | /* 95 | * Use large-enough types. 96 | */ 97 | typedef long long CONSZ; 98 | typedef unsigned long long U_CONSZ; 99 | typedef long long OFFSZ; 100 | 101 | #define CONFMT "%lld" /* format for printing constants */ 102 | #define LABFMT "L%d" /* format for printing labels */ 103 | 104 | #define BACKAUTO /* stack grows negatively for automatics */ 105 | #define BACKTEMP /* stack grows negatively for temporaries */ 106 | 107 | #undef FIELDOPS /* no bit-field instructions */ 108 | #define TARGET_ENDIAN TARGET_LE 109 | 110 | /* Definitions mostly used in pass2 */ 111 | 112 | #define BYTEOFF(x) 1 113 | #define BITOOR(x) ((x)/SZCHAR) /* bit offset to oreg offset */ 114 | 115 | #define STOARG(p) 116 | #define STOFARG(p) 117 | #define STOSTARG(p) 118 | #define genfcall(a,b) gencall(a,b) 119 | 120 | #define szty(t) (((t) == LONG || (t) == ULONG || \ 121 | (ISPTR(t) && ISFTN(DECREF(t)))) ? 2 : 1) 122 | 123 | /* 124 | * m16c register classes: 125 | * A - 16-bit data registers R0-R3 126 | * B - 16-bit address registers A0-A1 127 | * C - 8-bit data registers R0H, R0L, R1H, R1L 128 | */ 129 | 130 | #define R0 0 131 | #define R2 1 132 | #define R1 2 133 | #define R3 3 134 | 135 | #define A0 4 136 | #define A1 5 137 | #define FB 6 138 | #define SP 7 139 | 140 | #define R0H 8 141 | #define R0L 9 142 | #define R1H 10 143 | #define R1L 11 144 | 145 | #define NUMCLASS 4 /* Number of register classes */ 146 | 147 | #define RETREG(x) (x == CHAR || x == UCHAR ? R0L : R0) 148 | 149 | #define FPREG FB /* frame pointer */ 150 | #define STKREG SP /* stack pointer */ 151 | 152 | #if 0 153 | #define REGSZ 8 /* Number of registers */ 154 | #define MINRVAR R1 /* first register variable */ 155 | #define MAXRVAR R2 /* last register variable */ 156 | #endif 157 | 158 | #define MAXREGS 12 /* 12 registers */ 159 | 160 | #define RSTATUS \ 161 | SAREG|TEMPREG, SAREG|PERMREG, SAREG|TEMPREG, SAREG|PERMREG, \ 162 | SBREG|TEMPREG, SBREG|PERMREG, 0, 0, SCREG, SCREG, SCREG, SCREG, 163 | 164 | #define ROVERLAP \ 165 | {R0H, R0L, -1},\ 166 | {-1},\ 167 | {R1H, R1L, -1},\ 168 | {-1},\ 169 | \ 170 | {-1},\ 171 | {-1},\ 172 | \ 173 | {-1},\ 174 | {-1},\ 175 | \ 176 | {R0, -1},\ 177 | {R0, -1},\ 178 | {R1, -1},\ 179 | {R1, -1}, 180 | 181 | #define PCLASS(p) (p->n_type <= UCHAR ? SCREG : ISPTR(p->n_type) ? SBREG:SAREG) 182 | 183 | int COLORMAP(int c, int *r); 184 | #define GCLASS(x) (x < 4 ? CLASSA : x < 6 ? CLASSB : x < 12 ? CLASSC : CLASSD) 185 | #define DECRA(x,y) (((x) >> (y*6)) & 63) /* decode encoded regs */ 186 | #define ENCRD(x) (x) /* Encode dest reg in n_reg */ 187 | #define ENCRA1(x) ((x) << 6) /* A1 */ 188 | #define ENCRA2(x) ((x) << 12) /* A2 */ 189 | #define ENCRA(x,y) ((x) << (6+y*6)) /* encode regs in int */ 190 | 191 | #define MYADDEDGE(x, t) 192 | 193 | #ifndef NEW_READER 194 | //#define TAILCALL 195 | #endif 196 | #define SFTN (SPECIAL|6) 197 | -------------------------------------------------------------------------------- /arch/mips/TODO: -------------------------------------------------------------------------------- 1 | * Fix floating-point arguments in registers 2 | * Fix structure arguments in registers 3 | -------------------------------------------------------------------------------- /arch/nova/README: -------------------------------------------------------------------------------- 1 | Calling conventions, stack frame and zero page: 2 | 3 | The variables that normally are placed on the stack or in registers in C 4 | are instead allocated in the zero page and saved on a (fictive) stack 5 | when calling functions. Some locations have predefined functions though. 6 | Arrays allocated as automatics are stored on the stack with a pointer 7 | in zero page to its destination. 8 | 9 | 0-7 Unused 10 | 10 Stack pointer 11 | 11 Frame pointer 12 | 12-14 Unused 13 | 15 Used by prolog 14 | 16 Prolog address, written in crt0 15 | 17 Epilog address, written in crt0 16 | 20-27 Auto-increment, scratch 17 | 30-37 Auto-decrement, scratch 18 | 40-47 Unused 19 | 50-57 Scratch/Arguments 20 | 60-77 Permanent, save before use. 21 | 100-377 Addresses for subroutines, written by the assembler 22 | 23 | The normal registers (AC0-AC3) are all considered scratch registers. 24 | 25 | Register classes are assigned as: 26 | AC0-AC3: AREGs. 27 | AC2-AC3: BREGs. 28 | 50-77: CREGs. 29 | ...and eventually register pairs as DREGs. 30 | 31 | In byte code the low half of a word is the first byte (little-endian). 32 | This is bit 8-15 in Nova syntax. 33 | 34 | The stack is growing towards lower adresses (as opposed to the Eclipse stack). 35 | Stack layout: 36 | 37 | ! arg1 ! 38 | ! arg0 ! 39 | fp -> ! old pc! 40 | ! old fp! 41 | pc -> ! saved ! 42 | 43 | A reference to a struct member in assembler, a = b->c; b is in ZP 50 44 | + is zeropage-addressing 45 | * is fp-adressing 46 | 47 | # offset 0 48 | + lda 0,@50 # load value from indirect ZP 50 into ac0 49 | * lda 2,,3 # load value from (ac3) into ac2 50 | * lda 0,,2 # load value from (ac2) into ac0 51 | 52 | # offset 12 53 | + lda 2,50 # load value from ZP 50 into ac2 54 | + lda 0,12,2 # load value from (ac2+12) into ac0 55 | * lda 2,,3 # load value from (ac3) into ac2 56 | * lda 0,12,2 # load value from 12(ac2) into ac0 57 | 58 | # offset 517 59 | + lda 2,50 # load value from ZP 50 into ac2 60 | + lda 0,.L42-.,1 # load offset from .L42 PC-indexed 61 | + addz 0,2,skp # add offset to ac2 and skip 62 | +.L42: .word 517 # offset value 63 | + lda 0,,2 # load value from (ac2) into ac0 64 | 65 | The prolog/epilog implementation; it is implemented as subroutines. 66 | 67 | .L42: .word 13 # number of words to save 68 | func: 69 | sta 3,@40 # save return address on stack 70 | lda 2,.L42-.,1 # get save word count 71 | jsr @45 # go to prolog 72 | ... 73 | lda 2,.L42-.,1 # get restore word count 74 | jmp @46 # jump to epilog 75 | 76 | # words to save in 2, return address in 3 77 | prolog: 78 | sta 2,45 # save # of words to move at scratch 79 | lda 0,41 # get old fp 80 | lda 1,40 # get sp 81 | sta 1,41 # save new fp 82 | dsz 40 # decrement stack, will never be 0 83 | sta 0,@40 # save old fp 84 | dsz 40 85 | 86 | lda 0,off57 # fetch address of regs to save - 1 87 | sta 0,20 # store address at autoincr 88 | 1: lda 0,@20 # get word to copy 89 | sta 0,@40 # push on stack 90 | dsz 40 # manually decrement sp 91 | dsz 45 # copied all words? 92 | jmp 1b,1 # no, continue 93 | jmp 0,3 # return 94 | 95 | epilog: 96 | sta 2,45 # save # of words to move at scratch 97 | 98 | lda 3,off57 # fetch address of regs to save 99 | sta 3,20 # store at autoincr 100 | lda 3,41 # fetch fp 101 | sta 3,30 # store at autodecr 102 | lda 3,@30 # get old fp 103 | 104 | 1: lda 2,@30 # fetch word from stack 105 | sta 2,@20 # store at orig place 106 | dsz 45 # enough? 107 | jmp 1b,1 # no, continue 108 | 109 | lda 2,41 # get new fp 110 | sta 2,40 # restore stack 111 | sta 3,41 # restore old fp 112 | jmp @40 # Return 113 | 114 | Assembler syntax and functions. 115 | 116 | The assembler syntax mimics the DG assembler. 117 | Load and store to addresses is written "lda 0,foo" to load from address foo. 118 | If foo is not in zero page then the assembler will put the lda in the 119 | text area close to the instruction and do an indirect pc-relative load. 120 | 121 | -------------------------------------------------------------------------------- /arch/nova/code.c: -------------------------------------------------------------------------------- 1 | /* $Id: code.c,v 1.8 2011/06/04 07:41:11 ragge Exp $ */ 2 | /* 3 | * Copyright (c) 2006 Anders Magnusson (ragge@ludd.luth.se). 4 | * All rights reserved. 5 | * 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions 8 | * are met: 9 | * 1. Redistributions of source code must retain the above copyright 10 | * notice, this list of conditions and the following disclaimer. 11 | * 2. Redistributions in binary form must reproduce the above copyright 12 | * notice, this list of conditions and the following disclaimer in the 13 | * documentation and/or other materials provided with the distribution. 14 | * 3. The name of the author may not be used to endorse or promote products 15 | * derived from this software without specific prior written permission 16 | * 17 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 18 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 19 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 20 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 21 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 22 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 23 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 24 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 25 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 26 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 | */ 28 | 29 | 30 | # include "pass1.h" 31 | 32 | /* 33 | * cause the alignment to become a multiple of n 34 | * never called for text segment. 35 | */ 36 | void 37 | defalign(int n) 38 | { 39 | /* alignment are always correct */ 40 | } 41 | 42 | /* 43 | * define the current location as the name p->soname 44 | * never called for text segment. 45 | */ 46 | void 47 | defnam(struct symtab *p) 48 | { 49 | char *c = p->soname; 50 | 51 | if (p->sclass == EXTDEF) 52 | printf(" .globl %s\n", c); 53 | printf("%s:\n", c); 54 | } 55 | 56 | 57 | /* 58 | * code for the end of a function 59 | * deals with struct return here 60 | */ 61 | void 62 | efcode() 63 | { 64 | NODE *p, *q; 65 | int sz; 66 | 67 | if (cftnsp->stype != STRTY+FTN && cftnsp->stype != UNIONTY+FTN) 68 | return; 69 | cerror("efcode"); 70 | /* address of return struct is in eax */ 71 | /* create a call to memcpy() */ 72 | /* will get the result in eax */ 73 | p = block(REG, NIL, NIL, CHAR+PTR, 0, 0); 74 | // p->n_rval = EAX; 75 | q = block(OREG, NIL, NIL, CHAR+PTR, 0, 0); 76 | // q->n_rval = EBP; 77 | q->n_lval = 8; /* return buffer offset */ 78 | p = block(CM, q, p, INT, 0, 0); 79 | sz = (tsize(STRTY, cftnsp->sdf, cftnsp->ssue)+SZCHAR-1)/SZCHAR; 80 | p = block(CM, p, bcon(sz), INT, 0, 0); 81 | p->n_right->n_name = ""; 82 | p = block(CALL, bcon(0), p, CHAR+PTR, 0, 0); 83 | p->n_left->n_name = "memcpy"; 84 | p = clocal(p); 85 | send_passt(IP_NODE, p); 86 | } 87 | 88 | /* 89 | * code for the beginning of a function; a is an array of 90 | * indices in symtab for the arguments; n is the number 91 | */ 92 | void 93 | bfcode(struct symtab **a, int n) 94 | { 95 | int i; 96 | 97 | if (cftnsp->stype != STRTY+FTN && cftnsp->stype != UNIONTY+FTN) 98 | return; 99 | cerror("bfcode"); 100 | /* Function returns struct, adjust arg offset */ 101 | for (i = 0; i < n; i++) 102 | a[i]->soffset += SZPOINT(INT); 103 | } 104 | 105 | 106 | /* called just before final exit */ 107 | /* flag is 1 if errors, 0 if none */ 108 | void 109 | ejobcode(int flag ) 110 | { 111 | } 112 | 113 | void 114 | bjobcode() 115 | { 116 | } 117 | 118 | /* 119 | * Print character t at position i in one string, until t == -1. 120 | * Locctr & label is already defined. 121 | */ 122 | void 123 | bycode(int t, int i) 124 | { 125 | static int lastoctal = 0; 126 | 127 | /* put byte i+1 in a string */ 128 | 129 | if (t < 0) { 130 | if (i != 0) 131 | puts("\""); 132 | } else { 133 | if (i == 0) 134 | printf("\t.ascii \""); 135 | if (t == '\\' || t == '"') { 136 | lastoctal = 0; 137 | putchar('\\'); 138 | putchar(t); 139 | } else if (t < 040 || t >= 0177) { 140 | lastoctal++; 141 | printf("\\%o",t); 142 | } else if (lastoctal && '0' <= t && t <= '9') { 143 | lastoctal = 0; 144 | printf("\"\n\t.ascii \"%c", t); 145 | } else { 146 | lastoctal = 0; 147 | putchar(t); 148 | } 149 | } 150 | } 151 | 152 | /* fix up type of field p */ 153 | void 154 | fldty(struct symtab *p) 155 | { 156 | } 157 | 158 | /* 159 | * XXX - fix genswitch. 160 | */ 161 | int 162 | mygenswitch(int num, TWORD type, struct swents **p, int n) 163 | { 164 | return 0; 165 | } 166 | /* 167 | * Called with a function call with arguments as argument. 168 | * This is done early in buildtree() and only done once. 169 | */ 170 | NODE * 171 | funcode(NODE *p) 172 | { 173 | return p; 174 | } 175 | -------------------------------------------------------------------------------- /arch/nova/macdefs.h: -------------------------------------------------------------------------------- 1 | /* $Id: macdefs.h,v 1.5 2011/06/05 10:19:24 ragge Exp $ */ 2 | /* 3 | * Copyright (c) 2006 Anders Magnusson (ragge@ludd.luth.se). 4 | * All rights reserved. 5 | * 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions 8 | * are met: 9 | * 1. Redistributions of source code must retain the above copyright 10 | * notice, this list of conditions and the following disclaimer. 11 | * 2. Redistributions in binary form must reproduce the above copyright 12 | * notice, this list of conditions and the following disclaimer in the 13 | * documentation and/or other materials provided with the distribution. 14 | * 15 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 16 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 17 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 18 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 19 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 20 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 21 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 22 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 23 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 24 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 25 | */ 26 | 27 | /* 28 | * Machine-dependent defines for Data General Nova. 29 | */ 30 | 31 | /* 32 | * Convert (multi-)character constant to integer. 33 | */ 34 | #define makecc(val,i) lastcon = (lastcon<<8)|(val); 35 | 36 | #define ARGINIT 16 /* adjusted in MD code */ 37 | #define AUTOINIT 16 /* adjusted in MD code */ 38 | 39 | /* 40 | * Storage space requirements 41 | */ 42 | #define SZCHAR 8 43 | #define SZINT 16 44 | #define SZFLOAT 32 45 | #define SZDOUBLE 64 46 | #define SZLDOUBLE 64 47 | #define SZLONG 32 48 | #define SZSHORT 16 49 | #define SZLONGLONG 32 50 | #define SZPOINT(t) 16 /* Actually 15 */ 51 | 52 | /* 53 | * Alignment constraints 54 | */ 55 | #define ALCHAR 8 56 | #define ALINT 16 57 | #define ALFLOAT 16 58 | #define ALDOUBLE 16 59 | #define ALLDOUBLE 16 60 | #define ALLONG 16 61 | #define ALLONGLONG 16 62 | #define ALSHORT 16 63 | #define ALPOINT 16 64 | #define ALSTRUCT 16 65 | #define ALSTACK 16 66 | 67 | /* 68 | * Min/max values. 69 | */ 70 | #define MIN_CHAR -128 71 | #define MAX_CHAR 127 72 | #define MAX_UCHAR 255 73 | #define MIN_SHORT -32768 74 | #define MAX_SHORT 32767 75 | #define MAX_USHORT 65535 76 | #define MIN_INT MIN_SHORT 77 | #define MAX_INT MAX_SHORT 78 | #define MAX_UNSIGNED MAX_USHORT 79 | #define MIN_LONG 0x80000000L 80 | #define MAX_LONG 0x7fffffffL 81 | #define MAX_ULONG 0xffffffffUL 82 | #define MIN_LONGLONG MIN_LONG 83 | #define MAX_LONGLONG MAX_LONG 84 | #define MAX_ULONGLONG MAX_ULONG 85 | 86 | /* Default char is unsigned */ 87 | #define CHAR_UNSIGNED 88 | #define WORD_ADDRESSED 89 | 90 | /* 91 | * Use large-enough types. 92 | */ 93 | typedef long CONSZ; 94 | typedef unsigned long U_CONSZ; 95 | typedef long OFFSZ; 96 | 97 | #define CONFMT "%ld" /* format for printing constants */ 98 | #define LABFMT ".L%d" /* format for printing labels */ 99 | #define STABLBL ".LL%d" /* format for stab (debugging) labels */ 100 | #ifdef FORTRAN 101 | #define XL 8 102 | #define FLABELFMT "%s:\n" 103 | #define USETEXT ".text" 104 | #define USECONST ".data\t0" /* XXX - fix */ 105 | #define USEBSS ".data\t1" /* XXX - fix */ 106 | #define USEINIT ".data\t2" /* XXX - fix */ 107 | #define MAXREGVAR 3 /* XXX - fix */ 108 | #define BLANKCOMMON "_BLNK_" 109 | #define MSKIREG (M(TYSHORT)|M(TYLONG)) 110 | #define TYIREG TYLONG 111 | #define FSZLENG FSZLONG 112 | #define FUDGEOFFSET 1 113 | #define AUTOREG EBP 114 | #define ARGREG EBP 115 | #define ARGOFFSET 4 116 | #endif 117 | 118 | #define BACKAUTO /* stack grows negatively for automatics */ 119 | #define BACKTEMP /* stack grows negatively for temporaries */ 120 | 121 | #undef FIELDOPS /* no bit-field instructions */ 122 | #define TARGET_ENDIAN TARGET_LE 123 | 124 | /* Definitions mostly used in pass2 */ 125 | 126 | #define BYTEOFF(x) ((x)&01) 127 | #define wdal(k) (BYTEOFF(k)==0) 128 | #define BITOOR(x) (x) /* bit offset to oreg offset XXX die! */ 129 | 130 | #define STOARG(p) 131 | #define STOFARG(p) 132 | #define STOSTARG(p) 133 | #define genfcall(a,b) gencall(a,b) 134 | 135 | #define szty(t) (((t) == DOUBLE || (t) == LDOUBLE) ? 4 : \ 136 | ((t) == LONGLONG || (t) == ULONGLONG || \ 137 | (t) == LONG || (t) == ULONG) ? 2 : 1) 138 | 139 | /* 140 | * The Nova has three register classes. Note that the space used in 141 | * zero page is considered registers. 142 | * Register 28 and 29 are FP and SP. 143 | * 144 | * The classes used on Nova are: 145 | * A - AC0-AC3 (as non-index registers) : reg 0-3 146 | * B - AC2-AC3 (as index registers) : reg 2-3 147 | * C - address 50-77 in memory : reg 4-27 148 | */ 149 | #define MAXREGS 30 /* 0-29 */ 150 | 151 | #define RSTATUS \ 152 | SAREG|TEMPREG, SAREG|TEMPREG, SAREG|SBREG|TEMPREG, SAREG|SBREG|TEMPREG,\ 153 | SCREG|TEMPREG, SCREG|TEMPREG, SCREG|TEMPREG, SCREG|TEMPREG, \ 154 | SCREG|TEMPREG, SCREG|TEMPREG, SCREG|TEMPREG, SCREG|TEMPREG, \ 155 | SCREG|PERMREG, SCREG|PERMREG, SCREG|PERMREG, SCREG|PERMREG, \ 156 | SCREG|PERMREG, SCREG|PERMREG, SCREG|PERMREG, SCREG|PERMREG, \ 157 | SCREG|PERMREG, SCREG|PERMREG, SCREG|PERMREG, SCREG|PERMREG, \ 158 | SCREG|PERMREG, SCREG|PERMREG, SCREG|PERMREG, SCREG|PERMREG, \ 159 | 0, 0 160 | 161 | #define ROVERLAP \ 162 | { -1 }, { -1 }, { -1 }, { -1 }, { -1 }, { -1 }, { -1 }, { -1 }, \ 163 | { -1 }, { -1 }, { -1 }, { -1 }, { -1 }, { -1 }, { -1 }, { -1 }, \ 164 | { -1 }, { -1 }, { -1 }, { -1 }, { -1 }, { -1 }, { -1 }, { -1 }, \ 165 | { -1 }, { -1 }, { -1 }, { -1 }, { -1 }, { -1 }, 166 | 167 | 168 | /* Return a register class based on the type of the node */ 169 | /* all types in all classes */ 170 | #define PCLASS(p) (SAREG|SBREG|SCREG) 171 | 172 | #define NUMCLASS 4 /* highest number of reg classes used */ 173 | /* XXX - must be 4 */ 174 | 175 | int COLORMAP(int c, int *r); 176 | #define GCLASS(x) (x < 4 ? CLASSA : CLASSC) 177 | #define DECRA(x,y) (((x) >> (y*6)) & 63) /* decode encoded regs */ 178 | #define ENCRD(x) (x) /* Encode dest reg in n_reg */ 179 | #define ENCRA1(x) ((x) << 6) /* A1 */ 180 | #define ENCRA2(x) ((x) << 12) /* A2 */ 181 | #define ENCRA(x,y) ((x) << (6+y*6)) /* encode regs in int */ 182 | #define RETREG(x) (0) /* ? Sanity */ 183 | 184 | /* XXX - to die */ 185 | #define FPREG 28 /* frame pointer */ 186 | #define STKREG 29 /* stack pointer */ 187 | -------------------------------------------------------------------------------- /arch/nova/order.c: -------------------------------------------------------------------------------- 1 | /* $Id: order.c,v 1.4 2008/09/27 07:35:23 ragge Exp $ */ 2 | /* 3 | * Copyright (c) 2006 Anders Magnusson (ragge@ludd.luth.se). 4 | * All rights reserved. 5 | * 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions 8 | * are met: 9 | * 1. Redistributions of source code must retain the above copyright 10 | * notice, this list of conditions and the following disclaimer. 11 | * 2. Redistributions in binary form must reproduce the above copyright 12 | * notice, this list of conditions and the following disclaimer in the 13 | * documentation and/or other materials provided with the distribution. 14 | * 3. The name of the author may not be used to endorse or promote products 15 | * derived from this software without specific prior written permission 16 | * 17 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 18 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 19 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 20 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 21 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 22 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 23 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 24 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 25 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 26 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 | */ 28 | 29 | 30 | # include "pass2.h" 31 | 32 | #include 33 | 34 | int canaddr(NODE *); 35 | 36 | /* is it legal to make an OREG or NAME entry which has an 37 | * offset of off, (from a register of r), if the 38 | * resulting thing had type t */ 39 | int 40 | notoff(TWORD t, int r, CONSZ off, char *cp) 41 | { 42 | if (r != 2 && r != 3) 43 | return 1; /* can only index ac2 and ac3 */ 44 | if (t == CHAR || t == UCHAR) { 45 | if (off < -256 || off > 254) 46 | return 1; 47 | } else if (off < -128 || off > 127) 48 | return 1; 49 | return(0); /* YES */ 50 | } 51 | 52 | /* 53 | * Turn a UMUL-referenced node into OREG. 54 | * Be careful about register classes, this is a place where classes change. 55 | */ 56 | void 57 | offstar(NODE *p, int shape) 58 | { 59 | NODE *r; 60 | 61 | if (x2debug) 62 | printf("offstar(%p)\n", p); 63 | 64 | if (isreg(p)) 65 | return; /* Is already OREG */ 66 | 67 | r = p->n_right; 68 | if( p->n_op == PLUS || p->n_op == MINUS ){ 69 | if( r->n_op == ICON ){ 70 | if (isreg(p->n_left) == 0 || 71 | (p->n_left->n_op == REG && 72 | p->n_left->n_rval != 2 && p->n_left->n_rval != 3)) 73 | (void)geninsn(p->n_left, INBREG); 74 | /* Converted in ormake() */ 75 | return; 76 | } 77 | } 78 | (void)geninsn(p, INBREG); 79 | } 80 | 81 | /* 82 | * Do the actual conversion of offstar-found OREGs into real OREGs. 83 | */ 84 | void 85 | myormake(NODE *q) 86 | { 87 | if (x2debug) 88 | printf("myormake(%p)\n", q); 89 | } 90 | 91 | /* 92 | * Shape matches for UMUL. Cooperates with offstar(). 93 | */ 94 | int 95 | shumul(NODE *p, int order) 96 | { 97 | 98 | if (x2debug) 99 | printf("shumul(%p)\n", p); 100 | 101 | /* Turns currently anything into OREG on x86 */ 102 | if (shape & SOREG) 103 | return SROREG; 104 | return SRNOPE; 105 | } 106 | 107 | /* 108 | * Rewrite increment/decrement operation. 109 | */ 110 | int 111 | setincr(NODE *p) 112 | { 113 | if (x2debug) 114 | printf("setincr(%p)\n", p); 115 | 116 | return(0); 117 | } 118 | 119 | /* 120 | * Rewrite operations on binary operators (like +, -, etc...). 121 | * Called as a result of table lookup. 122 | */ 123 | int 124 | setbin(NODE *p) 125 | { 126 | 127 | if (x2debug) 128 | printf("setbin(%p)\n", p); 129 | return 0; 130 | 131 | } 132 | 133 | /* setup for assignment operator */ 134 | int 135 | setasg(NODE *p, int cookie) 136 | { 137 | if (x2debug) 138 | printf("setasg(%p)\n", p); 139 | return(0); 140 | } 141 | 142 | /* setup for unary operator */ 143 | int 144 | setuni(NODE *p, int cookie) 145 | { 146 | return 0; 147 | } 148 | 149 | /* 150 | * Special handling of some instruction register allocation. 151 | */ 152 | struct rspecial * 153 | nspecial(struct optab *q) 154 | { 155 | comperr("nspecial entry %d", q - table); 156 | return 0; /* XXX gcc */ 157 | } 158 | 159 | /* 160 | * Set evaluation order of a binary node if it differs from default. 161 | */ 162 | int 163 | setorder(NODE *p) 164 | { 165 | return 0; 166 | } 167 | /* 168 | * Set registers "live" at function calls (like arguments in registers). 169 | * This is for liveness analysis of registers. 170 | */ 171 | int * 172 | livecall(NODE *p) 173 | { 174 | static int r[1] = { -1 }; /* Terminate with -1 */ 175 | 176 | return &r[0]; 177 | } 178 | 179 | /* 180 | * Signal whether the instruction is acceptable for this target. 181 | */ 182 | int 183 | acceptable(struct optab *op) 184 | { 185 | return 1; 186 | } 187 | -------------------------------------------------------------------------------- /arch/pdp10/README: -------------------------------------------------------------------------------- 1 | 2 | 3 | PDP10 C calling convention 4 | -------------------------- 5 | Register 1-7 are argument registers. Types of sizes up to 36 bits are 6 | given in one register, two otherwise. CHAR and SHORT are given as INTs. 7 | 8 | If the argument that would end up in register 7 requires two registers, 9 | it is saved on the stack instead and no more registers would end up 10 | on the stack. 11 | 12 | struct return: a hidden argument containing the address of the struct 13 | is stored as the first argument _on_the_stack_, never in register. 14 | 15 | struct argument: always saved on stack, and terminates the list 16 | of arguments that are kept in registers. 17 | 18 | In case of debugging all arguments are saved on stack in the function. 19 | 20 | All variadic arguments are always saved on the stack. 21 | -------------------------------------------------------------------------------- /arch/pdp10/code.c: -------------------------------------------------------------------------------- 1 | /* $Id: code.c,v 1.41 2011/06/04 07:41:11 ragge Exp $ */ 2 | /* 3 | * Copyright (c) 2003 Anders Magnusson (ragge@ludd.luth.se). 4 | * All rights reserved. 5 | * 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions 8 | * are met: 9 | * 1. Redistributions of source code must retain the above copyright 10 | * notice, this list of conditions and the following disclaimer. 11 | * 2. Redistributions in binary form must reproduce the above copyright 12 | * notice, this list of conditions and the following disclaimer in the 13 | * documentation and/or other materials provided with the distribution. 14 | * 3. The name of the author may not be used to endorse or promote products 15 | * derived from this software without specific prior written permission 16 | * 17 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 18 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 19 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 20 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 21 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 22 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 23 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 24 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 25 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 26 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 | */ 28 | 29 | 30 | # include "pass1.h" 31 | 32 | /* 33 | * Define everything needed to print out some data (or text). 34 | * This means segment, alignment, visibility, etc. 35 | */ 36 | void 37 | defloc(struct symtab *sp) 38 | { 39 | char *nextsect = NULL; /* notyet */ 40 | static char *loctbl[] = { "text", "data", "section .rodata" }; 41 | static int lastloc = -1; 42 | TWORD t; 43 | int s; 44 | 45 | if (sp == NULL) { 46 | lastloc = -1; 47 | return; 48 | } 49 | t = sp->stype; 50 | s = ISFTN(t) ? PROG : ISCON(cqual(t, sp->squal)) ? RDATA : DATA; 51 | if (nextsect) { 52 | printf(" .section %s\n", nextsect); 53 | nextsect = NULL; 54 | s = -1; 55 | } else if (s != lastloc) 56 | printf(" .%s\n", loctbl[s]); 57 | lastloc = s; 58 | if (sp->sclass == EXTDEF) 59 | printf(" .globl %s\n", sp->soname); 60 | if (sp->slevel == 0) 61 | printf("%s:\n", sp->soname); 62 | else 63 | printf(LABFMT ":\n", sp->soffset); 64 | } 65 | 66 | /* 67 | * code for the end of a function 68 | */ 69 | void 70 | efcode() 71 | { 72 | } 73 | 74 | /* 75 | * code for the beginning of a function; a is an array of 76 | * indices in stab for the arguments; n is the number 77 | */ 78 | void 79 | bfcode(struct symtab **sp, int cnt) 80 | { 81 | NODE *p, *q; 82 | int i, n; 83 | 84 | if (cftnsp->stype == STRTY+FTN || cftnsp->stype == UNIONTY+FTN) { 85 | uerror("no struct return yet"); 86 | } 87 | /* recalculate the arg offset and create TEMP moves */ 88 | for (n = 1, i = 0; i < cnt; i++) { 89 | if (n < 8) { 90 | p = tempnode(0, sp[i]->stype, sp[i]->sdf, sp[i]->ssue); 91 | q = block(REG, NIL, NIL, 92 | sp[i]->stype, sp[i]->sdf, sp[i]->ssue); 93 | q->n_rval = n; 94 | p = buildtree(ASSIGN, p, q); 95 | sp[i]->soffset = regno(p->n_left); 96 | sp[i]->sflags |= STNODE; 97 | ecomp(p); 98 | } else { 99 | sp[i]->soffset += SZINT * n; 100 | if (xtemps) { 101 | /* put stack args in temps if optimizing */ 102 | p = tempnode(0, sp[i]->stype, 103 | sp[i]->sdf, sp[i]->ssue); 104 | p = buildtree(ASSIGN, p, nametree(sp[i])); 105 | sp[i]->soffset = regno(p->n_left); 106 | sp[i]->sflags |= STNODE; 107 | ecomp(p); 108 | } 109 | } 110 | n += szty(sp[i]->stype); 111 | } 112 | } 113 | 114 | 115 | void 116 | bjobcode() 117 | { 118 | } 119 | 120 | /* called just before final exit */ 121 | /* flag is 1 if errors, 0 if none */ 122 | void 123 | ejobcode(int flag ) 124 | { 125 | } 126 | 127 | /* 128 | * Make a register node, helper for funcode. 129 | */ 130 | static NODE * 131 | mkreg(NODE *p, int n) 132 | { 133 | NODE *r; 134 | 135 | r = block(REG, NIL, NIL, p->n_type, p->n_df, p->n_sue); 136 | if (szty(p->n_type) == 2) 137 | n += 16; 138 | r->n_rval = n; 139 | return r; 140 | } 141 | 142 | static int regnum; 143 | /* 144 | * Move args to registers and emit expressions bottom-up. 145 | */ 146 | static void 147 | fixargs(NODE *p) 148 | { 149 | NODE *r; 150 | 151 | if (p->n_op == CM) { 152 | fixargs(p->n_left); 153 | r = p->n_right; 154 | if (r->n_op == STARG) 155 | regnum = 9; /* end of register list */ 156 | else if (regnum + szty(r->n_type) > 8) 157 | p->n_right = block(FUNARG, r, NIL, r->n_type, 158 | r->n_df, r->n_sue); 159 | else 160 | p->n_right = buildtree(ASSIGN, mkreg(r, regnum), r); 161 | } else { 162 | if (p->n_op == STARG) { 163 | regnum = 9; /* end of register list */ 164 | } else { 165 | r = talloc(); 166 | *r = *p; 167 | r = buildtree(ASSIGN, mkreg(r, regnum), r); 168 | *p = *r; 169 | nfree(r); 170 | } 171 | r = p; 172 | } 173 | regnum += szty(r->n_type); 174 | } 175 | 176 | 177 | /* 178 | * Called with a function call with arguments as argument. 179 | * This is done early in buildtree() and only done once. 180 | */ 181 | NODE * 182 | funcode(NODE *p) 183 | { 184 | 185 | regnum = 1; 186 | 187 | fixargs(p->n_right); 188 | return p; 189 | } 190 | 191 | /* fix up type of field p */ 192 | void 193 | fldty(struct symtab *p) 194 | { 195 | } 196 | 197 | /* 198 | * XXX - fix genswitch. 199 | */ 200 | int 201 | mygenswitch(int num, TWORD type, struct swents **p, int n) 202 | { 203 | return 0; 204 | } 205 | -------------------------------------------------------------------------------- /arch/pdp10/order.c: -------------------------------------------------------------------------------- 1 | /* $Id: order.c,v 1.63 2008/01/15 21:47:06 ragge Exp $ */ 2 | /* 3 | * Copyright (c) 2003 Anders Magnusson (ragge@ludd.luth.se). 4 | * All rights reserved. 5 | * 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions 8 | * are met: 9 | * 1. Redistributions of source code must retain the above copyright 10 | * notice, this list of conditions and the following disclaimer. 11 | * 2. Redistributions in binary form must reproduce the above copyright 12 | * notice, this list of conditions and the following disclaimer in the 13 | * documentation and/or other materials provided with the distribution. 14 | * 3. The name of the author may not be used to endorse or promote products 15 | * derived from this software without specific prior written permission 16 | * 17 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 18 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 19 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 20 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 21 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 22 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 23 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 24 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 25 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 26 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 | */ 28 | 29 | 30 | # include "pass2.h" 31 | 32 | int canaddr(NODE *); 33 | 34 | /* is it legal to make an OREG or NAME entry which has an 35 | * offset of off, (from a register of r), if the 36 | * resulting thing had type t */ 37 | int 38 | notoff(TWORD t, int r, CONSZ off, char *cp) 39 | { 40 | return(0); /* YES */ 41 | } 42 | 43 | int radebug = 0; 44 | 45 | void 46 | offstar(NODE *p, int shape) 47 | { 48 | NODE *q; 49 | 50 | if (x2debug) 51 | printf("offstar(%p)\n", p); 52 | 53 | if( p->n_op == PLUS || p->n_op == MINUS ){ 54 | if( p->n_right->n_op == ICON ){ 55 | q = p->n_left; 56 | if (q->n_op != REG) 57 | geninsn(q, INAREG); 58 | p->n_su = -1; 59 | } 60 | } 61 | geninsn(p, INAREG); 62 | } 63 | 64 | /* 65 | * findops() failed, see if we can rewrite it to match. 66 | */ 67 | int 68 | setbin(NODE *p) 69 | { 70 | TWORD ty; 71 | NODE *r, *s; 72 | 73 | ty = p->n_type; 74 | switch (p->n_op) { 75 | case MINUS: 76 | switch (ty) { 77 | case PTR+CHAR: 78 | case PTR+UCHAR: 79 | case PTR+SHORT: 80 | case PTR+USHORT: 81 | /* 82 | * Must negate the right side and change op to PLUS. 83 | */ 84 | r = p->n_right; 85 | if (r->n_op == ICON) { 86 | r->n_lval = -r->n_lval; 87 | } else { 88 | s = talloc(); 89 | s->n_type = r->n_type; 90 | s->n_op = UMINUS; 91 | s->n_left = r; 92 | p->n_right = s; 93 | } 94 | p->n_op = PLUS; 95 | return 1; 96 | } 97 | } 98 | return 0; 99 | } 100 | 101 | /* setup for assignment operator */ 102 | int 103 | setasg(NODE *p, int cookie) 104 | { 105 | return(0); 106 | } 107 | 108 | /* setup for unary operator */ 109 | int 110 | setuni(NODE *p, int cookie) 111 | { 112 | return 0; 113 | } 114 | 115 | int 116 | special(NODE *p, int shape) 117 | { 118 | switch (shape) { 119 | case SUSHCON: 120 | if (p->n_op == ICON && p->n_name[0] == '\0' && 121 | (p->n_lval > 0 && p->n_lval <= 0777777)) 122 | return 1; 123 | break; 124 | 125 | case SNSHCON: 126 | if (p->n_op == ICON && p->n_name[0] == '\0' && 127 | (p->n_lval < 0 && p->n_lval > -01000000)) 128 | return 1; 129 | break; 130 | case SILDB: 131 | if (p->n_op == ASSIGN && p->n_left->n_op == REG && 132 | p->n_right->n_op == PLUS && 133 | p->n_right->n_left->n_op == REG && 134 | p->n_right->n_right->n_op == ICON && 135 | p->n_right->n_right->n_lval == 1 && 136 | p->n_right->n_left->n_rval == p->n_left->n_rval) 137 | return 1; 138 | break; 139 | } 140 | return 0; 141 | } 142 | 143 | /* 144 | * Set evaluation order of a binary node if it differs from default. 145 | */ 146 | int 147 | setorder(NODE *p) 148 | { 149 | return 0; /* nothing differs on x86 */ 150 | } 151 | 152 | /* 153 | * Special handling of some instruction register allocation. 154 | */ 155 | struct rspecial * 156 | nspecial(struct optab *q) 157 | { 158 | return 0; /* XXX gcc */ 159 | } 160 | 161 | /* 162 | * Do the actual conversion of offstar-found OREGs into real OREGs. 163 | */ 164 | void 165 | myormake(NODE *p) 166 | { 167 | if (x2debug) 168 | printf("myormake(%p)\n", p); 169 | } 170 | 171 | /* 172 | * set registers in calling conventions live. 173 | */ 174 | int * 175 | livecall(NODE *p) 176 | { 177 | static int r[8], *s = r; 178 | 179 | *s = -1; 180 | if (p->n_op == UCALL || p->n_op == UFORTCALL || p->n_op == USTCALL || 181 | p->n_op == FORTCALL) 182 | return s; 183 | for (p = p->n_right; p->n_op == CM; p = p->n_left) { 184 | if (p->n_right->n_op == ASSIGN && 185 | p->n_right->n_left->n_op == REG) 186 | *s++ = p->n_right->n_left->n_rval; 187 | } 188 | if (p->n_op == ASSIGN && 189 | p->n_left->n_op == REG) 190 | *s++ = p->n_left->n_rval; 191 | *s = -1; 192 | return r; 193 | } 194 | 195 | /* 196 | * Signal whether the instruction is acceptable for this target. 197 | */ 198 | int 199 | acceptable(struct optab *op) 200 | { 201 | return 1; 202 | } 203 | -------------------------------------------------------------------------------- /arch/pdp11/code.c: -------------------------------------------------------------------------------- 1 | /* $Id: code.c,v 1.5 2011/06/04 07:41:11 ragge Exp $ */ 2 | /* 3 | * Copyright (c) 2003 Anders Magnusson (ragge@ludd.luth.se). 4 | * All rights reserved. 5 | * 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions 8 | * are met: 9 | * 1. Redistributions of source code must retain the above copyright 10 | * notice, this list of conditions and the following disclaimer. 11 | * 2. Redistributions in binary form must reproduce the above copyright 12 | * notice, this list of conditions and the following disclaimer in the 13 | * documentation and/or other materials provided with the distribution. 14 | * 3. The name of the author may not be used to endorse or promote products 15 | * derived from this software without specific prior written permission 16 | * 17 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 18 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 19 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 20 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 21 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 22 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 23 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 24 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 25 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 26 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 | */ 28 | 29 | 30 | # include "pass1.h" 31 | 32 | int lastloc = -1; 33 | 34 | /* 35 | * Define everything needed to print out some data (or text). 36 | * This means segment, alignment, visibility, etc. 37 | */ 38 | void 39 | defloc(struct symtab *sp) 40 | { 41 | static char *loctbl[] = { "text", "data", "data" }; 42 | TWORD t; 43 | char *n; 44 | int s; 45 | 46 | if (sp == NULL) { 47 | lastloc = -1; 48 | return; 49 | } 50 | t = sp->stype; 51 | s = ISFTN(t) ? PROG : ISCON(cqual(t, sp->squal)) ? RDATA : DATA; 52 | if (s != lastloc) 53 | printf(" .%s\n", loctbl[s]); 54 | lastloc = s; 55 | while (ISARY(t)) 56 | t = DECREF(t); 57 | n = sp->soname ? sp->soname : exname(sp->sname); 58 | if (sp->sclass == EXTDEF) 59 | printf(" .globl %s\n", n); 60 | if (ISFTN(sp->stype) || talign(sp->stype, sp->ssue) > ALCHAR) 61 | printf(".even\n"); 62 | if (sp->slevel == 0) { 63 | printf("%s:\n", n); 64 | } else { 65 | printf(LABFMT ":\n", sp->soffset); 66 | } 67 | } 68 | 69 | /* 70 | * code for the end of a function 71 | * deals with struct return here 72 | */ 73 | void 74 | efcode() 75 | { 76 | NODE *p, *q; 77 | 78 | if (cftnsp->stype != STRTY+FTN && cftnsp->stype != UNIONTY+FTN) 79 | return; 80 | /* Create struct assignment */ 81 | q = block(OREG, NIL, NIL, PTR+STRTY, 0, cftnsp->ssue); 82 | q->n_rval = R5; 83 | q->n_lval = 8; /* return buffer offset */ 84 | q = buildtree(UMUL, q, NIL); 85 | p = block(REG, NIL, NIL, PTR+STRTY, 0, cftnsp->ssue); 86 | p = buildtree(UMUL, p, NIL); 87 | p = buildtree(ASSIGN, q, p); 88 | ecomp(p); 89 | } 90 | 91 | /* 92 | * code for the beginning of a function; a is an array of 93 | * indices in symtab for the arguments; n is the number 94 | */ 95 | void 96 | bfcode(struct symtab **sp, int cnt) 97 | { 98 | struct symtab *sp2; 99 | NODE *n; 100 | int i; 101 | 102 | if (cftnsp->stype == STRTY+FTN || cftnsp->stype == UNIONTY+FTN) { 103 | /* Function returns struct, adjust arg offset */ 104 | for (i = 0; i < cnt; i++) 105 | sp[i]->soffset += SZPOINT(INT); 106 | } 107 | 108 | if (xtemps == 0) 109 | return; 110 | 111 | /* put arguments in temporaries */ 112 | for (i = 0; i < cnt; i++) { 113 | if (sp[i]->stype == STRTY || sp[i]->stype == UNIONTY || 114 | cisreg(sp[i]->stype) == 0) 115 | continue; 116 | sp2 = sp[i]; 117 | n = tempnode(0, sp[i]->stype, sp[i]->sdf, sp[i]->ssue); 118 | n = buildtree(ASSIGN, n, nametree(sp2)); 119 | sp[i]->soffset = regno(n->n_left); 120 | sp[i]->sflags |= STNODE; 121 | ecomp(n); 122 | } 123 | } 124 | 125 | 126 | /* called just before final exit */ 127 | /* flag is 1 if errors, 0 if none */ 128 | void 129 | ejobcode(int flag ) 130 | { 131 | } 132 | 133 | void 134 | bjobcode() 135 | { 136 | } 137 | 138 | /* 139 | * Called with a function call with arguments as argument. 140 | * This is done early in buildtree() and only done once. 141 | * Returns p. 142 | */ 143 | NODE * 144 | funcode(NODE *p) 145 | { 146 | NODE *r, *l; 147 | 148 | /* Fix function call arguments. On x86, just add funarg */ 149 | for (r = p->n_right; r->n_op == CM; r = r->n_left) { 150 | if (r->n_right->n_op != STARG) 151 | r->n_right = block(FUNARG, r->n_right, NIL, 152 | r->n_right->n_type, r->n_right->n_df, 153 | r->n_right->n_sue); 154 | } 155 | if (r->n_op != STARG) { 156 | l = talloc(); 157 | *l = *r; 158 | r->n_op = FUNARG; 159 | r->n_left = l; 160 | r->n_type = l->n_type; 161 | } 162 | return p; 163 | } 164 | 165 | /* fix up type of field p */ 166 | void 167 | fldty(struct symtab *p) 168 | { 169 | } 170 | 171 | /* 172 | * XXX - fix genswitch. 173 | */ 174 | int 175 | mygenswitch(int num, TWORD type, struct swents **p, int n) 176 | { 177 | return 0; 178 | } 179 | -------------------------------------------------------------------------------- /arch/pdp11/order.c: -------------------------------------------------------------------------------- 1 | /* $Id: order.c,v 1.3 2008/10/04 08:43:17 ragge Exp $ */ 2 | /* 3 | * Copyright (c) 2003 Anders Magnusson (ragge@ludd.luth.se). 4 | * All rights reserved. 5 | * 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions 8 | * are met: 9 | * 1. Redistributions of source code must retain the above copyright 10 | * notice, this list of conditions and the following disclaimer. 11 | * 2. Redistributions in binary form must reproduce the above copyright 12 | * notice, this list of conditions and the following disclaimer in the 13 | * documentation and/or other materials provided with the distribution. 14 | * 3. The name of the author may not be used to endorse or promote products 15 | * derived from this software without specific prior written permission 16 | * 17 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 18 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 19 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 20 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 21 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 22 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 23 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 24 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 25 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 26 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 | */ 28 | 29 | 30 | # include "pass2.h" 31 | 32 | #include 33 | 34 | int canaddr(NODE *); 35 | 36 | /* is it legal to make an OREG or NAME entry which has an 37 | * offset of off, (from a register of r), if the 38 | * resulting thing had type t */ 39 | int 40 | notoff(TWORD t, int r, CONSZ off, char *cp) 41 | { 42 | return(0); /* YES */ 43 | } 44 | 45 | static int 46 | inctree(NODE *p) 47 | { 48 | if (p->n_op == MINUS && p->n_left->n_op == ASSIGN && 49 | p->n_left->n_right->n_op == PLUS && 50 | treecmp(p->n_left->n_left, p->n_left->n_right->n_left) && 51 | p->n_right->n_op == ICON && p->n_right->n_lval == 1 && 52 | p->n_left->n_right->n_right->n_op == ICON && 53 | p->n_left->n_right->n_right->n_lval == 1) { 54 | /* post-increment by 1; (r0)+ */ 55 | if (isreg(p->n_left->n_left)) /* Ignore if index not in reg */ 56 | return 1; 57 | } 58 | return 0; 59 | } 60 | 61 | /* 62 | * Turn a UMUL-referenced node into OREG. 63 | * Be careful about register classes, this is a place where classes change. 64 | */ 65 | void 66 | offstar(NODE *p, int shape) 67 | { 68 | if (x2debug) 69 | printf("offstar(%p)\n", p); 70 | 71 | if (isreg(p)) 72 | return; /* Is already OREG */ 73 | 74 | if (p->n_op == UMUL) 75 | p = p->n_left; /* double indexed umul */ 76 | 77 | if (inctree(p)) /* Do post-inc conversion */ 78 | return; 79 | 80 | if( p->n_op == PLUS || p->n_op == MINUS ){ 81 | if (p->n_right->n_op == ICON) { 82 | if (isreg(p->n_left) == 0) 83 | (void)geninsn(p->n_left, INAREG); 84 | /* Converted in ormake() */ 85 | return; 86 | } 87 | } 88 | (void)geninsn(p, INAREG); 89 | } 90 | 91 | /* 92 | * Do the actual conversion of offstar-found OREGs into real OREGs. 93 | */ 94 | void 95 | myormake(NODE *p) 96 | { 97 | NODE *q = p->n_left; 98 | 99 | if (x2debug) { 100 | printf("myormake(%p)\n", p); 101 | fwalk(p, e2print, 0); 102 | } 103 | if (inctree(q)) { 104 | if (q->n_left->n_left->n_op == TEMP) 105 | return; 106 | p->n_op = OREG; 107 | p->n_lval = 0; /* Add support for index offset */ 108 | p->n_rval = R2PACK(regno(q->n_left->n_left), 0, 1); 109 | tfree(q); 110 | return; 111 | } 112 | if (q->n_op != OREG) 113 | return; 114 | p->n_op = OREG; 115 | p->n_lval = q->n_lval; 116 | p->n_rval = R2PACK(q->n_rval, 0, 0); 117 | nfree(q); 118 | } 119 | 120 | /* 121 | * Shape matches for UMUL. Cooperates with offstar(). 122 | */ 123 | int 124 | shumul(NODE *p, int shape) 125 | { 126 | 127 | if (x2debug) 128 | printf("shumul(%p)\n", p); 129 | 130 | if (p->n_op == NAME && (shape & STARNM)) 131 | return SRDIR; 132 | if (shape & SOREG) 133 | return SROREG; /* Calls offstar */ 134 | return SRNOPE; 135 | } 136 | 137 | /* 138 | * Rewrite operations on binary operators (like +, -, etc...). 139 | * Called as a result of table lookup. 140 | */ 141 | int 142 | setbin(NODE *p) 143 | { 144 | 145 | if (x2debug) 146 | printf("setbin(%p)\n", p); 147 | return 0; 148 | 149 | } 150 | 151 | /* setup for assignment operator */ 152 | int 153 | setasg(NODE *p, int cookie) 154 | { 155 | if (x2debug) 156 | printf("setasg(%p)\n", p); 157 | return(0); 158 | } 159 | 160 | /* setup for unary operator */ 161 | int 162 | setuni(NODE *p, int cookie) 163 | { 164 | return(0); 165 | } 166 | 167 | /* 168 | * Special handling of some instruction register allocation. 169 | */ 170 | struct rspecial * 171 | nspecial(struct optab *q) 172 | { 173 | switch (q->op) { 174 | case MUL: 175 | if (q->visit == INAREG) { 176 | static struct rspecial s[] = { { NLEFT, R1 }, { 0 } }; 177 | return s; 178 | } else if (q->visit == INBREG) { 179 | static struct rspecial s[] = { { NRES, R01 }, { 0 } }; 180 | return s; 181 | } 182 | break; 183 | 184 | case DIV: 185 | if (q->visit == INAREG && q->ltype == TUNSIGNED) { 186 | static struct rspecial s[] = { 187 | { NLEFT, R0 }, { NRIGHT, R1 }, { NRES, R0 }, { 0 } }; 188 | return s; 189 | } else if (q->visit == INAREG) { 190 | static struct rspecial s[] = { 191 | { NRES, R0 }, { 0 } }; 192 | return s; 193 | } else if (q->visit == INBREG) { 194 | static struct rspecial s[] = { { NRES, R01 }, { 0 } }; 195 | return s; 196 | } 197 | break; 198 | 199 | case MOD: 200 | if (q->visit == INAREG && q->ltype == TUNSIGNED) { 201 | static struct rspecial s[] = { 202 | { NLEFT, R0 }, { NRIGHT, R1 }, { NRES, R0 }, { 0 } }; 203 | return s; 204 | } else if (q->visit == INBREG) { 205 | static struct rspecial s[] = { { NRES, R01 }, { 0 } }; 206 | return s; 207 | } 208 | break; 209 | 210 | case SCONV: 211 | if (q->lshape == SAREG) { 212 | static struct rspecial s[] = { 213 | { NLEFT, R1 }, { NRES, R01 }, { 0 } }; 214 | return s; 215 | } 216 | break; 217 | } 218 | comperr("nspecial entry %d", q - table); 219 | return 0; /* XXX gcc */ 220 | } 221 | 222 | /* 223 | * Set evaluation order of a binary node if it differs from default. 224 | */ 225 | int 226 | setorder(NODE *p) 227 | { 228 | return 0; /* nothing differs on x86 */ 229 | } 230 | 231 | /* 232 | * set registers in calling conventions live. 233 | */ 234 | int * 235 | livecall(NODE *p) 236 | { 237 | static int r[] = { -1 }; 238 | 239 | return r; 240 | } 241 | 242 | /* 243 | * Signal whether the instruction is acceptable for this target. 244 | */ 245 | int 246 | acceptable(struct optab *op) 247 | { 248 | return 1; 249 | } 250 | -------------------------------------------------------------------------------- /arch/powerpc/README: -------------------------------------------------------------------------------- 1 | macdefs.h ; machine-dependent definitions 2 | code.c ; machine-dependent code for prologs, switches (pass 1) 3 | local.c ; machine-dependent code for prologs, switches (pass 1) 4 | local2.c ; misc routines and tables of register names (pass 2) 5 | order.c ; machine-dependent code-generation strategy (pass 2) 6 | table.c ; code templates (pass 2) 7 | 8 | On OS X, binaries are not ELF and all binaries are compiled PIC. To use pcc 9 | on OS X while linking against the system libraries, use the -k option. 10 | 11 | Current issues: 12 | 13 | - no floating point (need mickey's patches to support >64 registers) 14 | - mod/div on longlong not supported 15 | - the stack frame is always 200 bytes - need to calculate size and patch 16 | OREGs to temporaries and arguments [see discussion below] 17 | - function arguments are always saved to the stack [need to change MI code] 18 | - permanent registers >R13 are not saved [need to change MI code] 19 | - structure arguments don't work 20 | - return of structure doesn't work 21 | - function pointers don't work for PIC 22 | - constant structure assignment doesn't work properly for PIC 23 | - no built-in vararg support [shouldn't be too hard to add] 24 | 25 | The way most modern CPUs create the stack is to allocate the frame 26 | to contain room for the temporaries, to save the permanent registers 27 | and to store the arguments to functions invoked from within the function. 28 | To achieve this, all the information must be known when the prologue 29 | is generated. Currently we only know the size of the temporaries - 30 | we don't know the size of the argument space for each function that 31 | gets invoked from this function. Even if we did know this information, 32 | we create ops to save the register arguments (R3-R10), early in pass1 33 | and don't know the position of the stack pointer, and the size of the 34 | argument space required to "step over". 35 | 36 | One solution is to have two pointers to the stack. One for the top 37 | of the stack and the other pointing just below the temporaries but above 38 | the argument space. Then our function arguments and the permanent registers can 39 | be saved fixed-relative to this register. If we don't know the size of 40 | argument space, we cannot "dynamically" alter the stack (like we do with mips), 41 | since the powerpc ABI specifies that the "lowest" address 42 | in the stack frame is the saved stack pointer (pointing to the previous 43 | stack frame). While this is a nice feature for tracking back through the 44 | stack frames (which mips has always had problems with), it makes it 45 | next-to-impossible to increase the strack frame dynamically. 46 | 47 | I guess the best approach is to determine the size of the argument stack 48 | and have a second frame pointer. 49 | -------------------------------------------------------------------------------- /arch/sparc64/local.c: -------------------------------------------------------------------------------- 1 | /* $Id: local.c,v 1.34 2011/06/23 13:41:25 ragge Exp $ */ 2 | 3 | /* 4 | * Copyright (c) 2008 David Crawshaw 5 | * 6 | * Permission to use, copy, modify, and/or distribute this software for any 7 | * purpose with or without fee is hereby granted, provided that the above 8 | * copyright notice and this permission notice appear in all copies. 9 | * 10 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 11 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 12 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 13 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 14 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 15 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 16 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 17 | */ 18 | 19 | #include "pass1.h" 20 | 21 | NODE * 22 | clocal(NODE *p) 23 | { 24 | struct symtab *sp; 25 | int op; 26 | NODE *r, *l; 27 | 28 | op = p->n_op; 29 | sp = p->n_sp; 30 | l = p->n_left; 31 | r = p->n_right; 32 | 33 | #ifdef PCC_DEBUG 34 | if (xdebug) { 35 | printf("clocal in: %p, %s\n", p, copst(op)); 36 | fwalk(p, eprint, 0); 37 | } 38 | #endif 39 | 40 | switch (op) { 41 | 42 | case NAME: 43 | if (sp->sclass == PARAM || sp->sclass == AUTO) { 44 | /* 45 | * Use a fake structure reference to 46 | * write out frame pointer offsets. 47 | */ 48 | l = block(REG, NIL, NIL, PTR+STRTY, 0, 0); 49 | l->n_lval = 0; 50 | l->n_rval = FP; 51 | r = p; 52 | p = stref(block(STREF, l, r, 0, 0, 0)); 53 | } 54 | break; 55 | case PCONV: /* Remove what PCONVs we can. */ 56 | if (l->n_op == SCONV) 57 | break; 58 | 59 | if (l->n_op == ICON || (ISPTR(p->n_type) && ISPTR(l->n_type))) { 60 | l->n_type = p->n_type; 61 | l->n_qual = p->n_qual; 62 | l->n_df = p->n_df; 63 | l->n_ap = p->n_ap; 64 | nfree(p); 65 | p = l; 66 | } 67 | break; 68 | 69 | case SCONV: 70 | /* Remove redundant conversions. */ 71 | if ((p->n_type & TMASK) == 0 && (l->n_type & TMASK) == 0 && 72 | tsize(p->n_type, p->n_df, p->n_ap) == 73 | tsize(l->n_type, l->n_df, l->n_ap) && 74 | p->n_type != FLOAT && p->n_type != DOUBLE && 75 | l->n_type != FLOAT && l->n_type != DOUBLE && 76 | l->n_type != DOUBLE && p->n_type != LDOUBLE) { 77 | if (l->n_op == NAME || l->n_op == UMUL || 78 | l->n_op == TEMP) { 79 | l->n_type = p->n_type; 80 | nfree(p); 81 | p = l; 82 | break; 83 | } 84 | } 85 | 86 | /* Convert floating point to int before to char or short. */ 87 | if ((l->n_type == FLOAT || l->n_type == DOUBLE || l->n_type == LDOUBLE) 88 | && (DEUNSIGN(p->n_type) == CHAR || DEUNSIGN(p->n_type) == SHORT)) { 89 | p = block(SCONV, p, NIL, p->n_type, p->n_df, p->n_ap); 90 | p->n_left->n_type = INT; 91 | break; 92 | } 93 | 94 | /* Transform constants now. */ 95 | if (l->n_op != ICON) 96 | break; 97 | 98 | if (ISPTR(p->n_type)) { 99 | l->n_type = p->n_type; 100 | nfree(p); 101 | p = l; 102 | break; 103 | } 104 | 105 | switch (p->n_type) { 106 | case BOOL: l->n_lval = (l->n_lval != 0); break; 107 | case CHAR: l->n_lval = (char)l->n_lval; break; 108 | case UCHAR: l->n_lval = l->n_lval & 0377; break; 109 | case SHORT: l->n_lval = (short)l->n_lval; break; 110 | case USHORT: l->n_lval = l->n_lval & 0177777; break; 111 | case UNSIGNED: l->n_lval = l->n_lval & 0xffffffff; break; 112 | case INT: l->n_lval = (int)l->n_lval; break; 113 | case ULONG: 114 | case ULONGLONG: l->n_lval = l->n_lval; break; 115 | case LONG: 116 | case LONGLONG: l->n_lval = (long long)l->n_lval; break; 117 | case FLOAT: 118 | case DOUBLE: 119 | case LDOUBLE: 120 | l->n_op = FCON; 121 | l->n_dcon = l->n_lval; 122 | break; 123 | case VOID: 124 | break; 125 | default: 126 | cerror("sconv type unknown %d", p->n_type); 127 | } 128 | 129 | l->n_type = p->n_type; 130 | nfree(p); 131 | p = l; 132 | break; 133 | 134 | case FORCE: 135 | /* Put attached value into the return register. */ 136 | p->n_op = ASSIGN; 137 | p->n_right = p->n_left; 138 | p->n_left = block(REG, NIL, NIL, p->n_type, 0, 0); 139 | p->n_left->n_rval = RETREG_PRE(p->n_type); 140 | break; 141 | } 142 | 143 | #ifdef PCC_DEBUG 144 | if (xdebug) { 145 | printf("clocal out: %p, %s\n", p, copst(op)); 146 | fwalk(p, eprint, 0); 147 | } 148 | #endif 149 | 150 | return p; 151 | } 152 | 153 | void 154 | myp2tree(NODE *p) 155 | { 156 | struct symtab *sp; 157 | 158 | if (p->n_op != FCON) 159 | return; 160 | 161 | sp = tmpalloc(sizeof(struct symtab)); 162 | sp->sclass = STATIC; 163 | sp->slevel = 1; 164 | sp->soffset = getlab(); 165 | sp->sflags = 0; 166 | sp->stype = p->n_type; 167 | sp->squal = (CON >> TSHIFT); 168 | 169 | defloc(sp); 170 | ninval(0, tsize(p->n_type, p->n_df, p->n_ap), p); 171 | 172 | p->n_op = NAME; 173 | p->n_lval = 0; 174 | p->n_sp = sp; 175 | } 176 | 177 | int 178 | andable(NODE *p) 179 | { 180 | return 1; 181 | } 182 | 183 | int 184 | cisreg(TWORD t) 185 | { 186 | /* SPARCv9 registers are all 64-bits wide. */ 187 | return 1; 188 | } 189 | 190 | void 191 | spalloc(NODE *t, NODE *p, OFFSZ off) 192 | { 193 | cerror("spalloc"); 194 | } 195 | 196 | int 197 | ninval(CONSZ off, int fsz, NODE *p) 198 | { 199 | union { float f; double d; int i; long long l; } u; 200 | 201 | switch (p->n_type) { 202 | case FLOAT: 203 | u.f = (float)p->n_dcon; 204 | printf("\t.long %d\n", u.i); 205 | break; 206 | case DOUBLE: 207 | u.d = (double)p->n_dcon; 208 | printf("\t.xword %lld\n", u.l); 209 | break; 210 | default: 211 | return 0; 212 | } 213 | return 1; 214 | } 215 | 216 | char * 217 | exname(char *p) 218 | { 219 | return p ? p : ""; 220 | } 221 | 222 | TWORD 223 | ctype(TWORD type) 224 | { 225 | switch (BTYPE(type)) { 226 | case LONGLONG: 227 | MODTYPE(type,LONG); 228 | break; 229 | case ULONGLONG: 230 | MODTYPE(type,ULONG); 231 | 232 | } 233 | return type; 234 | } 235 | 236 | void 237 | calldec(NODE *p, NODE *q) 238 | { 239 | } 240 | 241 | void 242 | extdec(struct symtab *q) 243 | { 244 | } 245 | 246 | void 247 | defzero(struct symtab *sp) 248 | { 249 | int off; 250 | char *name; 251 | 252 | if ((name = sp->soname) == NULL) 253 | name = exname(sp->sname); 254 | off = tsize(sp->stype, sp->sdf, sp->sap); 255 | SETOFF(off,SZCHAR); 256 | off /= SZCHAR; 257 | 258 | if (sp->sclass == STATIC) 259 | printf("\t.local %s\n", name); 260 | if (sp->slevel == 0) 261 | printf("\t.comm %s,%d\n", name, off); 262 | else 263 | printf("\t.comm " LABFMT ",%d\n", sp->soffset, off); 264 | } 265 | 266 | int 267 | mypragma(char *str) 268 | { 269 | return 0; 270 | } 271 | 272 | void 273 | fixdef(struct symtab *sp) 274 | { 275 | } 276 | 277 | void 278 | pass1_lastchance(struct interpass *ip) 279 | { 280 | } 281 | 282 | -------------------------------------------------------------------------------- /arch/sparc64/order.c: -------------------------------------------------------------------------------- 1 | /* $Id: order.c,v 1.7 2011/06/05 08:54:42 plunky Exp $ */ 2 | 3 | /* 4 | * Copyright (c) 2008 David Crawshaw 5 | * 6 | * Permission to use, copy, modify, and/or distribute this software for any 7 | * purpose with or without fee is hereby granted, provided that the above 8 | * copyright notice and this permission notice appear in all copies. 9 | * 10 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 11 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 12 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 13 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 14 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 15 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 16 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 17 | */ 18 | 19 | #include "pass2.h" 20 | 21 | /* is it legal to make an OREG or NAME entry which has an 22 | * offset of off, (from a register of r), if the 23 | * resulting thing had type t */ 24 | int 25 | notoff(TWORD t, int r, CONSZ off, char *cp) 26 | { 27 | return !SIMM13(off); 28 | } 29 | 30 | /* 31 | * Turn a UMUL-referenced node into OREG. 32 | */ 33 | void 34 | offstar(NODE *p, int shape) 35 | { 36 | if (x2debug) 37 | printf("offstar(%p)\n", p); 38 | 39 | if (p->n_op == PLUS || p->n_op == MINUS) { 40 | if (p->n_right->n_op == ICON && SIMM13(p->n_right->n_lval)) { 41 | if (isreg(p->n_left) == 0) 42 | (void)geninsn(p->n_left, INAREG); 43 | /* Converted in ormake() */ 44 | return; 45 | } 46 | } 47 | (void)geninsn(p, INAREG); 48 | } 49 | 50 | void 51 | myormake(NODE *q) 52 | { 53 | } 54 | 55 | int 56 | shumul(NODE *p, int shape) 57 | { 58 | if (shape & SOREG) 59 | return SROREG; 60 | return SRNOPE; 61 | } 62 | 63 | int 64 | setbin(NODE *p) 65 | { 66 | return 0; 67 | } 68 | 69 | int 70 | setasg(NODE *p, int cookie) 71 | { 72 | return 0; 73 | } 74 | 75 | int 76 | setuni(NODE *p, int cookie) 77 | { 78 | return 0; 79 | } 80 | 81 | struct rspecial * 82 | nspecial(struct optab *q) 83 | { 84 | switch (q->op) { 85 | case STASG: { 86 | static struct rspecial s[] = { 87 | { NEVER, O0 }, 88 | { NRIGHT, O1 }, 89 | { NEVER, O2 }, 90 | { 0 } 91 | }; 92 | return s; 93 | } 94 | } 95 | 96 | comperr("unknown nspecial %d: %s", q - table, q->cstring); 97 | return 0; /* XXX */ 98 | } 99 | 100 | int 101 | setorder(NODE *p) 102 | { 103 | return 0; 104 | } 105 | 106 | int * 107 | livecall(NODE *p) 108 | { 109 | static int ret[] = { O0, O1, O2, O3, O4, O5, O6, O7, -1 }; 110 | return ret; 111 | } 112 | 113 | int 114 | acceptable(struct optab *op) 115 | { 116 | return 1; 117 | } 118 | -------------------------------------------------------------------------------- /cc/Makefile.in: -------------------------------------------------------------------------------- 1 | # $Id: Makefile.in,v 1.9 2012/01/01 16:27:25 ragge Exp $ 2 | # 3 | # Makefile.in for top-level of pcc. 4 | # 5 | 6 | @SET_MAKE@ 7 | 8 | ALL_SUBDIRS= cc cpp ccom cxxcom 9 | DIST_SUBDIRS= $(ALL_SUBDIRS) driver 10 | 11 | all install clean: 12 | @for subdir in $(ALL_SUBDIRS); do \ 13 | _nextdir_=$${_thisdir_+$$_thisdir_/}$$subdir; \ 14 | echo "===> $$_nextdir_"; \ 15 | (_thisdir_=$$_nextdir_; export _thisdir_; cd $$subdir && \ 16 | exec $(MAKE) $(MFLAGS) $@) || exit $$?; \ 17 | echo "<=== $$_nextdir_"; \ 18 | done 19 | 20 | distclean: 21 | @for subdir in $(DIST_SUBDIRS); do \ 22 | _nextdir_=$${_thisdir_+$$_thisdir_/}$$subdir; \ 23 | echo "===> $$_nextdir_"; \ 24 | (_thisdir_=$$_nextdir_; export _thisdir_; cd $$subdir && \ 25 | exec $(MAKE) $(MFLAGS) $@) || exit $$?; \ 26 | echo "<=== $$_nextdir_"; \ 27 | done 28 | rm -f Makefile 29 | -------------------------------------------------------------------------------- /cc/cc/Makefile.in: -------------------------------------------------------------------------------- 1 | # $Id: Makefile.in,v 1.29 2012/03/15 09:22:12 plunky Exp $ 2 | # 3 | # Makefile.in for the cc part of pcc. 4 | # 5 | VPATH=@srcdir@ 6 | srcdir=@srcdir@ 7 | top_srcdir=@top_srcdir@ 8 | top_builddir=@top_builddir@ 9 | prefix = @prefix@ 10 | exec_prefix = @exec_prefix@ 11 | bindir = @bindir@ 12 | libdir = @libdir@ 13 | libexecdir = @libexecdir@ 14 | includedir = @includedir@ 15 | datarootdir = @datarootdir@ 16 | mandir = @mandir@ 17 | strip = @strip@ 18 | CC = @CC@ 19 | EXEEXT = @EXEEXT@ 20 | TARGOS = @targos@ 21 | TARGOSVER = @targosver@ 22 | TARGMACH = @targmach@ 23 | TARGET = @target@ 24 | VERSION = @PACKAGE_VERSION@ 25 | PCCLIBDIR = $(libdir)/pcc/$(TARGET)/$(VERSION)/lib 26 | PCCINCDIR = $(libdir)/pcc/$(TARGET)/$(VERSION)/include 27 | CFLAGS = @CFLAGS@ @ADD_CFLAGS@ 28 | CPPFLAGS = @CPPFLAGS@ -DLIBEXECDIR=\"${libexecdir}/\" \ 29 | @ADD_CPPFLAGS@ -DINCLUDEDIR=\"${includedir}/\" \ 30 | -DPCCINCDIR=\"${PCCINCDIR}/\" -DPCCLIBDIR=\"${PCCLIBDIR}/\" \ 31 | -Dos_${TARGOS} -Dmach_${TARGMACH} -DTARGOSVER=${TARGOSVER} \ 32 | -I${top_builddir} -I${top_srcdir}/os/${TARGOS} -I${MIPDIR} -I${MDIR} 33 | LIBS = @LIBS@ 34 | LDFLAGS = @LDFLAGS@ 35 | INSTALL = @INSTALL@ 36 | INSTALL_PROGRAM = @INSTALL_PROGRAM@ 37 | INSTALL_DATA = @INSTALL_DATA@ 38 | 39 | OBJS=cc.o compat.o 40 | DEST=@BINPREFIX@pcc$(EXEEXT) 41 | 42 | MIPDIR=${top_srcdir}/mip 43 | MDIR=${top_srcdir}/arch/$(TARGMACH) 44 | 45 | all: ${DEST} 46 | 47 | ${DEST}: $(OBJS) 48 | $(CC) $(LDFLAGS) $(OBJS) -o $@ $(LIBS) 49 | 50 | .c.o: 51 | $(CC) $(CFLAGS) $(CPPFLAGS) -c -o $@ $< 52 | 53 | compat.o: $(MIPDIR)/compat.c 54 | $(CC) $(CFLAGS) $(CPPFLAGS) -c -o $@ $(MIPDIR)/compat.c 55 | 56 | install: 57 | test -z "${DESTDIR}$(bindir)" || mkdir -p "${DESTDIR}$(bindir)" 58 | ${INSTALL_PROGRAM} ${DEST} ${DESTDIR}${bindir} 59 | @if [ ${strip} = yes ]; then \ 60 | strip ${DESTDIR}${bindir}/${DEST} ; \ 61 | echo strip ${DESTDIR}${bindir}/${DEST} ; \ 62 | fi 63 | test -z "${DESTDIR}$(mandir)/man1" || mkdir -p "${DESTDIR}$(mandir)/man1" 64 | ${INSTALL_DATA} $(srcdir)/cc.1 ${DESTDIR}${mandir}/man1/${DEST}.1 65 | test -z "${DESTDIR}$(PCCINCDIR)" || mkdir -p "${DESTDIR}$(PCCINCDIR)" 66 | test -z "${DESTDIR}$(PCCLIBDIR)" || mkdir -p "${DESTDIR}$(PCCLIBDIR)" 67 | 68 | clean: 69 | rm -f $(OBJS) ${DEST} 70 | 71 | distclean: clean 72 | rm -f Makefile 73 | -------------------------------------------------------------------------------- /cc/ccom/Makefile.in: -------------------------------------------------------------------------------- 1 | # $Id: Makefile.in,v 1.42 2012/03/15 09:22:12 plunky Exp $ 2 | # 3 | # Makefile.in for ccom 4 | # 5 | VPATH=@srcdir@ 6 | srcdir=@srcdir@ 7 | top_srcdir=@top_srcdir@ 8 | builddir=@builddir@ 9 | top_builddir=@top_builddir@ 10 | CC = @CC@ 11 | EXEEXT = @EXEEXT@ 12 | CC_FOR_BUILD = @CC_FOR_BUILD@ 13 | CFLAGS = @CFLAGS@ @ADD_CFLAGS@ 14 | CPPFLAGS = @CPPFLAGS@ @ADD_CPPFLAGS@ -D_ISOC99_SOURCE \ 15 | -Dos_$(TARGOS) -Dmach_$(TARGMACH) \ 16 | -I$(srcdir) -I$(builddir) -I$(top_builddir) -I$(MIPDIR) -I$(MDIR) \ 17 | -I$(top_srcdir)/os/$(TARGOS) 18 | LIBS = @LIBS@ 19 | LDFLAGS = @LDFLAGS@ 20 | LEX = @LEX@ 21 | LFLAGS = 22 | LEX_OUTPUT_ROOT = @LEX_OUTPUT_ROOT@ 23 | YACC = @YACC@ 24 | YFLAGS = @YFLAGS@ 25 | TARGOS = @targos@ 26 | TARGOSVER = @targosver@ 27 | TARGMACH = @targmach@ 28 | prefix = @prefix@ 29 | exec_prefix = @exec_prefix@ 30 | libexecdir = @libexecdir@ 31 | datarootdir = @datarootdir@ 32 | mandir = @mandir@ 33 | strip = @strip@ 34 | INSTALL = @INSTALL@ 35 | INSTALL_PROGRAM = @INSTALL_PROGRAM@ 36 | INSTALL_DATA = @INSTALL_DATA@ 37 | 38 | MDIR=$(top_srcdir)/arch/$(TARGMACH) 39 | MIPDIR=$(top_srcdir)/mip 40 | 41 | DEST=@BINPREFIX@ccom$(EXEEXT) 42 | MKEXT=mkext$(EXEEXT) 43 | 44 | all: $(DEST) 45 | 46 | OBJS= builtins.o cgram.o code.o common.o compat.o external.o \ 47 | gcc_compat.o init.o inline.o local.o local2.o main.o \ 48 | match.o optim.o optim2.o order.o pftn.o reader.o \ 49 | regs.o scan.o stabs.o symtabs.o table.o trees.o 50 | 51 | LOBJS= mkext.lo common.lo table.lo 52 | 53 | HDRS= $(srcdir)/pass1.h $(MIPDIR)/pass2.h $(MIPDIR)/manifest.h \ 54 | $(MDIR)/macdefs.h $(MIPDIR)/node.h $(MIPDIR)/compat.h 55 | 56 | # 57 | # round 1: generate external.[ch], cgram.[ch] & scan.c 58 | # 59 | 60 | $(LOBJS): $(HDRS) 61 | 62 | mkext.lo: $(MIPDIR)/mkext.c 63 | $(CC_FOR_BUILD) $(CFLAGS) $(CPPFLAGS) -DMKEXT -c -o $@ $(MIPDIR)/mkext.c 64 | 65 | common.lo: $(MIPDIR)/common.c 66 | $(CC_FOR_BUILD) $(CFLAGS) $(CPPFLAGS) -DMKEXT -c -o $@ $(MIPDIR)/common.c 67 | 68 | table.lo: $(MDIR)/table.c 69 | $(CC_FOR_BUILD) $(CFLAGS) $(CPPFLAGS) -DMKEXT -c -o $@ $(MDIR)/table.c 70 | 71 | $(MKEXT): $(LOBJS) 72 | $(CC_FOR_BUILD) $(LDFLAGS) $(LOBJS) -o $@ $(LIBS) 73 | 74 | external.c: $(MKEXT) 75 | $(builddir)/$(MKEXT) 76 | 77 | cgram.c: $(srcdir)/cgram.y 78 | $(YACC) $(YFLAGS) -d $(srcdir)/cgram.y 79 | mv -f y.tab.c cgram.c 80 | mv -f y.tab.h cgram.h 81 | 82 | scan.c: $(srcdir)/scan.l 83 | $(LEX) $(LFLAGS) $(srcdir)/scan.l 84 | mv -f $(LEX_OUTPUT_ROOT).c scan.c 85 | 86 | # 87 | # round 2: compile $(OBJS) 88 | # 89 | 90 | $(OBJS): $(HDRS) external.c cgram.c 91 | 92 | builtins.o: $(srcdir)/builtins.c 93 | $(CC) $(CFLAGS) $(CPPFLAGS) -c -o $@ $(srcdir)/builtins.c 94 | 95 | cgram.o: cgram.c 96 | $(CC) $(CFLAGS) $(CPPFLAGS) -c -o $@ cgram.c 97 | 98 | code.o: $(MDIR)/code.c 99 | $(CC) $(CFLAGS) $(CPPFLAGS) -c -o $@ $(MDIR)/code.c 100 | 101 | common.o: $(MIPDIR)/common.c 102 | $(CC) $(CFLAGS) $(CPPFLAGS) -c -o $@ $(MIPDIR)/common.c 103 | 104 | compat.o: $(MIPDIR)/compat.c 105 | $(CC) $(CFLAGS) $(CPPFLAGS) -c -o $@ $(MIPDIR)/compat.c 106 | 107 | external.o: external.c 108 | $(CC) $(CFLAGS) $(CPPFLAGS) -c -o $@ external.c 109 | 110 | gcc_compat.o: $(srcdir)/gcc_compat.c 111 | $(CC) $(CFLAGS) $(CPPFLAGS) -c -o $@ $(srcdir)/gcc_compat.c 112 | 113 | init.o: $(srcdir)/init.c 114 | $(CC) $(CFLAGS) $(CPPFLAGS) -c -o $@ $(srcdir)/init.c 115 | 116 | inline.o: $(srcdir)/inline.c 117 | $(CC) $(CFLAGS) $(CPPFLAGS) -c -o $@ $(srcdir)/inline.c 118 | 119 | local.o: $(MDIR)/local.c 120 | $(CC) $(CFLAGS) $(CPPFLAGS) -c -o $@ $(MDIR)/local.c 121 | 122 | local2.o: $(MDIR)/local2.c 123 | $(CC) $(CFLAGS) $(CPPFLAGS) -c -o $@ $(MDIR)/local2.c 124 | 125 | main.o: $(srcdir)/main.c 126 | $(CC) $(CFLAGS) $(CPPFLAGS) -c -o $@ $(srcdir)/main.c 127 | 128 | match.o: $(MIPDIR)/match.c 129 | $(CC) $(CFLAGS) $(CPPFLAGS) -c -o $@ $(MIPDIR)/match.c 130 | 131 | optim.o: $(srcdir)/optim.c 132 | $(CC) $(CFLAGS) $(CPPFLAGS) -c -o $@ $(srcdir)/optim.c 133 | 134 | optim2.o: $(MIPDIR)/optim2.c 135 | $(CC) $(CFLAGS) $(CPPFLAGS) -c -o $@ $(MIPDIR)/optim2.c 136 | 137 | order.o: $(MDIR)/order.c 138 | $(CC) $(CFLAGS) $(CPPFLAGS) -c -o $@ $(MDIR)/order.c 139 | 140 | pftn.o: $(srcdir)/pftn.c 141 | $(CC) $(CFLAGS) $(CPPFLAGS) -c -o $@ $(srcdir)/pftn.c 142 | 143 | reader.o: $(MIPDIR)/reader.c 144 | $(CC) $(CFLAGS) $(CPPFLAGS) -c -o $@ $(MIPDIR)/reader.c 145 | 146 | regs.o: $(MIPDIR)/regs.c 147 | $(CC) $(CFLAGS) $(CPPFLAGS) -c -o $@ $(MIPDIR)/regs.c 148 | 149 | scan.o: scan.c 150 | $(CC) $(CFLAGS) $(CPPFLAGS) -c -o $@ scan.c 151 | 152 | stabs.o: $(srcdir)/stabs.c 153 | $(CC) $(CFLAGS) $(CPPFLAGS) -c -o $@ $(srcdir)/stabs.c 154 | 155 | symtabs.o: $(srcdir)/symtabs.c 156 | $(CC) $(CFLAGS) $(CPPFLAGS) -c -o $@ $(srcdir)/symtabs.c 157 | 158 | table.o: $(MDIR)/table.c 159 | $(CC) $(CFLAGS) $(CPPFLAGS) -c -o $@ $(MDIR)/table.c 160 | 161 | trees.o: $(srcdir)/trees.c 162 | $(CC) $(CFLAGS) $(CPPFLAGS) -c -o $@ $(srcdir)/trees.c 163 | 164 | # 165 | # round 3: build $(DEST) 166 | # 167 | 168 | $(DEST): $(OBJS) 169 | $(CC) $(LDFLAGS) $(OBJS) -o $@ $(LIBS) 170 | 171 | install: $(DEST) 172 | test -z "$(DESTDIR)$(libexecdir)" || mkdir -p "$(DESTDIR)$(libexecdir)" 173 | $(INSTALL_PROGRAM) $(DEST) $(DESTDIR)$(libexecdir) 174 | @if [ $(strip) = yes ]; then \ 175 | strip $(DESTDIR)$(libexecdir)/$(DEST) ; \ 176 | echo strip $(DESTDIR)$(libexecdir)/$(DEST) ; \ 177 | fi 178 | test -z "$(DESTDIR)$(mandir)/man1" || mkdir -p "$(DESTDIR)$(mandir)/man1" 179 | $(INSTALL_DATA) $(srcdir)/ccom.1 $(DESTDIR)$(mandir)/man1/$(DEST).1 180 | 181 | clean: 182 | rm -f $(DEST) $(OBJS) $(MKEXT) $(LOBJS) $(LEX_OUTPUT_ROOT).c \ 183 | scan.c y.tab.[ch] cgram.[ch] external.[ch] 184 | 185 | distclean: clean 186 | rm -f Makefile 187 | -------------------------------------------------------------------------------- /cc/cpp/Makefile.in: -------------------------------------------------------------------------------- 1 | # $Id: Makefile.in,v 1.40 2012/03/15 09:22:12 plunky Exp $ 2 | # 3 | # Makefile.in for cpp 4 | # 5 | VPATH=@srcdir@ 6 | srcdir=@srcdir@ 7 | top_srcdir=@top_srcdir@ 8 | builddir=@builddir@ 9 | top_builddir=@top_builddir@ 10 | prefix = @prefix@ 11 | exec_prefix = @exec_prefix@ 12 | bindir = @bindir@ 13 | libexecdir = @libexecdir@ 14 | datarootdir = @datarootdir@ 15 | mandir = @mandir@ 16 | strip = @strip@ 17 | CC = @CC@ 18 | EXEEXT = @EXEEXT@ 19 | CFLAGS = @CFLAGS@ @ADD_CFLAGS@ 20 | CPPFLAGS = @CPPFLAGS@ @ADD_CPPFLAGS@ \ 21 | -I$(srcdir) -I$(top_builddir) -I$(builddir) -I$(MIPDIR) -I$(MDIR) 22 | LIBS = @LIBS@ 23 | LDFLAGS = @LDFLAGS@ 24 | LEX = @LEX@ 25 | YACC = @YACC@ 26 | YFLAGS = @YFLAGS@ 27 | INSTALL = @INSTALL@ 28 | INSTALL_PROGRAM = @INSTALL_PROGRAM@ 29 | INSTALL_DATA = @INSTALL_DATA@ 30 | TARGMACH = @targmach@ 31 | 32 | OBJS=cpp.o cpy.o token.o compat.o 33 | HEADERS=cpp.h 34 | DEST=@BINPREFIX@cpp$(EXEEXT) 35 | 36 | MIPDIR=$(top_srcdir)/mip 37 | MDIR=$(top_srcdir)/arch/$(TARGMACH) 38 | 39 | all: ${DEST} 40 | 41 | ${DEST}: $(OBJS) $(HEADERS) 42 | $(CC) $(LDFLAGS) $(OBJS) -o $@ $(LIBS) 43 | 44 | .c.o: 45 | $(CC) $(CFLAGS) $(CPPFLAGS) -c -o $@ $< 46 | 47 | .l.o: 48 | $(LEX) $(LFLAGS) $< 49 | $(CC) $(CFLAGS) $(CPPFLAGS) -c -o $@ lex.yy.c 50 | 51 | .y.o: 52 | $(YACC) -d $(YFLAGS) $< 53 | $(CC) $(CFLAGS) $(CPPFLAGS) -c -o $@ y.tab.c 54 | 55 | compat.o: $(MIPDIR)/compat.c 56 | $(CC) $(CFLAGS) $(CPPFLAGS) -c -o $@ $(MIPDIR)/compat.c 57 | 58 | $(OBJS): $(HEADERS) 59 | 60 | cpp.o: cpy.o 61 | token.o: cpy.o 62 | 63 | test: 64 | ./cpp < tests/test1 > tests/run1 65 | cmp tests/run1 tests/res1 66 | ./cpp < tests/test2 > tests/run2 67 | cmp tests/run2 tests/res2 68 | ./cpp < tests/test3 > tests/run3 69 | cmp tests/run3 tests/res3 70 | ./cpp < tests/test4 > tests/run4 71 | cmp tests/run4 tests/res4 72 | ./cpp < tests/test5 > tests/run5 73 | cmp tests/run5 tests/res5 74 | ./cpp < tests/test6 > tests/run6 75 | cmp tests/run6 tests/res6 76 | ./cpp < tests/test7 > tests/run7 77 | cmp tests/run7 tests/res7 78 | ./cpp < tests/test8 > tests/run8 79 | cmp tests/run8 tests/res8 80 | ./cpp < tests/test9 > tests/run9 81 | cmp tests/run9 tests/res9 82 | ./cpp < tests/test10 > tests/run10 83 | cmp tests/run10 tests/res10 84 | ./cpp < tests/test11 > tests/run11 85 | cmp tests/run11 tests/res11 86 | ./cpp < tests/test12 > tests/run12 87 | cmp tests/run12 tests/res12 88 | ./cpp < tests/test13 > tests/run13 89 | cmp tests/run13 tests/res13 90 | 91 | 92 | install: 93 | test -z "${DESTDIR}$(libexecdir)" || mkdir -p "${DESTDIR}$(libexecdir)" 94 | ${INSTALL_PROGRAM} ${DEST} ${DESTDIR}${libexecdir} 95 | @if [ ${strip} = yes ]; then \ 96 | strip ${DESTDIR}${libexecdir}/${DEST} ; \ 97 | echo strip ${DESTDIR}${libexecdir}/${DEST} ; \ 98 | fi 99 | test -z "${DESTDIR}$(mandir)/man1" || mkdir -p "${DESTDIR}$(mandir)/man1" 100 | ${INSTALL_DATA} $(srcdir)/cpp.1 ${DESTDIR}${mandir}/man1/$(DEST).1 101 | 102 | clean: 103 | rm -f $(OBJS) $(DEST) lex.yy.c y.tab.[ch] tests/run* 104 | 105 | distclean: clean 106 | rm -f Makefile 107 | -------------------------------------------------------------------------------- /cc/cpp/cpp.h: -------------------------------------------------------------------------------- 1 | /* $Id: cpp.h,v 1.55 2011/09/27 08:34:59 plunky Exp $ */ 2 | 3 | /* 4 | * Copyright (c) 2004,2010 Anders Magnusson (ragge@ludd.luth.se). 5 | * All rights reserved. 6 | * 7 | * Redistribution and use in source and binary forms, with or without 8 | * modification, are permitted provided that the following conditions 9 | * are met: 10 | * 1. Redistributions of source code must retain the above copyright 11 | * notice, this list of conditions and the following disclaimer. 12 | * 2. Redistributions in binary form must reproduce the above copyright 13 | * notice, this list of conditions and the following disclaimer in the 14 | * documentation and/or other materials provided with the distribution. 15 | * 16 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 17 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 18 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 19 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 20 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 21 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 22 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 23 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 25 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 | */ 27 | 28 | #include /* for obuf */ 29 | #include 30 | 31 | #include "config.h" 32 | 33 | typedef unsigned char usch; 34 | extern usch yytext[]; 35 | extern usch *stringbuf; 36 | 37 | extern int trulvl; 38 | extern int flslvl; 39 | extern int elflvl; 40 | extern int elslvl; 41 | extern int dflag; 42 | extern int tflag, Cflag, Pflag; 43 | extern int Mflag, dMflag; 44 | extern usch *Mfile; 45 | extern int ofd; 46 | 47 | /* args for lookup() */ 48 | #define FIND 0 49 | #define ENTER 1 50 | 51 | /* buffer used internally */ 52 | #ifndef CPPBUF 53 | #if defined(mach_pdp11) 54 | #define CPPBUF BUFSIZ 55 | #define BUF_STACK 56 | #elif defined(os_win32) 57 | /* winxp seems to fail > 26608 bytes */ 58 | #define CPPBUF 16384 59 | #else 60 | #define CPPBUF (65536*2) 61 | #endif 62 | #endif 63 | 64 | #define MAXARGS 128 /* Max # of args to a macro. Should be enough */ 65 | 66 | #define NAMEMAX CPPBUF /* currently pushbackbuffer */ 67 | #define BBUFSZ (NAMEMAX+CPPBUF+1) 68 | 69 | #define GCCARG 0xfd /* has gcc varargs that may be replaced with 0 */ 70 | #define VARG 0xfe /* has varargs */ 71 | #define OBJCT 0xff 72 | #define WARN 1 /* SOH, not legal char */ 73 | #define CONC 2 /* STX, not legal char */ 74 | #define SNUFF 3 /* ETX, not legal char */ 75 | #define EBLOCK 4 /* EOT, not legal char */ 76 | 77 | /* Used in macro expansion */ 78 | #define RECMAX 10000 /* max # of recursive macros */ 79 | extern struct symtab *norep[RECMAX]; 80 | extern int norepptr; 81 | extern unsigned short bptr[RECMAX]; 82 | extern int bidx; 83 | #define MKB(l,h) (l+((h)<<8)) 84 | 85 | /* quick checks for some characters */ 86 | #define C_SPEC 001 87 | #define C_EP 002 88 | #define C_ID 004 89 | #define C_I (C_SPEC|C_ID) 90 | #define C_2 010 /* for yylex() tokenizing */ 91 | #define C_WSNL 020 /* ' ','\t','\r','\n' */ 92 | #define iswsnl(x) (spechr[x] & C_WSNL) 93 | extern char spechr[]; 94 | 95 | /* definition for include file info */ 96 | struct includ { 97 | struct includ *next; 98 | const usch *fname; /* current fn, changed if #line found */ 99 | const usch *orgfn; /* current fn, not changed */ 100 | int lineno; 101 | int infil; 102 | usch *curptr; 103 | usch *maxread; 104 | usch *ostr; 105 | usch *buffer; 106 | int idx; 107 | void *incs; 108 | const usch *fn; 109 | #ifdef BUF_STACK 110 | usch bbuf[BBUFSZ]; 111 | #else 112 | usch *bbuf; 113 | #endif 114 | } *ifiles; 115 | 116 | /* Symbol table entry */ 117 | struct symtab { 118 | const usch *namep; 119 | const usch *value; 120 | const usch *file; 121 | int line; 122 | }; 123 | 124 | struct initar { 125 | struct initar *next; 126 | int type; 127 | char *str; 128 | }; 129 | 130 | /* 131 | * Struct used in parse tree evaluation. 132 | * op is one of: 133 | * - number type (NUMBER, UNUMBER) 134 | * - zero (0) if divided by zero. 135 | */ 136 | struct nd { 137 | int op; 138 | union { 139 | long long val; 140 | unsigned long long uval; 141 | } n; 142 | }; 143 | 144 | #define nd_val n.val 145 | #define nd_uval n.uval 146 | 147 | struct symtab *lookup(const usch *namep, int enterf); 148 | usch *gotident(struct symtab *nl); 149 | int slow; /* scan slowly for new tokens */ 150 | int defining; 151 | int submac(struct symtab *nl, int); 152 | int kfind(struct symtab *nl); 153 | int doexp(void); 154 | int donex(void); 155 | void ppdir(void); 156 | 157 | void define(void); 158 | void include(void); 159 | void include_next(void); 160 | void line(void); 161 | 162 | int pushfile(const usch *fname, const usch *fn, int idx, void *incs); 163 | void popfile(void); 164 | void prtline(void); 165 | int yylex(void); 166 | int sloscan(void); 167 | void cunput(int); 168 | int curline(void); 169 | char *curfile(void); 170 | void setline(int); 171 | void setfile(char *); 172 | int yyparse(void); 173 | void yyerror(const char *); 174 | void unpstr(const usch *); 175 | usch *savstr(const usch *str); 176 | void savch(int c); 177 | void mainscan(void); 178 | void putch(int); 179 | void putstr(const usch *s); 180 | void line(void); 181 | usch *sheap(const char *fmt, ...); 182 | void xwarning(usch *); 183 | void xerror(usch *); 184 | #ifdef HAVE_CPP_VARARG_MACRO_GCC 185 | #define warning(...) xwarning(sheap(__VA_ARGS__)) 186 | #define error(...) xerror(sheap(__VA_ARGS__)) 187 | #else 188 | #define warning printf 189 | #define error printf 190 | #endif 191 | int cinput(void); 192 | void getcmnt(void); 193 | -------------------------------------------------------------------------------- /cc/cpp/tests/res1: -------------------------------------------------------------------------------- 1 | 2 | # 1 "" 3 | 4 | 5 | 6 | 7 | char p[] = "x ## y"; 8 | 9 | -------------------------------------------------------------------------------- /cc/cpp/tests/res10: -------------------------------------------------------------------------------- 1 | 2 | # 1 "" 3 | 4 | 5 | 6 | 7 | 8 | int midiopen(int); 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | foo_optarg 17 | -------------------------------------------------------------------------------- /cc/cpp/tests/res11: -------------------------------------------------------------------------------- 1 | 2 | # 1 "" 3 | 4 | 5 | 6 | 7 | 8 | a 9 | a b 10 | a b c 11 | a b c d 12 | 13 | 14 | 15 | 16 | 17 | 18 | __attribute__((__noreturn__)) 19 | 20 | 21 | 1 2 22 | 23 | -------------------------------------------------------------------------------- /cc/cpp/tests/res12: -------------------------------------------------------------------------------- 1 | 2 | # 1 "" 3 | 4 | 5 | 6 | 7 | 8 | 2 2 2 2 2; 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | (0 + 8) + 0, (0 + 8) + 0, (0 + 8) + 0, (0 + 8) + 0, (0 + 8) + 0, (0 + 8) + 0, (0 + 8) + 0, (0 + 8) + 0, (0 + 8) + 0, (0 + 8) + 0, (0 + 8) + 0, (0 + 8) + 0, (0 + 8) + 0, (0 + 8) + 0, (0 + 8) + 0, (0 + 8) + 0, (0 + 8) + 0, (0 + 8) + 0, (0 + 8) + 0, (0 + 8) + 0, (0 + 8) + 0, (0 + 8) + 0, (0 + 8) + 0, (0 + 8) + 0, (0 + 8) + 0, (0 + 8) + 0, (0 + 8) + 0, (0 + 8) + 0, (0 + 8) + 0, (0 + 8) + 0, (0 + 8) + 0, (0 + 8) + 0, (0 + 8) + 0, (0 + 8) + 0, (0 + 8) + 0, (0 + 8) + 0, (0 + 8) + 0, (0 + 8) + 0, (0 + 8) + 0, (0 + 8) + 0, (0 + 8) + 0, (0 + 8) + 0, (0 + 8) + 0, (0 + 8) + 0, (0 + 8) + 0, (0 + 8) + 0, (0 + 8) + 0, (0 + 8) + 0, (0 + 8) + 0, (0 + 8) + 0, (0 + 8) + 0, (0 + 8) + 0, (0 + 8) + 0, (0 + 8) + 0, (0 + 8) + 0, (0 + 8) + 0, (0 + 8) + 0, (0 + 8) + 0, (0 + 8) + 0, (0 + 8) + 0, (0 + 8) + 0, (0 + 8) + 0, (0 + 8) + 0, (0 + 8) + 0, (0 + 8) + 0, (0 + 8) + 0, (0 + 8) + 0, (0 + 8) + 0, (0 + 8) + 0, (0 + 8) + 0, (0 + 8) + 0, (0 + 8) + 0, (0 + 8) + 0, (0 + 8) + 0, (0 + 8) + 0, (0 + 8) + 0, (0 + 8) + 0, (0 + 8) + 0, (0 + 8) + 0, (0 + 8) + 0, (0 + 8) + 0, (0 + 8) + 0, (0 + 8) + 0, (0 + 8) + 0, (0 + 8) + 0, (0 + 8) + 0, (0 + 8) + 0, (0 + 8) + 0, (0 + 8) + 0, (0 + 8) + 0, (0 + 8) + 0, (0 + 8) + 0, (0 + 8) + 0, (0 + 8) + 0, (0 + 8) + 0, (0 + 8) + 0, (0 + 8) + 0, (0 + 8) + 0, (0 + 8) + 0, (0 + 8) + 0, (0 + 8) + 0, (0 + 8) + 0, (0 + 8) + 0, (0 + 8) + 0, (0 + 8) + 0, (0 + 8) + 0, (0 + 8) + 0, (0 + 8) + 0, (0 + 8) + 0, (0 + 8) + 0, (0 + 8) + 0, (0 + 8) + 0, (0 + 8) + 0, (0 + 8) + 0, (0 + 8) + 0, (0 + 8) + 0, (0 + 8) + 0, (0 + 8) + 0, (0 + 8) + 0, (0 + 8) + 0, (0 + 8) + 0, (0 + 8) + 0, (0 + 8) + 0, (0 + 8) + 0, (0 + 8) + 0, (0 + 8) + 0, (0 + 8) + 0, (0 + 8) + 0, (0 + 8) + 0, (0 + 8) + 0, (0 + 8) + 0, (0 + 8) + 0, (0 + 8) + 0, (0 + 8) + 0, (0 + 8) + 0, (0 + 8) + 0, (0 + 8) + 0, (0 + 8) + 0, (0 + 8) + 0, (0 + 8) + 0, (0 + 8) + 0, (0 + 8) + 0, (0 + 8) + 0, (0 + 8) + 0, (0 + 8) + 0, (0 + 8) + 0, (0 + 8) + 0, (0 + 8) + 0, (0 + 8) + 0, (0 + 8) + 0, (0 + 8) + 0, (0 + 8) + 0, (0 + 8) + 0, (0 + 8) + 0, (0 + 8) + 0, (0 + 8) + 0, (0 + 8) + 0, (0 + 8) + 0, (0 + 8) + 0, (0 + 8) + 0, (0 + 8) + 0, (0 + 8) + 0, (0 + 8) + 0, (0 + 8) + 0, (0 + 8) + 0, (0 + 8) + 0, (0 + 8) + 0, (0 + 8) + 0, (0 + 8) + 0, (0 + 8) + 0, (0 + 8) + 0, (0 + 8) + 0, (0 + 8) + 0, (0 + 8) + 0, (0 + 8) + 0, (0 + 8) + 0, (0 + 8) + 0, (0 + 8) + 0, (0 + 8) + 0, (0 + 8) + 0, (0 + 8) + 0, (0 + 8) + 0, (0 + 8) + 0, (0 + 8) + 0, (0 + 8) + 0, (0 + 8) + 0, (0 + 8) + 0, (0 + 8) + 0, (0 + 8) + 0, (0 + 8) + 0, (0 + 8) + 0, (0 + 8) + 0, (0 + 8) + 0, (0 + 8) + 0, (0 + 8) + 0, (0 + 8) + 0, (0 + 8) + 0, (0 + 8) + 0, (0 + 8) + 0, (0 + 8) + 0, (0 + 8) + 0, (0 + 8) + 0, (0 + 8) + 0, (0 + 8) + 0, (0 + 8) + 0, (0 + 8) + 0, (0 + 8) + 0, (0 + 8) + 0, (0 + 8) + 0, (0 + 8) + 0, (0 + 8) + 0, (0 + 8) + 0, (0 + 8) + 0, (0 + 8) + 0, (0 + 8) + 0, (0 + 8) + 0, (0 + 8) + 0, (0 + 8) + 0, (0 + 8) + 0, (0 + 8) + 0, (0 + 8) + 0, (0 + 8) + 0, (0 + 8) + 0, (0 + 8) + 0, (0 + 8) + 0, (0 + 8) + 0, (0 + 8) + 0, (0 + 8) + 0, (0 + 8) + 0, (0 + 8) + 0, (0 + 8) + 0, (0 + 8) + 0, (0 + 8) + 0, (0 + 8) + 0, (0 + 8) + 0, (0 + 8) + 0, (0 + 8) + 0, (0 + 8) + 0, (0 + 8) + 0, (0 + 8) + 0, (0 + 8) + 0, (0 + 8) + 0, (0 + 8) + 0, (0 + 8) + 0, (0 + 8) + 0, (0 + 8) + 0, (0 + 8) + 0, (0 + 8) + 0, (0 + 8) + 0, (0 + 8) + 0, (0 + 8) + 0, (0 + 8) + 0, (0 + 8) + 0, (0 + 8) + 0, (0 + 8) + 0, (0 + 8) + 0, 22 | -------------------------------------------------------------------------------- /cc/cpp/tests/res13: -------------------------------------------------------------------------------- 1 | 2 | # 1 "" 3 | 4 | 5 | 6 | 7 | long 8 | 9 | 10 | 11 | 12 | 13 | 14 | -------------------------------------------------------------------------------- /cc/cpp/tests/res2: -------------------------------------------------------------------------------- 1 | 2 | # 1 "" 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | f(2 * (y+1)) + f(2 * (f(2 * (z[0])))) % f(2 * (0)) + t(1); 18 | f(2 * (2+(3,4)-0,1)) | f(2 * (~ 5)) & 19 | f(2 * (0,1))^m(0,1); 20 | int i[] = { 1, 23, 4, 5, }; 21 | char c[2][6] = { "hello", "" }; 22 | 23 | 24 | 25 | 26 | 27 | 28 | -------------------------------------------------------------------------------- /cc/cpp/tests/res3: -------------------------------------------------------------------------------- 1 | 2 | # 1 "" 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | printf("x" "1" "= %d, x" "2" "= %s", x1, x2); 12 | fputs( 13 | "strncmp(\"abc\\0d\", \"abc\", '\\4') == 0" ": @\n", s); 14 | \#include "vers2.h" 15 | "hello"; 16 | "hello" ", world" 17 | -------------------------------------------------------------------------------- /cc/cpp/tests/res4: -------------------------------------------------------------------------------- 1 | 2 | # 1 "" 3 | 4 | 5 | 6 | (1) 7 | -------------------------------------------------------------------------------- /cc/cpp/tests/res5: -------------------------------------------------------------------------------- 1 | 2 | # 1 "" 3 | 4 | int j[] = { 123, 45, 67, 89, 5 | 10, 11, 12, }; 6 | -------------------------------------------------------------------------------- /cc/cpp/tests/res6: -------------------------------------------------------------------------------- 1 | 2 | # 1 "" 3 | 4 | 5 | foo 6 | -------------------------------------------------------------------------------- /cc/cpp/tests/res7: -------------------------------------------------------------------------------- 1 | 2 | # 1 "" 3 | 4 | 5 | a 6 | YES 7 | -------------------------------------------------------------------------------- /cc/cpp/tests/res8: -------------------------------------------------------------------------------- 1 | 2 | # 1 "" 3 | 4 | 5 | 6 | 7 | 8 | (hej.s_s.s_pos) 9 | 10 | -------------------------------------------------------------------------------- /cc/cpp/tests/res9: -------------------------------------------------------------------------------- 1 | 2 | # 1 "" 3 | 4 | 5 | 6 | ao 7 | -------------------------------------------------------------------------------- /cc/cpp/tests/test1: -------------------------------------------------------------------------------- 1 | #define hash_hash # ## # 2 | #define mkstr(a) # a 3 | #define in_between(a) mkstr(a) 4 | #define join(c, d) in_between(c hash_hash d) 5 | char p[] = join(x, y); // equivalent to 6 | // char p[] = "x ## y"; 7 | -------------------------------------------------------------------------------- /cc/cpp/tests/test10: -------------------------------------------------------------------------------- 1 | #define __CONCAT(x,y) x ## y 2 | #define dev_type_open(n) int n(int) 3 | #define dev_decl(n,t) __CONCAT(dev_type_,t)(__CONCAT(n,t)) 4 | #define cdev_decl(n) dev_decl(n,open) 5 | 6 | cdev_decl(midi); 7 | 8 | # define __GETOPT_PREFIX foo_ 9 | # define __GETOPT_CONCAT(x, y) x ## y 10 | # define __GETOPT_XCONCAT(x, y) __GETOPT_CONCAT (x, y) 11 | # define __GETOPT_ID(y) __GETOPT_XCONCAT (__GETOPT_PREFIX, y) 12 | # define optarg __GETOPT_ID (optarg) 13 | 14 | optarg 15 | -------------------------------------------------------------------------------- /cc/cpp/tests/test11: -------------------------------------------------------------------------------- 1 | #define D1(s, ...) s 2 | #define D2(s, ...) s D1(__VA_ARGS__) 3 | #define D3(s, ...) s D2(__VA_ARGS__) 4 | #define D4(s, ...) s D3(__VA_ARGS__) 5 | 6 | D1(a) 7 | D2(a, b) 8 | D3(a, b, c) 9 | D4(a, b, c, d) 10 | 11 | 12 | #define __sun_attr___noreturn__ __attribute__((__noreturn__)) 13 | #define ___sun_attr_inner(__a) __sun_attr_##__a 14 | #define __sun_attr__(__a) ___sun_attr_inner __a 15 | #define __NORETURN __sun_attr__((__noreturn__)) 16 | __NORETURN 17 | #define X(...) 18 | #define Y(...) 1 __VA_ARGS__ 2 19 | Y(X X() ()) 20 | 21 | -------------------------------------------------------------------------------- /cc/cpp/tests/test12: -------------------------------------------------------------------------------- 1 | #define y 2 2 | #define fe(p) sfe(p) p 3 | #define sfe(p) p 4 | #define Y fe(y) y fe(y) 5 | 6 | Y; 7 | 8 | # define S2B_QMIN 0 9 | # define S2B_CMIN (S2B_QMIN + 8) 10 | #define S2B_1(i) i, 11 | #define S2B_2(i) S2B_1(i) S2B_1(i) 12 | #define S2B_4(i) S2B_2(i) S2B_2(i) 13 | #define S2B_8(i) S2B_4(i) S2B_4(i) 14 | #define S2B_16(i) S2B_8(i) S2B_8(i) 15 | #define S2B_32(i) S2B_16(i) S2B_16(i) 16 | #define S2B_64(i) S2B_32(i) S2B_32(i) 17 | #define S2B_128(i) S2B_64(i) S2B_64(i) 18 | #define S2B_256(i) S2B_128(i) S2B_128(i) 19 | S2B_256(S2B_CMIN + 0) 20 | -------------------------------------------------------------------------------- /cc/cpp/tests/test13: -------------------------------------------------------------------------------- 1 | 2 | #define UL long, foo 3 | #define D(I,F) I 4 | #define E(I) D(I) 5 | E(UL) 6 | 7 | #define FOO 1 8 | 9 | #if (FOO == 1) 10 | 11 | #endif /* FOO */ 12 | -------------------------------------------------------------------------------- /cc/cpp/tests/test2: -------------------------------------------------------------------------------- 1 | #define x 3 2 | #define f(a) f(x * (a)) 3 | #undef x 4 | #define x 2 5 | #define g f 6 | #define z z[0] 7 | #define h g(~ 8 | #define m(a) a(w) 9 | #define w 0,1 10 | #define t(a) a 11 | #define p() int 12 | #define q(x) x 13 | #define r(x,y) x ## y 14 | #define str(x) # x 15 | f(y+1) + f(f(z)) % t(t(g)(0) + t)(1); 16 | g(x+(3,4)-w) | h 5) & m 17 | (f)^m(m); 18 | p() i[q()] = { q(1), r(2,3), r(4,), r(,5), r(,) }; 19 | char c[2][6] = { str(hello), str() }; 20 | /* 21 | * f(2 * (y+1)) + f(2 * (f(2 * (z[0])))) % f(2 * (0)) + t(1); 22 | * f(2 * (2+(3,4)-0,1)) | f(2 * (~ 5)) & f(2 * (0,1))^m(0,1); 23 | * int i[] = { 1, 23, 4, 5, }; 24 | * char c[2][6] = { "hello", "" }; 25 | */ 26 | -------------------------------------------------------------------------------- /cc/cpp/tests/test3: -------------------------------------------------------------------------------- 1 | #define str(s) # s 2 | #define xstr(s) str(s) 3 | #define debug(s, t) printf("x" # s "= %d, x" # t "= %s", \ 4 | x ## s, x ## t) 5 | #define INCFILE(n) vers ## n 6 | #define glue(a, b) a ## b 7 | #define xglue(a, b) glue(a, b) 8 | #define HIGHLOW "hello" 9 | #define LOW LOW ", world" 10 | debug(1, 2); 11 | fputs(str(strncmp("abc\0d", "abc", '\4') // this goes away 12 | == 0) str(: @\n), s); 13 | \#include xstr(INCFILE(2).h) 14 | glue(HIGH, LOW); 15 | xglue(HIGH, LOW) 16 | -------------------------------------------------------------------------------- /cc/cpp/tests/test4: -------------------------------------------------------------------------------- 1 | #define foobar 1 2 | #define C(x,y) x##y 3 | #define D(x) (C(x,bar)) 4 | D(foo) 5 | -------------------------------------------------------------------------------- /cc/cpp/tests/test5: -------------------------------------------------------------------------------- 1 | #define t(x,y,z) x ## y ## z 2 | int j[] = { t(1,2,3), t(,4,5), t(6,,7), t(8,9,), 3 | t(10,,), t(,11,), t(,,12), t(,,) }; 4 | -------------------------------------------------------------------------------- /cc/cpp/tests/test6: -------------------------------------------------------------------------------- 1 | #define X(a,b, \ 2 | c,d) \ 3 | foo 4 | 5 | X(1,2,3,4) 6 | -------------------------------------------------------------------------------- /cc/cpp/tests/test7: -------------------------------------------------------------------------------- 1 | #define a() YES 2 | #define b() a 3 | b() 4 | b()() 5 | -------------------------------------------------------------------------------- /cc/cpp/tests/test8: -------------------------------------------------------------------------------- 1 | // test macro expansion in arguments 2 | #define s_pos s_s.s_pos 3 | #define foo(x) (x) 4 | 5 | //hej.s_pos 6 | foo(hej.s_pos) 7 | 8 | -------------------------------------------------------------------------------- /cc/cpp/tests/test9: -------------------------------------------------------------------------------- 1 | #define C(a,b,c) a##b##c 2 | #define N(x,y) C(x,_,y) 3 | #define A_O ao 4 | N(A,O) 5 | -------------------------------------------------------------------------------- /cc/cxxcom/Makefile.in: -------------------------------------------------------------------------------- 1 | # $Id: Makefile.in,v 1.4 2012/03/15 09:22:12 plunky Exp $ 2 | # 3 | # Makefile.in for cxxcom 4 | # 5 | VPATH=@srcdir@ 6 | srcdir=@srcdir@ 7 | top_srcdir=@top_srcdir@ 8 | builddir=@builddir@ 9 | top_builddir=@top_builddir@ 10 | CC = @CC@ 11 | EXEEXT = @EXEEXT@ 12 | CC_FOR_BUILD = @CC_FOR_BUILD@ 13 | CFLAGS = @CFLAGS@ @ADD_CFLAGS@ 14 | CPPFLAGS = @CPPFLAGS@ @ADD_CPPFLAGS@ -D_ISOC99_SOURCE -DLANG_CXX \ 15 | -Dos_$(TARGOS) -Dmach_$(TARGMACH) \ 16 | -I$(srcdir) -I$(builddir) -I$(top_builddir) -I$(MIPDIR) -I$(MDIR) \ 17 | -I$(top_srcdir)/os/$(TARGOS) 18 | LIBS = @LIBS@ 19 | LDFLAGS = @LDFLAGS@ 20 | LEX = @LEX@ 21 | LFLAGS = 22 | LEX_OUTPUT_ROOT = @LEX_OUTPUT_ROOT@ 23 | YACC = @YACC@ 24 | YFLAGS = @YFLAGS@ 25 | TARGOS = @targos@ 26 | TARGOSVER = @targosver@ 27 | TARGMACH = @targmach@ 28 | prefix = @prefix@ 29 | exec_prefix = @exec_prefix@ 30 | libexecdir = @libexecdir@ 31 | datarootdir = @datarootdir@ 32 | mandir = @mandir@ 33 | strip = @strip@ 34 | INSTALL = @INSTALL@ 35 | INSTALL_PROGRAM = @INSTALL_PROGRAM@ 36 | INSTALL_DATA = @INSTALL_DATA@ 37 | 38 | MDIR=$(top_srcdir)/arch/$(TARGMACH) 39 | MIPDIR=$(top_srcdir)/mip 40 | 41 | DEST=@BINPREFIX@cxxcom$(EXEEXT) 42 | MKEXT=mkext$(EXEEXT) 43 | 44 | all: $(DEST) 45 | 46 | OBJS= builtins.o cgram.o code.o common.o compat.o external.o \ 47 | gcc_compat.o init.o inline.o local.o local2.o main.o cxxcode.o \ 48 | match.o optim.o optim2.o order.o pftn.o reader.o \ 49 | regs.o scan.o stabs.o symtabs.o table.o trees.o 50 | 51 | LOBJS= mkext.lo common.lo table.lo 52 | 53 | HDRS= $(srcdir)/pass1.h $(MIPDIR)/pass2.h $(MIPDIR)/manifest.h \ 54 | $(MDIR)/macdefs.h $(MIPDIR)/node.h $(MIPDIR)/compat.h 55 | 56 | # 57 | # round 1: generate external.[ch], cgram.[ch] & scan.c 58 | # 59 | 60 | $(LOBJS): $(HDRS) 61 | 62 | mkext.lo: $(MIPDIR)/mkext.c 63 | $(CC_FOR_BUILD) $(CFLAGS) $(CPPFLAGS) -DMKEXT -c -o $@ $(MIPDIR)/mkext.c 64 | 65 | common.lo: $(MIPDIR)/common.c 66 | $(CC_FOR_BUILD) $(CFLAGS) $(CPPFLAGS) -DMKEXT -c -o $@ $(MIPDIR)/common.c 67 | 68 | table.lo: $(MDIR)/table.c 69 | $(CC_FOR_BUILD) $(CFLAGS) $(CPPFLAGS) -DMKEXT -c -o $@ $(MDIR)/table.c 70 | 71 | $(MKEXT): $(LOBJS) 72 | $(CC_FOR_BUILD) $(LDFLAGS) $(LOBJS) -o $@ $(LIBS) 73 | 74 | external.c: $(MKEXT) 75 | $(builddir)/$(MKEXT) 76 | 77 | cgram.c: $(srcdir)/cgram.y 78 | $(YACC) $(YFLAGS) -d $(srcdir)/cgram.y 79 | mv -f y.tab.c cgram.c 80 | mv -f y.tab.h cgram.h 81 | 82 | scan.c: $(srcdir)/scan.l 83 | $(LEX) $(LFLAGS) $(srcdir)/scan.l 84 | mv -f $(LEX_OUTPUT_ROOT).c scan.c 85 | 86 | # 87 | # round 2: compile $(OBJS) 88 | # 89 | 90 | $(OBJS): $(HDRS) external.c cgram.c 91 | 92 | builtins.o: $(srcdir)/builtins.c 93 | $(CC) $(CFLAGS) $(CPPFLAGS) -c -o $@ $(srcdir)/builtins.c 94 | 95 | cgram.o: cgram.c 96 | $(CC) $(CFLAGS) $(CPPFLAGS) -c -o $@ cgram.c 97 | 98 | code.o: $(MDIR)/code.c 99 | $(CC) $(CFLAGS) $(CPPFLAGS) -c -o $@ $(MDIR)/code.c 100 | 101 | common.o: $(MIPDIR)/common.c 102 | $(CC) $(CFLAGS) $(CPPFLAGS) -c -o $@ $(MIPDIR)/common.c 103 | 104 | compat.o: $(MIPDIR)/compat.c 105 | $(CC) $(CFLAGS) $(CPPFLAGS) -c -o $@ $(MIPDIR)/compat.c 106 | 107 | cxxcode.o: $(srcdir)/cxxcode.c 108 | $(CC) $(CFLAGS) $(CPPFLAGS) -c -o $@ $(srcdir)/cxxcode.c 109 | 110 | external.o: external.c 111 | $(CC) $(CFLAGS) $(CPPFLAGS) -c -o $@ external.c 112 | 113 | gcc_compat.o: $(srcdir)/gcc_compat.c 114 | $(CC) $(CFLAGS) $(CPPFLAGS) -c -o $@ $(srcdir)/gcc_compat.c 115 | 116 | init.o: $(srcdir)/init.c 117 | $(CC) $(CFLAGS) $(CPPFLAGS) -c -o $@ $(srcdir)/init.c 118 | 119 | inline.o: $(srcdir)/inline.c 120 | $(CC) $(CFLAGS) $(CPPFLAGS) -c -o $@ $(srcdir)/inline.c 121 | 122 | local.o: $(MDIR)/local.c 123 | $(CC) $(CFLAGS) $(CPPFLAGS) -c -o $@ $(MDIR)/local.c 124 | 125 | local2.o: $(MDIR)/local2.c 126 | $(CC) $(CFLAGS) $(CPPFLAGS) -c -o $@ $(MDIR)/local2.c 127 | 128 | main.o: $(srcdir)/main.c 129 | $(CC) $(CFLAGS) $(CPPFLAGS) -c -o $@ $(srcdir)/main.c 130 | 131 | match.o: $(MIPDIR)/match.c 132 | $(CC) $(CFLAGS) $(CPPFLAGS) -c -o $@ $(MIPDIR)/match.c 133 | 134 | optim.o: $(srcdir)/optim.c 135 | $(CC) $(CFLAGS) $(CPPFLAGS) -c -o $@ $(srcdir)/optim.c 136 | 137 | optim2.o: $(MIPDIR)/optim2.c 138 | $(CC) $(CFLAGS) $(CPPFLAGS) -c -o $@ $(MIPDIR)/optim2.c 139 | 140 | order.o: $(MDIR)/order.c 141 | $(CC) $(CFLAGS) $(CPPFLAGS) -c -o $@ $(MDIR)/order.c 142 | 143 | pftn.o: $(srcdir)/pftn.c 144 | $(CC) $(CFLAGS) $(CPPFLAGS) -c -o $@ $(srcdir)/pftn.c 145 | 146 | reader.o: $(MIPDIR)/reader.c 147 | $(CC) $(CFLAGS) $(CPPFLAGS) -c -o $@ $(MIPDIR)/reader.c 148 | 149 | regs.o: $(MIPDIR)/regs.c 150 | $(CC) $(CFLAGS) $(CPPFLAGS) -c -o $@ $(MIPDIR)/regs.c 151 | 152 | scan.o: scan.c 153 | $(CC) $(CFLAGS) $(CPPFLAGS) -c -o $@ scan.c 154 | 155 | stabs.o: $(srcdir)/stabs.c 156 | $(CC) $(CFLAGS) $(CPPFLAGS) -c -o $@ $(srcdir)/stabs.c 157 | 158 | symtabs.o: $(srcdir)/symtabs.c 159 | $(CC) $(CFLAGS) $(CPPFLAGS) -c -o $@ $(srcdir)/symtabs.c 160 | 161 | table.o: $(MDIR)/table.c 162 | $(CC) $(CFLAGS) $(CPPFLAGS) -c -o $@ $(MDIR)/table.c 163 | 164 | trees.o: $(srcdir)/trees.c 165 | $(CC) $(CFLAGS) $(CPPFLAGS) -c -o $@ $(srcdir)/trees.c 166 | 167 | # 168 | # round 3: build $(DEST) 169 | # 170 | 171 | $(DEST): $(OBJS) 172 | $(CC) $(LDFLAGS) $(OBJS) -o $@ $(LIBS) 173 | 174 | install: $(DEST) 175 | test -z "$(DESTDIR)$(libexecdir)" || mkdir -p "$(DESTDIR)$(libexecdir)" 176 | $(INSTALL_PROGRAM) $(DEST) $(DESTDIR)$(libexecdir) 177 | @if [ $(strip) = yes ]; then \ 178 | strip $(DESTDIR)$(libexecdir)/$(DEST) ; \ 179 | echo strip $(DESTDIR)$(libexecdir)/$(DEST) ; \ 180 | fi 181 | test -z "$(DESTDIR)$(mandir)/man1" || mkdir -p "$(DESTDIR)$(mandir)/man1" 182 | # $(INSTALL_DATA) $(srcdir)/ccom.1 $(DESTDIR)$(mandir)/man1/$(DEST).1 183 | 184 | clean: 185 | rm -f $(DEST) $(OBJS) $(MKEXT) $(LOBJS) $(LEX_OUTPUT_ROOT).c \ 186 | scan.c y.tab.[ch] cgram.[ch] external.[ch] 187 | 188 | distclean: clean 189 | rm -f Makefile 190 | -------------------------------------------------------------------------------- /cc/cxxcom/cxxdefs.h: -------------------------------------------------------------------------------- 1 | 2 | 3 | enum { NM_NEW, NM_NWA, NM_DEL, NM_DLA, NM_NORMAL, }; 4 | 5 | enum { LINK_DEF, LINK_C }; /* linkage definitions */ 6 | extern int elnk; 7 | #define SCLINK 00020 /* for symtab */ 8 | 9 | extern int cppdebug; 10 | 11 | /* spole is symbol at base, nscur is where we are in the stack. */ 12 | extern struct symtab *spole, *nscur; 13 | 14 | /* insert a symbol into this something */ 15 | #define INSSYM(sp) (sp->snext = nscur->sup, nscur->sup = sp, sp->sdown = nscur) 16 | #define POPSYM() (nscur = nscur->sdown) 17 | 18 | /* C++-specific node types */ 19 | #define CONST_CAST (MAXOP+35) 20 | #define DYN_CAST (MAXOP+36) 21 | #define REINT_CAST (MAXOP+37) 22 | #define STATIC_CAST (MAXOP+38) 23 | #define NEWKW (MAXOP+39) 24 | #define DELETE (MAXOP+40) 25 | #define NMLIST (MAXOP+41) 26 | 27 | /* C++-specific symtab types */ 28 | #define CLNAME (MAXSTCL+1) /* symtab entry is class */ 29 | #define NSPACE (MAXSTCL+2) /* symtab entry is namespace */ 30 | 31 | char *decoratename(struct symtab *sp, int type); 32 | NODE *cxx_new(NODE *p); 33 | NODE *cxx_delete(NODE *p, int del); 34 | void dclns(NODE *attr, char *n); 35 | struct symtab *cxxlookup(NODE *p, int declare); 36 | void cxxsetname(struct symtab *sp); 37 | void cxxmember(struct symtab *sp); 38 | struct symtab *cxxstrvar(struct symtab *so); 39 | struct symtab *cxxdclstr(char *n); 40 | struct symtab *cxxftnfind(NODE *p, int flags); 41 | struct symtab *cxxdeclvar(NODE *p); 42 | void symtree(void); 43 | NODE *cxxrstruct(int soru, NODE *attr, NODE *t, char *tag); 44 | NODE *cxxmatchftn(NODE *, NODE *); 45 | NODE *cxxaddhidden(NODE *, NODE *); 46 | NODE *cxxstructref(NODE *p, int f, char *name); 47 | -------------------------------------------------------------------------------- /cc/driver/Makefile.in: -------------------------------------------------------------------------------- 1 | # $Id: Makefile.in,v 1.7 2012/03/15 09:22:12 plunky Exp $ 2 | # 3 | # Makefile.in for the cc driver part of pcc. 4 | # 5 | VPATH=@srcdir@ 6 | srcdir=@srcdir@ 7 | top_srcdir=@top_srcdir@ 8 | top_builddir=@top_builddir@ 9 | prefix = @prefix@ 10 | exec_prefix = @exec_prefix@ 11 | bindir = @bindir@ 12 | libdir = @libdir@ 13 | libexecdir = @libexecdir@ 14 | includedir = @includedir@ 15 | datarootdir = @datarootdir@ 16 | mandir = @mandir@ 17 | strip = @strip@ 18 | CC = @CC@ 19 | EXEEXT = @EXEEXT@ 20 | TARGOS = @targos@ 21 | TARGOSVER = @targosver@ 22 | TARGMACH = @targmach@ 23 | TARGET = @target@ 24 | VERSION = @PACKAGE_VERSION@ 25 | PCCLIBDIR = $(libdir)/pcc/$(TARGET)/$(VERSION)/lib 26 | PCCINCDIR = $(libdir)/pcc/$(TARGET)/$(VERSION)/include 27 | CFLAGS = @CFLAGS@ @ADD_CFLAGS@ 28 | CPPFLAGS = @CPPFLAGS@ -DLIBEXECDIR=\"${libexecdir}/\" \ 29 | @ADD_CPPFLAGS@ -DINCLUDEDIR=\"${includedir}/\" \ 30 | -DPCCINCDIR=\"${PCCINCDIR}/\" -DPCCLIBDIR=\"${PCCLIBDIR}/\" \ 31 | -DTARGOS=\"${TARGOS}\" -DTARGOSVER=${TARGOSVER} -Dos_${TARGOS} \ 32 | -DTARGMACH=\"${TARGMACH}\" -Dmach_${TARGMACH} \ 33 | -I${top_builddir} -I${top_srcdir}/os/${TARGOS} -I${MIPDIR} -I${MDIR} 34 | LIBS = @LIBS@ 35 | LDFLAGS = @LDFLAGS@ 36 | INSTALL = @INSTALL@ 37 | INSTALL_PROGRAM = @INSTALL_PROGRAM@ 38 | INSTALL_DATA = @INSTALL_DATA@ 39 | 40 | OBJS=driver.o platform.o strlist.o xalloc.o 41 | DEST=@BINPREFIX@pcc$(EXEEXT) 42 | 43 | MIPDIR=${top_srcdir}/mip 44 | MDIR=${top_srcdir}/arch/$(TARGMACH) 45 | 46 | all: ${DEST} 47 | 48 | ${DEST}: $(OBJS) 49 | $(CC) $(LDFLAGS) $(OBJS) -o $@ $(LIBS) 50 | 51 | .c.o: 52 | $(CC) $(CFLAGS) $(CPPFLAGS) -c -o $@ $< 53 | 54 | install: 55 | test -z "${DESTDIR}$(bindir)" || mkdir -p "${DESTDIR}$(bindir)" 56 | ${INSTALL_PROGRAM} ${DEST} ${DESTDIR}${bindir} 57 | @if [ ${strip} = yes ]; then \ 58 | strip ${DESTDIR}${bindir}/${DEST} ; \ 59 | echo strip ${DESTDIR}${bindir}/${DEST} ; \ 60 | fi 61 | 62 | clean: 63 | rm -f $(OBJS) ${DEST} 64 | 65 | distclean: clean 66 | rm -f Makefile 67 | -------------------------------------------------------------------------------- /cc/driver/driver.h: -------------------------------------------------------------------------------- 1 | /* $Id: driver.h,v 1.2 2011/05/26 16:48:40 plunky Exp $ */ 2 | 3 | /*- 4 | * Copyright (c) 2011 Joerg Sonnenberger . 5 | * All rights reserved. 6 | * 7 | * Redistribution and use in source and binary forms, with or without 8 | * modification, are permitted provided that the following conditions 9 | * are met: 10 | * 11 | * 1. Redistributions of source code must retain the above copyright 12 | * notice, this list of conditions and the following disclaimer. 13 | * 2. Redistributions in binary form must reproduce the above copyright 14 | * notice, this list of conditions and the following disclaimer in 15 | * the documentation and/or other materials provided with the 16 | * distribution. 17 | * 18 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 19 | * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 20 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 21 | * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 22 | * COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 23 | * INCIDENTAL, SPECIAL, EXEMPLARY OR CONSEQUENTIAL DAMAGES (INCLUDING, 24 | * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 25 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED 26 | * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 27 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT 28 | * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 29 | * SUCH DAMAGE. 30 | */ 31 | 32 | #ifndef DRIVER_H 33 | #define DRIVER_H 34 | 35 | #include "strlist.h" 36 | 37 | extern const char *isysroot; 38 | extern const char *sysroot; 39 | extern const char *preprocessor; 40 | extern const char *compiler; 41 | extern const char *assembler; 42 | extern const char *linker; 43 | 44 | extern struct strlist crtdirs; 45 | extern struct strlist sysincdirs; 46 | extern struct strlist libdirs; 47 | extern struct strlist progdirs; 48 | extern struct strlist preprocessor_flags; 49 | extern struct strlist compiler_flags; 50 | extern struct strlist assembler_flags; 51 | extern struct strlist early_linker_flags; 52 | extern struct strlist middle_linker_flags; 53 | extern struct strlist late_linker_flags; 54 | extern struct strlist stdlib_flags; 55 | extern struct strlist early_program_csu_files; 56 | extern struct strlist late_program_csu_files; 57 | extern struct strlist early_dso_csu_files; 58 | extern struct strlist late_dso_csu_files; 59 | 60 | void error(const char *fmt, ...); 61 | 62 | void init_platform_specific(const char *, const char *); 63 | 64 | #endif /* DRIVER_H */ 65 | -------------------------------------------------------------------------------- /cc/driver/strlist.c: -------------------------------------------------------------------------------- 1 | /* $Id: strlist.c,v 1.2 2011/05/26 16:48:40 plunky Exp $ */ 2 | 3 | /*- 4 | * Copyright (c) 2011 Joerg Sonnenberger . 5 | * All rights reserved. 6 | * 7 | * Redistribution and use in source and binary forms, with or without 8 | * modification, are permitted provided that the following conditions 9 | * are met: 10 | * 11 | * 1. Redistributions of source code must retain the above copyright 12 | * notice, this list of conditions and the following disclaimer. 13 | * 2. Redistributions in binary form must reproduce the above copyright 14 | * notice, this list of conditions and the following disclaimer in 15 | * the documentation and/or other materials provided with the 16 | * distribution. 17 | * 18 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 19 | * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 20 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 21 | * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 22 | * COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 23 | * INCIDENTAL, SPECIAL, EXEMPLARY OR CONSEQUENTIAL DAMAGES (INCLUDING, 24 | * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 25 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED 26 | * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 27 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT 28 | * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 29 | * SUCH DAMAGE. 30 | */ 31 | 32 | #include 33 | #include "strlist.h" 34 | #include "xalloc.h" 35 | 36 | void 37 | strlist_init(struct strlist *l) 38 | { 39 | l->first = l->last = NULL; 40 | } 41 | 42 | void 43 | strlist_free(struct strlist *l) 44 | { 45 | struct string *s1, *s2; 46 | 47 | STRLIST_FOREACH_MUTABLE(s1, l, s2) { 48 | free(s1->value); 49 | free(s1); 50 | } 51 | l->first = l->last = NULL; 52 | } 53 | 54 | void 55 | strlist_make_array(const struct strlist *l, char ***a, size_t *len) 56 | { 57 | const struct string *s; 58 | char **i; 59 | 60 | *len = 0; 61 | 62 | STRLIST_FOREACH(s, l) 63 | ++*len; 64 | 65 | *a = xcalloc(*len + 1, sizeof(*i)); 66 | i = *a; 67 | 68 | STRLIST_FOREACH(s, l) 69 | *i++ = xstrdup(s->value); 70 | *i = NULL; 71 | } 72 | 73 | void 74 | strlist_print(const struct strlist *l, FILE *f) 75 | { 76 | const struct string *s; 77 | int first = 1; 78 | 79 | STRLIST_FOREACH(s, l) { 80 | if (!first) 81 | putc(' ', f); 82 | fputs(s->value, f); 83 | first = 0; 84 | } 85 | } 86 | 87 | void 88 | strlist_append_nocopy(struct strlist *l, char *val) 89 | { 90 | struct string *s; 91 | 92 | s = xmalloc(sizeof(*s)); 93 | s->next = NULL; 94 | s->value = val; 95 | if (l->last != NULL) { 96 | l->last->next = s; 97 | l->last = s; 98 | } else { 99 | l->last = s; 100 | l->first = s; 101 | } 102 | } 103 | 104 | void 105 | strlist_append(struct strlist *l, const char *val) 106 | { 107 | strlist_append_nocopy(l, xstrdup(val)); 108 | } 109 | 110 | void 111 | strlist_append_list(struct strlist *l, const struct strlist *l2) 112 | { 113 | struct string *s; 114 | 115 | STRLIST_FOREACH(s, l2) 116 | strlist_append(l, s->value); 117 | } 118 | 119 | void 120 | strlist_append_array(struct strlist *l, const char * const *strings) 121 | { 122 | for (; *strings != NULL; ++strings) 123 | strlist_append(l, *strings); 124 | } 125 | 126 | void 127 | strlist_prepend_nocopy(struct strlist *l, char *val) 128 | { 129 | struct string *s; 130 | 131 | s = xmalloc(sizeof(*s)); 132 | s->next = l->first; 133 | s->value = val; 134 | l->first = s; 135 | if (l->last == NULL) { 136 | l->last = s; 137 | } 138 | } 139 | 140 | void 141 | strlist_prepend(struct strlist *l, const char *val) 142 | { 143 | strlist_prepend_nocopy(l, xstrdup(val)); 144 | } 145 | 146 | void 147 | strlist_prepend_list(struct strlist *l, const struct strlist *l2) 148 | { 149 | struct string *s, *s2, *s3, *s4; 150 | 151 | if (STRLIST_EMPTY(l2)) 152 | return; 153 | 154 | if (STRLIST_EMPTY(l)) { 155 | strlist_append_list(l, l2); 156 | return; 157 | } 158 | 159 | s2 = NULL; 160 | s4 = l->first; 161 | STRLIST_FOREACH(s, l2) { 162 | s3 = xmalloc(sizeof(*s3)); 163 | s3->value = xstrdup(s->value); 164 | s3->next = s4; 165 | if (s2 == NULL) 166 | l->first = s3; 167 | else 168 | s2->next = s3; 169 | } 170 | } 171 | -------------------------------------------------------------------------------- /cc/driver/strlist.h: -------------------------------------------------------------------------------- 1 | /* $Id: strlist.h,v 1.2 2011/05/26 16:48:40 plunky Exp $ */ 2 | 3 | /*- 4 | * Copyright (c) 2011 Joerg Sonnenberger . 5 | * All rights reserved. 6 | * 7 | * Redistribution and use in source and binary forms, with or without 8 | * modification, are permitted provided that the following conditions 9 | * are met: 10 | * 11 | * 1. Redistributions of source code must retain the above copyright 12 | * notice, this list of conditions and the following disclaimer. 13 | * 2. Redistributions in binary form must reproduce the above copyright 14 | * notice, this list of conditions and the following disclaimer in 15 | * the documentation and/or other materials provided with the 16 | * distribution. 17 | * 18 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 19 | * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 20 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 21 | * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 22 | * COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 23 | * INCIDENTAL, SPECIAL, EXEMPLARY OR CONSEQUENTIAL DAMAGES (INCLUDING, 24 | * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 25 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED 26 | * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 27 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT 28 | * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 29 | * SUCH DAMAGE. 30 | */ 31 | 32 | #ifndef STRLIST_H 33 | #define STRLIST_H 34 | 35 | #include 36 | #include 37 | 38 | struct string { 39 | struct string *next; 40 | char *value; 41 | }; 42 | 43 | struct strlist { 44 | struct string *first; 45 | struct string *last; 46 | }; 47 | 48 | void strlist_init(struct strlist *); 49 | void strlist_free(struct strlist *); 50 | void strlist_make_array(const struct strlist *, char ***, size_t *); 51 | void strlist_print(const struct strlist *, FILE *); 52 | 53 | void strlist_prepend(struct strlist *, const char *); 54 | void strlist_prepend_nocopy(struct strlist *, char *); 55 | void strlist_prepend_list(struct strlist *, const struct strlist *); 56 | void strlist_append(struct strlist *, const char *); 57 | void strlist_append_nocopy(struct strlist *, char *); 58 | void strlist_append_list(struct strlist *, const struct strlist *); 59 | void strlist_append_array(struct strlist *, const char * const *); 60 | 61 | #define STRLIST_FIRST(head) ((head)->first) 62 | #define STRLIST_NEXT(elem) ((elem)->next) 63 | #define STRLIST_FOREACH(var, head) \ 64 | for ((var) = STRLIST_FIRST(head); \ 65 | (var) != NULL; \ 66 | (var) = STRLIST_NEXT(var)) 67 | #define STRLIST_FOREACH_MUTABLE(var, head, var2) \ 68 | for ((var) = STRLIST_FIRST(head); \ 69 | (var) != NULL && ((var2) = STRLIST_NEXT(var), 1); \ 70 | (var) = (var2)) 71 | #define STRLIST_EMPTY(head) (STRLIST_FIRST(head) == NULL) 72 | 73 | #endif /* STRLIST_H */ 74 | -------------------------------------------------------------------------------- /cc/driver/xalloc.c: -------------------------------------------------------------------------------- 1 | /* $Id: xalloc.c,v 1.2 2011/05/26 16:48:40 plunky Exp $ */ 2 | 3 | /*- 4 | * Copyright (c) 2011 Joerg Sonnenberger . 5 | * All rights reserved. 6 | * 7 | * Redistribution and use in source and binary forms, with or without 8 | * modification, are permitted provided that the following conditions 9 | * are met: 10 | * 11 | * 1. Redistributions of source code must retain the above copyright 12 | * notice, this list of conditions and the following disclaimer. 13 | * 2. Redistributions in binary form must reproduce the above copyright 14 | * notice, this list of conditions and the following disclaimer in 15 | * the documentation and/or other materials provided with the 16 | * distribution. 17 | * 18 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 19 | * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 20 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 21 | * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 22 | * COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 23 | * INCIDENTAL, SPECIAL, EXEMPLARY OR CONSEQUENTIAL DAMAGES (INCLUDING, 24 | * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 25 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED 26 | * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 27 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT 28 | * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 29 | * SUCH DAMAGE. 30 | */ 31 | 32 | #include 33 | #include 34 | #include 35 | 36 | #include "xalloc.h" 37 | 38 | static void 39 | error(const char *str) 40 | { 41 | fprintf(stderr, "%s\n", str); 42 | exit(1); 43 | } 44 | 45 | void * 46 | xcalloc(size_t elem, size_t len) 47 | { 48 | void *ptr; 49 | 50 | if ((ptr = calloc(elem, len)) == NULL) 51 | error("calloc failed"); 52 | return ptr; 53 | } 54 | 55 | void * 56 | xmalloc(size_t len) 57 | { 58 | void *ptr; 59 | 60 | if ((ptr = malloc(len)) == NULL) 61 | error("malloc failed"); 62 | return ptr; 63 | } 64 | 65 | void * 66 | xrealloc(void *buf, size_t len) 67 | { 68 | void *ptr; 69 | 70 | if ((ptr = realloc(buf, len)) == NULL) 71 | error("realloc failed"); 72 | return ptr; 73 | } 74 | 75 | char * 76 | xstrdup(const char *str) 77 | { 78 | char *buf; 79 | 80 | if ((buf = strdup(str)) == NULL) 81 | error("strdup failed"); 82 | return buf; 83 | } 84 | -------------------------------------------------------------------------------- /cc/driver/xalloc.h: -------------------------------------------------------------------------------- 1 | /* $Id: xalloc.h,v 1.2 2011/05/26 16:48:40 plunky Exp $ */ 2 | 3 | /*- 4 | * Copyright (c) 2011 Joerg Sonnenberger . 5 | * All rights reserved. 6 | * 7 | * Redistribution and use in source and binary forms, with or without 8 | * modification, are permitted provided that the following conditions 9 | * are met: 10 | * 11 | * 1. Redistributions of source code must retain the above copyright 12 | * notice, this list of conditions and the following disclaimer. 13 | * 2. Redistributions in binary form must reproduce the above copyright 14 | * notice, this list of conditions and the following disclaimer in 15 | * the documentation and/or other materials provided with the 16 | * distribution. 17 | * 18 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 19 | * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 20 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 21 | * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 22 | * COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 23 | * INCIDENTAL, SPECIAL, EXEMPLARY OR CONSEQUENTIAL DAMAGES (INCLUDING, 24 | * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 25 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED 26 | * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 27 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT 28 | * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 29 | * SUCH DAMAGE. 30 | */ 31 | 32 | #ifndef XALLOC_H 33 | #define XALLOC_H 34 | 35 | #include 36 | 37 | void *xcalloc(size_t, size_t); 38 | void *xmalloc(size_t); 39 | void *xrealloc(void *, size_t); 40 | char *xstrdup(const char *); 41 | 42 | #endif /* XALLOC_H */ 43 | -------------------------------------------------------------------------------- /config.h.in: -------------------------------------------------------------------------------- 1 | /* config.h.in. Generated from configure.ac by autoheader. */ 2 | 3 | /* Using a.out ABI */ 4 | #undef AOUTABI 5 | 6 | /* Define path to alternate assembler */ 7 | #undef ASSEMBLER 8 | 9 | /* Using Classic 68k ABI */ 10 | #undef CLASSIC68K 11 | 12 | /* Using COFF ABI */ 13 | #undef COFFABI 14 | 15 | /* Define path to alternate compiler */ 16 | #undef COMPILER 17 | 18 | /* Using ECOFF ABI */ 19 | #undef ECOFFABI 20 | 21 | /* Using ELF ABI */ 22 | #undef ELFABI 23 | 24 | /* Enable STABS debugging output */ 25 | #undef STABS 26 | 27 | /* Define to 1 if you have the `basename' function. */ 28 | #undef HAVE_BASENAME 29 | 30 | /* Define to 1 if printf supports C99 size specifiers */ 31 | #undef HAVE_C99_FORMAT 32 | 33 | /* Define to 1 if your compiler supports C99 variadic macros */ 34 | #undef HAVE_CPP_VARARG_MACRO_GCC 35 | 36 | /* Define to 1 if you have the `ffs' function. */ 37 | #undef HAVE_FFS 38 | 39 | /* Define to 1 if you have the `getopt' function. */ 40 | #undef HAVE_GETOPT 41 | 42 | /* Define to 1 if you have the header file. */ 43 | #undef HAVE_INTTYPES_H 44 | 45 | /* Define to 1 if you have the header file. */ 46 | #undef HAVE_LIBGEN_H 47 | 48 | /* Define to 1 if you have the header file. */ 49 | #undef HAVE_MALLOC_H 50 | 51 | /* Define to 1 if you have the header file. */ 52 | #undef HAVE_MEMORY_H 53 | 54 | /* Define to 1 if you have the `mkstemp' function. */ 55 | #undef HAVE_MKSTEMP 56 | 57 | /* Define to 1 if you have the `snprintf' function. */ 58 | #undef HAVE_SNPRINTF 59 | 60 | /* Define to 1 if you have the header file. */ 61 | #undef HAVE_STDINT_H 62 | 63 | /* Define to 1 if you have the header file. */ 64 | #undef HAVE_STDLIB_H 65 | 66 | /* Define to 1 if you have the header file. */ 67 | #undef HAVE_STRINGS_H 68 | 69 | /* Define to 1 if you have the header file. */ 70 | #undef HAVE_STRING_H 71 | 72 | /* Define to 1 if you have the `strlcat' function. */ 73 | #undef HAVE_STRLCAT 74 | 75 | /* Define to 1 if you have the `strlcpy' function. */ 76 | #undef HAVE_STRLCPY 77 | 78 | /* Define to 1 if you have the `strtold' function. */ 79 | #undef HAVE_STRTOLD 80 | 81 | /* Define to 1 if you have the header file. */ 82 | #undef HAVE_SYS_STAT_H 83 | 84 | /* Define to 1 if you have the header file. */ 85 | #undef HAVE_SYS_TYPES_H 86 | 87 | /* Define to 1 if you have that is POSIX.1 compatible. */ 88 | #undef HAVE_SYS_WAIT_H 89 | 90 | /* Define to 1 if you have the header file. */ 91 | #undef HAVE_UNISTD_H 92 | 93 | /* Define to 1 if you have the `vfork' function. */ 94 | #undef HAVE_VFORK 95 | 96 | /* Define to 1 if you have the `vsnprintf' function. */ 97 | #undef HAVE_VSNPRINTF 98 | 99 | /* Define if host is BIG endian */ 100 | #undef HOST_BIG_ENDIAN 101 | 102 | /* Define if host is LITTLE endian */ 103 | #undef HOST_LITTLE_ENDIAN 104 | 105 | /* lex is flex */ 106 | #undef ISFLEX 107 | 108 | /* Define alternate standard lib directory */ 109 | #undef LIBDIR 110 | 111 | /* Define path to alternate linker */ 112 | #undef LINKER 113 | 114 | /* Using Mach-O ABI */ 115 | #undef MACHOABI 116 | 117 | /* Define to the address where bug reports for this package should be sent. */ 118 | #undef PACKAGE_BUGREPORT 119 | 120 | /* Define to the full name of this package. */ 121 | #undef PACKAGE_NAME 122 | 123 | /* Define to the full name and version of this package. */ 124 | #undef PACKAGE_STRING 125 | 126 | /* Define to the one symbol short name of this package. */ 127 | #undef PACKAGE_TARNAME 128 | 129 | /* Define to the version of this package. */ 130 | #undef PACKAGE_VERSION 131 | 132 | /* Major version no */ 133 | #undef PCC_MAJOR 134 | 135 | /* Minor version no */ 136 | #undef PCC_MINOR 137 | 138 | /* Minor minor version no */ 139 | #undef PCC_MINORMINOR 140 | 141 | /* Using PE/COFF ABI */ 142 | #undef PECOFFABI 143 | 144 | /* Define path to alternate preprocessor */ 145 | #undef PREPROCESSOR 146 | 147 | /* Define to 1 if you have the ANSI C header files. */ 148 | #undef STDC_HEADERS 149 | 150 | /* Define alternate standard include directory */ 151 | #undef STDINC 152 | 153 | /* Define if target defaults to BIG endian */ 154 | #undef TARGET_BIG_ENDIAN 155 | 156 | /* Define if target defaults to LITTLE endian */ 157 | #undef TARGET_LITTLE_ENDIAN 158 | 159 | /* Enable thread-local storage (TLS). */ 160 | #undef TLS 161 | 162 | /* Version string */ 163 | #undef VERSSTR 164 | 165 | /* Size of wide-character type in chars */ 166 | #undef WCHAR_SIZE 167 | 168 | /* Type to use for wide characters */ 169 | #undef WCHAR_TYPE 170 | 171 | /* Define to 1 if `lex' declares `yytext' as a `char *' by default, not a 172 | `char[]'. */ 173 | #undef YYTEXT_POINTER 174 | -------------------------------------------------------------------------------- /f77/Makefile.in: -------------------------------------------------------------------------------- 1 | # $Id: Makefile.in,v 1.7 2011/06/07 13:56:05 plunky Exp $ 2 | # 3 | # Makefile.in for top-level of pcc. 4 | # 5 | 6 | @SET_MAKE@ 7 | 8 | ALL_SUBDIRS= f77 fcom 9 | DIST_SUBDIRS= $(ALL_SUBDIRS) 10 | 11 | all install clean: 12 | @for subdir in $(ALL_SUBDIRS); do \ 13 | _nextdir_=$${_thisdir_+$$_thisdir_/}$$subdir; \ 14 | echo "===> $$_nextdir_"; \ 15 | (_thisdir_=$$_nextdir_; export _thisdir_; cd $$subdir && \ 16 | exec $(MAKE) $(MFLAGS) $@) || exit $$?; \ 17 | echo "<=== $$_nextdir_"; \ 18 | done 19 | 20 | distclean: 21 | @for subdir in $(DIST_SUBDIRS); do \ 22 | _nextdir_=$${_thisdir_+$$_thisdir_/}$$subdir; \ 23 | echo "===> $$_nextdir_"; \ 24 | (_thisdir_=$$_nextdir_; export _thisdir_; cd $$subdir && \ 25 | exec $(MAKE) $(MFLAGS) $@) || exit $$?; \ 26 | echo "<=== $$_nextdir_"; \ 27 | done 28 | rm -f Makefile 29 | -------------------------------------------------------------------------------- /f77/f77/Makefile.in: -------------------------------------------------------------------------------- 1 | # $Id: Makefile.in,v 1.20 2012/03/15 09:22:12 plunky Exp $ 2 | # 3 | # Makefile.in for the f77 frontend of pcc. 4 | # 5 | VPATH=@srcdir@ 6 | top_srcdir=@top_srcdir@ 7 | top_builddir=@top_builddir@ 8 | prefix = @prefix@ 9 | exec_prefix = @exec_prefix@ 10 | bindir = @bindir@ 11 | libdir = @libdir@ 12 | libexecdir = @libexecdir@ 13 | includedir = @includedir@ 14 | strip = @strip@ 15 | CC = @CC@ 16 | TARGOS = @targos@ 17 | TARGOSVER = @targosver@ 18 | TARGMACH = @targmach@ 19 | TARGET = @target@ 20 | VERSION = @PACKAGE_VERSION@ 21 | PCCLIBDIR = $(libdir)/pcc/$(TARGET)/$(VERSION)/lib 22 | PCCINCDIR = $(libdir)/pcc/$(TARGET)/$(VERSION)/include 23 | F77LIBDIR=-L${prefix}/lib 24 | CFLAGS = @CFLAGS@ @ADD_CFLAGS@ 25 | CPPFLAGS = @CPPFLAGS@ @ADD_CPPFLAGS@ -DLANG_F77 \ 26 | -DLIBEXECDIR=\"${libexecdir}\" -DINCLUDEDIR=\"${includedir}\" \ 27 | -DPCCINCDIR=\"${PCCINCDIR}/\" -DPCCLIBDIR=\"${PCCLIBDIR}/\" \ 28 | -DLIBDIR=\"${F77LIBDIR}\" -Dmach_${TARGMACH} -Dos_${TARGOS} \ 29 | -I${FCOMDIR} -I${top_builddir} -I${top_srcdir}/os/${TARGOS} -I${MDIR} 30 | LIBS = @LIBS@ 31 | LDFLAGS = @LDFLAGS@ 32 | INSTALL = @INSTALL@ 33 | INSTALL_PROGRAM = @INSTALL_PROGRAM@ 34 | INSTALL_DATA = @INSTALL_DATA@ 35 | OBJS=f77.o 36 | DEST=@BINPREFIX@f77 37 | 38 | MIPDIR=${top_srcdir}/mip 39 | MDIR=${top_srcdir}/arch/$(TARGMACH) 40 | FCOMDIR=${top_srcdir}/f77/fcom 41 | 42 | all: ${DEST} 43 | 44 | ${DEST}: $(OBJS) 45 | $(CC) $(LDFLAGS) $(OBJS) -o $@ $(LIBS) 46 | 47 | .c.o: 48 | $(CC) $(CFLAGS) $(CPPFLAGS) -c -o $@ $< 49 | 50 | install: 51 | ${INSTALL_PROGRAM} ${DEST} ${bindir} 52 | @if [ ${strip} = yes ]; then \ 53 | strip ${bindir}/${DEST} ; \ 54 | echo strip ${bindir}/${DEST} ; \ 55 | fi 56 | 57 | clean: 58 | rm -f $(OBJS) ${DEST} 59 | 60 | distclean: clean 61 | rm -f Makefile 62 | -------------------------------------------------------------------------------- /f77/f77/f77.1: -------------------------------------------------------------------------------- 1 | .\" $Id: f77.1,v 1.2 2008/12/24 17:40:41 sgk Exp $ 2 | .\" 3 | .\" Copyright(C) Caldera International Inc. 2001-2002. All rights reserved. 4 | .\" 5 | .\" Redistribution and use in source and binary forms, with or without 6 | .\" modification, are permitted provided that the following conditions 7 | .\" are met: 8 | .\" 9 | .\" Redistributions of source code and documentation must retain the above 10 | .\" copyright notice, this list of conditions and the following disclaimer. 11 | .\" Redistributions in binary form must reproduce the above copyright 12 | .\" notice, this list of conditionsand the following disclaimer in the 13 | .\" documentation and/or other materials provided with the distribution. 14 | .\" All advertising materials mentioning features or use of this software 15 | .\" must display the following acknowledgement: 16 | .\" This product includes software developed or owned by Caldera 17 | .\" International, Inc. 18 | .\" Neither the name of Caldera International, Inc. nor the names of other 19 | .\" contributors may be used to endorse or promote products derived from 20 | .\" this software without specific prior written permission. 21 | .\" 22 | .\" USE OF THE SOFTWARE PROVIDED FOR UNDER THIS LICENSE BY CALDERA 23 | .\" INTERNATIONAL, INC. AND CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR 24 | .\" IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 25 | .\" WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 26 | .\" DISCLAIMED. IN NO EVENT SHALL CALDERA INTERNATIONAL, INC. BE LIABLE 27 | .\" FOR ANY DIRECT, INDIRECT INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 28 | .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 29 | .\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 30 | .\" HOWEVER CAUSED AND ON ANY THEORY OFLIABILITY, WHETHER IN CONTRACT, 31 | .\" STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING 32 | .\" IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 33 | .\" POSSIBILITY OF SUCH DAMAGE. 34 | .\" 35 | .TH F77 1 36 | .SH NAME 37 | f77 \- Fortran 77 compiler 38 | .SH SYNOPSIS 39 | .B f77 40 | [ option ] ... file ... 41 | .SH DESCRIPTION 42 | .I F77 43 | is the UNIX Fortran 77 compiler. 44 | It accepts several types of arguments: 45 | .PP 46 | Arguments whose names end with `.f' are taken to be 47 | Fortran 77 source programs; 48 | they are compiled, and 49 | each object program is left on the file in the current directory 50 | whose name is that of the source with `.o' substituted 51 | for '.f'. 52 | .PP 53 | Arguments whose names end with `.r' or `.e' are taken to be Ratfor or EFL 54 | source programs, respectively; these are first transformed by the 55 | appropriate preprocessor, then compiled by f77. 56 | .PP 57 | In the same way, 58 | arguments whose names end with `.c' or `.s' are taken to be C or assembly source programs 59 | and are compiled or assembled, producing a `.o' file. 60 | .PP 61 | The following options have the same meaning as in 62 | .IR cc (1). 63 | See 64 | .IR ld (1) 65 | for load-time options. 66 | .TP 67 | .B \-c 68 | Suppress loading and produce `.o' files for each source 69 | file. 70 | .TP 71 | .B \-p 72 | Prepare object files for profiling, see 73 | .IR prof (1). 74 | .TP 75 | .SM 76 | .B \-O 77 | Invoke an 78 | object-code optimizer. 79 | .TP 80 | .SM 81 | .B \-S 82 | Compile the named programs, and leave the 83 | assembler-language output on corresponding files suffixed `.s'. 84 | (No `.o' is created.). 85 | .TP 86 | .B \-f 87 | Use a floating point interpreter (for PDP11's that lack 88 | 11/70-style floating point). 89 | .TP 90 | .BR \-o " output" 91 | Name the final output file 92 | .I output 93 | instead of `a.out'. 94 | .PP 95 | The following options are peculiar to 96 | .IR f77 . 97 | .TP 98 | .SM 99 | .BR \-onetrip 100 | Compile DO loops that are performed at least once if reached. 101 | (Fortran 77 DO loops are not performed at all if the upper limit is smaller than the lower limit.) 102 | .TP 103 | .BR \-u 104 | Make the default type of a variable `undefined' rather than using the default Fortran rules. 105 | .TP 106 | .BR \-q 107 | Suppress printing of procedure names during compilation. 108 | .TP 109 | .BR \-C 110 | Compile code to check that subscripts are within declared array bounds. 111 | .TP 112 | .BR \-w 113 | Suppress all warning messages. 114 | If the option is `\-w66', only Fortran 66 compatibility warnings are suppressed. 115 | .TP 116 | .BR \-F 117 | Apply EFL and Ratfor preprocessor to relevant files, put the result in the file 118 | with the suffix changed to `.f', but do not compile. 119 | .TP 120 | .BR \-m 121 | Apply the M4 preprocessor to each `.r' or `.e' file before transforming 122 | it with the Ratfor or EFL preprocessor. 123 | .TP 124 | .TP 125 | .BI \-E x 126 | Use the string 127 | .I x 128 | as an EFL option in processing `.e' files. 129 | .TP 130 | .BI \-R x 131 | Use the string 132 | .I x 133 | as a Ratfor option in processing `.r' files. 134 | .PP 135 | Other arguments 136 | are taken 137 | to be either loader option arguments, or F77-compatible 138 | object programs, typically produced by an earlier 139 | run, 140 | or perhaps libraries of F77-compatible routines. 141 | These programs, together with the results of any 142 | compilations specified, are loaded (in the order 143 | given) to produce an executable program with name 144 | `a.out'. 145 | .SH FILES 146 | .nf 147 | .ta \w'/usr/lib/libF77.a 'u 148 | file.[fresc] input file 149 | file.o object file 150 | a.out loaded output 151 | ./fort[pid].? temporary 152 | /usr/lib/f77pass1 compiler 153 | /lib/f1 pass 2 154 | /lib/c2 optional optimizer 155 | /usr/lib/libF77.a intrinsic function library 156 | /usr/lib/libI77.a Fortran I/O library 157 | /lib/libc.a C library, see section 3 158 | .fi 159 | .SH "SEE ALSO" 160 | S. I. Feldman, 161 | P. J. Weinberger, 162 | .I 163 | A Portable Fortran 77 Compiler 164 | .br 165 | prof(1), cc(1), ld(1) 166 | .SH DIAGNOSTICS 167 | The diagnostics produced by 168 | .I f77 169 | itself are intended to be 170 | self-explanatory. 171 | Occasional messages may be produced by the loader. 172 | .SH BUGS 173 | The Fortran 66 subset of the language has been 174 | exercised extensively; 175 | the newer features have not. 176 | -------------------------------------------------------------------------------- /f77/fcom/Makefile.in: -------------------------------------------------------------------------------- 1 | # $Id: Makefile.in,v 1.22 2012/03/15 09:22:13 plunky Exp $ 2 | # 3 | # Makefile for the Fortran 77 compiler 4 | # 5 | srcdir=@srcdir@ 6 | top_srcdir=@top_srcdir@ 7 | builddir=@builddir@ 8 | top_builddir=@top_builddir@ 9 | CC = @CC@ 10 | CC_FOR_BUILD = @CC_FOR_BUILD@ 11 | CFLAGS = @CFLAGS@ @ADD_CFLAGS@ 12 | CPPFLAGS = @CPPFLAGS@ @ADD_CPPFLAGS@ -DFCOM -DLANG_F77 \ 13 | -Dos_$(TARGOS) -Dmach_$(TARGMACH) \ 14 | -I$(srcdir) -I$(builddir) -I$(top_builddir) \ 15 | -I$(MIPDIR) -I$(MDIR) -I$(top_srcdir)/os/$(TARGOS) 16 | LIBS = @LIBS@ 17 | LDFLAGS = @LDFLAGS@ 18 | LEX = @LEX@ 19 | LFLAGS = 20 | LEX_OUTPUT_ROOT = @LEX_OUTPUT_ROOT@ 21 | YACC = @YACC@ 22 | YFLAGS = @YFLAGS@ 23 | TARGOS = @targos@ 24 | TARGOSVER = @targosver@ 25 | TARGMACH = @targmach@ 26 | prefix = @prefix@ 27 | exec_prefix = @exec_prefix@ 28 | libexecdir = @libexecdir@ 29 | datarootdir = @datarootdir@ 30 | mandir = @mandir@ 31 | strip = @strip@ 32 | INSTALL = @INSTALL@ 33 | INSTALL_PROGRAM = @INSTALL_PROGRAM@ 34 | INSTALL_DATA = @INSTALL_DATA@ 35 | 36 | MDIR=$(top_srcdir)/arch/$(TARGMACH) 37 | MIPDIR=$(top_srcdir)/mip 38 | 39 | DEST=@BINPREFIX@fcom$(EXEEXT) 40 | MKEXT=mkext$(EXEEXT) 41 | 42 | OBJS= common.o compat.o data.o equiv.o error.o exec.o expr.o \ 43 | external.o flocal.o gram.o init.o intr.o io.o lex.o \ 44 | local2.o main.o match.o misc.o optim2.o order.o proc.o \ 45 | put.o putscj.o reader.o regs.o table.o 46 | 47 | LOBJS= common.lo mkext.lo table.lo 48 | 49 | HDRS= $(srcdir)/defs.h $(srcdir)/defines.h $(srcdir)/ftypes.h \ 50 | $(MIPDIR)/pass2.h $(MIPDIR)/manifest.h $(MIPDIR)/node.h \ 51 | $(MDIR)/macdefs.h 52 | 53 | GSRC= $(srcdir)/gram.head $(srcdir)/gram.dcl $(srcdir)/gram.expr \ 54 | $(srcdir)/gram.exec $(srcdir)/gram.io 55 | 56 | all: $(DEST) 57 | 58 | # 59 | # round 1: generate external.[ch] & gram.[ch] 60 | # 61 | 62 | $(LOBJS): $(HDRS) 63 | 64 | common.lo: $(MIPDIR)/common.c 65 | $(CC_FOR_BUILD) $(CFLAGS) $(CPPFLAGS) -DMKEXT -c -o $@ $(MIPDIR)/common.c 66 | 67 | mkext.lo: $(MIPDIR)/mkext.c 68 | $(CC_FOR_BUILD) $(CFLAGS) $(CPPFLAGS) -DMKEXT -c -o $@ $(MIPDIR)/mkext.c 69 | 70 | table.lo: $(MDIR)/table.c 71 | $(CC_FOR_BUILD) $(CFLAGS) $(CPPFLAGS) -DMKEXT -c -o $@ $(MDIR)/table.c 72 | 73 | $(MKEXT): $(LOBJS) 74 | $(CC_FOR_BUILD) $(LDFLAGS) $(LOBJS) -o $@ $(LIBS) 75 | 76 | external.c: $(MKEXT) 77 | $(builddir)/$(MKEXT) 78 | 79 | gram.c: $(GSRC) $(srcdir)/tokens 80 | ( grep -n . < $(srcdir)/tokens | sed "s/\([^:]*\):\(.*\)/%token \2 \1/"; \ 81 | cat $(GSRC) ) > gram.y 82 | $(YACC) $(YFLAGS) -d gram.y 83 | mv -f y.tab.c gram.c 84 | mv -f y.tab.h gram.h 85 | 86 | # 87 | # round 2: compile $(OBJS) 88 | # 89 | 90 | $(OBJS): $(HDRS) external.c gram.c 91 | 92 | common.o: $(MIPDIR)/common.c 93 | $(CC) $(CFLAGS) $(CPPFLAGS) -c -o $@ $(MIPDIR)/common.c 94 | 95 | compat.o: $(MIPDIR)/compat.c 96 | $(CC) $(CFLAGS) $(CPPFLAGS) -c -o $@ $(MIPDIR)/compat.c 97 | 98 | data.o: $(srcdir)/data.c 99 | $(CC) $(CFLAGS) $(CPPFLAGS) -c -o $@ $(srcdir)/data.c 100 | 101 | equiv.o: $(srcdir)/equiv.c 102 | $(CC) $(CFLAGS) $(CPPFLAGS) -c -o $@ $(srcdir)/equiv.c 103 | 104 | error.o: $(srcdir)/error.c 105 | $(CC) $(CFLAGS) $(CPPFLAGS) -c -o $@ $(srcdir)/error.c 106 | 107 | exec.o: $(srcdir)/exec.c 108 | $(CC) $(CFLAGS) $(CPPFLAGS) -c -o $@ $(srcdir)/exec.c 109 | 110 | expr.o: $(srcdir)/expr.c 111 | $(CC) $(CFLAGS) $(CPPFLAGS) -c -o $@ $(srcdir)/expr.c 112 | 113 | external.o: external.c 114 | $(CC) $(CFLAGS) $(CPPFLAGS) -c -o $@ external.c 115 | 116 | flocal.o: $(MDIR)/flocal.c 117 | $(CC) $(CFLAGS) $(CPPFLAGS) -c -o $@ $(MDIR)/flocal.c 118 | 119 | gram.o: gram.c 120 | $(CC) $(CFLAGS) $(CPPFLAGS) -c -o $@ gram.c 121 | 122 | init.o: $(srcdir)/init.c 123 | $(CC) $(CFLAGS) $(CPPFLAGS) -c -o $@ $(srcdir)/init.c 124 | 125 | intr.o: $(srcdir)/intr.c 126 | $(CC) $(CFLAGS) $(CPPFLAGS) -c -o $@ $(srcdir)/intr.c 127 | 128 | io.o: $(srcdir)/io.c 129 | $(CC) $(CFLAGS) $(CPPFLAGS) -c -o $@ $(srcdir)/io.c 130 | 131 | lex.o: $(srcdir)/lex.c 132 | $(CC) $(CFLAGS) $(CPPFLAGS) -c -o $@ $(srcdir)/lex.c 133 | 134 | local2.o: $(MDIR)/local2.c 135 | $(CC) $(CFLAGS) $(CPPFLAGS) -c -o $@ $(MDIR)/local2.c 136 | 137 | main.o: $(srcdir)/main.c 138 | $(CC) $(CFLAGS) $(CPPFLAGS) -c -o $@ $(srcdir)/main.c 139 | 140 | match.o: $(MIPDIR)/match.c 141 | $(CC) $(CFLAGS) $(CPPFLAGS) -c -o $@ $(MIPDIR)/match.c 142 | 143 | misc.o: $(srcdir)/misc.c 144 | $(CC) $(CFLAGS) $(CPPFLAGS) -c -o $@ $(srcdir)/misc.c 145 | 146 | optim2.o: $(MIPDIR)/optim2.c 147 | $(CC) $(CFLAGS) $(CPPFLAGS) -c -o $@ $(MIPDIR)/optim2.c 148 | 149 | order.o: $(MDIR)/order.c 150 | $(CC) $(CFLAGS) $(CPPFLAGS) -c -o $@ $(MDIR)/order.c 151 | 152 | proc.o: $(srcdir)/proc.c 153 | $(CC) $(CFLAGS) $(CPPFLAGS) -c -o $@ $(srcdir)/proc.c 154 | 155 | put.o: $(srcdir)/put.c 156 | $(CC) $(CFLAGS) $(CPPFLAGS) -c -o $@ $(srcdir)/put.c 157 | 158 | putscj.o: $(srcdir)/putscj.c 159 | $(CC) $(CFLAGS) $(CPPFLAGS) -c -o $@ $(srcdir)/putscj.c 160 | 161 | reader.o: $(MIPDIR)/reader.c 162 | $(CC) $(CFLAGS) $(CPPFLAGS) -c -o $@ $(MIPDIR)/reader.c 163 | 164 | regs.o: $(MIPDIR)/regs.c 165 | $(CC) $(CFLAGS) $(CPPFLAGS) -c -o $@ $(MIPDIR)/regs.c 166 | 167 | table.o: $(MDIR)/table.c 168 | $(CC) $(CFLAGS) $(CPPFLAGS) -c -o $@ $(MDIR)/table.c 169 | 170 | # 171 | # round 3: build $(DEST) 172 | # 173 | 174 | $(DEST): $(OBJS) 175 | $(CC) $(LDFLAGS) $(OBJS) -o $@ $(LIBS) 176 | 177 | install: $(DEST) 178 | test -z "$(DESTDIR)$(libexecdir)" || mkdir -p "$(DESTDIR)$(libexecdir)" 179 | $(INSTALL_PROGRAM) $(DEST) $(DESTDIR)$(libexecdir) 180 | @if [ $(strip) = yes ]; then \ 181 | strip $(DESTDIR)$(libexecdir)/$(DEST) ; \ 182 | echo strip $(DESTDIR)$(libexecdir)/$(DEST) ; \ 183 | fi 184 | 185 | clean: 186 | rm -f $(DEST) $(OBJS) $(MKEXT) $(LOBJS) \ 187 | y.tab.[ch] gram.[ych] external.[ch] 188 | 189 | distclean: clean 190 | rm -f Makefile 191 | -------------------------------------------------------------------------------- /f77/fcom/error.c: -------------------------------------------------------------------------------- 1 | /* $Id: error.c,v 1.8 2008/05/10 07:53:41 ragge Exp $ */ 2 | /* 3 | * Copyright(C) Caldera International Inc. 2001-2002. All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions 7 | * are met: 8 | * 9 | * Redistributions of source code and documentation must retain the above 10 | * copyright notice, this list of conditions and the following disclaimer. 11 | * Redistributions in binary form must reproduce the above copyright 12 | * notice, this list of conditions and the following disclaimer in the 13 | * documentation and/or other materials provided with the distribution. 14 | * All advertising materials mentioning features or use of this software 15 | * must display the following acknowledgement: 16 | * This product includes software developed or owned by Caldera 17 | * International, Inc. 18 | * Neither the name of Caldera International, Inc. nor the names of other 19 | * contributors may be used to endorse or promote products derived from 20 | * this software without specific prior written permission. 21 | * 22 | * USE OF THE SOFTWARE PROVIDED FOR UNDER THIS LICENSE BY CALDERA 23 | * INTERNATIONAL, INC. AND CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR 24 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 25 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 26 | * DISCLAIMED. IN NO EVENT SHALL CALDERA INTERNATIONAL, INC. BE LIABLE 27 | * FOR ANY DIRECT, INDIRECT INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 28 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 29 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 30 | * HOWEVER CAUSED AND ON ANY THEORY OFLIABILITY, WHETHER IN CONTRACT, 31 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING 32 | * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 33 | * POSSIBILITY OF SUCH DAMAGE. 34 | */ 35 | 36 | #include 37 | 38 | #include "defines.h" 39 | #include "defs.h" 40 | 41 | void 42 | warn(char *s, ...) 43 | { 44 | va_list ap; 45 | 46 | if(nowarnflag) 47 | return; 48 | 49 | va_start(ap, s); 50 | fprintf(diagfile, "Warning on line %d of %s: ", lineno, infname); 51 | vfprintf(diagfile, s, ap); 52 | fprintf(diagfile, "\n"); 53 | va_end(ap); 54 | ++nwarn; 55 | } 56 | 57 | void 58 | err(char *s, ...) 59 | { 60 | va_list ap; 61 | 62 | va_start(ap, s); 63 | fprintf(diagfile, "Error on line %d of %s: ", lineno, infname); 64 | vfprintf(diagfile, s, ap); 65 | fprintf(diagfile, "\n"); 66 | va_end(ap); 67 | ++nerr; 68 | } 69 | 70 | void 71 | yyerror(s) 72 | char *s; 73 | { err(s); } 74 | 75 | 76 | void 77 | dclerr(s, v) 78 | char *s; 79 | struct bigblock *v; 80 | { 81 | char buff[100]; 82 | 83 | if(v) { 84 | sprintf(buff, "Declaration error for %s: %s", 85 | varstr(VL, v->b_name.varname), s); 86 | err( buff); 87 | } else 88 | err1("Declaration error %s", s); 89 | } 90 | 91 | 92 | void 93 | execerr(char *s, ...) 94 | { 95 | va_list ap; 96 | 97 | va_start(ap, s); 98 | fprintf(diagfile, "Error on line %d of %s: Execution error ", 99 | lineno, infname); 100 | vfprintf(diagfile, s, ap); 101 | fprintf(diagfile, "\n"); 102 | va_end(ap); 103 | ++nerr; 104 | } 105 | 106 | void 107 | fatal(char *s, ...) 108 | { 109 | va_list ap; 110 | 111 | va_start(ap, s); 112 | fprintf(diagfile, "Compiler error line %d of %s: ", lineno, infname); 113 | vfprintf(diagfile, s, ap); 114 | fprintf(diagfile, "\n"); 115 | va_end(ap); 116 | 117 | if(debugflag) 118 | abort(); 119 | done(3); 120 | exit(3); 121 | } 122 | -------------------------------------------------------------------------------- /f77/fcom/ftypes.h: -------------------------------------------------------------------------------- 1 | /* $Id: ftypes.h,v 1.5 2008/12/19 08:08:48 ragge Exp $ */ 2 | /* 3 | * Copyright(C) Caldera International Inc. 2001-2002. All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions 7 | * are met: 8 | * 9 | * Redistributions of source code and documentation must retain the above 10 | * copyright notice, this list of conditions and the following disclaimer. 11 | * Redistributions in binary form must reproduce the above copyright 12 | * notice, this list of conditionsand the following disclaimer in the 13 | * documentation and/or other materials provided with the distribution. 14 | * All advertising materials mentioning features or use of this software 15 | * must display the following acknowledgement: 16 | * This product includes software developed or owned by Caldera 17 | * International, Inc. 18 | * Neither the name of Caldera International, Inc. nor the names of other 19 | * contributors may be used to endorse or promote products derived from 20 | * this software without specific prior written permission. 21 | * 22 | * USE OF THE SOFTWARE PROVIDED FOR UNDER THIS LICENSE BY CALDERA 23 | * INTERNATIONAL, INC. AND CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR 24 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 25 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 26 | * DISCLAIMED. IN NO EVENT SHALL CALDERA INTERNATIONAL, INC. BE LIABLE 27 | * FOR ANY DIRECT, INDIRECT INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 28 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 29 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 30 | * HOWEVER CAUSED AND ON ANY THEORY OFLIABILITY, WHETHER IN CONTRACT, 31 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING 32 | * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 33 | * POSSIBILITY OF SUCH DAMAGE. 34 | */ 35 | /* variable types 36 | * numeric assumptions: 37 | * int < reals < complexes 38 | * TYDREAL-TYREAL = TYDCOMPLEX-TYCOMPLEX 39 | */ 40 | 41 | #ifndef _FTYPES_H_ 42 | #define _FTYPES_H_ 43 | 44 | 45 | #define TYUNKNOWN 0 46 | #define TYADDR 1 47 | #define TYSHORT 2 48 | #define TYLONG 3 49 | #define TYREAL 4 50 | #define TYDREAL 5 51 | #define TYCOMPLEX 6 52 | #define TYDCOMPLEX 7 53 | #define TYLOGICAL 8 54 | #define TYCHAR 9 55 | #define TYSUBR 10 56 | #define TYERROR 11 57 | 58 | #define NTYPES (TYERROR+1) 59 | 60 | /* 61 | * Type conversion from pcc to f77 internal format. 62 | */ 63 | #define FSZADDR (SZPOINT(0)/SZCHAR) /* XXX - typecheck? */ 64 | #define FSZSHORT (SZSHORT/SZCHAR) 65 | #define FSZINT (SZINT/SZCHAR) 66 | #define FSZLONG (SZLONG/SZCHAR) 67 | #define ALIADDR (ALPOINT/ALCHAR) 68 | #define ALISHORT (ALSHORT/ALCHAR) 69 | #define ALILONG (ALLONG/ALCHAR) 70 | #define ALIDOUBLE (ALDOUBLE/ALCHAR) 71 | 72 | #ifndef SZINT 73 | #include "macdefs.h" 74 | #endif 75 | #if SZINT == SZSHORT 76 | #define TYINT TYSHORT 77 | #else /* SZLONG >= SZINT */ 78 | #define TYINT TYLONG 79 | #endif 80 | 81 | #define TYLENG TYLONG 82 | #endif /* !_FTYPES_H_ */ 83 | -------------------------------------------------------------------------------- /f77/fcom/gram.exec: -------------------------------------------------------------------------------- 1 | exec: iffable 2 | | SDO end_spec label opt_comma dospec 3 | { 4 | if($3->labdefined) 5 | execerr("no backward DO loops"); 6 | $3->blklevel = blklevel+1; 7 | exdo($3->labelno, $5); 8 | } 9 | | logif iffable 10 | { exendif(); thiswasbranch = NO; } 11 | | logif STHEN 12 | | SELSEIF end_spec SLPAR expr SRPAR STHEN 13 | { exelif($4); lastwasbranch = NO; } 14 | | SELSE end_spec 15 | { exelse(); lastwasbranch = NO; } 16 | | SENDIF end_spec 17 | { exendif(); lastwasbranch = NO; } 18 | ; 19 | 20 | logif: SLOGIF end_spec SLPAR expr SRPAR 21 | { exif($4); } 22 | ; 23 | 24 | dospec: name SEQUALS exprlist 25 | { $$ = mkchain($1, $3); } 26 | ; 27 | 28 | iffable: let lhs SEQUALS expr 29 | { exequals($2, $4); } 30 | | SASSIGN end_spec labelval STO name 31 | { exassign($5, $3); } 32 | | SCONTINUE end_spec 33 | | goto 34 | | io 35 | { inioctl = NO; } 36 | | SARITHIF end_spec SLPAR expr SRPAR label SCOMMA label SCOMMA label 37 | { exarif($4, $6, $8, $10); thiswasbranch = YES; } 38 | | call 39 | { excall($1, 0, 0, labarray); } 40 | | call SLPAR SRPAR 41 | { excall($1, 0, 0, labarray); } 42 | | call SLPAR callarglist SRPAR 43 | { excall($1, mklist($3), nstars, labarray); } 44 | | SRETURN end_spec opt_expr 45 | { exreturn($3); thiswasbranch = YES; } 46 | | stop end_spec opt_expr 47 | { exstop($1, $3); thiswasbranch = $1; } 48 | ; 49 | 50 | let: SLET 51 | { if(parstate == OUTSIDE) 52 | { 53 | newproc(); 54 | startproc(0, CLMAIN); 55 | } 56 | } 57 | ; 58 | 59 | goto: SGOTO end_spec label 60 | { exgoto($3); thiswasbranch = YES; } 61 | | SASGOTO end_spec name 62 | { exasgoto($3); thiswasbranch = YES; } 63 | | SASGOTO end_spec name opt_comma SLPAR labellist SRPAR 64 | { exasgoto($3); thiswasbranch = YES; } 65 | | SCOMPGOTO end_spec SLPAR labellist SRPAR opt_comma expr 66 | { putcmgo(fixtype($7), nstars, labarray); } 67 | ; 68 | 69 | opt_comma: 70 | | SCOMMA 71 | ; 72 | 73 | call: SCALL end_spec name 74 | { nstars = 0; $$ = $3; } 75 | ; 76 | 77 | callarglist: callarg 78 | { $$ = ($1 ? mkchain($1,0) : 0); } 79 | | callarglist SCOMMA callarg 80 | { if($3) { 81 | if($1) $$ = hookup($1, mkchain($3,0)); 82 | else $$ = mkchain($3,0); 83 | } 84 | } 85 | ; 86 | 87 | callarg: expr 88 | | SSTAR label 89 | { labarray[nstars++] = $2; $$ = 0; } 90 | ; 91 | 92 | stop: SPAUSE 93 | { $$ = 0; } 94 | | SSTOP 95 | { $$ = 1; } 96 | ; 97 | 98 | exprlist: expr 99 | { $$ = mkchain($1, 0); } 100 | | exprlist SCOMMA expr 101 | { $$ = hookup($1, mkchain($3,0) ); } 102 | ; 103 | 104 | end_spec: 105 | { if(parstate == OUTSIDE) 106 | { 107 | newproc(); 108 | startproc(0, CLMAIN); 109 | } 110 | if(parstate < INDATA) enddcl(); 111 | } 112 | ; 113 | -------------------------------------------------------------------------------- /f77/fcom/gram.expr: -------------------------------------------------------------------------------- 1 | funarglist: 2 | { $$ = 0; } 3 | | funargs 4 | ; 5 | 6 | funargs: expr 7 | { $$ = mkchain($1, 0); } 8 | | funargs SCOMMA expr 9 | { $$ = hookup($1, mkchain($3,0) ); } 10 | ; 11 | 12 | 13 | expr: uexpr 14 | | SLPAR expr SRPAR { $$ = $2; } 15 | | complex_const 16 | ; 17 | 18 | uexpr: lhs 19 | | simple_const 20 | | expr addop expr %prec SPLUS 21 | { $$ = mkexpr($2, $1, $3); } 22 | | expr SSTAR expr 23 | { $$ = mkexpr(OPSTAR, $1, $3); } 24 | | expr SSLASH expr 25 | { $$ = mkexpr(OPSLASH, $1, $3); } 26 | | expr SPOWER expr 27 | { $$ = mkexpr(OPPOWER, $1, $3); } 28 | | addop expr %prec SSTAR 29 | { if($1 == OPMINUS) 30 | $$ = mkexpr(OPNEG, $2, 0); 31 | else $$ = $2; 32 | } 33 | | expr relop expr %prec SEQ 34 | { $$ = mkexpr($2, $1, $3); } 35 | | expr SEQV expr 36 | { $$ = mkexpr(OPEQV, $1,$3); } 37 | | expr SNEQV expr 38 | { $$ = mkexpr(OPNEQV, $1, $3); } 39 | | expr SOR expr 40 | { $$ = mkexpr(OPOR, $1, $3); } 41 | | expr SAND expr 42 | { $$ = mkexpr(OPAND, $1, $3); } 43 | | SNOT expr 44 | { $$ = mkexpr(OPNOT, $2, 0); } 45 | | expr SCONCAT expr 46 | { $$ = mkexpr(OPCONCAT, $1, $3); } 47 | ; 48 | 49 | addop: SPLUS { $$ = OPPLUS; } 50 | | SMINUS { $$ = OPMINUS; } 51 | ; 52 | 53 | relop: SEQ { $$ = OPEQ; } 54 | | SGT { $$ = OPGT; } 55 | | SLT { $$ = OPLT; } 56 | | SGE { $$ = OPGE; } 57 | | SLE { $$ = OPLE; } 58 | | SNE { $$ = OPNE; } 59 | ; 60 | 61 | lhs: name 62 | { $$ = mkprim($1, 0, 0, 0); } 63 | | name SLPAR opt_expr SCOLON opt_expr SRPAR 64 | { $$ = mkprim($1, 0, $3, $5); } 65 | | name SLPAR funarglist SRPAR 66 | { $$ = mkprim($1, mklist($3), 0, 0); } 67 | | name SLPAR funarglist SRPAR SLPAR opt_expr SCOLON opt_expr SRPAR 68 | { $$ = mkprim($1, mklist($3), $6, $8); } 69 | ; 70 | 71 | opt_expr: 72 | { $$ = 0; } 73 | | expr 74 | ; 75 | 76 | simple: name 77 | { if($1->vclass == CLPARAM) 78 | $$ = cpexpr($1->b_param.paramval); 79 | } 80 | | simple_const 81 | ; 82 | 83 | simple_const: STRUE { $$ = mklogcon(1); } 84 | | SFALSE { $$ = mklogcon(0); } 85 | | SHOLLERITH { $$ = mkstrcon(toklen, token); } 86 | | SICON { $$ = mkintcon( convci(toklen, token) ); } 87 | | SRCON { $$ = mkrealcon(TYREAL, convcd(toklen, token)); } 88 | | SDCON { $$ = mkrealcon(TYDREAL, convcd(toklen, token)); } 89 | ; 90 | 91 | complex_const: SLPAR uexpr SCOMMA uexpr SRPAR 92 | { $$ = mkcxcon($2,$4); } 93 | ; 94 | 95 | bit_const: SHEXCON 96 | { $$ = mkbitcon(4, toklen, token); } 97 | | SOCTCON 98 | { $$ = mkbitcon(3, toklen, token); } 99 | | SBITCON 100 | { $$ = mkbitcon(1, toklen, token); } 101 | ; 102 | 103 | fexpr: unpar_fexpr 104 | | SLPAR fexpr SRPAR 105 | { $$ = $2; } 106 | ; 107 | 108 | unpar_fexpr: lhs 109 | | simple_const 110 | | fexpr addop fexpr %prec SPLUS 111 | { $$ = mkexpr($2, $1, $3); } 112 | | fexpr SSTAR fexpr 113 | { $$ = mkexpr(OPSTAR, $1, $3); } 114 | | fexpr SSLASH fexpr 115 | { $$ = mkexpr(OPSLASH, $1, $3); } 116 | | fexpr SPOWER fexpr 117 | { $$ = mkexpr(OPPOWER, $1, $3); } 118 | | addop fexpr %prec SSTAR 119 | { if($1 == OPMINUS) 120 | $$ = mkexpr(OPNEG, $2, 0); 121 | else $$ = $2; 122 | } 123 | | fexpr SCONCAT fexpr 124 | { $$ = mkexpr(OPCONCAT, $1, $3); } 125 | ; 126 | -------------------------------------------------------------------------------- /f77/fcom/gram.head: -------------------------------------------------------------------------------- 1 | %{ 2 | 3 | #include "defines.h" 4 | #include "defs.h" 5 | 6 | static int nstars; 7 | static int ndim; 8 | static int vartype; 9 | static ftnint varleng; 10 | struct uux dims[8]; 11 | static struct labelblock *labarray[100]; 12 | static int lastwasbranch = NO; 13 | static int thiswasbranch = NO; 14 | 15 | %} 16 | 17 | /* Specify precedences and associativies. */ 18 | 19 | %left SCOMMA 20 | %nonassoc SCOLON 21 | %right SEQUALS 22 | %left SEQV SNEQV 23 | %left SOR 24 | %left SAND 25 | %left SNOT 26 | %nonassoc SLT SGT SLE SGE SEQ SNE 27 | %left SCONCAT 28 | %left SPLUS SMINUS 29 | %left SSTAR SSLASH 30 | %right SPOWER 31 | 32 | %union { 33 | struct labelblock *label; 34 | struct extsym *extsym; 35 | 36 | bigptr bigptr; 37 | chainp chainp; 38 | 39 | ftnint fint; 40 | char *str; 41 | char token; 42 | int num; 43 | } 44 | 45 | %type