Author: gordon
Date: Sun Oct  7 12:31:42 2007
New Revision: 42736

URL: http://llvm.org/viewvc/llvm-project?rev=42736&view=rev
Log:
C and Objective Caml bindings for GlobalVariable::isConstant.

Modified:
    llvm/trunk/Xcode/LLVM.xcodeproj/project.pbxproj
    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/Xcode/LLVM.xcodeproj/project.pbxproj
URL: 
http://llvm.org/viewvc/llvm-project/llvm/trunk/Xcode/LLVM.xcodeproj/project.pbxproj?rev=42736&r1=42735&r2=42736&view=diff

==============================================================================
--- llvm/trunk/Xcode/LLVM.xcodeproj/project.pbxproj (original)
+++ llvm/trunk/Xcode/LLVM.xcodeproj/project.pbxproj Sun Oct  7 12:31:42 2007
@@ -142,6 +142,9 @@
                9F7C240C0CB81ECD00498408 /* analysis_ocaml.c */ = {isa = 
PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = 
analysis_ocaml.c; sourceTree = "<group>"; };
                9F7C240D0CB81ECD00498408 /* llvm_analysis.ml */ = {isa = 
PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = 
llvm_analysis.ml; sourceTree = "<group>"; };
                9F7C240E0CB81ECD00498408 /* llvm_analysis.mli */ = {isa = 
PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = 
llvm_analysis.mli; sourceTree = "<group>"; };
+               9F7C2C4F0CB9496C00498408 /* analysis.ml */ = {isa = 
PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = 
analysis.ml; sourceTree = "<group>"; };
+               9F7C2C520CB9496C00498408 /* bitwriter.ml */ = {isa = 
PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = 
bitwriter.ml; sourceTree = "<group>"; };
+               9F7C2C5D0CB9496C00498408 /* vmcore.ml */ = {isa = 
PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = vmcore.ml; 
sourceTree = "<group>"; };
                9FA638D90C77B184007F12AE /* AutoUpgrade.h */ = {isa = 
PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; path = 
AutoUpgrade.h; sourceTree = "<group>"; };
                9FA638DA0C77B184007F12AE /* GlobalAlias.h */ = {isa = 
PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; path = 
GlobalAlias.h; sourceTree = "<group>"; };
                9FA638DB0C77B1AB007F12AE /* APInt.h */ = {isa = 
PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; path = 
APInt.h; sourceTree = "<group>"; };
@@ -1071,6 +1074,7 @@
                                DE816FAC08CFB44C0093BDEF /* utils */,
                                DE66F38D08ABF35C00323D32 /* docs */,
                                9FD3E56D0CA0116100E54D15 /* bindings */,
+                               9F7C2B690CB9496B00498408 /* test */,
                                DE66F3FD08ABF37000323D32 /* examples */,
                                DE66F38C08ABF35300323D32 /* CREDITS.TXT */,
                                CFD99AA80AFE827B0068D19C /* LICENSE.TXT */,
@@ -1170,6 +1174,33 @@
                        path = analysis;
                        sourceTree = "<group>";
                };
+               9F7C2B690CB9496B00498408 /* test */ = {
+                       isa = PBXGroup;
+                       children = (
+                               9F7C2C4B0CB9496C00498408 /* Bindings */,
+                       );
+                       name = test;
+                       path = ../test;
+                       sourceTree = SOURCE_ROOT;
+               };
+               9F7C2C4B0CB9496C00498408 /* Bindings */ = {
+                       isa = PBXGroup;
+                       children = (
+                               9F7C2C4C0CB9496C00498408 /* Ocaml */,
+                       );
+                       path = Bindings;
+                       sourceTree = "<group>";
+               };
+               9F7C2C4C0CB9496C00498408 /* Ocaml */ = {
+                       isa = PBXGroup;
+                       children = (
+                               9F7C2C4F0CB9496C00498408 /* analysis.ml */,
+                               9F7C2C520CB9496C00498408 /* bitwriter.ml */,
+                               9F7C2C5D0CB9496C00498408 /* vmcore.ml */,
+                       );
+                       path = Ocaml;
+                       sourceTree = "<group>";
+               };
                9FA638E90C77B252007F12AE /* IPO */ = {
                        isa = PBXGroup;
                        children = (

Modified: llvm/trunk/bindings/ocaml/llvm/llvm.ml
URL: 
http://llvm.org/viewvc/llvm-project/llvm/trunk/bindings/ocaml/llvm/llvm.ml?rev=42736&r1=42735&r2=42736&view=diff

==============================================================================
--- llvm/trunk/bindings/ocaml/llvm/llvm.ml (original)
+++ llvm/trunk/bindings/ocaml/llvm/llvm.ml Sun Oct  7 12:31:42 2007
@@ -268,6 +268,9 @@
 external set_visibility : visibility -> llvalue -> unit = "llvm_set_visibility"
 external alignment : llvalue -> int = "llvm_alignment"
 external set_alignment : int -> llvalue -> unit = "llvm_set_alignment"
+external is_global_constant : llvalue -> bool = "llvm_is_global_constant"
+external set_global_constant : bool -> llvalue -> unit
+                             = "llvm_set_global_constant"
 
 (*--... Operations on global variables 
.....................................--*)
 external declare_global : lltype -> string -> llmodule -> llvalue

Modified: llvm/trunk/bindings/ocaml/llvm/llvm.mli
URL: 
http://llvm.org/viewvc/llvm-project/llvm/trunk/bindings/ocaml/llvm/llvm.mli?rev=42736&r1=42735&r2=42736&view=diff

==============================================================================
--- llvm/trunk/bindings/ocaml/llvm/llvm.mli (original)
+++ llvm/trunk/bindings/ocaml/llvm/llvm.mli Sun Oct  7 12:31:42 2007
@@ -251,6 +251,9 @@
 external set_visibility : visibility -> llvalue -> unit = "llvm_set_visibility"
 external alignment : llvalue -> int = "llvm_alignment"
 external set_alignment : int -> llvalue -> unit = "llvm_set_alignment"
+external is_global_constant : llvalue -> bool = "llvm_is_global_constant"
+external set_global_constant : bool -> llvalue -> unit
+                             = "llvm_set_global_constant"
 
 (*--... Operations on global variables 
.....................................--*)
 external declare_global : lltype -> string -> llmodule -> llvalue

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=42736&r1=42735&r2=42736&view=diff

==============================================================================
--- llvm/trunk/bindings/ocaml/llvm/llvm_ocaml.c (original)
+++ llvm/trunk/bindings/ocaml/llvm/llvm_ocaml.c Sun Oct  7 12:31:42 2007
@@ -445,6 +445,17 @@
   return Val_unit;
 }
 
+/* llvalue -> bool */
+CAMLprim value llvm_is_global_constant(LLVMValueRef GlobalVar) {
+  return Val_bool(LLVMIsGlobalConstant(GlobalVar));
+}
+
+/* bool -> llvalue -> unit */
+CAMLprim value llvm_set_global_constant(value Flag, LLVMValueRef GlobalVar) {
+  LLVMSetGlobalConstant(GlobalVar, Bool_val(Flag));
+  return Val_unit;
+}
+
 /*--... Operations on functions 
............................................--*/
 
 /* string -> lltype -> llmodule -> llvalue */

Modified: llvm/trunk/include/llvm-c/Core.h
URL: 
http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm-c/Core.h?rev=42736&r1=42735&r2=42736&view=diff

==============================================================================
--- llvm/trunk/include/llvm-c/Core.h (original)
+++ llvm/trunk/include/llvm-c/Core.h Sun Oct  7 12:31:42 2007
@@ -324,6 +324,8 @@
 void LLVMSetInitializer(LLVMValueRef GlobalVar, LLVMValueRef ConstantVal);
 int LLVMIsThreadLocal(LLVMValueRef GlobalVar);
 void LLVMSetThreadLocal(LLVMValueRef GlobalVar, int IsThreadLocal);
+int LLVMIsGlobalConstant(LLVMValueRef GlobalVar);
+void LLVMSetGlobalConstant(LLVMValueRef GlobalVar, int IsConstant);
 
 /* Operations on functions */
 LLVMValueRef LLVMAddFunction(LLVMModuleRef M, const char *Name,

Modified: llvm/trunk/lib/VMCore/Core.cpp
URL: 
http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/VMCore/Core.cpp?rev=42736&r1=42735&r2=42736&view=diff

==============================================================================
--- llvm/trunk/lib/VMCore/Core.cpp (original)
+++ llvm/trunk/lib/VMCore/Core.cpp Sun Oct  7 12:31:42 2007
@@ -557,6 +557,17 @@
   unwrap<GlobalVariable>(GlobalVar)->setThreadLocal(IsThreadLocal != 0);
 }
 
+int LLVMIsGlobalConstant(LLVMValueRef GlobalVar) {
+  bool res = unwrap<GlobalVariable>(GlobalVar)->isConstant();
+  fprintf(stderr, "LLVMIsConstantGlobal(0x%08x) = %s\n",
+                  (int) GlobalVar, res? "YES" : "NO");
+  return unwrap<GlobalVariable>(GlobalVar)->isConstant();
+}
+
+void LLVMSetGlobalConstant(LLVMValueRef GlobalVar, int IsConstant) {
+  unwrap<GlobalVariable>(GlobalVar)->setConstant(IsConstant != 0);
+}
+
 /*--.. Operations on functions 
.............................................--*/
 
 LLVMValueRef LLVMAddFunction(LLVMModuleRef M, const char *Name,

Modified: llvm/trunk/test/Bindings/Ocaml/vmcore.ml
URL: 
http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Bindings/Ocaml/vmcore.ml?rev=42736&r1=42735&r2=42736&view=diff

==============================================================================
--- llvm/trunk/test/Bindings/Ocaml/vmcore.ml (original)
+++ llvm/trunk/test/Bindings/Ocaml/vmcore.ml Sun Oct  7 12:31:42 2007
@@ -418,7 +418,15 @@
    *)
   group "delete";
   let g = define_global "GVar05" fourty_two32 m in
-  delete_global g
+  delete_global g;
+
+  (* RUN: grep -v {ConstGlobalVar.*constant} < %t.ll
+   *)
+  group "constant";
+  let g = define_global "ConstGlobalVar" fourty_two32 m in
+  insist (not (is_global_constant g));
+  set_global_constant true g;
+  insist (is_global_constant g)
 
 
 (*===-- Functions 
---------------------------------------------------------===*)


_______________________________________________
llvm-commits mailing list
[email protected]
http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits

Reply via email to