diff options
author | Chris Lattner <sabre@nondot.org> | 2001-10-18 21:55:32 +0000 |
---|---|---|
committer | Chris Lattner <sabre@nondot.org> | 2001-10-18 21:55:32 +0000 |
commit | f8f2afb8cc5f080b291faad678e0a256ea44d15f (patch) | |
tree | 379ee6deb37bce643073e445144af18aea82d9ed /lib/ExecutionEngine/Interpreter/UserInput.cpp | |
parent | b7e711838f8d6445f1ad7fa032515ad472060c84 (diff) |
Enhancements to pass argc & argv to main if required
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@909 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/ExecutionEngine/Interpreter/UserInput.cpp')
-rw-r--r-- | lib/ExecutionEngine/Interpreter/UserInput.cpp | 61 |
1 files changed, 61 insertions, 0 deletions
diff --git a/lib/ExecutionEngine/Interpreter/UserInput.cpp b/lib/ExecutionEngine/Interpreter/UserInput.cpp index 4c2faf6ca1..f579ef1a9b 100644 --- a/lib/ExecutionEngine/Interpreter/UserInput.cpp +++ b/lib/ExecutionEngine/Interpreter/UserInput.cpp @@ -7,6 +7,7 @@ #include "Interpreter.h" #include "llvm/Bytecode/Reader.h" #include "llvm/Assembly/Writer.h" +#include "llvm/DerivedTypes.h" #include <algorithm> enum CommandID { @@ -199,3 +200,63 @@ bool Interpreter::callMethod(const string &Name) { return false; } + + +// 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) { + vector<Value*> Options = LookupMatchingNames(Name); + + for (unsigned i = 0; i < Options.size(); ++i) { // Remove nonmethod matches... + if (!isa<Method>(Options[i])) { + Options.erase(Options.begin()+i); + --i; + } + } + + Value *PickedMeth = ChooseOneOption(Name, Options); + if (PickedMeth == 0) + return true; + + Method *M = cast<Method>(PickedMeth); + const MethodType *MT = M->getMethodType(); + + vector<GenericValue> Args; + switch (MT->getParamTypes().size()) { + default: + cout << "Unknown number of arguments to synthesize for '" << Name << "'!\n"; + return true; + case 2: { + PointerType *SPP = PointerType::get(PointerType::get(Type::SByteTy)); + if (MT->getParamTypes()[1] != SPP) { + cout << "Second argument of '" << Name << "' should have type: '" + << SPP->getDescription() << "'!\n"; + return true; + } + // TODO: + GenericValue GV; GV.PointerVal = 0; + Args.push_back(GV); + } + // fallthrough + case 1: + if (!MT->getParamTypes()[0]->isIntegral()) { + cout << "First argument of '" << Name << "' should be integral!\n"; + return true; + } else { + GenericValue GV; GV.IntVal = 1; + Args.insert(Args.begin(), GV); + } + // fallthrough + case 0: + break; + } + + callMethod(M, Args); // Start executing it... + + // Reset the current frame location to the top of stack + CurFrame = ECStack.size()-1; + + return false; +} |