llvm.org GIT mirror llvm / c84c16b
C and Objective Caml bindings for GlobalVariable::isConstant. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@42736 91177308-0d34-0410-b5e6-96231b3b80d8 Gordon Henriksen 11 years ago
7 changed file(s) with 70 addition(s) and 1 deletion(s). Raw diff Collapse all Expand all
141141 9F7C240C0CB81ECD00498408 /* analysis_ocaml.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = analysis_ocaml.c; sourceTree = ""; };
142142 9F7C240D0CB81ECD00498408 /* llvm_analysis.ml */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = llvm_analysis.ml; sourceTree = ""; };
143143 9F7C240E0CB81ECD00498408 /* llvm_analysis.mli */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = llvm_analysis.mli; sourceTree = ""; };
144 9F7C2C4F0CB9496C00498408 /* analysis.ml */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = analysis.ml; sourceTree = ""; };
145 9F7C2C520CB9496C00498408 /* bitwriter.ml */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = bitwriter.ml; sourceTree = ""; };
146 9F7C2C5D0CB9496C00498408 /* vmcore.ml */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = vmcore.ml; sourceTree = ""; };
144147 9FA638D90C77B184007F12AE /* AutoUpgrade.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; path = AutoUpgrade.h; sourceTree = ""; };
145148 9FA638DA0C77B184007F12AE /* GlobalAlias.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; path = GlobalAlias.h; sourceTree = ""; };
146149 9FA638DB0C77B1AB007F12AE /* APInt.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; path = APInt.h; sourceTree = ""; };
10701073 DE816FAC08CFB44C0093BDEF /* utils */,
10711074 DE66F38D08ABF35C00323D32 /* docs */,
10721075 9FD3E56D0CA0116100E54D15 /* bindings */,
1076 9F7C2B690CB9496B00498408 /* test */,
10731077 DE66F3FD08ABF37000323D32 /* examples */,
10741078 DE66F38C08ABF35300323D32 /* CREDITS.TXT */,
10751079 CFD99AA80AFE827B0068D19C /* LICENSE.TXT */,
11671171 9F7C240E0CB81ECD00498408 /* llvm_analysis.mli */,
11681172 );
11691173 path = analysis;
1174 sourceTree = "";
1175 };
1176 9F7C2B690CB9496B00498408 /* test */ = {
1177 isa = PBXGroup;
1178 children = (
1179 9F7C2C4B0CB9496C00498408 /* Bindings */,
1180 );
1181 name = test;
1182 path = ../test;
1183 sourceTree = SOURCE_ROOT;
1184 };
1185 9F7C2C4B0CB9496C00498408 /* Bindings */ = {
1186 isa = PBXGroup;
1187 children = (
1188 9F7C2C4C0CB9496C00498408 /* Ocaml */,
1189 );
1190 path = Bindings;
1191 sourceTree = "";
1192 };
1193 9F7C2C4C0CB9496C00498408 /* Ocaml */ = {
1194 isa = PBXGroup;
1195 children = (
1196 9F7C2C4F0CB9496C00498408 /* analysis.ml */,
1197 9F7C2C520CB9496C00498408 /* bitwriter.ml */,
1198 9F7C2C5D0CB9496C00498408 /* vmcore.ml */,
1199 );
1200 path = Ocaml;
11701201 sourceTree = "";
11711202 };
11721203 9FA638E90C77B252007F12AE /* IPO */ = {
267267 external set_visibility : visibility -> llvalue -> unit = "llvm_set_visibility"
268268 external alignment : llvalue -> int = "llvm_alignment"
269269 external set_alignment : int -> llvalue -> unit = "llvm_set_alignment"
270 external is_global_constant : llvalue -> bool = "llvm_is_global_constant"
271 external set_global_constant : bool -> llvalue -> unit
272 = "llvm_set_global_constant"
270273
271274 (*--... Operations on global variables .....................................--*)
272275 external declare_global : lltype -> string -> llmodule -> llvalue
250250 external set_visibility : visibility -> llvalue -> unit = "llvm_set_visibility"
251251 external alignment : llvalue -> int = "llvm_alignment"
252252 external set_alignment : int -> llvalue -> unit = "llvm_set_alignment"
253 external is_global_constant : llvalue -> bool = "llvm_is_global_constant"
254 external set_global_constant : bool -> llvalue -> unit
255 = "llvm_set_global_constant"
253256
254257 (*--... Operations on global variables .....................................--*)
255258 external declare_global : lltype -> string -> llmodule -> llvalue
444444 return Val_unit;
445445 }
446446
447 /* llvalue -> bool */
448 CAMLprim value llvm_is_global_constant(LLVMValueRef GlobalVar) {
449 return Val_bool(LLVMIsGlobalConstant(GlobalVar));
450 }
451
452 /* bool -> llvalue -> unit */
453 CAMLprim value llvm_set_global_constant(value Flag, LLVMValueRef GlobalVar) {
454 LLVMSetGlobalConstant(GlobalVar, Bool_val(Flag));
455 return Val_unit;
456 }
457
447458 /*--... Operations on functions ............................................--*/
448459
449460 /* string -> lltype -> llmodule -> llvalue */
323323 void LLVMSetInitializer(LLVMValueRef GlobalVar, LLVMValueRef ConstantVal);
324324 int LLVMIsThreadLocal(LLVMValueRef GlobalVar);
325325 void LLVMSetThreadLocal(LLVMValueRef GlobalVar, int IsThreadLocal);
326 int LLVMIsGlobalConstant(LLVMValueRef GlobalVar);
327 void LLVMSetGlobalConstant(LLVMValueRef GlobalVar, int IsConstant);
326328
327329 /* Operations on functions */
328330 LLVMValueRef LLVMAddFunction(LLVMModuleRef M, const char *Name,
556556 unwrap(GlobalVar)->setThreadLocal(IsThreadLocal != 0);
557557 }
558558
559 int LLVMIsGlobalConstant(LLVMValueRef GlobalVar) {
560 bool res = unwrap(GlobalVar)->isConstant();
561 fprintf(stderr, "LLVMIsConstantGlobal(0x%08x) = %s\n",
562 (int) GlobalVar, res? "YES" : "NO");
563 return unwrap(GlobalVar)->isConstant();
564 }
565
566 void LLVMSetGlobalConstant(LLVMValueRef GlobalVar, int IsConstant) {
567 unwrap(GlobalVar)->setConstant(IsConstant != 0);
568 }
569
559570 /*--.. Operations on functions .............................................--*/
560571
561572 LLVMValueRef LLVMAddFunction(LLVMModuleRef M, const char *Name,
417417 *)
418418 group "delete";
419419 let g = define_global "GVar05" fourty_two32 m in
420 delete_global g
420 delete_global g;
421
422 (* RUN: grep -v {ConstGlobalVar.*constant} < %t.ll
423 *)
424 group "constant";
425 let g = define_global "ConstGlobalVar" fourty_two32 m in
426 insist (not (is_global_constant g));
427 set_global_constant true g;
428 insist (is_global_constant g)
421429
422430
423431 (*===-- Functions ---------------------------------------------------------===*)