void genwhile(SNODE *stmt) /* * generate code to evaluate a while statement. */ { int lab1, lab2, lab3; initstack(); /* initialize temp registers */ lab1 = contlab; /* save old continue label */ contlab = nextlabel++; /* new continue label */ if( stmt->s1 != 0 ) /* has block */ { lab2 = breaklab; /* save old break label */ breaklab = nextlabel++; gen_code(op_jmp,0,make_label(contlab),0); lab3 = nextlabel++; gen_label(lab3); genstmt(stmt->s1); gen_label(contlab); if (stmt->lst) gen_line(stmt->lst); initstack(); truejp(stmt->exp,lab3); gen_label(breaklab); breaklab = lab2; /* restore old break label */ } else /* no loop code */ { if (stmt->lst) gen_line(stmt->lst); gen_label(contlab); initstack(); truejp(stmt->exp,contlab); } contlab = lab1; /* restore old continue label */ }
void gendo(SNODE *stmt) /* * generate code for a do - while loop. */ { int oldcont, oldbreak; oldcont = contlab; oldbreak = breaklab; contlab = nextlabel++; gen_label(contlab); if( stmt->s1 != 0 && stmt->s1->next != 0 ) { breaklab = nextlabel++; genstmt(stmt->s1); /* generate body */ initstack(); truejp(stmt->exp,contlab); gen_label(breaklab); } else { genstmt(stmt->s1); initstack(); truejp(stmt->exp,contlab); } breaklab = oldbreak; contlab = oldcont; }
void genselect(STATEMENT *stmt, SYMBOL *funcsp, BOOL jmptrue) { if (stmt->altlabel) { // gen_label(stmt->altlabel); // intermed_tail->dc.opcode = i_skipcompare; } if (jmptrue) truejp(stmt->select, funcsp, stmt->label); else falsejp(stmt->select, funcsp, stmt->label); if (stmt->altlabel) { // gen_label(stmt->altlabel); // intermed_tail->dc.opcode = i_skipcompare; } }
void gen_for(SNODE *stmt) /* * generate code to evaluate a for loop */ { int old_break, old_cont, exit_label, loop_label, start_label; int areg, sreg; old_break = breaklab; old_cont = contlab; loop_label = nextlabel++; contlab = nextlabel++; start_label = nextlabel++; exit_label = nextlabel++; InitRegs(); if (stmt->label != 0) { gen_void_external(stmt->label); } gen_codes(op_jmp, 0, make_label(start_label), 0); gen_label(loop_label); if (stmt->s1 != 0) { breaklab = exit_label; genstmt(stmt->s1); } if (stmt->lst) gen_line(stmt->lst); gen_label(contlab); InitRegs(); if (stmt->s2 != 0) { gen_void_external(stmt->s2); } gen_label(start_label); InitRegs(); ChooseRegs(&areg, &sreg); if (stmt->exp != 0) truejp(stmt->exp, areg, sreg, loop_label); else gen_codes(op_jmp, 0, make_label(loop_label), 0); gen_label(exit_label); breaklab = old_break; contlab = old_cont; }
void gendo(SNODE *stmt) /* * generate code for a do - while loop. */ { int oldcont, oldbreak, looplab; int areg, sreg; oldcont = contlab; oldbreak = breaklab; looplab = nextlabel++; contlab = nextlabel++; breaklab = nextlabel++; gen_label(looplab); genstmt(stmt->s1); /* generate body */ gen_label(contlab); InitRegs(); ChooseRegs(&areg, &sreg); truejp(stmt->exp, areg, sreg, looplab); gen_label(breaklab); breaklab = oldbreak; contlab = oldcont; }
void gen_for(SNODE *stmt) /* * generate code to evaluate a for loop */ { int old_break, old_cont, exit_label, loop_label; old_break = breaklab; old_cont = contlab; loop_label = nextlabel++; exit_label = nextlabel++; contlab = nextlabel++; initstack(); if( stmt->label != 0 ) gen_expr(stmt->label,F_ALL | F_NOVALUE ,natural_size(stmt->label)); gen_code(op_jmp,0,make_label(contlab),0); gen_label(loop_label); if( stmt->s1 != 0 ) { breaklab = exit_label; genstmt(stmt->s1); } initstack(); if( stmt->s2 != 0 ) gen_expr(stmt->s2,F_ALL | F_NOVALUE,natural_size(stmt->s2)); gen_label(contlab); if (stmt->lst) gen_line(stmt->lst); initstack(); if( stmt->exp != 0 ) truejp(stmt->exp,loop_label); else gen_code(op_jmp,0,make_label(loop_label),0); gen_label(exit_label); breaklab = old_break; contlab = old_cont; }