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
This commit is contained in:
Erick Tryzelaar
2009-08-16 23:36:33 +00:00
parent a15d890c34
commit 0e81f660db
2 changed files with 27 additions and 0 deletions

View File

@@ -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();