Intermediate Code Generator

Expressed as quadruples: Opr Arg1, Arg2, Store/result

If there is a while, add jmpf right away only

jmpf always come first

Intermediate Code Generator OperatorsIntermediate Code Generator OperatorsPasted image 20241214144120.png

Example Alvina Aulia Intermediate Code Generator

x := 1;
y := x + 10;
while (x<y) {
	x := x + 1;
	if (x % 2 == 1) then
		y := y + 1;
	else y := y - 2;
}
  1. mov 1, , x (x := 1)
  2. add x, 10, t1 (x + 10)
  3. mov t1, , y (y := ...)
  4. lt x, y, t2 (x < y)
  5. jmpf t2, , [17] (while ...)
  6. add x, 1, t3 (x + 1)
  7. mov x, , t3 (x := ...)
  8. mod x, 2, t4 (x % 2)
  9. eq t4, 1, t5 (... == 1)
  10. jmpf t5, , [14] (if ...)
  11. add y, 1, t6 (y + 1)
  12. mov t6, , y (y := ...)
  13. jmp , , [17] break
  14. sub y, 1, t7 (y - 2)
  15. mov t7, , y (y := ...)
  16. jmp , , [17] break
  17. ... remaining code

Status: #idea
Tags: compilation-techniques > Final ExamCompilation Techniques NotesMid Exam RE to DFA RE to E-NFA to DFA Context Free Grammar Top down parsing Final Exam Bottom Up Parsing Directed Acyclic Graph TAC, Triples, Quadriples Intermediate Code Generator Annotated Parse Tree Three Address Statement https://www.youtube.com/watch?v=\_Jng5xgLxkI&list=PLB2GiO0mMjw9J_OwnDMAqtsANzWsIylQz&index=9&ab_channel=HIMTIBINUS Status: #MOC Tags:


References