Suppose that the purpose of an assignment is to write a compiler that works on a subset of C language (you can assume a subset of whatever language, just supporting basic scripting expressiveness without having complex things as objects).
What kind of intermediate code could be used to verify the correctness of the compiler? I was talking with a professor and he spoke about the fact that he didn't know what to give to his students as the VM to be used for the "compiled code" so I wondered which could be a good solution.
Subset of C -> Compiler -> Code? -> VM
in which code could be either in binary format or better in an ASCII format (something like pseudo-asm).
I'm looking for something already made, not how to structure this intermediate code and the VM, just an easy and simple one ready to be used to test some compiled programs..
You could describe some abstract machine design and then provide it an instruction set in list-format. I small LISP parser is a nobrainer in parsers.
(label add-two)
(init-stack-frame 2)
(load r1 0)
(load r2 1)
(add val r1 r2)
(goto cont)
Also, writing a lisp interpreter to read this in is a nobrainer.
load_labels (index, expr, env)
if expr.first == 'label'
env.set(expr.second, index)
interpret (machine, expr, env)
return env.lookup(expr.first).eval(machine, expr.tail)