aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorChris Lattner <sabre@nondot.org>2002-08-26 17:53:56 +0000
committerChris Lattner <sabre@nondot.org>2002-08-26 17:53:56 +0000
commit93aeea3748b11fa213b345edf3c86275a4936a31 (patch)
tree729081dc2628b2926242f7f0a5b602e11b44f396 /lib
parente0b6b78e095f7dea9589e8df5ec4521e346ad005 (diff)
Add support for turning an array of characters into a string.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@3509 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib')
-rw-r--r--lib/VMCore/Constants.cpp18
1 files changed, 18 insertions, 0 deletions
diff --git a/lib/VMCore/Constants.cpp b/lib/VMCore/Constants.cpp
index 98df6ea4b7..40c714ec82 100644
--- a/lib/VMCore/Constants.cpp
+++ b/lib/VMCore/Constants.cpp
@@ -422,6 +422,24 @@ void ConstantArray::destroyConstant() {
destroyConstantImpl();
}
+// 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.
+// Otherwise, it asserts out.
+//
+std::string ConstantArray::getAsString() const {
+ std::string Result;
+ if (getType()->getElementType() == Type::SByteTy)
+ for (unsigned i = 0, e = getNumOperands(); i != e; ++i)
+ Result += (char)cast<ConstantSInt>(getOperand(i))->getValue();
+ else {
+ assert(getType()->getElementType() == Type::UByteTy && "Not a string!");
+ for (unsigned i = 0, e = getNumOperands(); i != e; ++i)
+ Result += (char)cast<ConstantUInt>(getOperand(i))->getValue();
+ }
+ return Result;
+}
+
+
//---- ConstantStruct::get() implementation...
//
static ValueMap<std::vector<Constant*>, ConstantStruct> StructConstants;