1 //===-- UserInput.cpp - Interpreter Input Loop support --------------------===//
3 // This file implements the interpreter Input I/O loop.
5 //===----------------------------------------------------------------------===//
7 #include "Interpreter.h"
8 #include "llvm/DerivedTypes.h"
9 #include "llvm/Function.h"
10 #include "llvm/Module.h"
12 // callMainFunction - This is a nasty gross hack that will dissapear when
13 // callFunction can parse command line options and stuff for us.
15 bool Interpreter::callMainFunction(const std::string &Name,
16 const std::vector<std::string> &InputArgv) {
17 Function *M = getModule().getNamedFunction(Name);
19 std::cerr << "Could not find function '" << Name << "' in module!\n";
22 const FunctionType *MT = M->getFunctionType();
24 std::vector<GenericValue> Args;
25 if (MT->getParamTypes().size() >= 2) {
26 PointerType *SPP = PointerType::get(PointerType::get(Type::SByteTy));
27 if (MT->getParamTypes()[1] != SPP) {
28 CW << "Second argument of '" << Name << "' should have type: '"
32 Args.push_back(PTOGV(CreateArgv(InputArgv)));
35 if (MT->getParamTypes().size() >= 1) {
36 if (!MT->getParamTypes()[0]->isInteger()) {
37 std::cout << "First argument of '" << Name << "' should be an integer!\n";
40 GenericValue GV; GV.UIntVal = InputArgv.size();
41 Args.insert(Args.begin(), GV);
45 callFunction(M, Args); // Start executing it...
47 // Reset the current frame location to the top of stack
48 CurFrame = ECStack.size()-1;