File tree Expand file tree Collapse file tree 5 files changed +19
-7
lines changed Expand file tree Collapse file tree 5 files changed +19
-7
lines changed Original file line number Diff line number Diff line change @@ -739,7 +739,7 @@ external define_qualified_global : string -> llvalue -> int -> llmodule ->
739
739
external lookup_global : string -> llmodule -> llvalue option
740
740
= " llvm_lookup_global"
741
741
external delete_global : llvalue -> unit = " llvm_delete_global"
742
- external global_initializer : llvalue -> llvalue = " LLVMGetInitializer "
742
+ external global_initializer : llvalue -> llvalue option = " llvm_global_initializer "
743
743
external set_initializer : llvalue -> llvalue -> unit = " llvm_set_initializer"
744
744
external remove_initializer : llvalue -> unit = " llvm_remove_initializer"
745
745
external is_thread_local : llvalue -> bool = " llvm_is_thread_local"
Original file line number Diff line number Diff line change @@ -1504,9 +1504,9 @@ val is_global_constant : llvalue -> bool
1504
1504
See the method [llvm::GlobalVariable::setConstant]. *)
1505
1505
val set_global_constant : bool -> llvalue -> unit
1506
1506
1507
- (* * [global_initializer gv] returns the initializer for the global variable
1508
- [gv ]. See the method [llvm::GlobalVariable::getInitializer]. *)
1509
- val global_initializer : llvalue -> llvalue
1507
+ (* * [global_initializer gv] If global variable [gv] has an initializer it is returned,
1508
+ otherwise returns [None ]. See the method [llvm::GlobalVariable::getInitializer]. *)
1509
+ val global_initializer : llvalue -> llvalue option
1510
1510
1511
1511
(* * [set_initializer c gv] sets the initializer for the global variable
1512
1512
[gv] to the constant [c].
Original file line number Diff line number Diff line change @@ -1334,6 +1334,18 @@ CAMLprim value llvm_delete_global(LLVMValueRef GlobalVar) {
1334
1334
return Val_unit;
1335
1335
}
1336
1336
1337
+ /* llvalue -> llvalue option */
1338
+ CAMLprim value llvm_global_initializer (LLVMValueRef GlobalVar) {
1339
+ CAMLparam0 ();
1340
+ LLVMValueRef Init;
1341
+ if ((Init = LLVMGetInitializer (GlobalVar))) {
1342
+ value Option = alloc (1 , 0 );
1343
+ Field (Option, 0 ) = (value) Init;
1344
+ CAMLreturn (Option);
1345
+ }
1346
+ CAMLreturn (Val_int (0 ));
1347
+ }
1348
+
1337
1349
/* llvalue -> llvalue -> unit */
1338
1350
CAMLprim value llvm_set_initializer (LLVMValueRef ConstantVal,
1339
1351
LLVMValueRef GlobalVar) {
Original file line number Diff line number Diff line change @@ -548,14 +548,14 @@ let test_global_variables () =
548
548
set_initializer forty_two32 in
549
549
insist (not (is_declaration g));
550
550
insist (not (is_declaration g2));
551
- insist ((global_initializer g) == (global_initializer g2));
551
+ insist ((global_initializer g) = (global_initializer g2));
552
552
553
553
let g = define_qualified_global " QGVar02" forty_two32 3 m in
554
554
let g2 = declare_qualified_global i32_type " QGVar03" 3 m ++
555
555
set_initializer forty_two32 in
556
556
insist (not (is_declaration g));
557
557
insist (not (is_declaration g2));
558
- insist ((global_initializer g) == (global_initializer g2));
558
+ insist ((global_initializer g) = (global_initializer g2));
559
559
end ;
560
560
561
561
(* CHECK: GVar04{{.*}}thread_local
Original file line number Diff line number Diff line change @@ -38,7 +38,7 @@ let test_irreader () =
38
38
let m = parse_ir context buf in
39
39
match lookup_global " foo" m with
40
40
| Some foo ->
41
- insist ((global_initializer foo) = (const_int (i32_type context) 42 ))
41
+ insist ((global_initializer foo) = (Some ( const_int (i32_type context) 42 ) ))
42
42
| None ->
43
43
failwith " global"
44
44
end ;
You can’t perform that action at this time.
0 commit comments