summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorReid Spencer <rspencer@reidspencer.com>2006-05-30 18:15:07 +0000
committerReid Spencer <rspencer@reidspencer.com>2006-05-30 18:15:07 +0000
commit461bed2b753c514ac15ff824befe585988408f45 (patch)
treeae6c79305341921ea57812f856b26239d080fa33 /lib
parent6b8e5a93183ab08811b7b71887d8c7d774666210 (diff)
downloadllvm-461bed2b753c514ac15ff824befe585988408f45.tar.gz
llvm-461bed2b753c514ac15ff824befe585988408f45.tar.bz2
llvm-461bed2b753c514ac15ff824befe585988408f45.tar.xz
Provide a simpler interface for getting a ConstantArray from a character
string. Instead of specifying the length, just specify whether the user wants a terminating null or not. The default is "true" to retain the same behavior as previously provided by this function. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@28562 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib')
-rw-r--r--lib/VMCore/Constants.cpp12
1 files changed, 4 insertions, 8 deletions
diff --git a/lib/VMCore/Constants.cpp b/lib/VMCore/Constants.cpp
index d5f221f5c1..3351385d0a 100644
--- a/lib/VMCore/Constants.cpp
+++ b/lib/VMCore/Constants.cpp
@@ -930,21 +930,17 @@ void ConstantArray::destroyConstant() {
/// Otherwise, the length parameter specifies how much of the string to use
/// and it won't be null terminated.
///
-Constant *ConstantArray::get(const std::string &Str, unsigned length) {
- assert(length <= Str.length() && "Invalid length for string");
+Constant *ConstantArray::get(const std::string &Str, bool AddNull) {
std::vector<Constant*> ElementVals;
-
- unsigned copy_len = (length == 0 ? Str.length() : length);
- for (unsigned i = 0; i < copy_len; ++i)
+ for (unsigned i = 0; i < Str.length(); ++i)
ElementVals.push_back(ConstantSInt::get(Type::SByteTy, Str[i]));
// Add a null terminator to the string...
- if (length == 0) {
+ if (AddNull) {
ElementVals.push_back(ConstantSInt::get(Type::SByteTy, 0));
- copy_len++;
}
- ArrayType *ATy = ArrayType::get(Type::SByteTy, copy_len);
+ ArrayType *ATy = ArrayType::get(Type::SByteTy, ElementVals.size());
return ConstantArray::get(ATy, ElementVals);
}