mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2024-08-17 21:29:20 +00:00
Pass command line arguments to main
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@5027 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
parent
395a8821bf
commit
041b31ce69
@ -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) {
|
||||
|
@ -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();
|
||||
|
@ -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) {
|
||||
|
Loading…
Reference in New Issue
Block a user