Pass command line arguments to main
authorChris Lattner <sabre@nondot.org>
Fri, 13 Dec 2002 16:48:57 +0000 (16:48 +0000)
committerChris Lattner <sabre@nondot.org>
Fri, 13 Dec 2002 16:48:57 +0000 (16:48 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@5027 91177308-0d34-0410-b5e6-96231b3b80d8

tools/jello/VM.cpp
tools/jello/VM.h
tools/jello/jello.cpp

index 5b0bf2f4ec375e4f85882538e2948d4e010c374b..e5e77c3e27574eb0731ba208a2c30b9961ddfbcb 100644 (file)
@@ -38,9 +38,14 @@ void VM::setupPassManager() {
 }
 
 int VM::run(Function *F) {
-  int(*PF)() = (int(*)())getPointerToFunction(F);
+  int(*PF)(int, char**) = (int(*)(int, char**))getPointerToFunction(F);
   assert(PF != 0 && "Null pointer to function?");
-  return PF();
+
+  unsigned NumArgs = 0;
+  for (; Argv[NumArgs]; ++NumArgs)
+    ;
+    
+  return PF(NumArgs, Argv);
 }
 
 void *VM::resolveFunctionReference(void *RefAddr) {
index 783b7dc12ebbe3b1937d2281c952649df16da79b..c02b4044f756c50e9af04645628d8512756890b5 100644 (file)
@@ -24,6 +24,7 @@ class VM {
   TargetMachine &TM;       // The current target we are compiling to
   PassManager PM;          // Passes to compile a function
   MachineCodeEmitter *MCE; // MCE object
+  char **Argv;
 
   // GlobalAddress - A mapping between LLVM values and their native code
   // generated versions...
@@ -35,8 +36,8 @@ class VM {
   //
   std::map<void*, Function*> FunctionRefs;
 public:
-  VM(const std::string &name, Module &m, TargetMachine &tm)
-    : ExeName(name), M(m), TM(tm) {
+  VM(const std::string &name, char **AV, Module &m, TargetMachine &tm)
+    : ExeName(name), M(m), TM(tm), Argv(AV) {
     MCE = createEmitter(*this);  // Initialize MCE
     setupPassManager();
     registerCallback();
index 52541f012c7ad2fa8d52c9f9ecc3cab46110e939..7fe37b02f65606a126928c3f741c2c7e01e858c2 100644 (file)
@@ -16,6 +16,9 @@ namespace {
   cl::opt<std::string>
   InputFile(cl::desc("<input bytecode>"), cl::Positional, cl::init("-"));
 
+   cl::list<std::string>
+   InputArgv(cl::ConsumeAfter, cl::desc("<program arguments>..."));
+
   cl::opt<std::string>
   MainFunction("f", cl::desc("Function to execute"), cl::init("main"),
                cl::value_desc("function name"));
@@ -41,8 +44,18 @@ int main(int argc, char **argv) {
     return 1;
   }
 
+  // Build an argv vector...
+  InputArgv.insert(InputArgv.begin(), InputFile);
+  char **Argv = new char*[InputArgv.size()+1];
+  for (unsigned i = 0, e = InputArgv.size(); i != e; ++i) {
+    Argv[i] = new char[InputArgv[i].size()+1];
+    std::copy(InputArgv[i].begin(), InputArgv[i].end(), Argv[i]);
+    Argv[i][InputArgv[i].size()] = 0;
+  }
+  Argv[InputArgv.size()] = 0;
+
   // Create the virtual machine object...
-  VM TheVM(argv[0], *M.get(), *Target.get());
+  VM TheVM(argv[0], Argv, *M.get(), *Target.get());
 
   Function *F = M.get()->getNamedFunction(MainFunction);
   if (F == 0) {