Advanced Code Generation
- Parameter Passing
- Short-circuit boolean evaluation
- Arrays
- Classes
Advanced Code Generation Parameter Passing Short-circuit boolean - - PowerPoint PPT Presentation
Advanced Code Generation Parameter Passing Short-circuit boolean evaluation Arrays Classes Advanced Code Generation Parameter Passing Short-circuit boolean evaluation Arrays Classes Im away this
mid (locals & temps)
(state)
return pc high low A
return value
sp sp
fp
lo A mid (locals & temps)
(state)
return pc
return value
sp sp
fp
String r1 = Machine.getReg() foreach a := STO in argument list, p := STO in parameter list do Machine.emitLoad(a, r1); Machine.emitStoreArg(r1, p); end String r1 = Machine.getReg() foreach a := STO in argument list, p := STO in parameter list do Machine.emitLoad(a, r1); Machine.emitStoreArg(r1, p); end
return val?
in regs, like SPARC?
return val?
in regs, like SPARC?
w := qsort(A, lo+mid, hi)
if (x != 0 && y/x > 2) (* when 1st fails, don't test 2nd *) S1 if (y == 0 || x/y < 0) (* when 1st succeeds, don't test 2nd *) S2
if (x != 0) if (y/x > 2) S1 if (y == 0) S2 else if (x/y < 0) S2
if (x != 0 && y/x > 2) (* when 1st fails, don't test 2nd *) S1 if (y == 0 || x/y < 0) (* when 1st succeeds, don't test 2nd *) S2
if (x != 0) if (y/x > 2) S1 if (y == 0) S2 else if (x/y < 0) S2
code is an inherited attribute, need a code buffer).
jump to the same single piece of code?
so produce a value, not control flow. We abandoned our model-driven approach!
code is an inherited attribute, need a code buffer).
jump to the same single piece of code?
so produce a value, not control flow. We abandoned our model-driven approach!
E ::= E:e1 T_OR {: orTrueStack.push(Machine.newLabel());
RESULT = new ExprSTO(TypeValues.bool); Machine.emitCond(e1, orTrueStack.top()); // if true, jump to set true :} E:e2 {: Machine.emitCond(e2, orTrueStack.top()); // if true, jump, to set true Machine.emitSetFalse(RESULT); // fall through to set false Machine.emitGoto(orFalseStack.top()); Machine.emitLabel(orTrueStack.top()); Machine.emitSetTrue(RESULT); Machine.emitLabel(orFalseStack.pop()); Machine.emitLabel(orTrueStack.pop()); :} E ::= E:e1 T_OR {: orTrueStack.push(Machine.newLabel());
RESULT = new ExprSTO(TypeValues.bool); Machine.emitCond(e1, orTrueStack.top()); // if true, jump to set true :} E:e2 {: Machine.emitCond(e2, orTrueStack.top()); // if true, jump, to set true Machine.emitSetFalse(RESULT); // fall through to set false Machine.emitGoto(orFalseStack.top()); Machine.emitLabel(orTrueStack.top()); Machine.emitSetTrue(RESULT); Machine.emitLabel(orFalseStack.pop()); Machine.emitLabel(orTrueStack.pop()); :}