[llvm-commits] [llvm] r42101 - in /llvm/trunk: bindings/ocaml/llvm/llvm.ml bindings/ocaml/llvm/llvm.mli bindings/ocaml/llvm/llvm_ocaml.c include/llvm-c/Core.h lib/VMCore/Core.cpp test/Bindings/Ocaml/vmcore.ml
Gordon Henriksen
gordonhenriksen at mac.com
Tue Sep 18 11:07:52 PDT 2007
Author: gordon
Date: Tue Sep 18 13:07:51 2007
New Revision: 42101
URL: http://llvm.org/viewvc/llvm-project?rev=42101&view=rev
Log:
Tests of the ocaml (and thus C) bindings for constants.
Modified:
llvm/trunk/bindings/ocaml/llvm/llvm.ml
llvm/trunk/bindings/ocaml/llvm/llvm.mli
llvm/trunk/bindings/ocaml/llvm/llvm_ocaml.c
llvm/trunk/include/llvm-c/Core.h
llvm/trunk/lib/VMCore/Core.cpp
llvm/trunk/test/Bindings/Ocaml/vmcore.ml
Modified: llvm/trunk/bindings/ocaml/llvm/llvm.ml
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/bindings/ocaml/llvm/llvm.ml?rev=42101&r1=42100&r2=42101&view=diff
==============================================================================
--- llvm/trunk/bindings/ocaml/llvm/llvm.ml (original)
+++ llvm/trunk/bindings/ocaml/llvm/llvm.ml Tue Sep 18 13:07:51 2007
@@ -141,14 +141,18 @@
external set_value_name : string -> llvalue -> unit = "llvm_set_value_name"
(*--... Operations on constants of (mostly) any type .......................--*)
+external is_constant : llvalue -> bool = "llvm_is_constant"
external make_null : lltype -> llvalue = "llvm_make_null"
-external make_all_ones : lltype -> llvalue = "llvm_make_all_ones"
+external make_all_ones : (*int|vec*)lltype -> llvalue = "llvm_make_all_ones"
external make_undef : lltype -> llvalue = "llvm_make_undef"
external is_null : llvalue -> bool = "llvm_is_null"
+external is_undef : llvalue -> bool = "llvm_is_undef"
(*--... Operations on scalar constants .....................................--*)
external make_int_constant : lltype -> int -> bool -> llvalue
= "llvm_make_int_constant"
+external make_int64_constant : lltype -> Int64.t -> bool -> llvalue
+ = "llvm_make_int64_constant"
external make_real_constant : lltype -> float -> llvalue
= "llvm_make_real_constant"
Modified: llvm/trunk/bindings/ocaml/llvm/llvm.mli
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/bindings/ocaml/llvm/llvm.mli?rev=42101&r1=42100&r2=42101&view=diff
==============================================================================
--- llvm/trunk/bindings/ocaml/llvm/llvm.mli (original)
+++ llvm/trunk/bindings/ocaml/llvm/llvm.mli Tue Sep 18 13:07:51 2007
@@ -124,14 +124,18 @@
external set_value_name : string -> llvalue -> unit = "llvm_set_value_name"
(*--... Operations on constants of (mostly) any type .......................--*)
+external is_constant : llvalue -> bool = "llvm_is_constant"
external make_null : lltype -> llvalue = "llvm_make_null"
-external make_all_ones : lltype -> llvalue = "llvm_make_all_ones"
+external make_all_ones : (*int|vec*)lltype -> llvalue = "llvm_make_all_ones"
external make_undef : lltype -> llvalue = "llvm_make_undef"
external is_null : llvalue -> bool = "llvm_is_null"
+external is_undef : llvalue -> bool = "llvm_is_undef"
(*--... Operations on scalar constants .....................................--*)
external make_int_constant : lltype -> int -> bool -> llvalue
= "llvm_make_int_constant"
+external make_int64_constant : lltype -> Int64.t -> bool -> llvalue
+ = "llvm_make_int64_constant"
external make_real_constant : lltype -> float -> llvalue
= "llvm_make_real_constant"
Modified: llvm/trunk/bindings/ocaml/llvm/llvm_ocaml.c
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/bindings/ocaml/llvm/llvm_ocaml.c?rev=42101&r1=42100&r2=42101&view=diff
==============================================================================
--- llvm/trunk/bindings/ocaml/llvm/llvm_ocaml.c (original)
+++ llvm/trunk/bindings/ocaml/llvm/llvm_ocaml.c Tue Sep 18 13:07:51 2007
@@ -248,10 +248,20 @@
}
/* llvalue -> bool */
+CAMLprim value llvm_is_constant(value Ty) {
+ return Val_bool(LLVMIsConstant((LLVMValueRef) Ty));
+}
+
+/* llvalue -> bool */
CAMLprim value llvm_is_null(value Val) {
return Val_bool(LLVMIsNull((LLVMValueRef) Val));
}
+/* llvalue -> bool */
+CAMLprim value llvm_is_undef(value Ty) {
+ return Val_bool(LLVMIsUndef((LLVMValueRef) Ty));
+}
+
/*--... Operations on scalar constants .....................................--*/
/* lltype -> int -> bool -> llvalue */
@@ -266,6 +276,12 @@
return (value) LLVMGetIntConstant((LLVMTypeRef) IntTy, N2, Bool_val(SExt));
}
+/* lltype -> Int64.t -> bool -> llvalue */
+CAMLprim value llvm_make_int64_constant(value IntTy, value N, value SExt) {
+ return (value) LLVMGetIntConstant((LLVMTypeRef) IntTy, Int64_val(N),
+ Bool_val(SExt));
+}
+
/* lltype -> float -> llvalue */
CAMLprim value llvm_make_real_constant(value RealTy, value N) {
return (value) LLVMGetRealConstant((LLVMTypeRef) RealTy, Double_val(N));
@@ -276,7 +292,7 @@
/* string -> bool -> llvalue */
CAMLprim value llvm_make_string_constant(value Str, value NullTerminate) {
return (value) LLVMGetStringConstant(String_val(Str),
- Wosize_val(Str),
+ caml_string_length(Str),
Bool_val(NullTerminate) == 0);
}
Modified: llvm/trunk/include/llvm-c/Core.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm-c/Core.h?rev=42101&r1=42100&r2=42101&view=diff
==============================================================================
--- llvm/trunk/include/llvm-c/Core.h (original)
+++ llvm/trunk/include/llvm-c/Core.h Tue Sep 18 13:07:51 2007
@@ -176,7 +176,9 @@
LLVMValueRef LLVMGetNull(LLVMTypeRef Ty); /* all zeroes */
LLVMValueRef LLVMGetAllOnes(LLVMTypeRef Ty); /* only for int/vector */
LLVMValueRef LLVMGetUndef(LLVMTypeRef Ty);
+int LLVMIsConstant(LLVMValueRef Val);
int LLVMIsNull(LLVMValueRef Val);
+int LLVMIsUndef(LLVMValueRef Val);
/* Operations on scalar constants */
LLVMValueRef LLVMGetIntConstant(LLVMTypeRef IntTy, unsigned long long N,
Modified: llvm/trunk/lib/VMCore/Core.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/VMCore/Core.cpp?rev=42101&r1=42100&r2=42101&view=diff
==============================================================================
--- llvm/trunk/lib/VMCore/Core.cpp (original)
+++ llvm/trunk/lib/VMCore/Core.cpp Tue Sep 18 13:07:51 2007
@@ -201,12 +201,20 @@
return wrap(UndefValue::get(unwrap(Ty)));
}
+int LLVMIsConstant(LLVMValueRef Ty) {
+ return isa<Constant>(unwrap(Ty));
+}
+
int LLVMIsNull(LLVMValueRef Val) {
if (Constant *C = dyn_cast<Constant>(unwrap(Val)))
return C->isNullValue();
return false;
}
+int LLVMIsUndef(LLVMValueRef Val) {
+ return isa<UndefValue>(unwrap(Val));
+}
+
/*--.. Operations on scalar constants ......................................--*/
LLVMValueRef LLVMGetIntConstant(LLVMTypeRef IntTy, unsigned long long N,
Modified: llvm/trunk/test/Bindings/Ocaml/vmcore.ml
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Bindings/Ocaml/vmcore.ml?rev=42101&r1=42100&r2=42101&view=diff
==============================================================================
--- llvm/trunk/test/Bindings/Ocaml/vmcore.ml (original)
+++ llvm/trunk/test/Bindings/Ocaml/vmcore.ml Tue Sep 18 13:07:51 2007
@@ -11,27 +11,21 @@
open Llvm_bitwriter
-(* Tiny unit test framework *)
+(* Tiny unit test framework - really just to help find which line is busted *)
let exit_status = ref 0
let case_num = ref 0
-let all_done () =
- prerr_endline "";
- exit !exit_status
-
let group name =
- prerr_endline "";
case_num := 0;
- prerr_string (" " ^ name ^ "... ")
+ prerr_endline (" " ^ name ^ "...")
let insist cond =
incr case_num;
- prerr_char ' ';
- if not cond then begin
- exit_status := 10;
- prerr_char '!'
- end;
- prerr_int !case_num
+ let msg = if cond then " pass " else begin
+ exit_status := 10;
+ " FAIL "
+ end in
+ prerr_endline (msg ^ (string_of_int !case_num))
let suite name f =
prerr_endline (name ^ ":");
@@ -133,6 +127,102 @@
insist (ty <> make_opaque_type ())
+(*===-- Constants ---------------------------------------------------------===*)
+
+let test_constants () =
+ (* RUN: grep {Const01.*i32.*-1} < %t.ll
+ *)
+ group "int";
+ let c = make_int_constant i32_type (-1) true in
+ ignore (define_global "Const01" c m);
+ insist (i32_type = type_of c);
+ insist (is_constant c);
+
+ (* RUN: grep {Const02.*i64.*-1} < %t.ll
+ *)
+ group "sext int";
+ let c = make_int_constant i64_type (-1) true in
+ ignore (define_global "Const02" c m);
+ insist (i64_type = type_of c);
+
+ (* RUN: grep {Const03.*i64.*4294967295} < %t.ll
+ *)
+ group "zext int64";
+ let c = make_int64_constant i64_type (Int64.of_string "4294967295") false in
+ ignore (define_global "Const03" c m);
+ insist (i64_type = type_of c);
+
+ (* RUN: grep {Const04.*"cruel\\\\00world"} < %t.ll
+ *)
+ group "string";
+ let c = make_string_constant "cruel\x00world" false in
+ ignore (define_global "Const04" c m);
+ insist ((make_array_type i8_type 11) = type_of c);
+
+ (* RUN: grep {Const05.*"hi\\\\00again\\\\00"} < %t.ll
+ *)
+ group "string w/ null";
+ let c = make_string_constant "hi\x00again" true in
+ ignore (define_global "Const05" c m);
+ insist ((make_array_type i8_type 9) = type_of c);
+
+ (* RUN: grep {Const06.*3.1459} < %t.ll
+ *)
+ group "real";
+ let c = make_real_constant double_type 3.1459 in
+ ignore (define_global "Const06" c m);
+ insist (double_type = type_of c);
+
+ let one = make_int_constant i16_type 1 true in
+ let two = make_int_constant i16_type 2 true in
+ let three = make_int_constant i32_type 3 true in
+ let four = make_int_constant i32_type 4 true in
+
+ (* RUN: grep {Const07.*\\\[ i32 3, i32 4 \\\]} < %t.ll
+ *)
+ group "array";
+ let c = make_array_constant i32_type [| three; four |] in
+ ignore (define_global "Const07" c m);
+ insist ((make_array_type i32_type 2) = (type_of c));
+
+ (* RUN: grep {Const08.*< i16 1, i16 2.* >} < %t.ll
+ *)
+ group "vector";
+ let c = make_vector_constant [| one; two; one; two;
+ one; two; one; two |] in
+ ignore (define_global "Const08" c m);
+ insist ((make_vector_type i16_type 8) = (type_of c));
+
+ (* RUN: grep {Const09.*\{ i16, i16, i32, i32 \} \{} < %t.ll
+ *)
+ group "structure";
+ let c = make_struct_constant [| one; two; three; four |] false in
+ ignore (define_global "Const09" c m);
+ insist ((make_struct_type [| i16_type; i16_type; i32_type; i32_type |] false)
+ = (type_of c));
+
+ (* RUN: grep {Const10.*zeroinit} < %t.ll
+ *)
+ group "null";
+ let c = make_null (make_struct_type [| i1_type; i8_type;
+ i64_type; double_type |] true) in
+ ignore (define_global "Const10" c m);
+
+ (* RUN: grep {Const11.*-1} < %t.ll
+ *)
+ group "all ones";
+ let c = make_all_ones i64_type in
+ ignore (define_global "Const11" c m);
+
+ (* RUN: grep {Const12.*undef} < %t.ll
+ *)
+ group "undef";
+ let c = make_undef i1_type in
+ ignore (define_global "Const12" c m);
+ insist (i1_type = type_of c);
+ insist (is_undef c)
+
+
(*===-- Global Values -----------------------------------------------------===*)
let test_global_values () =
@@ -143,8 +233,6 @@
*)
group "naming";
let g = define_global "TEMPORARY" zero32 m in
- prerr_endline "";
- prerr_endline (value_name g);
insist ("TEMPORARY" = value_name g);
set_value_name "GVal01" g;
insist ("GVal01" = value_name g);
@@ -210,6 +298,7 @@
(* RUN: grep -v {GVar05} < %t.ll
*)
+ group "delete";
let g = define_global "GVar05" fourty_two32 m in
delete_global g
@@ -227,7 +316,8 @@
let _ =
suite "types" test_types;
+ suite "constants" test_constants;
suite "global values" test_global_values;
suite "global variables" test_global_variables;
suite "writer" test_writer;
- all_done ()
+ exit !exit_status
More information about the llvm-commits
mailing list