mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-06-19 18:24:00 +00:00
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:
@ -84,6 +84,11 @@ public:
|
|||||||
/// type is the integer type that corresponds to the bit width of the value.
|
/// type is the integer type that corresponds to the bit width of the value.
|
||||||
static ConstantInt* get(LLVMContext &Context, const APInt& V);
|
static ConstantInt* get(LLVMContext &Context, const APInt& V);
|
||||||
|
|
||||||
|
/// Return a ConstantInt constructed from the string strStart with the given
|
||||||
|
/// radix.
|
||||||
|
static ConstantInt* get(const IntegerType* Ty, const StringRef& Str,
|
||||||
|
uint8_t radix);
|
||||||
|
|
||||||
/// If Ty is a vector type, return a Constant with a splat of the given
|
/// If Ty is a vector type, return a Constant with a splat of the given
|
||||||
/// value. Otherwise return a ConstantInt for the given value.
|
/// value. Otherwise return a ConstantInt for the given value.
|
||||||
static Constant* get(const Type* Ty, const APInt& V);
|
static Constant* get(const Type* Ty, const APInt& V);
|
||||||
@ -250,6 +255,7 @@ public:
|
|||||||
/// only be used for simple constant values like 2.0/1.0 etc, that are
|
/// only be used for simple constant values like 2.0/1.0 etc, that are
|
||||||
/// known-valid both as host double and as the target format.
|
/// known-valid both as host double and as the target format.
|
||||||
static Constant* get(const Type* Ty, double V);
|
static Constant* get(const Type* Ty, double V);
|
||||||
|
static Constant* get(const Type* Ty, const StringRef& Str);
|
||||||
static ConstantFP* get(LLVMContext &Context, const APFloat& V);
|
static ConstantFP* get(LLVMContext &Context, const APFloat& V);
|
||||||
static ConstantFP* getNegativeZero(const Type* Ty);
|
static ConstantFP* getNegativeZero(const Type* Ty);
|
||||||
|
|
||||||
|
@ -314,6 +314,11 @@ Constant* ConstantInt::get(const Type* Ty, const APInt& V) {
|
|||||||
return C;
|
return C;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ConstantInt* ConstantInt::get(const IntegerType* Ty, const StringRef& Str,
|
||||||
|
uint8_t radix) {
|
||||||
|
return get(Ty->getContext(), APInt(Ty->getBitWidth(), Str, radix));
|
||||||
|
}
|
||||||
|
|
||||||
//===----------------------------------------------------------------------===//
|
//===----------------------------------------------------------------------===//
|
||||||
// ConstantFP
|
// ConstantFP
|
||||||
//===----------------------------------------------------------------------===//
|
//===----------------------------------------------------------------------===//
|
||||||
@ -352,6 +357,22 @@ Constant* ConstantFP::get(const Type* Ty, double V) {
|
|||||||
return C;
|
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) {
|
ConstantFP* ConstantFP::getNegativeZero(const Type* Ty) {
|
||||||
LLVMContext &Context = Ty->getContext();
|
LLVMContext &Context = Ty->getContext();
|
||||||
APFloat apf = cast <ConstantFP>(Constant::getNullValue(Ty))->getValueAPF();
|
APFloat apf = cast <ConstantFP>(Constant::getNullValue(Ty))->getValueAPF();
|
||||||
|
Reference in New Issue
Block a user