[llvm-commits] [llvm] r53051 - /llvm/trunk/include/llvm/Support/IRBuilder.h

Eric Christopher echristo at apple.com
Wed Jul 2 15:58:00 PDT 2008


Author: echristo
Date: Wed Jul  2 17:57:59 2008
New Revision: 53051

URL: http://llvm.org/viewvc/llvm-project?rev=53051&view=rev
Log:
Add a couple more helper functions to deal with
creating global constant strings and pointers
to global constant strings.

Modified:
    llvm/trunk/include/llvm/Support/IRBuilder.h

Modified: llvm/trunk/include/llvm/Support/IRBuilder.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Support/IRBuilder.h?rev=53051&r1=53050&r2=53051&view=diff

==============================================================================
--- llvm/trunk/include/llvm/Support/IRBuilder.h (original)
+++ llvm/trunk/include/llvm/Support/IRBuilder.h Wed Jul  2 17:57:59 2008
@@ -18,6 +18,8 @@
 #include "llvm/BasicBlock.h"
 #include "llvm/Instructions.h"
 #include "llvm/Constants.h"
+#include "llvm/GlobalVariable.h"
+#include "llvm/Function.h"
 
 namespace llvm {
 
@@ -308,7 +310,24 @@
     
     return Insert(GetElementPtrInst::Create(Ptr, Idxs, Idxs+2), Name);
   }
-  
+  Value *CreateGlobalString(const char *Str = "", const char *Name = "") {
+    Constant *StrConstant = ConstantArray::get(Str, true);
+    GlobalVariable *gv = new llvm::GlobalVariable(StrConstant->getType(),
+                                                  true, 
+                                                  GlobalValue::InternalLinkage,
+                                                  StrConstant,
+                                                  "",
+                                                  BB->getParent()->getParent(),
+                                                  false);
+    gv->setName(Name);
+    return gv;
+  }
+  Value *CreateGlobalStringPtr(const char *Str = "", const char *Name = "") {
+    Value *gv = CreateGlobalString(Str, Name);
+    Value *zero = llvm::ConstantInt::get(llvm::Type::Int32Ty, 0);
+    Value *Args[] = { zero, zero };
+    return CreateGEP(gv, Args, Args+2, Name);    
+  }
   //===--------------------------------------------------------------------===//
   // Instruction creation methods: Cast/Conversion Operators
   //===--------------------------------------------------------------------===//





More information about the llvm-commits mailing list