2
votes

How is native code generated using llvm?

If it is possible, can it be done using a Haskell binding?

upd: I mean generate code not in memory, I mean how to generate code and for example save it to file.

1

1 Answers

10
votes

LLVM is a compiler infrastructure that generates native code by processing its internal language — produced by compilers as textual source or an in-memory representation — through a wide variety of optimisations and transformations before converting and linking it into the final native code. So, yes, LLVM can generate native code; in fact, that's its primary purpose.

There is a binding to the LLVM library for Haskell. You can produce LLVM bitcode files with writeBitcodeToFile; llvm-ld can then link those into native code.