[llvm-commits] CVS: llvm/tools/lli/Interpreter/Execution.cpp Interpreter.cpp Interpreter.h UserInput.cpp

Brian Gaeke gaeke at cs.uiuc.edu
Thu Sep 4 23:47:02 PDT 2003


Changes in directory llvm/tools/lli/Interpreter:

Execution.cpp updated: 1.93 -> 1.94
Interpreter.cpp updated: 1.10 -> 1.11
Interpreter.h updated: 1.36 -> 1.37
UserInput.cpp (r1.27) removed

---
Log message:

Remove support for interactive (step finish next) instructions.
Remove printCurrentInstruction, printStackFrame and infoValue
 (only used interactively) and other unused methods of Interpreter.
Fold UserInput.cpp containing only callMainFunction() into Interpreter.cpp.
Remove unused Profile flag.


---
Diffs of the changes:

Index: llvm/tools/lli/Interpreter/Execution.cpp
diff -u llvm/tools/lli/Interpreter/Execution.cpp:1.93 llvm/tools/lli/Interpreter/Execution.cpp:1.94
--- llvm/tools/lli/Interpreter/Execution.cpp:1.93	Thu Sep  4 18:15:40 2003
+++ llvm/tools/lli/Interpreter/Execution.cpp	Thu Sep  4 23:46:26 2003
@@ -1048,46 +1048,6 @@
   CurFrame = ECStack.size()-1;
 }
 
-void Interpreter::stepInstruction() {  // Do the 'step' command
-  if (ECStack.empty()) {
-    std::cout << "Error: no program running, cannot step!\n";
-    return;
-  }
-
-  // Run an instruction...
-  executeInstruction();
-
-  // Print the next instruction to execute...
-  printCurrentInstruction();
-}
-
-// --- UI Stuff...
-void Interpreter::nextInstruction() {  // Do the 'next' command
-  if (ECStack.empty()) {
-    std::cout << "Error: no program running, cannot 'next'!\n";
-    return;
-  }
-
-  // If this is a call instruction, step over the call instruction...
-  // TODO: ICALL, CALL WITH, ...
-  if (ECStack.back().CurInst->getOpcode() == Instruction::Call) {
-    unsigned StackSize = ECStack.size();
-    // Step into the function...
-    executeInstruction();
-
-    // If we we able to step into the function, finish it now.  We might not be
-    // able the step into a function, if it's external for example.
-    if (ECStack.size() != StackSize)
-      finish(); // Finish executing the function...
-    else
-      printCurrentInstruction();
-
-  } else {
-    // Normal instruction, just step...
-    stepInstruction();
-  }
-}
-
 void Interpreter::run() {
   if (ECStack.empty()) {
     std::cout << "Error: no program running, cannot run!\n";
@@ -1098,40 +1058,6 @@
     // Run an instruction...
     executeInstruction();
   }
-
-  // Print the next instruction to execute...
-  printCurrentInstruction();
-}
-
-void Interpreter::finish() {
-  if (ECStack.empty()) {
-    std::cout << "Error: no program running, cannot run!\n";
-    return;
-  }
-
-  unsigned StackSize = ECStack.size();
-  while (ECStack.size() >= StackSize) {
-    // Run an instruction...
-    executeInstruction();
-  }
-
-  // Print the next instruction to execute...
-  printCurrentInstruction();
-}
-
-// printCurrentInstruction - Print out the instruction that the virtual PC is
-// at, or fail silently if no program is running.
-//
-void Interpreter::printCurrentInstruction() {
-  if (!ECStack.empty()) {
-    if (ECStack.back().CurBB->begin() == ECStack.back().CurInst)  // print label
-      WriteAsOperand(std::cout, ECStack.back().CurBB) << ":\n";
-
-    Instruction &I = *ECStack.back().CurInst;
-    InstNumber *IN = (InstNumber*)I.getAnnotation(SlotNumberAID);
-    assert(IN && "Instruction has no numbering annotation!");
-    std::cout << "#" << IN->InstNum << I;
-  }
 }
 
 void Interpreter::printValue(const Type *Ty, GenericValue V) {
@@ -1177,44 +1103,3 @@
     std::cout << "\n";
   }
 }
-
-void Interpreter::infoValue(const std::string &Name) {
-  Value *PickedVal = ChooseOneOption(Name, LookupMatchingNames(Name));
-  if (!PickedVal) return;
-
-  std::cout << "Value: ";
-  print(PickedVal->getType(), 
-        getOperandValue(PickedVal, ECStack[CurFrame]));
-  std::cout << "\n";
-  printOperandInfo(PickedVal, ECStack[CurFrame]);
-}
-
-// printStackFrame - Print information about the specified stack frame, or -1
-// for the default one.
-//
-void Interpreter::printStackFrame(int FrameNo) {
-  if (FrameNo == -1) FrameNo = CurFrame;
-  Function *F = ECStack[FrameNo].CurFunction;
-  const Type *RetTy = F->getReturnType();
-
-  CW << ((FrameNo == CurFrame) ? '>' : '-') << "#" << FrameNo << ". "
-     << (Value*)RetTy << " \"" << F->getName() << "\"(";
-  
-  unsigned i = 0;
-  for (Function::aiterator I = F->abegin(), E = F->aend(); I != E; ++I, ++i) {
-    if (i != 0) std::cout << ", ";
-    CW << *I << "=";
-    
-    printValue(I->getType(), getOperandValue(I, ECStack[FrameNo]));
-  }
-
-  std::cout << ")\n";
-
-  if (FrameNo != int(ECStack.size()-1)) {
-    BasicBlock::iterator I = ECStack[FrameNo].CurInst;
-    CW << --I;
-  } else {
-    CW << *ECStack[FrameNo].CurInst;
-  }
-}
-


Index: llvm/tools/lli/Interpreter/Interpreter.cpp
diff -u llvm/tools/lli/Interpreter/Interpreter.cpp:1.10 llvm/tools/lli/Interpreter/Interpreter.cpp:1.11
--- llvm/tools/lli/Interpreter/Interpreter.cpp:1.10	Thu Sep  4 17:21:24 2003
+++ llvm/tools/lli/Interpreter/Interpreter.cpp	Thu Sep  4 23:46:26 2003
@@ -8,6 +8,8 @@
 
 #include "Interpreter.h"
 #include "llvm/Module.h"
+#include "llvm/DerivedTypes.h"
+#include "llvm/Function.h"
 
 /// create - Create a new interpreter object.  This can never fail.
 ///
@@ -76,3 +78,45 @@
   return ExitCode;
 }
 
+
+// callMainFunction - Construct call to typical C main() function and
+// call it using callFunction().
+//
+bool Interpreter::callMainFunction(const std::string &Name,
+                                   const std::vector<std::string> &InputArgv) {
+  Function *M = getModule().getNamedFunction(Name);
+  if (M == 0) {
+    std::cerr << "Could not find function '" << Name << "' in module!\n";
+    return 1;
+  }
+  const FunctionType *MT = M->getFunctionType();
+
+  std::vector<GenericValue> Args;
+  if (MT->getParamTypes().size() >= 2) {
+    PointerType *SPP = PointerType::get(PointerType::get(Type::SByteTy));
+    if (MT->getParamTypes()[1] != SPP) {
+      CW << "Second argument of '" << Name << "' should have type: '"
+	 << SPP << "'!\n";
+      return true;
+    }
+    Args.push_back(PTOGV(CreateArgv(InputArgv)));
+  }
+
+  if (MT->getParamTypes().size() >= 1) {
+    if (!MT->getParamTypes()[0]->isInteger()) {
+      std::cout << "First argument of '" << Name
+		<< "' should be an integer!\n";
+      return true;
+    } else {
+      GenericValue GV; GV.UIntVal = InputArgv.size();
+      Args.insert(Args.begin(), GV);
+    }
+  }
+
+  callFunction(M, Args);  // Start executing it...
+
+  // Reset the current frame location to the top of stack
+  CurFrame = ECStack.size()-1;
+
+  return false;
+}


Index: llvm/tools/lli/Interpreter/Interpreter.h
diff -u llvm/tools/lli/Interpreter/Interpreter.h:1.36 llvm/tools/lli/Interpreter/Interpreter.h:1.37
--- llvm/tools/lli/Interpreter/Interpreter.h:1.36	Thu Sep  4 18:15:40 2003
+++ llvm/tools/lli/Interpreter/Interpreter.h	Thu Sep  4 23:46:26 2003
@@ -71,7 +71,6 @@
 //
 class Interpreter : public ExecutionEngine, public InstVisitor<Interpreter> {
   int ExitCode;                // The exit code to be returned by the lli util
-  bool Profile;                // Profiling enabled?
   bool Trace;                  // Tracing enabled?
   int CurFrame;                // The current stack frame being inspected
   TargetData TD;
@@ -91,11 +90,6 @@
   ///
   static ExecutionEngine *create(Module *M, bool TraceMode);
 
-  /// getExitCode - return the code that should be the exit code for the lli
-  /// utility.
-  ///
-  inline int getExitCode() const { return ExitCode; }
-
   /// run - Start execution with the specified function and arguments.
   ///
   virtual int run(const std::string &FnName,
@@ -103,15 +97,12 @@
                   const char ** envp);
  
 
-  // enableProfiling() - Turn profiling on, clear stats?
-  void enableProfiling() { Profile = true; }
   void enableTracing() { Trace = true; }
 
   void handleUserInput();
 
   // User Interation Methods...
   bool callFunction(const std::string &Name);      // return true on failure
-  void infoValue(const std::string &Name);
   void print(const std::string &Name);
   static void print(const Type *Ty, GenericValue V);
   static void printValue(const Type *Ty, GenericValue V);
@@ -119,17 +110,11 @@
   bool callMainFunction(const std::string &MainName,
                         const std::vector<std::string> &InputFilename);
 
-  void list();             // Do the 'list' command
-  void printStackTrace();  // Do the 'backtrace' command
-
   // Code execution methods...
   void callFunction(Function *F, const std::vector<GenericValue> &ArgVals);
   void executeInstruction(); // Execute one instruction...
 
-  void stepInstruction();  // Do the 'step' command
-  void nextInstruction();  // Do the 'next' command
   void run();              // Do the 'run' command
-  void finish();           // Do the 'finish' command
 
   // Opcode Implementations
   void visitReturnInst(ReturnInst &I);
@@ -195,11 +180,6 @@
   // at, or fail silently if no program is running.
   //
   void printCurrentInstruction();
-
-  // printStackFrame - Print information about the specified stack frame, or -1
-  // for the default one.
-  //
-  void printStackFrame(int FrameNo = -1);
 
   // LookupMatchingNames - Search the current function namespace, then the
   // global namespace looking for values that match the specified name.  Return





More information about the llvm-commits mailing list