From 45d6ac2cc13f7881687c2d7f03f9b9892fd85e6e Mon Sep 17 00:00:00 2001 From: Erick Tryzelaar Date: Sun, 16 Aug 2009 23:37:03 +0000 Subject: Expose creating constant ints and floats from strings to ocaml. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@79214 91177308-0d34-0410-b5e6-96231b3b80d8 --- bindings/ocaml/llvm/llvm.ml | 4 ++++ bindings/ocaml/llvm/llvm.mli | 10 ++++++++++ bindings/ocaml/llvm/llvm_ocaml.c | 13 +++++++++++++ 3 files changed, 27 insertions(+) (limited to 'bindings') diff --git a/bindings/ocaml/llvm/llvm.ml b/bindings/ocaml/llvm/llvm.ml index ed3e1865fc..63c79301b2 100644 --- a/bindings/ocaml/llvm/llvm.ml +++ b/bindings/ocaml/llvm/llvm.ml @@ -237,7 +237,11 @@ external is_undef : llvalue -> bool = "llvm_is_undef" external const_int : lltype -> int -> llvalue = "llvm_const_int" external const_of_int64 : lltype -> Int64.t -> bool -> llvalue = "llvm_const_of_int64" +external const_int_of_string : lltype -> string -> int -> llvalue + = "llvm_const_int_of_string" external const_float : lltype -> float -> llvalue = "llvm_const_float" +external const_float_of_string : lltype -> string -> llvalue + = "llvm_const_float_of_string" (*--... Operations on composite constants ..................................--*) external const_string : string -> llvalue = "llvm_const_string" diff --git a/bindings/ocaml/llvm/llvm.mli b/bindings/ocaml/llvm/llvm.mli index f7fcfd999e..cdcbdae61d 100644 --- a/bindings/ocaml/llvm/llvm.mli +++ b/bindings/ocaml/llvm/llvm.mli @@ -469,10 +469,20 @@ external const_int : lltype -> int -> llvalue = "llvm_const_int" external const_of_int64 : lltype -> Int64.t -> bool -> llvalue = "llvm_const_of_int64" +(** [const_int_of_string ty s r] returns the integer constant of type [ty] and + * value [s], with the radix [r]. See the method [llvm::ConstantInt::get]. *) +external const_int_of_string : lltype -> string -> int -> llvalue + = "llvm_const_int_of_string" + (** [const_float ty n] returns the floating point constant of type [ty] and value [n]. See the method [llvm::ConstantFP::get]. *) external const_float : lltype -> float -> llvalue = "llvm_const_float" +(** [const_float_of_string ty s] returns the floating point constant of type + [ty] and value [n]. See the method [llvm::ConstantFP::get]. *) +external const_float_of_string : lltype -> string -> llvalue + = "llvm_const_float_of_string" + (** {7 Operations on composite constants} *) diff --git a/bindings/ocaml/llvm/llvm_ocaml.c b/bindings/ocaml/llvm/llvm_ocaml.c index 88c9a23109..69bd0a2fbc 100644 --- a/bindings/ocaml/llvm/llvm_ocaml.c +++ b/bindings/ocaml/llvm/llvm_ocaml.c @@ -388,11 +388,24 @@ CAMLprim LLVMValueRef llvm_const_of_int64(LLVMTypeRef IntTy, value N, return LLVMConstInt(IntTy, Int64_val(N), Bool_val(SExt)); } +/* lltype -> string -> int -> llvalue */ +CAMLprim LLVMValueRef llvm_const_int_of_string(LLVMTypeRef IntTy, value S, + value Radix) { + return LLVMConstIntOfStringAndSize(IntTy, String_val(S), caml_string_length(S), + Int_val(Radix)); +} + /* lltype -> float -> llvalue */ CAMLprim LLVMValueRef llvm_const_float(LLVMTypeRef RealTy, value N) { return LLVMConstReal(RealTy, Double_val(N)); } +/* lltype -> string -> llvalue */ +CAMLprim LLVMValueRef llvm_const_float_of_string(LLVMTypeRef RealTy, value S) { + return LLVMConstRealOfStringAndSize(RealTy, String_val(S), + caml_string_length(S)); +} + /*--... Operations on composite constants ..................................--*/ /* string -> llvalue */ -- cgit v1.2.3