2009-12-28 22:28:46 +01:00
|
|
|
//===---- IRBuilder.cpp - Builder for LLVM Instrs -------------------------===//
|
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
|
|
|
// This file implements the IRBuilder class, which is used as a convenient way
|
|
|
|
// to create LLVM instructions with a consistent and simplified interface.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#include "llvm/Support/IRBuilder.h"
|
|
|
|
#include "llvm/GlobalVariable.h"
|
2009-12-28 22:50:56 +01:00
|
|
|
#include "llvm/Function.h"
|
2009-12-28 22:45:40 +01:00
|
|
|
#include "llvm/LLVMContext.h"
|
2009-12-28 22:28:46 +01:00
|
|
|
using namespace llvm;
|
|
|
|
|
|
|
|
/// CreateGlobalString - Make a new global variable with an initializer that
|
|
|
|
/// has array of i8 type filled in the the nul terminated string value
|
|
|
|
/// specified. If Name is specified, it is the name of the global variable
|
|
|
|
/// created.
|
|
|
|
Value *IRBuilderBase::CreateGlobalString(const char *Str, const Twine &Name) {
|
|
|
|
Constant *StrConstant = ConstantArray::get(Context, Str, true);
|
|
|
|
Module &M = *BB->getParent()->getParent();
|
|
|
|
GlobalVariable *GV = new GlobalVariable(M, StrConstant->getType(),
|
|
|
|
true, GlobalValue::InternalLinkage,
|
|
|
|
StrConstant, "", 0, false);
|
|
|
|
GV->setName(Name);
|
|
|
|
return GV;
|
|
|
|
}
|
2009-12-28 22:45:40 +01:00
|
|
|
|
|
|
|
/// SetCurrentDebugLocation - Set location information used by debugging
|
|
|
|
/// information.
|
|
|
|
void IRBuilderBase::SetCurrentDebugLocation(MDNode *L) {
|
|
|
|
if (DbgMDKind == 0)
|
2009-12-29 10:01:33 +01:00
|
|
|
DbgMDKind = Context.getMDKindID("dbg");
|
2009-12-28 22:45:40 +01:00
|
|
|
CurDbgLocation = L;
|
|
|
|
}
|
|
|
|
|
|
|
|
void IRBuilderBase::SetInstDebugLocation(Instruction *I) const {
|
|
|
|
if (CurDbgLocation)
|
2009-12-29 00:41:32 +01:00
|
|
|
I->setMetadata(DbgMDKind, CurDbgLocation);
|
2009-12-28 22:45:40 +01:00
|
|
|
}
|
2009-12-28 22:50:56 +01:00
|
|
|
|
|
|
|
const Type *IRBuilderBase::getCurrentFunctionReturnType() const {
|
|
|
|
assert(BB && BB->getParent() && "No current function!");
|
|
|
|
return BB->getParent()->getReturnType();
|
|
|
|
}
|