I’ve been looking at compiler design. I’ve done a one semester course on it at University and have been reading Modern Compiler Design by Grune et al, the book seems to advocate an annotated Abstract Syntax Tree as the intermediate code, and this is what we used in the course.
My question is what are the benefits of this approach versus producing some kind of stack-machine language or low level pseudo code , particularly with regard to having a compiler which can target many machines.
Is it a good idea to simply target an already existing low level representation such as LLVM and use that as the intermediate representation?
If your language is complicated enough, you’d end up having a sequence of slightly different intermediate representations any way. And it does not really matter, which representation will be your final target – llvm, C, native code, CLR, JVM, whatever. It should not affect the design and architecture of your compiler.
And, from my personal experience, the more intermediate steps you have, with transforms in between as trivial as possible, the better your compiler’s architecture is.