Provide argv for commands
authorChris Lattner <sabre@nondot.org>
Sat, 27 Oct 2001 05:54:31 +0000 (05:54 +0000)
committerChris Lattner <sabre@nondot.org>
Sat, 27 Oct 2001 05:54:31 +0000 (05:54 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@987 91177308-0d34-0410-b5e6-96231b3b80d8

lib/ExecutionEngine/Interpreter/Execution.cpp
lib/ExecutionEngine/Interpreter/Interpreter.h
lib/ExecutionEngine/Interpreter/UserInput.cpp
tools/lli/lli.cpp

index 9ad5abab2d92adc07052876fd34a39ea3c94b081..1f2d6f132d8f9ac4a30635b0979252438c1ee52d 100644 (file)
@@ -544,7 +544,7 @@ static void executeLoadInst(LoadInst *I, ExecutionContext &SF) {
   case Type::LongTyID:    Result.LongVal = Ptr->LongVal; break;
   case Type::FloatTyID:   Result.FloatVal = Ptr->FloatVal; break;
   case Type::DoubleTyID:  Result.DoubleVal = Ptr->DoubleVal; break;
-  case Type::PointerTyID: Result.PointerVal = Ptr->PointerVal; break;
+  case Type::PointerTyID: Result.PointerVal =(GenericValue*)Ptr->LongVal; break;
   default:
     cout << "Cannot load value of type " << I->getType() << "!\n";
   }
index d9a6834128dc85f05ab63bdc9d272dbdc7a88969..5b123466aa6eebff34121cb131c7110a4d6bc1fd 100644 (file)
@@ -88,7 +88,7 @@ public:
 
   // Hack until we can parse command line args...
   bool callMainMethod(const string &MainName,
-                      const string &InputFilename);
+                      const vector<string> &InputFilename);
 
   void list();             // Do the 'list' command
   void printStackTrace();  // Do the 'backtrace' command
index 2989ae95e86f03b94ff1d3d68f2a34cd4a8584ba..efe7150c137ecaaebc308dd291374c0d81268271 100644 (file)
@@ -212,12 +212,28 @@ bool Interpreter::callMethod(const string &Name) {
   return false;
 }
 
+static void *CreateArgv(const vector<string> &InputArgv) {
+  // Pointers are 64 bits...
+  uint64_t *Result = new uint64_t[InputArgv.size()+1];
+
+  for (unsigned i = 0; i < InputArgv.size(); ++i) {
+    unsigned Size = InputArgv[i].size()+1;
+    char *Dest = new char[Size];
+    copy(InputArgv[i].begin(), InputArgv[i].end(), Dest);
+    Dest[Size-1] = 0;
+    Result[i] = (uint64_t)Dest;
+  }
+
+  Result[InputArgv.size()] = 0;
+  return Result;
+}
+
 
 // callMainMethod - This is a nasty gross hack that will dissapear when
 // callMethod can parse command line options and stuff for us.
 //
 bool Interpreter::callMainMethod(const string &Name,
-                                 const string &InputFilename) {
+                                 const vector<string> &InputArgv) {
   vector<Value*> Options = LookupMatchingNames(Name);
 
   for (unsigned i = 0; i < Options.size(); ++i) { // Remove nonmethod matches...
@@ -246,8 +262,8 @@ bool Interpreter::callMainMethod(const string &Name,
            << SPP->getDescription() << "'!\n";
       return true;
     }
-    // TODO:
-    GenericValue GV; GV.PointerVal = 0;
+
+    GenericValue GV; GV.PointerVal = (GenericValue*)CreateArgv(InputArgv);
     Args.push_back(GV);
   }
     // fallthrough
@@ -256,7 +272,7 @@ bool Interpreter::callMainMethod(const string &Name,
       cout << "First argument of '" << Name << "' should be integral!\n";
       return true;
     } else {
-      GenericValue GV; GV.IntVal = 1;
+      GenericValue GV; GV.UIntVal = InputArgv.size();
       Args.insert(Args.begin(), GV);
     }
     // fallthrough
index 818931c5f79ba029f2a32d8846e9872cbc394896..29d45d68306191aadf8fbd61aa513abd6231f169 100644 (file)
@@ -10,7 +10,7 @@
 #include "Interpreter.h"
 #include "llvm/Support/CommandLine.h"
 
-cl::String InputFilename(""       , "Input filename", cl::NoFlags, "-");
+cl::StringList InputArgv(""   , "Input command line", cl::ConsumeAfter);
 cl::String MainFunction ("f"      , "Function to execute", cl::NoFlags, "main");
 cl::Flag   DebugMode    ("debug"  , "Start program in debugger");
 cl::Alias  DebugModeA   ("d"      , "Alias for -debug", cl::NoFlags, DebugMode);
@@ -21,7 +21,7 @@ cl::Flag   ProfileMode  ("profile", "Enable Profiling [unimp]");
 //
 Interpreter::Interpreter() : ExitCode(0), Profile(ProfileMode), CurFrame(-1) {
   CurMod = 0;
-  loadModule(InputFilename);
+  loadModule(InputArgv.size() ? InputArgv[0] : "");
 
   // Initialize the "backend"
   initializeExecutionEngine();
@@ -49,7 +49,7 @@ int main(int argc, char** argv) {
 
   // Start interpreter into the main function...
   //
-  if (!I.callMainMethod(MainFunction, InputFilename) && !DebugMode) {
+  if (!I.callMainMethod(MainFunction, InputArgv) && !DebugMode) {
     // If not in debug mode and if the call succeeded, run the code now...
     I.run();
   }