void cgcmp(char *inst) { int lab = label(); gen("xorl\t%edx,%edx"); if (empty == Q_type) { cgpop2(); gen("cmpl\t%eax,%ecx"); } else { cgsynth("cmpl"); } lgen("%s\t%c%d", inst, lab); gen("incl\t%edx"); genlab(lab); gen("movl\t%edx,%eax"); }
void cgbrcond(char *i, int n) { int lab = label(); if (empty == Q_type) { cgpop2(); gen("cmpl\t%eax,%ecx"); } else { cgsynth("cmpl"); } lgen("%s\t%c%d", i, lab); lgen("%s\t%c%d", "jmp", n); genlab(lab); }
void cgcmp(char *inst) { int lab = label(); gen("xor\tdx,dx"); if (empty == Q_type) { cgpop2(); gen("cmp\tcx,ax"); } else { cgsynth("cmp"); } lgen("%s\t%c%d", inst, lab); gen("inc\tdx"); genlab(lab); gen("mov\tax,dx"); }
void cgcmp(char *inst) { int lab; lab = label(); gen("xorl\t%edx,%edx"); cgpop2(); gen("cmpl\t%eax,%ecx"); lgen("%s\t%c%d", inst, lab); gen("incl\t%edx"); genlab(lab); gen("movl\t%edx,%eax"); }
void cgcmp(char *inst) { int lab; lab = label(); gen("movi(r2, 0);"); cgpop2(); gen("cmp(r1, r0);"); lgen("%s(%c%d);", inst, lab); gen("addi(r2, 1);"); genlab(lab); gen("mov(r0, r2);"); }
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 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; }
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; }