aboutsummaryrefslogtreecommitdiff
path: root/bindings/ocaml/llvm/llvm_ocaml.c
diff options
context:
space:
mode:
authorErick Tryzelaar <idadesub@users.sourceforge.net>2009-08-16 02:20:37 +0000
committerErick Tryzelaar <idadesub@users.sourceforge.net>2009-08-16 02:20:37 +0000
commit1b42cfd1ca03e48835e8e4c91c5dbb598030257f (patch)
treeea956bf23821660f7b4091d6454008e4ed6f7ce2 /bindings/ocaml/llvm/llvm_ocaml.c
parente0f8bf6cbe1bee904021a8ae45008e3703dde283 (diff)
Expose most of the Constant creation functions to ocaml.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@79162 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'bindings/ocaml/llvm/llvm_ocaml.c')
-rw-r--r--bindings/ocaml/llvm/llvm_ocaml.c43
1 files changed, 43 insertions, 0 deletions
diff --git a/bindings/ocaml/llvm/llvm_ocaml.c b/bindings/ocaml/llvm/llvm_ocaml.c
index 610380ca69..d9d4e88ffb 100644
--- a/bindings/ocaml/llvm/llvm_ocaml.c
+++ b/bindings/ocaml/llvm/llvm_ocaml.c
@@ -452,6 +452,49 @@ CAMLprim LLVMValueRef llvm_const_gep(LLVMValueRef ConstantVal, value Indices) {
Wosize_val(Indices));
}
+/* llvalue -> llvalue array -> llvalue */
+CAMLprim LLVMValueRef llvm_const_in_bounds_gep(LLVMValueRef ConstantVal,
+ value Indices) {
+ return LLVMConstInBoundsGEP(ConstantVal, (LLVMValueRef*) Op_val(Indices),
+ Wosize_val(Indices));
+}
+
+/* llvalue -> int array -> llvalue */
+CAMLprim LLVMValueRef llvm_const_extractvalue(LLVMValueRef Aggregate,
+ value Indices) {
+ CAMLparam1(Indices);
+ int size = Wosize_val(Indices);
+ int i;
+ LLVMValueRef result;
+
+ unsigned* idxs = (unsigned*)malloc(size * sizeof(unsigned));
+ for (i = 0; i < size; i++) {
+ idxs[i] = Int_val(Field(Indices, i));
+ }
+
+ result = LLVMConstExtractValue(Aggregate, idxs, size);
+ free(idxs);
+ CAMLreturnT(LLVMValueRef, result);
+}
+
+/* llvalue -> llvalue -> int array -> llvalue */
+CAMLprim LLVMValueRef llvm_const_insertvalue(LLVMValueRef Aggregate,
+ LLVMValueRef Val, value Indices) {
+ CAMLparam1(Indices);
+ int size = Wosize_val(Indices);
+ int i;
+ LLVMValueRef result;
+
+ unsigned* idxs = (unsigned*)malloc(size * sizeof(unsigned));
+ for (i = 0; i < size; i++) {
+ idxs[i] = Int_val(Field(Indices, i));
+ }
+
+ result = LLVMConstInsertValue(Aggregate, Val, idxs, size);
+ free(idxs);
+ CAMLreturnT(LLVMValueRef, result);
+}
+
/*--... Operations on global variables, functions, and aliases (globals) ...--*/
/* llvalue -> bool */