[LLVMdev] OCaml bindings patch
jianzhou at seas.upenn.edu
Fri Aug 20 17:12:30 PDT 2010
The attached is the OCaml binding patch to 2.6. This still works on
2.6, because the optimizations I am working on rely on some features
of 2.6, which were removed from 2.7. But from the view of OCaml
bindings, it does not change too much from 2.6 to 2.7, I also merged
some new bindings in 2.7 into 2.6.
What this patch does are
1) bindings to define an LLVM IR pretty printer in OCaml, which
traverses a LLVM AST and prints each node. To do so, it allows to
access more properties of prmitive Classes: get Opcode of each
instruction, get ValueID of a subclass of Value. For example, given an
AllocationInst, it can return the allocation size, and other accessing
methods for different kinds of Instructions.
To generate names for unnamed values, the patch also makes
SlotTracker visibly from ./lib/VMCore/AsmWriter.cpp to
Such bindings are defined at ./binding/OCaml/llvm
with other changes at
2) also more bindings to parse data layout.
The existing methods in llvm::TargetData do not allow to get back
contents from llvm::TargetData::Alignments. The patch adds more
methods at include/llvm/Target/TargetData.h to return each element in
These bindings are defined at ./binding/OCaml/target
with other changes at
3) merged some bindings from 2.7...
The patch was generated by
diff -crBN ./llvm-2.6 ./llvm-2.6patch > llvm-2.6-ocamlbindings.patch
where llvm-2.6patch is the upated src wrt the original code ./llvm-2.6/
To apply the patch, go to a dir that contains ./llvm-2.6, and then do
patch -p0 -i llvm-2.6-ocamlbindings.patch
The LLVM IR pretty printer in OCaml using those bindings just works
now. But we are not sure if the bindings are safe, following code
style of LLVM, or breaking other assumptions. The bindings for
SlotTracker and TargetData changed the Core code in LLVM, but they are
orthogonal to other bindings, so can be removed. Any input about how
to improve these bindings is very helpful.
-------------- next part --------------
A non-text attachment was scrubbed...
Size: 89945 bytes
Desc: not available
More information about the llvm-dev