[PATCH] [review request] OCaml bindings: implement Llvm_target.{qualified_, }intptr_type_in_context

Peter Zotov whitequark at whitequark.org
Sat Oct 12 10:31:53 PDT 2013


Hi sylvestre.ledru,

This commit exposes several TargetData functions which accept an explicit context along with their counterparts implicitly using the global context.

In the present form, the changes are backwards compatible. However, nowhere else OCaml bindings have implicitly used the global context. It would be much nicer to only have functions which accept context explicitly here, too.

I do not think much (if any) existing code will be affected, because the TargetData interface is not very useful to frontends without its TargetMachine counterpart.

http://llvm-reviews.chandlerc.com/D1925

Files:
  bindings/ocaml/target/llvm_target.ml
  bindings/ocaml/target/llvm_target.mli
  bindings/ocaml/target/target_ocaml.c

Index: bindings/ocaml/target/llvm_target.ml
===================================================================
--- bindings/ocaml/target/llvm_target.ml
+++ bindings/ocaml/target/llvm_target.ml
@@ -26,10 +26,14 @@
 external byte_order : DataLayout.t -> Endian.t = "llvm_byte_order"
 external pointer_size : DataLayout.t -> int = "llvm_pointer_size"
 external intptr_type : DataLayout.t -> Llvm.lltype = "LLVMIntPtrType"
+external intptr_type_in_context : DataLayout.t -> Llvm.llcontext -> Llvm.lltype
+                                = "llvm_intptr_type_in_context"
 external qualified_pointer_size : DataLayout.t -> int -> int
                                 = "llvm_qualified_pointer_size"
 external qualified_intptr_type : DataLayout.t -> int -> Llvm.lltype
                                = "llvm_qualified_intptr_type"
+external qualified_intptr_type_in_context : DataLayout.t -> Llvm.llcontext -> int -> Llvm.lltype
+                               = "llvm_qualified_intptr_type_in_context"
 external size_in_bits : DataLayout.t -> Llvm.lltype -> Int64.t
                       = "llvm_size_in_bits"
 external store_size : DataLayout.t -> Llvm.lltype -> Int64.t = "llvm_store_size"
Index: bindings/ocaml/target/llvm_target.mli
===================================================================
--- bindings/ocaml/target/llvm_target.mli
+++ bindings/ocaml/target/llvm_target.mli
@@ -53,6 +53,11 @@
     See the method llvm::DataLayout::getIntPtrType. *)
 external intptr_type : DataLayout.t -> Llvm.lltype = "LLVMIntPtrType"
 
+(** Returns the integer type that is the same size as a pointer on a target.
+    See the method llvm::DataLayout::getIntPtrType. *)
+external intptr_type_in_context : DataLayout.t -> Llvm.llcontext -> Llvm.lltype
+                                = "llvm_intptr_type_in_context"
+
 (** Returns the pointer size in bytes for a target in a given address
     space.
     See the method llvm::DataLayout::getPointerSize. *)
@@ -65,6 +70,13 @@
 external qualified_intptr_type : DataLayout.t -> int -> Llvm.lltype
                                = "llvm_qualified_intptr_type"
 
+(** Returns the integer type that is the same size as a pointer on a target
+    in a given address space.
+    See the method llvm::DataLayout::getIntPtrType. *)
+external qualified_intptr_type_in_context
+            : DataLayout.t -> Llvm.llcontext -> int -> Llvm.lltype
+            = "llvm_qualified_intptr_type_in_context"
+
 (** Computes the size of a type in bytes for a target.
     See the method llvm::DataLayout::getTypeSizeInBits. *)
 external size_in_bits : DataLayout.t -> Llvm.lltype -> Int64.t
Index: bindings/ocaml/target/target_ocaml.c
===================================================================
--- bindings/ocaml/target/target_ocaml.c
+++ bindings/ocaml/target/target_ocaml.c
@@ -53,6 +53,11 @@
   return Val_int(LLVMPointerSize(TD));
 }
 
+/* DataLayout.t -> Llvm.llcontext -> int */
+CAMLprim LLVMTypeRef llvm_intptr_type_in_context(value TD, LLVMContextRef C) {
+  return LLVMIntPtrTypeInContext(TargetData_val(TD), C);;
+}
+
 /* DataLayout.t -> int -> int */
 CAMLprim value llvm_qualified_pointer_size(LLVMTargetDataRef TD, value AS) {
   return Val_int(LLVMPointerSizeForAS(TD, Int_val(AS)));
@@ -63,6 +68,12 @@
   return LLVMIntPtrTypeForAS(TD, Int_val(AS));
 }
 
+/* DataLayout.t -> Llvm.llcontext -> int -> Llvm.lltype */
+CAMLprim LLVMTypeRef llvm_qualified_intptr_type_in_context(value TD, LLVMContextRef C,
+                                                           value AS) {
+  return LLVMIntPtrTypeForASInContext(TargetData_val(TD), C, Int_val(AS));
+}
+
 /* DataLayout.t -> Llvm.lltype -> Int64.t */
 CAMLprim value llvm_size_in_bits(LLVMTargetDataRef TD, LLVMTypeRef Ty) {
   return caml_copy_int64(LLVMSizeOfTypeInBits(TD, Ty));
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D1925.1.patch
Type: text/x-patch
Size: 3787 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20131012/d5321098/attachment.bin>


More information about the llvm-commits mailing list