llvm.org GIT mirror llvm / 45d6ac2
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 Erick Tryzelaar 11 years ago
4 changed file(s) with 39 addition(s) and 0 deletion(s). Raw diff Collapse all Expand all
236236 external const_int : lltype -> int -> llvalue = "llvm_const_int"
237237 external const_of_int64 : lltype -> Int64.t -> bool -> llvalue
238238 = "llvm_const_of_int64"
239 external const_int_of_string : lltype -> string -> int -> llvalue
240 = "llvm_const_int_of_string"
239241 external const_float : lltype -> float -> llvalue = "llvm_const_float"
242 external const_float_of_string : lltype -> string -> llvalue
243 = "llvm_const_float_of_string"
240244
241245 (*--... Operations on composite constants ..................................--*)
242246 external const_string : string -> llvalue = "llvm_const_string"
468468 external const_of_int64 : lltype -> Int64.t -> bool -> llvalue
469469 = "llvm_const_of_int64"
470470
471 (** [const_int_of_string ty s r] returns the integer constant of type [ty] and
472 * value [s], with the radix [r]. See the method [llvm::ConstantInt::get]. *)
473 external const_int_of_string : lltype -> string -> int -> llvalue
474 = "llvm_const_int_of_string"
475
471476 (** [const_float ty n] returns the floating point constant of type [ty] and
472477 value [n]. See the method [llvm::ConstantFP::get]. *)
473478 external const_float : lltype -> float -> llvalue = "llvm_const_float"
479
480 (** [const_float_of_string ty s] returns the floating point constant of type
481 [ty] and value [n]. See the method [llvm::ConstantFP::get]. *)
482 external const_float_of_string : lltype -> string -> llvalue
483 = "llvm_const_float_of_string"
474484
475485
476486 (** {7 Operations on composite constants} *)
387387 return LLVMConstInt(IntTy, Int64_val(N), Bool_val(SExt));
388388 }
389389
390 /* lltype -> string -> int -> llvalue */
391 CAMLprim LLVMValueRef llvm_const_int_of_string(LLVMTypeRef IntTy, value S,
392 value Radix) {
393 return LLVMConstIntOfStringAndSize(IntTy, String_val(S), caml_string_length(S),
394 Int_val(Radix));
395 }
396
390397 /* lltype -> float -> llvalue */
391398 CAMLprim LLVMValueRef llvm_const_float(LLVMTypeRef RealTy, value N) {
392399 return LLVMConstReal(RealTy, Double_val(N));
400 }
401
402 /* lltype -> string -> llvalue */
403 CAMLprim LLVMValueRef llvm_const_float_of_string(LLVMTypeRef RealTy, value S) {
404 return LLVMConstRealOfStringAndSize(RealTy, String_val(S),
405 caml_string_length(S));
393406 }
394407
395408 /*--... Operations on composite constants ..................................--*/
211211 ignore (define_global "Const03" c m);
212212 insist (i64_type = type_of c);
213213
214 (* RUN: grep {ConstIntString.*i32.*-1} < %t.ll
215 *)
216 group "int string";
217 let c = const_int_of_string i32_type "-1" 10 in
218 ignore (define_global "ConstIntString" c m);
219 insist (i32_type = type_of c);
220
214221 (* RUN: grep {Const04.*"cruel\\\\00world"} < %t.ll
215222 *)
216223 group "string";
227234
228235 (* RUN: grep {ConstSingle.*2.75} < %t.ll
229236 * RUN: grep {ConstDouble.*3.1459} < %t.ll
237 * RUN: grep {ConstDoubleString.*1.25} < %t.ll
230238 *)
231239 begin group "real";
232240 let cs = const_float float_type 2.75 in
235243
236244 let cd = const_float double_type 3.1459 in
237245 ignore (define_global "ConstDouble" cd m);
246 insist (double_type = type_of cd);
247
248 let cd = const_float_of_string double_type "1.25" in
249 ignore (define_global "ConstDoubleString" cd m);
238250 insist (double_type = type_of cd)
239251 end;
240252