[llvm-commits] [PATCH] OCaml/C bindings updates

Cameron Zwarich zwarich at apple.com
Mon Oct 10 23:11:53 PDT 2011


There are a bunch of tabs throughout these changes. Please convert them to spaces before committing.

#4 has an extraneous change to lib/VMCore/Core.cpp that shouldn't be there.

The indentation here is a bit strange. What is the Ocaml standard in LLVM?

diff --git a/bindings/ocaml/llvm/llvm.ml b/bindings/ocaml/llvm/llvm.ml
index 23b51f6..eecfa91 100644
--- a/bindings/ocaml/llvm/llvm.ml
+++ b/bindings/ocaml/llvm/llvm.ml
@@ -1126,7 +1126,14 @@ let rec string_of_lltype ty =
   (* FIXME: stop infinite recursion! :) *)
   match classify_type ty with
     TypeKind.Integer -> "i" ^ string_of_int (integer_bitwidth ty)
-  | TypeKind.Pointer -> (string_of_lltype (element_type ty)) ^ "*"
+  | TypeKind.Pointer ->
+          (let ety = element_type ty in
+          match classify_type ety with
+          | TypeKind.Struct ->
+                  (match struct_name ety with
+                  | None -> (string_of_lltype ety)
+                  | Some s -> s) ^ "*"
+          | _ -> (string_of_lltype (element_type ty)) ^ "*")
   | TypeKind.Struct ->
       let s = "{ " ^ (concat2 ", " (
                 Array.map string_of_lltype (struct_element_types ty)

I only took a look at the patches that you said weren't trivial, but it looks good to me besides those issues.

Cameron

On Oct 5, 2011, at 6:12 AM, Török Edwin wrote:

> Hi,
> 
> Attached is a series of patches to bring the OCaml bindings in sync with the C bindings,
> they are mostly trivial changes.
> 
> Even with these patches there are some C bindings that are not yet exposed in the OCaml bindings
> for various reasons, I will try to add more bindings as I find them.
> 
> Some patches also add C bindings: LLVMTypeIsSized, LLVMGetStructName,
> LLVMGetInstructionOpcode, LLVMGetICmpPredicate,
> LLVMGetMDString, LLVMGetMDNumOperands, LLVMGetMDNodeOperand, LLVMGetNamedMetadataNumOperands,
> LLVMGetNamedMetadataOperands.
> These allow the OCaml bindings to be usable for analyzing LLVM IR, not just emitting LLVM IR.
> 
> These are the trivial patches, I intend to commit them (after compile-testing each) unless there are objections:
> 0001-add-tests.patch
> 0002-Don-t-require-C-bindings-opcode-numbers-to-be-kept-i.patch
> 0005-ocaml-bindings-add-llvm_ipo-based-on-IPO.h.patch
> 0007-C-OCaml-API-to-retrieve-struct-name.patch
> 0009-ocaml-C-bindings-getmdstring-add-num_op-get_op-shoul.patch
> 0010-add-binding-to-read-icmp-predicate.patch
> 0011-ocaml-C-bindings-type-isSized.patch
> 0013-Add-uwtable-returnstwice-and-nonlazybind-to-the-C-bi.patch
> 
> These patches are somewhat larger, but mostly mechanical. Wouldn't hurt if someone else double-checkes them though:
> 0003-ocaml-bindings-add-getopcode-for-constant-and-instru.patch
> 0014-OCaml-bindings-add-some-missing-functions-and-testca.patch
> 
> And finally these are the patches which would need review:
> 
> 0004-ocaml-bindings-introduce-classify_value.patch
> 0006-ocaml-bindings-add-findlib-META-support.patch
> 0008-fix-infinite-recursion-on-string_of_lltype.patch
> 0012-OCaml-bindings-fix-attributes-to-use-all-32-bits.patch




More information about the llvm-commits mailing list