- OCaml LLVM bindings tutorial, part 1
- OCaml LLVM bindings tutorial, part 2
- OCaml LLVM bindings tutorial, part 3
In the previous examples, we’ve seen how to build OCaml applications to read, manipulate and write LLVM bitcode.
To be able to generate realistic code, we now need to add a few more things. This part explains how to create bitcode with a correctly specified target triple, how to verify bitcode, and write a hello world application.
Target Triple and Data Layout
While LLVM IR is (or should be) target independent, there are a few things that are not. For example, the support for some instructions, the padding and alignment inside structures, the endianness, the size of pointers, etc. All these things are specified in two attributes of modules: the target triple, and the data layout.
In the current (3.5) version of LLVM, these two attributes are optional. However, they could become mandatory in the future, so it is best specifying them.
Note: in my personal opinion, specifying that inside the module is clearly
redundant with the
-march= option of
llc. Most of this could have been
handled by compiler flags, instead of creating situations where one can ...