We now introduce a code generation scheme for statements:
S[if(e) s1 else s2] = E[e]
cmpl $1, %eax
jnz lab1
S[s1;]
jmp lab2
lab1: S[s2;]
lab2: …
Here, lab1 and lab2 are new labels and
S[e;] = G[e]
For a WHILE-DO loop,
S[while(e) s] = lab1: E[e]
cmpl $1, %eax
jnz lab2
S[s]
jmp lab1
lab2: …
Here, lab1 and lab2 are new labels.
An alternative code generation rule for a WHILE-DO loop:
S[while(e) s] = jmp lab2
lab1: S[s]
lab2: E[e]
cmpl $1, %eax
jz lab1
The constructs of high-level languages can be implemented using sequences of machine instructions. It is important to select good target instructions for each source construct. Code Generation schemes can be used to describe the mapping between the IR and target language. To get better code quality, we should:
3.145.125.51