Reputation: 782
I've read through the llvm Kaleidoscope tutorial, but it's about how to use their tools. I'm looking for a way to write my own code that allow me to take an abstract syntax tree and generate the llvm IR.
Unfortunately, I'm a little lost on how to go about doing that. My current idea was to have each node of my AST do a fill in the blank style string generation. However this seems inelegant, and there is probably a better way to do this.
I read this question which is simalar to mine, but from my understanding of the llvm IR, which could be completely off, is that it behaves similar to a higher level language than traditional assembly languages, with it having functions, and variables(infinite registers). So I think different techniques may apply.
Upvotes: 0
Views: 397
Reputation: 8088
Not inelegant at all. Generally speaking: at this point most compilers are likely going to generate some form of IR or VM instruction set which likely gets optimized based on well documented approaches. At the end, the compiler translates that result/outcome to the target machine code.
Think of LLVM-IR as that internal IR that you are going to generate and let the toolchain take care of optimizing and creating machine code.
Upvotes: 1