diff options
-rw-r--r-- | include/llvm/LLVMContext.h | 162 | ||||
-rw-r--r-- | lib/VMCore/CMakeLists.txt | 1 | ||||
-rw-r--r-- | lib/VMCore/LLVMContext.cpp | 379 | ||||
-rw-r--r-- | lib/VMCore/LLVMContextImpl.h | 20 |
4 files changed, 562 insertions, 0 deletions
diff --git a/include/llvm/LLVMContext.h b/include/llvm/LLVMContext.h new file mode 100644 index 0000000..018d777 --- /dev/null +++ b/include/llvm/LLVMContext.h @@ -0,0 +1,162 @@ +//===-- llvm/LLVMContext.h - Class for managing "global" state --*- C++ -*-===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +#ifndef LLVM_LLVMCONTEXT_H +#define LLVM_LLVMCONTEXT_H + +#include "llvm/Support/DataTypes.h" +#include <vector> +#include <string> + +namespace llvm { + +class LLVMContextImpl; +class Constant; +class ConstantInt; +class ConstantPointerNull; +class ConstantStruct; +class ConstantAggregateZero; +class ConstantArray; +class ConstantFP; +class ConstantVector; +class IntegerType; +class PointerType; +class StructType; +class ArrayType; +class VectorType; +class Type; +class APInt; +class APFloat; +class Value; + +class LLVMContext { + LLVMContextImpl* pImpl; +public: + LLVMContext(); + ~LLVMContext(); + + // ConstantInt accessors + ConstantInt* getConstantIntTrue(); + ConstantInt* getConstantIntFalse(); + ConstantInt* getConstantInt(const IntegerType* Ty, uint64_t V, + bool isSigned = false); + ConstantInt* getConstantIntSigned(const IntegerType* Ty, int64_t V); + ConstantInt* getConstantInt(const APInt& V); + Constant* getConstantInt(const Type* Ty, const APInt& V); + ConstantInt* getAllOnesConstantInt(const Type* Ty); + + // ConstantPointerNull accessors + ConstantPointerNull* getConstantPointerNull(const PointerType* T); + + // ConstantStruct accessors + Constant* getConstantStruct(const StructType* T, + const std::vector<Constant*>& V); + Constant* getConstantStruct(const std::vector<Constant*>& V, + bool Packed = false); + Constant* getConstantStruct(Constant* const *Vals, unsigned NumVals, + bool Packed = false); + + // ConstantAggregateZero accessors + ConstantAggregateZero* getConstantAggregateZero(const Type* Ty); + + // ConstantArray accessors + Constant* getConstantArray(const ArrayType* T, + const std::vector<Constant*>& V); + Constant* getConstantArray(const ArrayType* T, Constant* const* Vals, + unsigned NumVals); + Constant* getConstantArray(const std::string& Initializer, + bool AddNull = false); + + // ConstantExpr accessors + Constant* getConstantExpr(unsigned Opcode, Constant* C1, Constant* C2); + Constant* getConstantExprTrunc(Constant* C, const Type* Ty); + Constant* getConstantExprSExt(Constant* C, const Type* Ty); + Constant* getConstantExprZExt(Constant* C, const Type* Ty); + Constant* getConstantExprFPTrunc(Constant* C, const Type* Ty); + Constant* getConstantExprFPExtend(Constant* C, const Type* Ty); + Constant* getConstantExprUIToFP(Constant* C, const Type* Ty); + Constant* getConstantExprSIToFP(Constant* C, const Type* Ty); + Constant* getConstantExprFPToUI(Constant* C, const Type* Ty); + Constant* getConstantExprFPToSI(Constant* C, const Type* Ty); + Constant* getConstantExprPtrToInt(Constant* C, const Type* Ty); + Constant* getConstantExprIntToPtr(Constant* C, const Type* Ty); + Constant* getConstantExprBitCast(Constant* C, const Type* Ty); + Constant* getConstantExprCast(unsigned ops, Constant* C, const Type* Ty); + Constant* getConstantExprZExtOrBitCast(Constant* C, const Type* Ty); + Constant* getConstantExprSExtOrBitCast(Constant* C, const Type* Ty); + Constant* getConstantExprTruncOrBitCast(Constant* C, const Type* Ty); + Constant* getConstantExprPointerCast(Constant* C, const Type* Ty); + Constant* getConstantExprIntegerCast(Constant* C, const Type* Ty, + bool isSigned); + Constant* getConstantExprFPCast(Constant* C, const Type* Ty); + Constant* getConstantExprSelect(Constant* C, Constant* V1, Constant* V2); + Constant* getConstantExprAlignOf(const Type* Ty); + Constant* getConstantExprCompare(unsigned short pred, + Constant* C1, Constant* C2); + Constant* getConstantExprNeg(Constant* C); + Constant* getConstantExprFNeg(Constant* C); + Constant* getConstantExprNot(Constant* C); + Constant* getConstantExprAdd(Constant* C1, Constant* C2); + Constant* getConstantExprFAdd(Constant* C1, Constant* C2); + Constant* getConstantExprSub(Constant* C1, Constant* C2); + Constant* getConstantExprFSub(Constant* C1, Constant* C2); + Constant* getConstantExprMul(Constant* C1, Constant* C2); + Constant* getConstantExprFMul(Constant* C1, Constant* C2); + Constant* getConstantExprUDiv(Constant* C1, Constant* C2); + Constant* getConstantExprSDiv(Constant* C1, Constant* C2); + Constant* getConstantExprFDiv(Constant* C1, Constant* C2); + Constant* getConstantExprURem(Constant* C1, Constant* C2); + Constant* getConstantExprSRem(Constant* C1, Constant* C2); + Constant* getConstantExprFRem(Constant* C1, Constant* C2); + Constant* getConstantExprAnd(Constant* C1, Constant* C2); + Constant* getConstantExprOr(Constant* C1, Constant* C2); + Constant* getConstantExprXor(Constant* C1, Constant* C2); + Constant* getConstantExprICmp(unsigned short pred, Constant* LHS, + Constant* RHS); + Constant* getConstantExprFCmp(unsigned short pred, Constant* LHS, + Constant* RHS); + Constant* getConstantExprVICmp(unsigned short pred, Constant* LHS, + Constant* RHS); + Constant* getConstantExprVFCmp(unsigned short pred, Constant* LHS, + Constant* RHS); + Constant* getConstantExprShl(Constant* C1, Constant* C2); + Constant* getConstantExprLShr(Constant* C1, Constant* C2); + Constant* getConstantExprAShr(Constant* C1, Constant* C2); + Constant* getConstantExprGetElementPtr(Constant* C, Constant* const* IdxList, + unsigned NumIdx); + Constant* getConstantExprGetElementPtr(Constant* C, Value* const* IdxList, + unsigned NumIdx); + Constant* getConstantExprExtractElement(Constant* Vec, Constant* Idx); + Constant* getConstantExprInsertElement(Constant* Vec, Constant* Elt, + Constant* Idx); + Constant* getConstantExprShuffleVector(Constant* V1, Constant* V2, + Constant* Mask); + Constant* getConstantExprExtractValue(Constant* Agg, const unsigned* IdxList, + unsigned NumIdx); + Constant* getConstantExprInsertValue(Constant* Agg, Constant* Val, + const unsigned* IdxList, + unsigned NumIdx); + Constant* getZeroValueForNegation(const Type* Ty); + + // ConstantFP accessors + ConstantFP* getConstantFP(const APFloat& V); + Constant* getConstantFP(const Type* Ty, double V); + ConstantFP* getConstantFPNegativeZero(const Type* Ty); + + // ConstantVector accessors + Constant* getConstantVector(const VectorType* T, + const std::vector<Constant*>& V); + Constant* getConstantVector(const std::vector<Constant*>& V); + Constant* getConstantVector(Constant* const* Vals, unsigned NumVals); + ConstantVector* getConstantVectorAllOnes(const VectorType* Ty); +}; + +} + +#endif diff --git a/lib/VMCore/CMakeLists.txt b/lib/VMCore/CMakeLists.txt index d78e093..c9cdce4 100644 --- a/lib/VMCore/CMakeLists.txt +++ b/lib/VMCore/CMakeLists.txt @@ -14,6 +14,7 @@ add_llvm_library(LLVMCore Instructions.cpp IntrinsicInst.cpp LeakDetector.cpp + LLVMContext.cpp Mangler.cpp Module.cpp ModuleProvider.cpp diff --git a/lib/VMCore/LLVMContext.cpp b/lib/VMCore/LLVMContext.cpp new file mode 100644 index 0000000..f93616b --- /dev/null +++ b/lib/VMCore/LLVMContext.cpp @@ -0,0 +1,379 @@ +//===-- LLVMContext.cpp - Implement LLVMContext -----------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +#include "llvm/LLVMContext.h" +#include "llvm/Constants.h" +#include "LLVMContextImpl.h" + +using namespace llvm; + +LLVMContext::LLVMContext() : pImpl(new LLVMContextImpl()) { } +LLVMContext::~LLVMContext() { delete pImpl; } + +// ConstantInt accessors. +ConstantInt* LLVMContext::getConstantIntTrue() { + return ConstantInt::getTrue(); +} + +ConstantInt* LLVMContext::getConstantIntFalse() { + return ConstantInt::getFalse(); +} + +ConstantInt* LLVMContext::getConstantInt(const IntegerType* Ty, uint64_t V, + bool isSigned) { + return ConstantInt::get(Ty, V, isSigned); +} + +ConstantInt* LLVMContext::getConstantIntSigned(const IntegerType* Ty, + int64_t V) { + return ConstantInt::getSigned(Ty, V); +} + +ConstantInt* LLVMContext::getConstantInt(const APInt& V) { + return ConstantInt::get(V); +} + +Constant* LLVMContext::getConstantInt(const Type* Ty, const APInt& V) { + return ConstantInt::get(Ty, V); +} + +ConstantInt* LLVMContext::getAllOnesConstantInt(const Type* Ty) { + return ConstantInt::getAllOnesValue(Ty); +} + + +// ConstantPointerNull accessors. +ConstantPointerNull* LLVMContext::getConstantPointerNull(const PointerType* T) { + return ConstantPointerNull::get(T); +} + + +// ConstantStruct accessors. +Constant* LLVMContext::getConstantStruct(const StructType* T, + const std::vector<Constant*>& V) { + return ConstantStruct::get(T, V); +} + +Constant* LLVMContext::getConstantStruct(const std::vector<Constant*>& V, + bool Packed) { + return ConstantStruct::get(V, Packed); +} + +Constant* LLVMContext::getConstantStruct(Constant* const *Vals, + unsigned NumVals, bool Packed) { + return ConstantStruct::get(Vals, NumVals, Packed); +} + + +// ConstantAggregateZero accessors. +ConstantAggregateZero* LLVMContext::getConstantAggregateZero(const Type* Ty) { + return ConstantAggregateZero::get(Ty); +} + + +// ConstantArray accessors. +Constant* LLVMContext::getConstantArray(const ArrayType* T, + const std::vector<Constant*>& V) { + return ConstantArray::get(T, V); +} + +Constant* LLVMContext::getConstantArray(const ArrayType* T, + Constant* const* Vals, + unsigned NumVals) { + return ConstantArray::get(T, Vals, NumVals); +} + +Constant* LLVMContext::getConstantArray(const std::string& Initializer, + bool AddNull) { + return ConstantArray::get(Initializer, AddNull); +} + + +// ConstantExpr accessors. +Constant* LLVMContext::getConstantExpr(unsigned Opcode, Constant* C1, + Constant* C2) { + return ConstantExpr::get(Opcode, C1, C2); +} + +Constant* LLVMContext::getConstantExprTrunc(Constant* C, const Type* Ty) { + return ConstantExpr::getTrunc(C, Ty); +} + +Constant* LLVMContext::getConstantExprSExt(Constant* C, const Type* Ty) { + return ConstantExpr::getSExt(C, Ty); +} + +Constant* LLVMContext::getConstantExprZExt(Constant* C, const Type* Ty) { + return ConstantExpr::getZExt(C, Ty); +} + +Constant* LLVMContext::getConstantExprFPTrunc(Constant* C, const Type* Ty) { + return ConstantExpr::getFPTrunc(C, Ty); +} + +Constant* LLVMContext::getConstantExprFPExtend(Constant* C, const Type* Ty) { + return ConstantExpr::getFPExtend(C, Ty); +} + +Constant* LLVMContext::getConstantExprUIToFP(Constant* C, const Type* Ty) { + return ConstantExpr::getUIToFP(C, Ty); +} + +Constant* LLVMContext::getConstantExprSIToFP(Constant* C, const Type* Ty) { + return ConstantExpr::getSIToFP(C, Ty); +} + +Constant* LLVMContext::getConstantExprFPToUI(Constant* C, const Type* Ty) { + return ConstantExpr::getFPToUI(C, Ty); +} + +Constant* LLVMContext::getConstantExprFPToSI(Constant* C, const Type* Ty) { + return ConstantExpr::getFPToSI(C, Ty); +} + +Constant* LLVMContext::getConstantExprPtrToInt(Constant* C, const Type* Ty) { + return ConstantExpr::getPtrToInt(C, Ty); +} + +Constant* LLVMContext::getConstantExprIntToPtr(Constant* C, const Type* Ty) { + return ConstantExpr::getIntToPtr(C, Ty); +} + +Constant* LLVMContext::getConstantExprBitCast(Constant* C, const Type* Ty) { + return ConstantExpr::getBitCast(C, Ty); +} + +Constant* LLVMContext::getConstantExprCast(unsigned ops, Constant* C, + const Type* Ty) { + return ConstantExpr::getCast(ops, C, Ty); +} + +Constant* LLVMContext::getConstantExprZExtOrBitCast(Constant* C, + const Type* Ty) { + return ConstantExpr::getZExtOrBitCast(C, Ty); +} + +Constant* LLVMContext::getConstantExprSExtOrBitCast(Constant* C, + const Type* Ty) { + return ConstantExpr::getSExtOrBitCast(C, Ty); +} + +Constant* LLVMContext::getConstantExprTruncOrBitCast(Constant* C, + const Type* Ty) { + return ConstantExpr::getTruncOrBitCast(C, Ty); +} + +Constant* LLVMContext::getConstantExprPointerCast(Constant* C, const Type* Ty) { + return ConstantExpr::getPointerCast(C, Ty); +} + +Constant* LLVMContext::getConstantExprIntegerCast(Constant* C, const Type* Ty, + bool isSigned) { + return ConstantExpr::getIntegerCast(C, Ty, isSigned); +} + +Constant* LLVMContext::getConstantExprFPCast(Constant* C, const Type* Ty) { + return ConstantExpr::getFPCast(C, Ty); +} + +Constant* LLVMContext::getConstantExprSelect(Constant* C, Constant* V1, + Constant* V2) { + return ConstantExpr::getSelect(C, V1, V2); +} + +Constant* LLVMContext::getConstantExprAlignOf(const Type* Ty) { + return ConstantExpr::getAlignOf(Ty); +} + +Constant* LLVMContext::getConstantExprCompare(unsigned short pred, + Constant* C1, Constant* C2) { + return ConstantExpr::getCompare(pred, C1, C2); +} + +Constant* LLVMContext::getConstantExprNeg(Constant* C) { + return ConstantExpr::getNeg(C); +} + +Constant* LLVMContext::getConstantExprFNeg(Constant* C) { + return ConstantExpr::getFNeg(C); +} + +Constant* LLVMContext::getConstantExprNot(Constant* C) { + return ConstantExpr::getNot(C); +} + +Constant* LLVMContext::getConstantExprAdd(Constant* C1, Constant* C2) { + return ConstantExpr::getAdd(C1, C2); +} + +Constant* LLVMContext::getConstantExprFAdd(Constant* C1, Constant* C2) { + return ConstantExpr::getFAdd(C1, C2); +} + +Constant* LLVMContext::getConstantExprSub(Constant* C1, Constant* C2) { + return ConstantExpr::getSub(C1, C2); +} + +Constant* LLVMContext::getConstantExprFSub(Constant* C1, Constant* C2) { + return ConstantExpr::getFSub(C1, C2); +} + +Constant* LLVMContext::getConstantExprMul(Constant* C1, Constant* C2) { + return ConstantExpr::getMul(C1, C2); +} + +Constant* LLVMContext::getConstantExprFMul(Constant* C1, Constant* C2) { + return ConstantExpr::getFMul(C1, C2); +} + +Constant* LLVMContext::getConstantExprUDiv(Constant* C1, Constant* C2) { + return ConstantExpr::getUDiv(C1, C2); +} + +Constant* LLVMContext::getConstantExprSDiv(Constant* C1, Constant* C2) { + return ConstantExpr::getSDiv(C1, C2); +} + +Constant* LLVMContext::getConstantExprFDiv(Constant* C1, Constant* C2) { + return ConstantExpr::getFDiv(C1, C2); +} + +Constant* LLVMContext::getConstantExprURem(Constant* C1, Constant* C2) { + return ConstantExpr::getURem(C1, C2); +} + +Constant* LLVMContext::getConstantExprSRem(Constant* C1, Constant* C2) { + return ConstantExpr::getSRem(C1, C2); +} + +Constant* LLVMContext::getConstantExprFRem(Constant* C1, Constant* C2) { + return ConstantExpr::getFRem(C1, C2); +} + +Constant* LLVMContext::getConstantExprAnd(Constant* C1, Constant* C2) { + return ConstantExpr::getAnd(C1, C2); +} + +Constant* LLVMContext::getConstantExprOr(Constant* C1, Constant* C2) { + return ConstantExpr::getOr(C1, C2); +} + +Constant* LLVMContext::getConstantExprXor(Constant* C1, Constant* C2) { + return ConstantExpr::getXor(C1, C2); +} + +Constant* LLVMContext::getConstantExprICmp(unsigned short pred, Constant* LHS, + Constant* RHS) { + return ConstantExpr::getICmp(pred, LHS, RHS); +} + +Constant* LLVMContext::getConstantExprFCmp(unsigned short pred, Constant* LHS, + Constant* RHS) { + return ConstantExpr::getFCmp(pred, LHS, RHS); +} + +Constant* LLVMContext::getConstantExprVICmp(unsigned short pred, Constant* LHS, + Constant* RHS) { + return ConstantExpr::getVICmp(pred, LHS, RHS); +} + +Constant* LLVMContext::getConstantExprVFCmp(unsigned short pred, Constant* LHS, + Constant* RHS) { + return ConstantExpr::getVFCmp(pred, LHS, RHS); +} + +Constant* LLVMContext::getConstantExprShl(Constant* C1, Constant* C2) { + return ConstantExpr::getShl(C1, C2); +} + +Constant* LLVMContext::getConstantExprLShr(Constant* C1, Constant* C2) { + return ConstantExpr::getLShr(C1, C2); +} + +Constant* LLVMContext::getConstantExprAShr(Constant* C1, Constant* C2) { + return ConstantExpr::getAShr(C1, C2); +} + +Constant* LLVMContext::getConstantExprGetElementPtr(Constant* C, + Constant* const* IdxList, + unsigned NumIdx) { + return ConstantExpr::getGetElementPtr(C, IdxList, NumIdx); +} + +Constant* LLVMContext::getConstantExprGetElementPtr(Constant* C, + Value* const* IdxList, + unsigned NumIdx) { + return ConstantExpr::getGetElementPtr(C, IdxList, NumIdx); +} + +Constant* LLVMContext::getConstantExprExtractElement(Constant* Vec, + Constant* Idx) { + return ConstantExpr::getExtractElement(Vec, Idx); +} + +Constant* LLVMContext::getConstantExprInsertElement(Constant* Vec, + Constant* Elt, + Constant* Idx) { + return ConstantExpr::getInsertElement(Vec, Elt, Idx); +} + +Constant* LLVMContext::getConstantExprShuffleVector(Constant* V1, Constant* V2, + Constant* Mask) { + return ConstantExpr::getShuffleVector(V1, V2, Mask); +} + +Constant* LLVMContext::getConstantExprExtractValue(Constant* Agg, + const unsigned* IdxList, + unsigned NumIdx) { + return ConstantExpr::getExtractValue(Agg, IdxList, NumIdx); +} + +Constant* LLVMContext::getConstantExprInsertValue(Constant* Agg, Constant* Val, + const unsigned* IdxList, + unsigned NumIdx) { + return ConstantExpr::getInsertValue(Agg, Val, IdxList, NumIdx); +} + +Constant* LLVMContext::getZeroValueForNegation(const Type* Ty) { + return ConstantExpr::getZeroValueForNegationExpr(Ty); +} + + +// ConstantFP accessors. +ConstantFP* LLVMContext::getConstantFP(const APFloat& V) { + return ConstantFP::get(V); +} + +Constant* LLVMContext::getConstantFP(const Type* Ty, double V) { + return ConstantFP::get(Ty, V); +} + +ConstantFP* LLVMContext::getConstantFPNegativeZero(const Type* Ty) { + return ConstantFP::getNegativeZero(Ty); +} + + +// ConstantVector accessors. +Constant* LLVMContext::getConstantVector(const VectorType* T, + const std::vector<Constant*>& V) { + return ConstantVector::get(T, V); +} + +Constant* LLVMContext::getConstantVector(const std::vector<Constant*>& V) { + return ConstantVector::get(V); +} + +Constant* LLVMContext::getConstantVector(Constant* const* Vals, + unsigned NumVals) { + return ConstantVector::get(Vals, NumVals); +} + +ConstantVector* LLVMContext::getConstantVectorAllOnes(const VectorType* Ty) { + return ConstantVector::getAllOnesValue(Ty); +} diff --git a/lib/VMCore/LLVMContextImpl.h b/lib/VMCore/LLVMContextImpl.h new file mode 100644 index 0000000..8d0a70c --- /dev/null +++ b/lib/VMCore/LLVMContextImpl.h @@ -0,0 +1,20 @@ +//===-- llvm/SymbolTableListTraitsImpl.h - Implementation ------*- C++ -*--===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +#ifndef LLVM_LLVMCONTEXT_IMPL_H +#define LLVM_LLVMCONTEXT_IMPL_H + +namespace llvm { +class LLVMContextImpl { + +}; + +} + +#endif
\ No newline at end of file |