How to pass arbitrary arguments to runFunctionAsMain?

I’m trying to call the function main passing arbitrary parameters. My code is something like:

Please note that MyInterpreter extends Interpreter

StringRef filename = argv[1];
std::unique_ptr m(parseIRFile(filename, error, context));

MyInterpreter * v = new MyInterpreter(std::move(m));
errs() << “Done\n”;
Function *main = v->FindFunctionNamed(“main”);

errs() << " Function " << main->getName().str() << “\n”;

std::vectorstd::string parameters;

parameters.insert(parameters.begin(), “argv”);

const char* const* envp;
for (int i=1; i<argc;i++)

v->runFunctionAsMain(main, parameters, envp);

Is it correct or should I construct parameters in another way?

Thanks a lot

envp remains uninitialized here, and runFunctionAsMain appears to
iterate through it until it reaches a nullptr, so that'll probably
crash. I think you want

  const char* const* envp = {nullptr};

Other than that, it looked sensible to me.



Hi Tim,
Thanks for your answer. I’ll fix the problem with envp now.

I don’t know if you have seen my other question but i was doubting of that code because I cannot get the proper value of argv at runtime using my Interpreter. I hope this is the problem. Do you think the same?

Thanks again