void cgincbind(char *r, char *i, int v) { if (!strcmp(r, "bx")) sgen("%s\tbx,%s", "mov", r); ngen("%s\tal,%d", "mov", v); sgen("%s\t[bx],al", i, NULL); }
void cgincbglob(char *i, char *s, int v) { ngen("%s\tcl,%d", "mov", v); sgen("%s\t%s,cl", i, s); }
void cgincglob(char *i, char *s, int v) { ngen("%s\tcx,%d", "mov", v); sgen("%s\t%s,cx", i, s); }
void cgstorgw(char *s) { sgen("%s\t%s,ax", "mov", s); }
/* * 386 -> videocore mapping * * eax r0 * ecx r1 * edx r2 * tmp r3 * ebp r23 * esp r25 * * g = global * l = local * s = static * * b = byte * w = word * a = address * */ static int lab_data_skip; void cgdeclare(int id) { lgenraw("%s(%c%d);", "declare", id); } void cglab(int id) { lgenraw("%s(%c%d);", "label", id); } void cgname(char *name) { sgenraw("%s(C%s);", "\nlabel", name); } void cgdata(void) { if (lab_data_skip==0) { lab_data_skip = label(); lgen("%s(%c%d);", "b", lab_data_skip); } /*gen(".data;");*/ } void cgtext(void) { if (lab_data_skip) { cglab(lab_data_skip); lab_data_skip=0; } /*gen(".text;");*/ } void cgprelude(void) { } void cgpostlude(void) { } void cgpublic(char *s) { sgenraw("%s(%s);", "\nglobal", s); /*ngen(".globl\t%s", s, 0);*/ } void cgstatic(char *s) { sgenraw("%s(%s);", "\nstatic", s); } void cglit(int v) { ngen("%s(r0, %d);", "movi", v); } /* ngen("%s\t$%d,%%eax", "movl", v); } */ void cgclear(void) { ngen("%s(r0, %d);", "movi", 0); } /* gen("xorl\t%eax,%eax;"); } */ void cgldgb(char *s) { sgen("%s(r0, %s);", "ldb_rd_u", s); } /* sgen("%s\t%s,%%al", "movb", s); } */ void cgldgw(char *s) { sgen("%s(r0, %s);", "ld_rd_u", s); } /* sgen("%s\t%s,%%eax", "movl", s); } */
/* { int lab; lab = label(); gen("orl\t%eax,%eax;"); lgen("%s\t%c%d", how, lab); lgen("%s\t%c%d", "jmp", n); genlab(lab); } */ void cgbrtrue(int n) { cgbr("beq", n); } /* cgbr("jz", n); } */ void cgbrfalse(int n) { cgbr("bne", n); } /* cgbr("jnz", n); } */ void cgjump(int n) { lgen("%s(%c%d);", "b", n); } /* lgen("%s\t%c%d", "jmp", n); } */ void cgldswtch(int n) { lgen("%s(r2, %c%d);", "movi", n); } /* lgen("%s\t$%c%d,%%edx", "movl", n); } */ void cgcalswtch(void) { gen("b(switch);"); } /* gen("jmp\tswitch;"); } */ void cgcase(int v, int l) { lgen2("dc(%d); dc(%c%d);", v, l); } /* lgen2(".long\t%d,%c%d", v, l); } */ void cgpopptr(void) { gen("ld_rd_rs_inc(r2, r25);"); } /* gen("popl\t%edx;"); } */ void cgstorib(void) { ngen("%s(r0, r2);", "stb_rd_rs", 0); } /* ngen("%s\t%%al,(%%edx);", "movb", 0); } */ void cgstoriw(void) { ngen("%s(r0, r2);", "st_rd_rs", 0); } /* ngen("%s\t%%eax,(%%edx);", "movl", 0); } */ void cgstorlb(int n) { ngen("%s(r0, %d, r23);", "stb_rd_o_rs", n); } /* ngen("%s\t%%al,%d(%%ebp);", "movb", n); } */ void cgstorlw(int n) { ngen("%s(r0, %d, r23);", "st_rd_o_rs", n); } /* \t%%eax,%d(%%ebp);", "movl", n); } */ void cgstorsb(int n) { lgen("%s(r0, %c%d);", "stb_rd_o_rs", n); } /* lgen("%s\t%%al,%c%d", "movb", n); } */ void cgstorsw(int n) { lgen("%s(r0, %c%d);", "st_rd_o_rs", n); } /* lgen("\t%%eax,%c%d", "movl", n); } */ void cgstorgb(char *s) { sgen("%s(r0, %s);", "stb_rd_rs", s); } /* sgen("%s\t%%al,%s", "movb", s); } */ void cgstorgw(char *s) { sgen("%s(r0, %s);", "st_rd_rs", s); } /* sgen("%s\t%%eax,%s", "movl", s); } */ void cginitlw(int v, int a) { ngen("%s(r3,%d);", "movi", v); ngen("%s(r3,%d,r23);", "st_rd_o_rs", v); } /* ngen2("%s\t$%d,%d(%%ebp);", "movl", v, a); } */ void cgcall(char *s) { sgen("%s(%s);", "bl", s); } /* sgen("%s\t%s", "call", s); } */
/* { int lab; lab = label(); gen("orl\t%eax,%eax;"); lgen("%s\t%c%d", how, lab); lgen("%s\t%c%d", "jmp", n); genlab(lab); } */ void cgbrtrue(int n) { cgbr("beq", n); } /* cgbr("jz", n); } */ void cgbrfalse(int n) { cgbr("bne", n); } /* cgbr("jnz", n); } */ void cgjump(int n) { lgen("%s(%c%d);", "b", n); } /* lgen("%s\t%c%d", "jmp", n); } */ void cgldswtch(int n) { lgen("%s(r2, %c%d);", "movi", n); } /* lgen("%s\t$%c%d,%%edx", "movl", n); } */ void cgcalswtch(void) { gen("b(switch);"); } /* gen("jmp\tswitch;"); } */ void cgcase(int v, int l) { lgen2("dc(%d); dc(%c%d);", v, l); } /* lgen2(".long\t%d,%c%d", v, l); } */ void cgpopptr(void) { gen("ld_rd_rs_inc(r2, r25);"); } /* gen("popl\t%edx;"); } */ void cgstorib(void) { ngen("%s(r0, r2);", "stb_rd_rs", 0); } /* ngen("%s\t%%al,(%%edx);", "movb", 0); } */ void cgstoriw(void) { ngen("%s(r0, r2);", "st_rd_rs", 0); } /* ngen("%s\t%%eax,(%%edx);", "movl", 0); } */ void cgstorlb(int n) { ngen("%s(r0, %d, r23);", "stb_rd_o_rs", n); } /* ngen("%s\t%%al,%d(%%ebp);", "movb", n); } */ void cgstorlw(int n) { ngen("%s(r0, %d, r23);", "st_rd_o_rs", n); } /* \t%%eax,%d(%%ebp);", "movl", n); } */ void cgstorsb(int n) { lgen("%s(r0, %c%d);", "stb_rd_o_rs", n); } /* lgen("%s\t%%al,%c%d", "movb", n); } */ void cgstorsw(int n) { lgen("%s(r0, %c%d);", "st_rd_o_rs", n); } /* lgen("\t%%eax,%c%d", "movl", n); } */ void cgstorgb(char *s) { sgen("%s(r0, %s);", "stb_rd_rs", s); } /* sgen("%s\t%%al,%s", "movb", s); } */
/* increment/decrement pointer to local, static, global */ void cgincpl(int a, int v) { ngen("%s(r3, %d, r23);", "ld_rd_o_rs", a); ngen("%s(r3,%d);", "addi", v); ngen("%s(r3, %d, r23);", "st_rd_o_rs", a); } /* ngen2("%s\t$%d,%d(%%ebp);", "addl", v, a); } */ void cgdecpl(int a, int v) { ngen("%s(r3, %d, r23);", "ld_rd_o_rs", a); ngen("%s(r3,%d);", "subi", v); ngen("%s(r3, %d, r23);", "st_rd_o_rs", a); } /* ngen2("%s\t$%d,%d(%%ebp);", "subl", v, a); } */ void cgincps(int a, int v) { lgen("%s(r3, %c%d);", "ld_rd_u", a); ngen("%s(r3,%d);", "addi", v); lgen("%s(r3, %c%d);", "st_rd_u", a); } /* lgen2("addl\t$%d,%c%d", v, a); } */ void cgdecps(int a, int v) { lgen("%s(r3, %c%d);", "ld_rd_u", a); ngen("%s(r3,%d);", "subi", v); lgen("%s(r3, %c%d);", "st_rd_u", a); } /* { lgen2("subl\t$%d,%c%d", v, a); } */ void cgincpg(char *s, int v) { sgen("%s(r3, %s);", "ld_rd_u", s); ngen("%s(r3,%d);", "addi", v); sgen("%s(r3, %s);", "st_rd_u", s); } /* sgen2("%s\t$%d,%s", "addl", v, s); } */ void cgdecpg(char *s, int v) { sgen("%s(r3, %s);", "ld_rd_u", s); ngen("%s(r3,%d);", "subi", v); sgen("%s(r3, %s);", "st_rd_u", s); } /* sgen2("%s\t$%d,%s", "subl", v, s); } */ void cginc1iw(void) { cginc1pi(1); } /* ngen("%s\t(%%eax);", "incl", 0); } */ void cgdec1iw(void) { cgdec1pi(1); } /* ngen("%s\t(%%eax);", "decl", 0); } */ void cginc2iw(void) { cginc2pi(1); } /* ngen("%s\t(%%edx);", "incl", 0); } */ void cgdec2iw(void) { cgdec2pi(1); } /* ngen("%s\t(%%edx);", "decl", 0); } */ void cginclw(int a) { cgincpl(a, 1); } /* ngen("%s\t%d(%%ebp);", "incl", a); } */ void cgdeclw(int a) { cgdecpl(a, 1); } /* ngen("%s\t%d(%%ebp);", "decl", a); } */ void cgincsw(int a) { cgincps(a, 1); } /* lgen("%s\t%c%d", "incl", a); } */ void cgdecsw(int a) { cgdecps(a, 1); } /* lgen("%s\t%c%d", "decl", a); } */ void cgincgw(char *s) { cgincpg(s, 1); } /* sgen("%s\t%s", "incl", s); } */ void cgdecgw(char *s) { cgdecpg(s, 1); } /* sgen("%s\t%s", "decl", s); } */ void cginc1ib(void) { ngen("ldb(r3, r0); %s(r3, %d); stb(r3, r0);", "addi", 1); } /* ngen("%s\t(%%eax);", "incb", 0); } */ void cgdec1ib(void) { ngen("ldb(r3, r0); %s(r3, %d); stb(r3, r0);", "subi", 1); } /* ngen("%s\t(%%eax);", "decb", 0); } */ void cginc2ib(void) { ngen("ldb(r3, r2); %s(r3, %d); stb(r3, r2);", "addi", 1); } /* ngen("%s\t(%%edx);", "incb", 0); } */ void cgdec2ib(void) { ngen("ldb(r3, r2); %s(r3, %d); stb(r3, r2);", "subi", 1); } /* ngen("%s\t(%%edx);", "decb", 0); } */ void cginclb(int a) { ngen("%s(r3, %d, r23);", "ldb_rd_o_rs", a); ngen("%s(r3, %d);", "addi", 1); ngen("%s(r3, %d, r23);", "stb_rd_o_rs", a); } /* ngen("%s\t%d(%%ebp);", "incb", a); } */ void cgdeclb(int a) { ngen("%s(r3, %d, r23);", "ldb_rd_o_rs", a); ngen("%s(r3, %d);", "subi", 1); ngen("%s(r3, %d, r23);", "stb_rd_o_rs", a); } /* ngen("%s\t%d(%%ebp);", "decb", a); } */ void cgincsb(int a) { ngen("%s(r3, %c%d);", "ldb_rd_u", a); ngen("%s(r3, %d);", "addi", 1); ngen("%s(r3, %c%d);", "stb_rd_u", a); } /* lgen("%s\t%c%d", "incb", a); } */ void cgdecsb(int a) { ngen("%s(r3, %c%d);", "ldb_rd_u", a); ngen("%s(r3, %d);", "subi", 1); ngen("%s(r3, %c%d);", "stb_rd_u", a); } /* lgen("%s\t%c%d", "decb", a); } */ void cgincgb(char *s) { sgen("%s(r3, %s);", "ldb_rd_u", s); ngen("%s(r3, %d);", "addi", 1); sgen("%s(r3, %s);", "stb_rd_u", s); } /* sgen("%s\t%s", "incb", s); } */
void cgcall(char *s) { sgen("%s\t%s", "call", s); }
void cgstorgb(char *s) { sgen("%s\t%%al,%s", "movb", s); }
void cgldga(char *s) { sgen("%s\tax,offset %s", "mov", s); }
void cgldgw(char *s) { sgen("%s\tax,%s", "mov", s); }
void cgldgb(char *s) { sgen("%s\tal,%s", "mov", s); }
int cgload(void) { char *op = "mov"; int n = Q_val; char *s = gsym(Q_name); int q; switch (Q_type) { case addr_auto: ngen("%s\tcx,[bp%+d]", "lea", n); break; case addr_static: lgen("%s\tcx,offset %c%d", op, n); break; case addr_globl: sgen("%s\tcx,offset %s", op, s); break; case addr_label: lgen("%s\tcx,offset %c%d", op, n); break; case literal: ngen("%s\tcx,%d", op, n); break; case auto_byte: cgclear2(); ngen("%s\tcl,[bp%+d]", op, n); break; case auto_word: ngen("%s\tcx,[bp%+d]", op, n); break; case static_byte: cgclear2(); lgen("%s\tcl,%c%d", op, n); break; case static_word: lgen("%s\tcx,%c%d", op, n); break; case globl_byte: cgclear2(); sgen("%s\tcl,%s", op, s); break; case globl_word: sgen("%s\tcx,%s", op, s); break; case empty: cgpop2(); break; default: fatal("internal: bad type in cgsynth()"); } q = Q_type; Q_type = empty; return empty == q; }
void cgincgb(char *s) { sgen("%s\t%s", "incb", s); }
int cgload(void) { char *op = "movl"; char *opb = "movb"; int n = Q_val; char *s = gsym(Q_name); int q; switch (Q_type) { case addr_auto: ngen("%s\t%d(%%ebp),%%ecx", "leal", n); break; case addr_static: lgen("%s\t$%c%d,%%ecx", op, n); break; case addr_globl: sgen("%s\t$%s,%%ecx", op, s); break; case addr_label: lgen("%s\t$%c%d,%%ecx", op, n); break; case literal: ngen("%s\t$%d,%%ecx", op, n); break; case auto_byte: cgclear2(); ngen("%s\t%d(%%ebp),%%cl", opb, n); break; case auto_word: ngen("%s\t%d(%%ebp),%%ecx", op, n); break; case static_byte: cgclear2(); lgen("%s\t%c%d,%%cl", opb, n); break; case static_word: lgen("%s\t%c%d,%%ecx", op, n); break; case globl_byte: cgclear2(); sgen("%s\t%s,%%cl", opb, s); break; case globl_word: sgen("%s\t%s,%%ecx", op, s); break; case empty: cgpop2(); break; default: fatal("internal: bad type in cgsynth()"); } q = Q_type; Q_type = empty; return empty == q; }
void cgdecgb(char *s) { sgen("%s\t%s", "decb", s); }
void cgldgb(char *s) { sgen("%s\t%s,%%al", "movb", s); }
void cgstorgw(char *s) { sgen("%s\t%%eax,%s", "movl", s); }
void cgldgw(char *s) { sgen("%s\t%s,%%eax", "movl", s); }
/* increment/decrement pointer to local, static, global */ void cgincpl(int a, int v) { ngen("%s(r3, %d, r23);", "ld_rd_o_rs", a); ngen("%s(r3,%d);", "addi", v); ngen("%s(r3, %d, r23);", "st_rd_o_rs", a); } /* ngen2("%s\t$%d,%d(%%ebp);", "addl", v, a); } */ void cgdecpl(int a, int v) { ngen("%s(r3, %d, r23);", "ld_rd_o_rs", a); ngen("%s(r3,%d);", "subi", v); ngen("%s(r3, %d, r23);", "st_rd_o_rs", a); } /* ngen2("%s\t$%d,%d(%%ebp);", "subl", v, a); } */ void cgincps(int a, int v) { lgen("%s(r3, %c%d);", "ld_rd_u", a); ngen("%s(r3,%d);", "addi", v); lgen("%s(r3, %c%d);", "st_rd_u", a); } /* lgen2("addl\t$%d,%c%d", v, a); } */ void cgdecps(int a, int v) { lgen("%s(r3, %c%d);", "ld_rd_u", a); ngen("%s(r3,%d);", "subi", v); lgen("%s(r3, %c%d);", "st_rd_u", a); } /* { lgen2("subl\t$%d,%c%d", v, a); } */ void cgincpg(char *s, int v) { sgen("%s(r3, %s);", "ld_rd_u", s); ngen("%s(r3,%d);", "addi", v); sgen("%s(r3, %s);", "st_rd_u", s); } /* sgen2("%s\t$%d,%s", "addl", v, s); } */ void cgdecpg(char *s, int v) { sgen("%s(r3, %s);", "ld_rd_u", s); ngen("%s(r3,%d);", "subi", v); sgen("%s(r3, %s);", "st_rd_u", s); } /* sgen2("%s\t$%d,%s", "subl", v, s); } */
void cgldga(char *s) { sgen("%s\t$%s,%%eax", "movl", s); }
/* increment/decrement pointer to local, static, global */ void cgincpl(int a, int v) { ngen("%s(r3, %d, r23);", "ld_rd_o_rs", a); ngen("%s(r3,%d);", "addi", v); ngen("%s(r3, %d, r23);", "st_rd_o_rs", a); } /* ngen2("%s\t$%d,%d(%%ebp);", "addl", v, a); } */ void cgdecpl(int a, int v) { ngen("%s(r3, %d, r23);", "ld_rd_o_rs", a); ngen("%s(r3,%d);", "subi", v); ngen("%s(r3, %d, r23);", "st_rd_o_rs", a); } /* ngen2("%s\t$%d,%d(%%ebp);", "subl", v, a); } */ void cgincps(int a, int v) { lgen("%s(r3, %c%d);", "ld_rd_u", a); ngen("%s(r3,%d);", "addi", v); lgen("%s(r3, %c%d);", "st_rd_u", a); } /* lgen2("addl\t$%d,%c%d", v, a); } */ void cgdecps(int a, int v) { lgen("%s(r3, %c%d);", "ld_rd_u", a); ngen("%s(r3,%d);", "subi", v); lgen("%s(r3, %c%d);", "st_rd_u", a); } /* { lgen2("subl\t$%d,%c%d", v, a); } */ void cgincpg(char *s, int v) { sgen("%s(r3, %s);", "ld_rd_u", s); ngen("%s(r3,%d);", "addi", v); sgen("%s(r3, %s);", "st_rd_u", s); } /* sgen2("%s\t$%d,%s", "addl", v, s); } */ void cgdecpg(char *s, int v) { sgen("%s(r3, %s);", "ld_rd_u", s); ngen("%s(r3,%d);", "subi", v); sgen("%s(r3, %s);", "st_rd_u", s); } /* sgen2("%s\t$%d,%s", "subl", v, s); } */ void cginc1iw(void) { cginc1pi(1); } /* ngen("%s\t(%%eax);", "incl", 0); } */ void cgdec1iw(void) { cgdec1pi(1); } /* ngen("%s\t(%%eax);", "decl", 0); } */ void cginc2iw(void) { cginc2pi(1); } /* ngen("%s\t(%%edx);", "incl", 0); } */ void cgdec2iw(void) { cgdec2pi(1); } /* ngen("%s\t(%%edx);", "decl", 0); } */ void cginclw(int a) { cgincpl(a, 1); } /* ngen("%s\t%d(%%ebp);", "incl", a); } */ void cgdeclw(int a) { cgdecpl(a, 1); } /* ngen("%s\t%d(%%ebp);", "decl", a); } */ void cgincsw(int a) { cgincps(a, 1); } /* lgen("%s\t%c%d", "incl", a); } */ void cgdecsw(int a) { cgdecps(a, 1); } /* lgen("%s\t%c%d", "decl", a); } */ void cgincgw(char *s) { cgincpg(s, 1); } /* sgen("%s\t%s", "incl", s); } */ void cgdecgw(char *s) { cgdecpg(s, 1); } /* sgen("%s\t%s", "decl", s); } */ void cginc1ib(void) { ngen("ldb(r3, r0); %s(r3, %d); stb(r3, r0);", "addi", 1); } /* ngen("%s\t(%%eax);", "incb", 0); } */ void cgdec1ib(void) { ngen("ldb(r3, r0); %s(r3, %d); stb(r3, r0);", "subi", 1); } /* ngen("%s\t(%%eax);", "decb", 0); } */ void cginc2ib(void) { ngen("ldb(r3, r2); %s(r3, %d); stb(r3, r2);", "addi", 1); } /* ngen("%s\t(%%edx);", "incb", 0); } */ void cgdec2ib(void) { ngen("ldb(r3, r2); %s(r3, %d); stb(r3, r2);", "subi", 1); } /* ngen("%s\t(%%edx);", "decb", 0); } */ void cginclb(int a) { ngen("%s(r3, %d, r23);", "ldb_rd_o_rs", a); ngen("%s(r3, %d);", "addi", 1); ngen("%s(r3, %d, r23);", "stb_rd_o_rs", a); } /* ngen("%s\t%d(%%ebp);", "incb", a); } */ void cgdeclb(int a) { ngen("%s(r3, %d, r23);", "ldb_rd_o_rs", a); ngen("%s(r3, %d);", "subi", 1); ngen("%s(r3, %d, r23);", "stb_rd_o_rs", a); } /* ngen("%s\t%d(%%ebp);", "decb", a); } */ void cgincsb(int a) { ngen("%s(r3, %c%d);", "ldb_rd_u", a); ngen("%s(r3, %d);", "addi", 1); ngen("%s(r3, %c%d);", "stb_rd_u", a); } /* lgen("%s\t%c%d", "incb", a); } */ void cgdecsb(int a) { ngen("%s(r3, %c%d);", "ldb_rd_u", a); ngen("%s(r3, %d);", "subi", 1); ngen("%s(r3, %c%d);", "stb_rd_u", a); } /* lgen("%s\t%c%d", "decb", a); } */ void cgincgb(char *s) { sgen("%s(r3, %s);", "ldb_rd_u", s); ngen("%s(r3, %d);", "addi", 1); sgen("%s(r3, %s);", "stb_rd_u", s); } /* sgen("%s\t%s", "incb", s); } */ void cgdecgb(char *s) { sgen("%s(r3, %s);", "ldb_rd_u", s); ngen("%s(r3, %d);", "subi", 1); sgen("%s(r3, %s);", "stb_rd_u", s); } /* sgen("%s\t%s", "decb", s); } */
void cgsynth(char *op) { int n = Q_val; char *s = gsym(Q_name); switch (Q_type) { case addr_auto: ngen("%s\t%d(%%ebp),%%ecx", "leal", n); sgen("%s\t%s,%%eax", op, "%ecx"); break; case addr_static: lgen("%s\t$%c%d,%%eax", op, n); break; case addr_globl: sgen("%s\t$%s,%%eax", op, s); break; case addr_label: lgen("%s\t$%c%d,%%eax", op, n); break; case literal: ngen("%s\t$%d,%%eax", op, n); break; case auto_word: ngen("%s\t%d(%%ebp),%%eax", op, n); break; case static_word: lgen("%s\t%c%d,%%eax", op, n); break; case globl_word: sgen("%s\t%s,%%eax", op, s); break; case auto_byte: case static_byte: case globl_byte: cgload(); ngen("%s\t%%ecx,%%eax", op, 0); break; case empty: cgpop2(); sgen("%s\t%s,%%eax", op, "%ecx"); break; default: fatal("internal: bad type in cgsynth()"); } Q_type = empty; }
/* { int lab; lab = label(); gen("orl\t%eax,%eax;"); lgen("%s\t%c%d", how, lab); lgen("%s\t%c%d", "jmp", n); genlab(lab); } */ void cgbrtrue(int n) { cgbr("beq", n); } /* cgbr("jz", n); } */ void cgbrfalse(int n) { cgbr("bne", n); } /* cgbr("jnz", n); } */ void cgjump(int n) { lgen("%s(%c%d);", "b", n); } /* lgen("%s\t%c%d", "jmp", n); } */ void cgldswtch(int n) { lgen("%s(r2, %c%d);", "movi", n); } /* lgen("%s\t$%c%d,%%edx", "movl", n); } */ void cgcalswtch(void) { gen("b(switch);"); } /* gen("jmp\tswitch;"); } */ void cgcase(int v, int l) { lgen2("dc(%d); dc(%c%d);", v, l); } /* lgen2(".long\t%d,%c%d", v, l); } */ void cgpopptr(void) { gen("ld_rd_rs_inc(r2, r25);"); } /* gen("popl\t%edx;"); } */ void cgstorib(void) { ngen("%s(r0, r2);", "stb_rd_rs", 0); } /* ngen("%s\t%%al,(%%edx);", "movb", 0); } */ void cgstoriw(void) { ngen("%s(r0, r2);", "st_rd_rs", 0); } /* ngen("%s\t%%eax,(%%edx);", "movl", 0); } */ void cgstorlb(int n) { ngen("%s(r0, %d, r23);", "stb_rd_o_rs", n); } /* ngen("%s\t%%al,%d(%%ebp);", "movb", n); } */ void cgstorlw(int n) { ngen("%s(r0, %d, r23);", "st_rd_o_rs", n); } /* \t%%eax,%d(%%ebp);", "movl", n); } */ void cgstorsb(int n) { lgen("%s(r0, %c%d);", "stb_rd_o_rs", n); } /* lgen("%s\t%%al,%c%d", "movb", n); } */ void cgstorsw(int n) { lgen("%s(r0, %c%d);", "st_rd_o_rs", n); } /* lgen("\t%%eax,%c%d", "movl", n); } */ void cgstorgb(char *s) { sgen("%s(r0, %s);", "stb_rd_rs", s); } /* sgen("%s\t%%al,%s", "movb", s); } */ void cgstorgw(char *s) { sgen("%s(r0, %s);", "st_rd_rs", s); } /* sgen("%s\t%%eax,%s", "movl", s); } */
void cgincgw(char *s) { sgen("%s\t%s", "incl", s); }
void cgldgb(char *s) { sgen("%s(r0, %s);", "ldb_rd_u", s); } /* sgen("%s\t%s,%%al", "movb", s); } */
void cgdecgw(char *s) { sgen("%s\t%s", "decl", s); }
/* * 386 -> videocore mapping * * eax r0 * ecx r1 * edx r2 * tmp r3 * ebp r23 * esp r25 * * g = global * l = local * s = static * * b = byte * w = word * a = address * */ static int lab_data_skip; void cgdeclare(int id) { lgenraw("%s(%c%d);", "declare", id); } void cglab(int id) { lgenraw("%s(%c%d);", "label", id); } void cgname(char *name) { sgenraw("%s(C%s);", "\nlabel", name); } void cgdata(void) { if (lab_data_skip==0) { lab_data_skip = label(); lgen("%s(%c%d);", "b", lab_data_skip); } /*gen(".data;");*/ } void cgtext(void) { if (lab_data_skip) { cglab(lab_data_skip); lab_data_skip=0; } /*gen(".text;");*/ } void cgprelude(void) { } void cgpostlude(void) { } void cgpublic(char *s) { sgenraw("%s(%s);", "\nglobal", s); /*ngen(".globl\t%s", s, 0);*/ } void cgstatic(char *s) { sgenraw("%s(%s);", "\nstatic", s); } void cglit(int v) { ngen("%s(r0, %d);", "movi", v); } /* ngen("%s\t$%d,%%eax", "movl", v); } */ void cgclear(void) { ngen("%s(r0, %d);", "movi", 0); } /* gen("xorl\t%eax,%eax;"); } */ void cgldgb(char *s) { sgen("%s(r0, %s);", "ldb_rd_u", s); } /* sgen("%s\t%s,%%al", "movb", s); } */ void cgldgw(char *s) { sgen("%s(r0, %s);", "ld_rd_u", s); } /* sgen("%s\t%s,%%eax", "movl", s); } */ void cgldlb(int n) { ngen("%s(r0, %d, r23);", "ldb_rd_o_rs", n); } /* { ngen("%s\t%d(%%ebp),%%al", "movb", n); } */ void cgldlw(int n) { ngen("%s(r0, %d, r23);", "ld_rd_o_rs", n); } /* { ngen("%s\t%d(%%ebp),%%eax", "movl", n); } */ void cgldsb(int n) { lgen("%s(r0, %c%d);", "ldb_rd_u", n); } /* lgen("%s\t%c%d,%%al", "movb", n); } */ void cgldsw(int n) { lgen("%s(r0, %c%d);", "ld_rd_u", n); } /* lgen("%s\t%c%d,%%eax", "movl", n); } */ void cgldla(int n) { ngen("%s(r0, %d, r23);", "lea_rd_o_rs", n); } /* ngen("%s\t%d(%%ebp),%%eax", "leal", n); } */ void cgldsa(int n) { lgen("%s(r0, %c%d);", "lea_rd_u", n); } /* lgen("%s\t$%c%d,%%eax", "movl", n); } */ void cgldga(char *s) { sgen("%s(r0, %s);", "lea_rd_u", s); } /* sgen("%s\t$%s,%%eax", "movl", s); } */
void cgstorgb(char *s) { sgen("%s\t%s,al", "mov", s); }