[llvm-commits] CVS: llvm/tools/jello/VM.cpp VM.h jello.cpp
Chris Lattner
lattner at cs.uiuc.edu
Fri Dec 13 10:50:01 PST 2002
Changes in directory llvm/tools/jello:
VM.cpp updated: 1.5 -> 1.6
VM.h updated: 1.4 -> 1.5
jello.cpp updated: 1.8 -> 1.9
---
Log message:
Pass command line arguments to main
---
Diffs of the changes:
Index: llvm/tools/jello/VM.cpp
diff -u llvm/tools/jello/VM.cpp:1.5 llvm/tools/jello/VM.cpp:1.6
--- llvm/tools/jello/VM.cpp:1.5 Thu Dec 12 23:40:28 2002
+++ llvm/tools/jello/VM.cpp Fri Dec 13 10:48:57 2002
@@ -38,9 +38,14 @@
}
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: llvm/tools/jello/VM.h
diff -u llvm/tools/jello/VM.h:1.4 llvm/tools/jello/VM.h:1.5
--- llvm/tools/jello/VM.h:1.4 Wed Dec 4 00:45:40 2002
+++ llvm/tools/jello/VM.h Fri Dec 13 10:48:57 2002
@@ -24,6 +24,7 @@
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 @@
//
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: llvm/tools/jello/jello.cpp
diff -u llvm/tools/jello/jello.cpp:1.8 llvm/tools/jello/jello.cpp:1.9
--- llvm/tools/jello/jello.cpp:1.8 Tue Dec 3 16:48:59 2002
+++ llvm/tools/jello/jello.cpp Fri Dec 13 10:48:57 2002
@@ -16,6 +16,9 @@
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 @@
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) {
More information about the llvm-commits
mailing list