But we did have to write a parser, (after we augmented, and finzlized the grammer). Then once that was saved in an internal data stucture, we then did work on going to an intermediate low level (3 operand format, with basic blocks and such) code format. The prof has written code to take it from the low level to x86. The prof also had written an small optimizer, and a few other things.
But here is the final code that he wanted us to run:
int a;
int addThem(int d, int e) {
int f;
f = d + e;
return f;
}
int main (void) {
int b;
int c;
int g;
int h;
int i;
b = 5;
if (b == 5) {
a = 3;
}
else {
a = 4;
}
g = 0;
i = 1;
while (i <= 8) {
g = g + i;
i = i+1;
}
h = g / 3;
g = h * 4;
c = addThem(a, b);
putchar (c+g);
putchar (12);
return 0;
}
|