%{ #include "c.h" #define NODEPTR_TYPE Node #define OP_LABEL(p) ((p)->op) #define LEFT_CHILD(p) ((p)->kids[0]) #define RIGHT_CHILD(p) ((p)->kids[1]) #define STATE_LABEL(p) ((p)->x.state) static void address(Symbol, Symbol, long); static void defaddress(Symbol); static void defconst(int, int, Value); static void defstring(int, char *); static void defsymbol(Symbol); static void emit2(Node); static void export(Symbol); static void function(Symbol, Symbol [], Symbol [], int); static void global(Symbol); static void import(Symbol); static void local(Symbol); static void progbeg(int, char **); static void progend(void); static void segment(int); static void space(int); static void blockbeg(Env* env); static void blockend(Env* env); extern void stackemit(Node forest); extern Node stackgen(Node forest); extern void swtch(Symbol label); %} %start stmt %term STACKP=727 %term COPYP=759 %term CNSTF4=4113 %term CNSTF8=8209 %term CNSTI1=1045 %term CNSTI2=2069 %term CNSTI4=4117 %term CNSTI8=8213 %term CNSTP4=4119 %term CNSTU1=1046 %term CNSTU2=2070 %term CNSTU4=4118 %term CNSTU8=8214 %term ARGB=41 %term ARGF4=4129 %term ARGF8=8225 %term ARGI4=4133 %term ARGI8=8229 %term ARGP4=4135 %term ARGU4=4134 %term ARGU8=8230 %term ASGNB=57 %term ASGNF4=4145 %term ASGNF8=8241 %term ASGNI1=1077 %term ASGNI2=2101 %term ASGNI4=4149 %term ASGNI8=8245 %term ASGNP4=4151 %term ASGNU1=1078 %term ASGNU2=2102 %term ASGNU4=4150 %term ASGNU8=8246 %term INDIRB=73 %term INDIRF4=4161 %term INDIRF8=8257 %term INDIRI1=1093 %term INDIRI2=2117 %term INDIRI4=4165 %term INDIRI8=8261 %term INDIRP4=4167 %term INDIRU1=1094 %term INDIRU2=2118 %term INDIRU4=4166 %term INDIRU8=8262 %term CVFF4=4209 %term CVFF8=8305 %term CVFI4=4213 %term CVFI8=8309 %term CVIF4=4225 %term CVIF8=8321 %term CVII1=1157 %term CVII2=2181 %term CVII4=4229 %term CVII8=8325 %term CVIU1=1158 %term CVIU2=2182 %term CVIU4=4230 %term CVIU8=8326 %term CVPU4=4246 %term CVUI1=1205 %term CVUI2=2229 %term CVUI4=4277 %term CVUI8=8373 %term CVUP4=4279 %term CVUU1=1206 %term CVUU2=2230 %term CVUU4=4278 %term CVUU8=8374 %term NEGF4=4289 %term NEGF8=8385 %term NEGI4=4293 %term NEGI8=8389 %term CALLB=217 %term CALLF4=4305 %term CALLF8=8401 %term CALLI4=4309 %term CALLI8=8405 %term CALLP4=4311 %term CALLU4=4310 %term CALLU8=8406 %term CALLV=216 %term RETF4=4337 %term RETF8=8433 %term RETI4=4341 %term RETI8=8437 %term RETP4=4343 %term RETU4=4342 %term RETU8=8438 %term RETV=248 %term ADDRGP4=4359 %term ADDRFP4=437 %term ADDRLP4=4391 %term ADDF4=4401 %term ADDF8=8497 %term ADDI4=4405 %term ADDI8=8501 %term ADDP4=4407 %term ADDU4=4406 %term ADDU8=8502 %term SUBF4=4417 %term SUBF8=8513 %term SUBI4=4421 %term SUBI8=8517 %term SUBP4=4423 %term SUBU4=4422 %term SUBU8=8518 %term LSHI4=4437 %term LSHI8=8533 %term LSHU4=4438 %term LSHU8=8534 %term MODI4=4453 %term MODI8=8549 %term MODU4=4454 %term MODU8=8550 %term RSHI4=4469 %term RSHI8=8565 %term RSHU4=4470 %term RSHU8=8566 %term BANDI4=4485 %term BANDI8=8581 %term BANDU4=4486 %term BANDU8=8582 %term BCOMI4=4501 %term BCOMI8=8597 %term BCOMU4=4502 %term BCOMU8=8598 %term BORI4=4517 %term BORI8=8613 %term BORU4=4518 %term BORU8=8614 %term BXORI4=4533 %term BXORI8=8629 %term BXORU4=4534 %term BXORU8=8630 %term DIVF4=4545 %term DIVF8=8641 %term DIVI4=4549 %term DIVI8=8645 %term DIVU4=4550 %term DIVU8=8646 %term MULF4=4561 %term MULF8=8657 %term MULI4=4565 %term MULI8=8661 %term MULU4=4566 %term MULU8=8662 %term EQF4=4577 %term EQF8=8673 %term EQI4=4581 %term EQI8=8677 %term EQU4=4582 %term EQU8=8678 %term GEF4=4593 %term GEF8=8689 %term GEI4=4597 %term GEI8=8693 %term GEU4=4598 %term GEU8=8694 %term GTF4=4609 %term GTF8=8705 %term GTI4=4613 %term GTI8=8709 %term GTU4=4614 %term GTU8=8710 %term LEF4=4625 %term LEF8=8721 %term LEI4=4629 %term LEI8=8725 %term LEU4=4630 %term LEU8=8726 %term LTF4=4641 %term LTF8=8737 %term LTI4=4645 %term LTI8=8741 %term LTU4=4646 %term LTU8=8742 %term NEF4=4657 %term NEF8=8753 %term NEI4=4661 %term NEI8=8757 %term NEU4=4662 %term NEU8=8758 %term JUMPV=584 %term LABELV=600 %term TUCKF4=4833 %term TUCKF8=8929 %term TUCKI1=1765 %term TUCKI2=2789 %term TUCKI4=4837 %term TUCKI8=8933 %term TUCKP4=4839 %term TUCKU1=1766 %term TUCKU2=2790 %term TUCKU4=4838 %term TUCKU8=8934 %% sread: STACKP "rot1\n" range(a, 1, 1) sread: STACKP "rot2\n" range(a, 2, 2) sread: STACKP "rot3\n" range(a, 3, 3) sread: STACKP "rot4\n" range(a, 4, 4) sread: COPYP "copy%b\n" range(a, 1, 4) sread: COPYP "any\n" range(a, 0, 0) stk: INDIRI1(sread) "\n" 1 stk: INDIRU1(sread) "\n" 1 stk: INDIRI2(sread) "\n" 1 stk: INDIRU2(sread) "\n" 1 stk: INDIRF4(sread) "\n" 1 stk: INDIRI4(sread) "\n" 1 stk: INDIRP4(sread) "\n" 1 stk: INDIRU4(sread) "\n" 1 stk: TUCKI1(stk) "#\n" range(a, 1, 1) stk: TUCKU1(stk) "#\n" range(a, 1, 1) stk: TUCKI2(stk) "#\n" range(a, 1, 1) stk: TUCKU2(stk) "#\n" range(a, 1, 1) stk: TUCKI4(stk) "#\n" range(a, 1, 1) stk: TUCKU4(stk) "#\n" range(a, 1, 1) stk: TUCKF4(stk) "#\n" range(a, 1, 1) stk: TUCKP4(stk) "#\n" range(a, 1, 1) stk: TUCKI1(stk) "#\n" range(a, 2, 2) stk: TUCKU1(stk) "#\n" range(a, 2, 2) stk: TUCKI2(stk) "#\n" range(a, 2, 2) stk: TUCKU2(stk) "#\n" range(a, 2, 2) stk: TUCKI4(stk) "#\n" range(a, 2, 2) stk: TUCKU4(stk) "#\n" range(a, 2, 2) stk: TUCKF4(stk) "#\n" range(a, 2, 2) stk: TUCKP4(stk) "#\n" range(a, 2, 2) stk: TUCKI1(stk) "#\n" range(a, 3, 3) stk: TUCKU1(stk) "#\n" range(a, 3, 3) stk: TUCKI2(stk) "#\n" range(a, 3, 3) stk: TUCKU2(stk) "#\n" range(a, 3, 3) stk: TUCKI4(stk) "#\n" range(a, 3, 3) stk: TUCKU4(stk) "#\n" range(a, 3, 3) stk: TUCKF4(stk) "#\n" range(a, 3, 3) stk: TUCKP4(stk) "#\n" range(a, 3, 3) stk: TUCKI1(stk) "#\n" range(a, 4, 4) stk: TUCKU1(stk) "#\n" range(a, 4, 4) stk: TUCKI2(stk) "#\n" range(a, 4, 4) stk: TUCKU2(stk) "#\n" range(a, 4, 4) stk: TUCKI4(stk) "#\n" range(a, 4, 4) stk: TUCKU4(stk) "#\n" range(a, 4, 4) stk: TUCKF4(stk) "#\n" range(a, 4, 4) stk: TUCKP4(stk) "#\n" range(a, 4, 4) stmt: TUCKI1(stk) "rrot1; %a\n" range(a, 1, 1) stmt: TUCKU1(stk) "rrot1; %a\n" range(a, 1, 1) stmt: TUCKI2(stk) "rrot1; %a\n" range(a, 1, 1) stmt: TUCKU2(stk) "rrot1; %a\n" range(a, 1, 1) stmt: TUCKI4(stk) "rrot1; %a\n" range(a, 1, 1) stmt: TUCKU4(stk) "rrot1; %a\n" range(a, 1, 1) stmt: TUCKF4(stk) "rrot1; %a\n" range(a, 1, 1) stmt: TUCKP4(stk) "rrot1; %a\n" range(a, 1, 1) stmt: TUCKI1(stk) "rrot2; %a\n" range(a, 2, 2) stmt: TUCKU1(stk) "rrot2; %a\n" range(a, 2, 2) stmt: TUCKI2(stk) "rrot2; %a\n" range(a, 2, 2) stmt: TUCKU2(stk) "rrot2; %a\n" range(a, 2, 2) stmt: TUCKI4(stk) "rrot2; %a\n" range(a, 2, 2) stmt: TUCKU4(stk) "rrot2; %a\n" range(a, 2, 2) stmt: TUCKF4(stk) "rrot2; %a\n" range(a, 2, 2) stmt: TUCKP4(stk) "rrot2; %a\n" range(a, 2, 2) stmt: TUCKI1(stk) "rrot3; %a\n" range(a, 3, 3) stmt: TUCKU1(stk) "rrot3; %a\n" range(a, 3, 3) stmt: TUCKI2(stk) "rrot3; %a\n" range(a, 3, 3) stmt: TUCKU2(stk) "rrot3; %a\n" range(a, 3, 3) stmt: TUCKI4(stk) "rrot3; %a\n" range(a, 3, 3) stmt: TUCKU4(stk) "rrot3; %a\n" range(a, 3, 3) stmt: TUCKF4(stk) "rrot3; %a\n" range(a, 3, 3) stmt: TUCKP4(stk) "rrot3; %a\n" range(a, 3, 3) stmt: TUCKI1(stk) "rrot4; %a\n" range(a, 4, 4) stmt: TUCKU1(stk) "rrot4; %a\n" range(a, 4, 4) stmt: TUCKI2(stk) "rrot4; %a\n" range(a, 4, 4) stmt: TUCKU2(stk) "rrot4; %a\n" range(a, 4, 4) stmt: TUCKI4(stk) "rrot4; %a\n" range(a, 4, 4) stmt: TUCKU4(stk) "rrot4; %a\n" range(a, 4, 4) stmt: TUCKF4(stk) "rrot4; %a\n" range(a, 4, 4) stmt: TUCKP4(stk) "rrot4; %a\n" range(a, 4, 4) stmt: ASGNI1(stk, var) "\n" stmt: ASGNU1(stk, var) "\n" stmt: ASGNI2(stk, var) "\n" stmt: ASGNU2(stk, var) "\n" stmt: ASGNF4(stk, var) "\n" stmt: ASGNI4(stk, var) "\n" stmt: ASGNP4(stk, var) "\n" stmt: ASGNU4(stk, var) "\n" var: STACKP "#\n" range(a, 1, 1) var: STACKP "#\n" range(a, 2, 2)+1 var: STACKP "#\n" range(a, 3, 3)+1 var: STACKP "#\n" range(a, 4, 4)+1 cnst1: CNSTI1 "" range(a, 1, 1) cnst1: CNSTI2 "" range(a, 1, 1) cnst1: CNSTI4 "" range(a, 1, 1) cnst1: CNSTU1 "" range(a, 1, 1) cnst1: CNSTU2 "" range(a, 1, 1) cnst1: CNSTU4 "" range(a, 1, 1) cnst1: CNSTP4 "" range(a, 1, 1) stk: CNSTI1 "lit %a\n" 3 stk: CNSTI2 "lit %a\n" 3 stk: CNSTI4 "lit %a\n" 3 stk: CNSTF4 "lit %a\n" 3 stk: CNSTU1 "lit %a\n" 3 stk: CNSTU2 "lit %a\n" 3 stk: CNSTU4 "lit %a\n" 3 stk: CNSTP4 "lit %a\n" 3 stmt: stk "drop\n" 1 glob: ADDRGP4 "%a" local: ADDRLP4 "#" stk: glob "lit %0\n" 2 stk: ADDRLP4 "lit %a\n@fp\nadd\n" 3 stmt: ASGNI1(stk, local) "!loc %1\n" 3 stmt: ASGNU1(stk, local) "!loc %1\n" 3 stmt: ASGNI2(stk, local) "!loc %1\n" 3 stmt: ASGNU2(stk, local) "!loc %1\n" 3 stmt: ASGNI4(stk, local) "!loc %1\n" 3 stmt: ASGNU4(stk, local) "!loc %1\n" 3 stmt: ASGNF4(stk, local) "!loc %1\n" 3 stmt: ASGNP4(stk, local) "!loc %1\n" 3 stmt: ASGNI1(stk,stk) "!.b\n" 3 stmt: ASGNU1(stk,stk) "!.b\n" 3 stmt: ASGNI2(stk,stk) "!.w\n" 3 stmt: ASGNU2(stk,stk) "!.w\n" 3 stmt: ASGNI4(stk,stk) "! \n" 3 stmt: ASGNU4(stk,stk) "! \n" 3 stmt: ASGNP4(stk,stk) "! \n" 3 stmt: ASGNF4(stk,stk) "! \n" 3 stk: INDIRI1(glob) "@%0\n" 3 stk: INDIRU1(glob) "@%0\n" 3 stk: INDIRI2(glob) "@%0\n" 3 stk: INDIRU2(glob) "@%0\n" 3 stk: INDIRP4(glob) "@%0\n" 3 stk: INDIRI4(glob) "@%0\n" 3 stk: INDIRU4(glob) "@%0\n" 3 stk: INDIRF4(glob) "@%0\n" 3 stk: INDIRI1(local) "@loc %0\n" 3 stk: INDIRU1(local) "@loc %0\n" 3 stk: INDIRI2(local) "@loc %0\n" 3 stk: INDIRU2(local) "@loc %0\n" 3 stk: INDIRP4(local) "@loc %0\n" 3 stk: INDIRI4(local) "@loc %0\n" 3 stk: INDIRU4(local) "@loc %0\n" 3 stk: INDIRF4(local) "@loc %0\n" 3 stk: INDIRI1(stk) "@.b\n" 3 stk: INDIRU1(stk) "@.b\n" 3 stk: INDIRI2(stk) "@.w\n" 3 stk: INDIRU2(stk) "@.w\n" 3 stk: INDIRI4(stk) "@\n" 3 stk: INDIRU4(stk) "@\n" 3 stk: INDIRP4(stk) "@\n" 3 stk: INDIRF4(stk) "@\n" 3 stk: MODI4(stk,stk) "mod\n" 20 stk: MODU4(stk,stk) "modu\n" 10 stk: MULI4(stk,stk) "mul\n" 8 stk: MULU4(stk,stk) "mul\n" 10 stk: DIVI4(stk,stk) "div\n" 20 stk: DIVU4(stk,stk) "divu\n" 20 stk: ADDI4(stk, stk) "add\n" 1 stk: ADDP4(stk, stk) "add\n" 1 stk: ADDU4(stk, stk) "add\n" 1 stk: BANDI4(stk, stk) "and\n" 1 stk: BORI4(stk, stk) "or\n" 1 stk: BXORI4(stk, stk) "xor\n" 1 stk: BANDU4(stk, stk) "and\n" 1 stk: BORU4(stk, stk) "or\n" 1 stk: BXORU4(stk, stk) "xor\n" 1 stk: SUBI4(stk, stk) "sub\n" 1 stk: SUBP4(stk, stk) "sub\n" 1 stk: SUBU4(stk, stk) "sub\n" 1 stk: LSHI4(stk, cnst1) "shl\n" 1 stk: LSHU4(stk, cnst1) "shl\n" 1 stk: LSHI4(stk,stk) "bshl\n" 10 stk: LSHU4(stk,stk) "bshl\n" 10 stk: RSHI4(stk,stk) "basr\n" 10 stk: RSHU4(stk,stk) "blsr\n" 10 stk: BCOMI4(stk) "inv\n" 1 stk: BCOMU4(stk) "inv\n" 1 stk: NEGI4(stk) "neg\n" 1 stk: ADDF4(stk,stk) "fadd\n" 15 stk: DIVF4(stk,stk) "fdiv\n" 60 stk: MULF4(stk,stk) "fmul\n" 30 stk: SUBF4(stk,stk) "fsub\n" 15 stk: NEGF4(stk) "fneg\n" 6 stk: CVII1(stk) "\n" stk: CVII2(stk) "\n" stk: CVII4(stk) "\n" stk: CVIU1(stk) "\n" stk: CVIU2(stk) "\n" stk: CVIU4(stk) "lit 0xff\nand\n" (a->syms[0]->u.c.v.i==1?4:LBURG_MAX) stk: CVIU4(stk) "lit 0xffff\nand\n" (a->syms[0]->u.c.v.i==2?4:LBURG_MAX) stk: CVIU4(stk) "\n" (a->syms[0]->u.c.v.i==4?0:LBURG_MAX) stk: CVUI1(stk) "\n" stk: CVUI2(stk) "\n" stk: CVUI4(stk) "lit 0xff\nand\n" (a->syms[0]->u.c.v.i==1?2:LBURG_MAX) stk: CVUI4(stk) "lit 0xffff\nand\n" (a->syms[0]->u.c.v.i==2?2:LBURG_MAX) stk: CVUI4(stk) "\n" (a->syms[0]->u.c.v.i==4?0:LBURG_MAX) stk: CVUU1(stk) "\n" stk: CVUU2(stk) "\n" stk: CVUU4(stk) "lit 0xff\nand\n" (a->syms[0]->u.c.v.i==1?2:LBURG_MAX) stk: CVUU4(stk) "lit 0xffff\nand\n" (a->syms[0]->u.c.v.i==2?2:LBURG_MAX) stk: CVUU4(stk) "\n" (a->syms[0]->u.c.v.i==4?0:LBURG_MAX) stk: CVIF4(stk) "call __i2f__\n" 10 stk: CVFI4(stk) "call __f2i__\n" 20 stk: CVPU4(stk) "\n" stk: CVUP4(stk) "\n" stmt: LABELV "%a:\n" stmt: JUMPV(glob) "jump %0\n" 1 stmt: JUMPV(stk) "ijump\n" 2 stmt: EQI4(stk,stk) "breq %a\n" 1 stmt: EQU4(stk,stk) "breq %a\n" 1 stmt: NEI4(stk,stk) "brne %a\n" 1 stmt: NEU4(stk,stk) "brne %a\n" 1 stmt: GEI4(stk,stk) "brlt %a\n" 2 stmt: GTI4(stk,stk) "brgt %a\n" 2 stmt: LEI4(stk,stk) "brgt %a\n" 2 stmt: LTI4(stk,stk) "brlt %a\n" 2 stmt: GEU4(stk, stk) "brltu %a\n" 2 stmt: GTU4(stk, stk) "brgtu %a\n" 2 stmt: LEU4(stk, stk) "brleu %a\n" 2 stmt: LTU4(stk, stk) "brltu %a\n" 2 stmt: EQF4(stk, stk) "call __cmpf__\nbrz %a\n" 2 stmt: LEF4(stk, stk) "call __cmpf__\ntgz\nbrz %a\n" 2 stmt: LTF4(stk, stk) "call __cmpf__\ntlz\nbrnz %a\n" 2 stmt: GEF4(stk, stk) "call __cmpf__\ntlz\nbrz %a\n" 2 stmt: GTF4(stk, stk) "call __cmpf__\ntgz\nbrnz %a\n" 2 stmt: NEF4(stk, stk) "call __cmpf__\nbrnz %a\n" 2 addr: ADDRGP4 "%a" addr: CNSTP4 "%a" stk: CALLF4(addr) "call %0\n" 4 stk: CALLI4(addr) "call %0\n" 4 stk: CALLP4(addr) "call %0\n" 4 stk: CALLU4(addr) "call %0\n" 4 stmt: CALLV(addr) "call %0\n" 4 stmt: CALLB(addr, stk) "call %0\n" 4 stk: CALLF4(stk) "icall\n" 3 stk: CALLI4(stk) "icall\n" 3 stk: CALLP4(stk) "icall\n" 3 stk: CALLU4(stk) "icall\n" 3 stmt: CALLV(stk) "icall\n" 3 stmt: CALLB(stk, stk) "icall\n" 3 stmt: RETF4(stk) "\n" 1 stmt: RETI4(stk) "\n" 1 stmt: RETU4(stk) "\n" 1 stmt: RETP4(stk) "\n" 1 stmt: RETV "\n" 1 stmt: ARGF4(stk) "\n" 0 stmt: ARGI4(stk) "\n" 0 stmt: ARGP4(stk) "\n" 0 stmt: ARGU4(stk) "\n" 0 stmt: ARGB(INDIRB(stk)) "INDIRB???\n" 0 stmt: ASGNB(INDIRB(stk), stk) "#\n" 10 stmt: ASGNB(INDIRB(ADDRLP4), ADDRLP4) "#\n" 10 stmt: ASGNB(INDIRB(stk), ADDRLP4) "#\n" 10 stmt: ASGNB(INDIRB(ADDRLP4), stk) "#\n" 10 %% static void preamble(Symbol f, Symbol caller[], Symbol callee[], int ncalls); static void postamble(Symbol f, Symbol caller[], Symbol callee[], int ncalls); static int makeTemp(Symbol p) { if (!isscalar(p->type) || p->type->size == 8) { p->sclass = AUTO; return 0; } else if (p->sclass == AUTO) { if (p->addressed) { return 0; } else { makeTemporary(p); return 1; } } else if (p->sclass == REGISTER) { makeTemporary(p); return 1; } else { return 0; } } static void local(Symbol p) { if (!makeTemp(p)) { mkauto(p); } } static void function(Symbol f, Symbol caller[], Symbol callee[], int ncalls) { int i, size, varargs; Node params; write_log("Function %s\n", f->x.name); offset = local_variable_count = 0; varargs = variadic(f->type); params = stackParameters(caller, callee); gencode(caller, callee); optimise(); framesize = roundup(offset, 4); preamble(f, caller, callee, ncalls); stackemit(params); emitcode(); postamble(f, caller, callee, ncalls); } static Node recalcNode(Node temp, Node calc) { int op = specific(calc->op); if (op == CNST + I || op == CNST + U || op == CNST + P) { return calc; } else { return temp; } } static int leaf; static char* localReg = "fp"; static int arguments = 0; static void preamble(Symbol f, Symbol caller[], Symbol callee[], int ncalls) { print(";function %s\n", f->x.name); while(*callee) { print("param %s\n", (*callee)->name); callee++; } } static void postamble(Symbol f, Symbol caller[], Symbol callee[], int ncalls) { print("exit\n\n"); } static char* neg(char sign) { return sign == '-' ? "-" : ""; } static void printName(Node p) { if (isdigit(p->syms[0]->name[0])) print("t%s", p->syms[0]->name); else print("%s", p->syms[0]->name); } static void emit2(Node p) { if (generic(p->op) == TUCK) { print("tuck%d;", p->syms[1]->u.c.v.i); printName(p); print("\n"); } else if (generic(p->op) == STACK) { print("rrot%d;", p->syms[1]->u.c.v.i); printName(p); print("\n"); } else { printName(p); } } static void defconst(int suffix, int size, Value v) { if (suffix == F && size == 4) print(".word 0x%x\n", (unsigned)(v.i)); else if (suffix == F && size == 8) print(".word 0x%x\n.word 0x%x\n", (unsigned)v.i, (unsigned)*(&(v.i)+1)); else if (suffix == P) print(".word 0x%x\n", (unsigned)v.p); else if (size == 1) print(".byte 0x%x\n", (unsigned)((unsigned char)(suffix == I ? v.i : v.u))); else if (size == 2) print(".short 0x%x\n", (unsigned)((unsigned short)(suffix == I ? v.i : v.u))); else if (size == 4) print(".word 0x%x\n", (unsigned)(suffix == I ? v.i : v.u)); } static void defaddress(Symbol p) { print(".word %s\n", p->x.name); } static void defstring(int n, char *str) { char *s; for (s = str; s < str + n; s++) print(".byte %d\n", (*s)&0377); } static void export(Symbol p) { // print("\n.export %s\n", p->x.name); } static void import(Symbol p) { if (!isfunc(p->type)) print(".extern %s %d\n", p->name, p->type->size); } static void defsymbol(Symbol p) { if (p->scope == LABELS) { p->x.name = stringf("L%s", p->name); } else if (p->temporary) { p->x.name = stringf("t%s", p->name); } else if (p->generated) { p->x.name = stringf("x%s", p->name); } else { p->x.name = stringf("%s", p->name); } } static void address(Symbol q, Symbol p, long n) { if (n) q->x.name = stringf("%s%s%d", p->name, n >= 0 ? "+" : "", n); else q->x.name = p->name; } static void global(Symbol p) { if (p->type->align != 1) { print(".align %d\n", p->type->align); } print(".global %s\n", p->x.name); } static void segment(int n) { switch (n) { case CODE: print(".text\n"); break; case LIT: print(".text\n"); break; case DATA: print(".data\n"); break; case BSS: print(".bss\n"); break; } } static void space(int n) { print(".skip %d\n", n); } static void stabinit(char *, int, char *[]); static void stabline(Coordinate *); static void stabsym(Symbol); static char *currentfile; /* stabinit - initialize stab output */ static void stabinit(char *file, int argc, char *argv[]) { if (file) { print(".file 2,\"%s\"\n", file); currentfile = file; } } /* stabline - emit stab entry for source coordinate *cp */ static void stabline(Coordinate *cp) { if (cp->file && cp->file != currentfile) { print(".file 2,\"%s\"\n", cp->file); currentfile = cp->file; } print(".loc 2,%d\n", cp->y); } /* stabsym - output a stab entry for symbol p */ static void stabsym(Symbol p) { if (p == cfunc && IR->stabline) (*IR->stabline)(&p->src); } static void progbeg(int argc, char *argv[]) { { union { char c; int i; } u; u.i = 0; u.c = 1; } backendflags(argc, argv); } static void blockbeg(Env* env) { } static void blockend(Env* env) { } static void progend(void){} Interface abstractIR = { { 1, 1, 0 }, /* char_metrics */ { 2, 2, 0 }, /* short_metrics */ { 4, 4, 0 }, /* int_metrics */ { 4, 4, 0 }, /* long_metrics */ { 4, 4, 1 }, /* long_long_metrics */ { 4, 4, 0 }, /* float_metrics */ { 4, 4, 1 }, /* double_metrics */ { 4, 4, 1 }, /* long_double_metrics */ { 4, 4, 0 }, /* word_metrics */ { 0, 4, 0 }, /* struct_metrics */ 0, /* little_endian */ 0, /* mulops_calls */ 0, /* wants_callb */ 0, /* wants_argb */ 1, /* left_to_right */ 0, /* wants_dag */ 0, /* unsigned_char */ address, blockbeg, blockend, defaddress, defconst, defstring, defsymbol, stackemit, export, function, stackgen, global, import, local, progbeg, progend, segment, space, 0, 0, 0, stabinit, stabline, stabsym, 0, swtch, { 1, /* max_unaligned_load */ 4, /* depth */ recalcNode, makeTemp, NULL, _label, _rule, _nts, _kids, _string, _templates, _isinstruction, _ntname, emit2, { 0, // sub 0, // lsh 0, // rsh 0, // mod 0, // div 0, // lt 0, // le 0, // gt 0 // ge } } };