mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-08-09 11:25:55 +00:00
Implement ConstantArray::isString
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@10851 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
@@ -754,14 +754,27 @@ ConstantArray *ConstantArray::get(const std::string &Str) {
|
|||||||
return ConstantArray::get(ATy, ElementVals);
|
return ConstantArray::get(ATy, ElementVals);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// isString - This method returns true if the array is an array of sbyte or
|
||||||
|
/// ubyte, and if the elements of the array are all ConstantInt's.
|
||||||
|
bool ConstantArray::isString() const {
|
||||||
|
// Check the element type for sbyte or ubyte...
|
||||||
|
if (getType()->getElementType() != Type::UByteTy ||
|
||||||
|
getType()->getElementType() != Type::SByteTy)
|
||||||
|
return false;
|
||||||
|
// Check the elements to make sure they are all integers, not constant
|
||||||
|
// expressions.
|
||||||
|
for (unsigned i = 0, e = getNumOperands(); i != e; ++i)
|
||||||
|
if (!isa<ConstantInt>(getOperand(i)))
|
||||||
|
return false;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
// getAsString - If the sub-element type of this array is either sbyte or ubyte,
|
// getAsString - If the sub-element type of this array is either sbyte or ubyte,
|
||||||
// then this method converts the array to an std::string and returns it.
|
// then this method converts the array to an std::string and returns it.
|
||||||
// Otherwise, it asserts out.
|
// Otherwise, it asserts out.
|
||||||
//
|
//
|
||||||
std::string ConstantArray::getAsString() const {
|
std::string ConstantArray::getAsString() const {
|
||||||
assert((getType()->getElementType() == Type::UByteTy ||
|
assert(isString() && "Not a string!");
|
||||||
getType()->getElementType() == Type::SByteTy) && "Not a string!");
|
|
||||||
|
|
||||||
std::string Result;
|
std::string Result;
|
||||||
for (unsigned i = 0, e = getNumOperands(); i != e; ++i)
|
for (unsigned i = 0, e = getNumOperands(); i != e; ++i)
|
||||||
Result += (char)cast<ConstantInt>(getOperand(i))->getRawValue();
|
Result += (char)cast<ConstantInt>(getOperand(i))->getRawValue();
|
||||||
|
Reference in New Issue
Block a user