[LLVMdev] Simplifying a front-end project
Bagel
bagel99 at gmail.com
Thu Aug 27 09:45:47 PDT 2009
Vikram, I have implemented a front-end for a new language that generates LLVM
assembly language. I used that approach for three reasons:
1. The API learning curve looked steep.
2. It is easy to read the LLVM assembly source to see if things are correct.
3. But mainly, I wanted to implement my front-end in my new language, so
the C/C++ bindings might not be applicable or easy to use.
Each node of my AST is typed. As I generate for it, I give it a
unique sequence number. Then I use a printf-like format to describe the
output. Here's what generating for an ADD AST looks like:
GenSub(node at .child[0]);
GenSub(node at .child[1]);
Tseqno += 1; node at .seqno = Tseqno;
Print("\t%N = add %T %0N, %1N\n", node);
This recursively generates the left and right side of the node, gives the node
a sequence number and then prints the LLVM assembly. In the format:
%N - prints node name
%T - prints node type
%0N - prints node name of child 0
%1N - prints node name of child 1
Obviously, there's more to it than that; but that's the general approach.
More information about the llvm-dev
mailing list