Added a parameter to control whether Constant::getStringValue() would chop
[oota-llvm.git] / lib / VMCore / Constants.cpp
index 1beb5bc9b7cfacbc15b8c5d6824ad975282fa9aa..28ca2a416d9449dc7ef8d08382a67a8d5b530a3c 100644 (file)
@@ -1715,8 +1715,10 @@ void Constant::clearAllValueMaps() {
 
 /// getStringValue - Turn an LLVM constant pointer that eventually points to a
 /// global into a string value.  Return an empty string if we can't do it.
+/// Parameter Chop determines if the result is chopped at the first null
+/// terminator.
 ///
-std::string Constant::getStringValue(unsigned Offset) {
+std::string Constant::getStringValue(bool Chop, unsigned Offset) {
   if (GlobalVariable *GV = dyn_cast<GlobalVariable>(this)) {
     if (GV->hasInitializer() && isa<ConstantArray>(GV->getInitializer())) {
       ConstantArray *Init = cast<ConstantArray>(GV->getInitializer());
@@ -1727,9 +1729,11 @@ std::string Constant::getStringValue(unsigned Offset) {
           Result.erase(Result.begin(), Result.begin()+Offset);
 
           // Take off the null terminator, and any string fragments after it.
-          std::string::size_type NullPos = Result.find_first_of((char)0);
-          if (NullPos != std::string::npos)
-            Result.erase(Result.begin()+NullPos, Result.end());
+          if (Chop) {
+            std::string::size_type NullPos = Result.find_first_of((char)0);
+            if (NullPos != std::string::npos)
+              Result.erase(Result.begin()+NullPos, Result.end());
+          }
           return Result;
         }
       }