Chris Lattner | 17079fc | 2009-12-28 21:28:46 +0000 | [diff] [blame] | 1 | //===---- IRBuilder.cpp - Builder for LLVM Instrs -------------------------===// |
| 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
| 5 | // This file is distributed under the University of Illinois Open Source |
| 6 | // License. See LICENSE.TXT for details. |
| 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | // |
| 10 | // This file implements the IRBuilder class, which is used as a convenient way |
| 11 | // to create LLVM instructions with a consistent and simplified interface. |
| 12 | // |
| 13 | //===----------------------------------------------------------------------===// |
| 14 | |
| 15 | #include "llvm/Support/IRBuilder.h" |
| 16 | #include "llvm/GlobalVariable.h" |
Chris Lattner | 49f9f76 | 2009-12-28 21:50:56 +0000 | [diff] [blame^] | 17 | #include "llvm/Function.h" |
Chris Lattner | 7ef1cac | 2009-12-28 21:45:40 +0000 | [diff] [blame] | 18 | #include "llvm/Metadata.h" |
| 19 | #include "llvm/LLVMContext.h" |
Chris Lattner | 17079fc | 2009-12-28 21:28:46 +0000 | [diff] [blame] | 20 | using namespace llvm; |
| 21 | |
| 22 | /// CreateGlobalString - Make a new global variable with an initializer that |
| 23 | /// has array of i8 type filled in the the nul terminated string value |
| 24 | /// specified. If Name is specified, it is the name of the global variable |
| 25 | /// created. |
| 26 | Value *IRBuilderBase::CreateGlobalString(const char *Str, const Twine &Name) { |
| 27 | Constant *StrConstant = ConstantArray::get(Context, Str, true); |
| 28 | Module &M = *BB->getParent()->getParent(); |
| 29 | GlobalVariable *GV = new GlobalVariable(M, StrConstant->getType(), |
| 30 | true, GlobalValue::InternalLinkage, |
| 31 | StrConstant, "", 0, false); |
| 32 | GV->setName(Name); |
| 33 | return GV; |
| 34 | } |
Chris Lattner | 7ef1cac | 2009-12-28 21:45:40 +0000 | [diff] [blame] | 35 | |
| 36 | /// SetCurrentDebugLocation - Set location information used by debugging |
| 37 | /// information. |
| 38 | void IRBuilderBase::SetCurrentDebugLocation(MDNode *L) { |
| 39 | if (DbgMDKind == 0) |
| 40 | DbgMDKind = Context.getMetadata().getMDKindID("dbg"); |
| 41 | CurDbgLocation = L; |
| 42 | } |
| 43 | |
| 44 | void IRBuilderBase::SetInstDebugLocation(Instruction *I) const { |
| 45 | if (CurDbgLocation) |
| 46 | Context.getMetadata().addMD(DbgMDKind, CurDbgLocation, I); |
| 47 | } |
Chris Lattner | 49f9f76 | 2009-12-28 21:50:56 +0000 | [diff] [blame^] | 48 | |
| 49 | const Type *IRBuilderBase::getCurrentFunctionReturnType() const { |
| 50 | assert(BB && BB->getParent() && "No current function!"); |
| 51 | return BB->getParent()->getReturnType(); |
| 52 | } |