summaryrefslogtreecommitdiff
path: root/lib/VMCore
diff options
context:
space:
mode:
authorErick Tryzelaar <idadesub@users.sourceforge.net>2009-08-16 23:36:33 +0000
committerErick Tryzelaar <idadesub@users.sourceforge.net>2009-08-16 23:36:33 +0000
commit0e81f660dbb7c437a3c95427bb495eb18822e42c (patch)
treef6847222c9895be3024c899b73d882b4af4d3866 /lib/VMCore
parenta15d890c34b5e3a6373c410ebc58453f2d52f43b (diff)
downloadllvm-0e81f660dbb7c437a3c95427bb495eb18822e42c.tar.gz
llvm-0e81f660dbb7c437a3c95427bb495eb18822e42c.tar.bz2
llvm-0e81f660dbb7c437a3c95427bb495eb18822e42c.tar.xz
Add helper functions to ConstantInt and ConstantFP to accept strings.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@79212 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/VMCore')
-rw-r--r--lib/VMCore/Constants.cpp21
1 files changed, 21 insertions, 0 deletions
diff --git a/lib/VMCore/Constants.cpp b/lib/VMCore/Constants.cpp
index f820033932..12483cd9c9 100644
--- a/lib/VMCore/Constants.cpp
+++ b/lib/VMCore/Constants.cpp
@@ -314,6 +314,11 @@ Constant* ConstantInt::get(const Type* Ty, const APInt& V) {
return C;
}
+ConstantInt* ConstantInt::get(const IntegerType* Ty, const StringRef& Str,
+ uint8_t radix) {
+ return get(Ty->getContext(), APInt(Ty->getBitWidth(), Str, radix));
+}
+
//===----------------------------------------------------------------------===//
// ConstantFP
//===----------------------------------------------------------------------===//
@@ -352,6 +357,22 @@ Constant* ConstantFP::get(const Type* Ty, double V) {
return C;
}
+
+Constant* ConstantFP::get(const Type* Ty, const StringRef& Str) {
+ LLVMContext &Context = Ty->getContext();
+
+ APFloat FV(*TypeToFloatSemantics(Ty->getScalarType()), Str);
+ Constant *C = get(Context, FV);
+
+ // For vectors, broadcast the value.
+ if (const VectorType *VTy = dyn_cast<VectorType>(Ty))
+ return ConstantVector::get(
+ std::vector<Constant *>(VTy->getNumElements(), C));
+
+ return C;
+}
+
+
ConstantFP* ConstantFP::getNegativeZero(const Type* Ty) {
LLVMContext &Context = Ty->getContext();
APFloat apf = cast <ConstantFP>(Constant::getNullValue(Ty))->getValueAPF();