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@.child[0]);
GenSub(node@.child[1]);
Tseqno += 1; node@.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.