[llvm-commits] CVS: llvm/lib/Debugger/ProgramInfo.cpp

Jim Laskey jlaskey at apple.com
Wed Mar 8 10:11:22 PST 2006



Changes in directory llvm/lib/Debugger:

ProgramInfo.cpp updated: 1.12 -> 1.13
---
Log message:

Get rid of the multiple copies of getStringValue.  Now a Constant:: method.


---
Diffs of the changes:  (+3 -42)

 ProgramInfo.cpp |   45 +++------------------------------------------
 1 files changed, 3 insertions(+), 42 deletions(-)


Index: llvm/lib/Debugger/ProgramInfo.cpp
diff -u llvm/lib/Debugger/ProgramInfo.cpp:1.12 llvm/lib/Debugger/ProgramInfo.cpp:1.13
--- llvm/lib/Debugger/ProgramInfo.cpp:1.12	Thu Jul  7 18:21:43 2005
+++ llvm/lib/Debugger/ProgramInfo.cpp	Wed Mar  8 12:11:07 2006
@@ -38,45 +38,6 @@
   }
 }
 
-/// 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.
-///
-static std::string getStringValue(Value *V, unsigned Offset = 0) {
-  if (GlobalVariable *GV = dyn_cast<GlobalVariable>(V)) {
-    if (GV->hasInitializer() && isa<ConstantArray>(GV->getInitializer())) {
-      ConstantArray *Init = cast<ConstantArray>(GV->getInitializer());
-      if (Init->isString()) {
-        std::string Result = Init->getAsString();
-        if (Offset < Result.size()) {
-          // If we are pointing INTO The string, erase the beginning...
-          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());
-          return Result;
-        }
-      }
-    }
-  } else if (Constant *C = dyn_cast<Constant>(V)) {
-    if (GlobalValue *GV = dyn_cast<GlobalValue>(C))
-      return getStringValue(GV, Offset);
-    else if (ConstantExpr *CE = dyn_cast<ConstantExpr>(C)) {
-      if (CE->getOpcode() == Instruction::GetElementPtr) {
-        // Turn a gep into the specified offset.
-        if (CE->getNumOperands() == 3 &&
-            cast<Constant>(CE->getOperand(1))->isNullValue() &&
-            isa<ConstantInt>(CE->getOperand(2))) {
-          return getStringValue(CE->getOperand(0),
-                   Offset+cast<ConstantInt>(CE->getOperand(2))->getRawValue());
-        }
-      }
-    }
-  }
-  return "";
-}
-
 /// getNextStopPoint - Follow the def-use chains of the specified LLVM value,
 /// traversing the use chains until we get to a stoppoint.  When we do, return
 /// the source location of the stoppoint.  If we don't find a stoppoint, return
@@ -158,8 +119,8 @@
         if (ConstantUInt *CUI = dyn_cast<ConstantUInt>(CS->getOperand(1)))
           Version = CUI->getValue();
 
-        BaseName  = getStringValue(CS->getOperand(3));
-        Directory = getStringValue(CS->getOperand(4));
+        BaseName  = CS->getOperand(3)->getStringValue();
+        Directory = CS->getOperand(4)->getStringValue();
       }
 }
 
@@ -199,7 +160,7 @@
           SourceFile = &PI.getSourceFile(GV);
 
         // Entry #2 is the function name.
-        Name = getStringValue(CS->getOperand(2));
+        Name = CS->getOperand(2)->getStringValue();
       }
 }
 






More information about the llvm-commits mailing list