* Moved InputArgv out of anonymous scope to be extern'd in another file.

* Added DEBUG() statements to print out parameters passed to executing programs
* Actually ADD parameters to a program running via the JIT (using vector<char*>)


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@7433 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Misha Brukman
2003-07-30 20:15:44 +00:00
parent e623fe3d0a
commit 9d679cbc6c

View File

@@ -40,15 +40,15 @@ namespace {
InputFile("input", cl::init("/dev/null"), InputFile("input", cl::init("/dev/null"),
cl::desc("Filename to pipe in as stdin (default: /dev/null)")); cl::desc("Filename to pipe in as stdin (default: /dev/null)"));
enum FileType { AsmFile, CFile };
}
// Anything specified after the --args option are taken as arguments to the // Anything specified after the --args option are taken as arguments to the
// program being debugged. // program being debugged.
cl::list<std::string> cl::list<std::string>
InputArgv("args", cl::Positional, cl::desc("<program arguments>..."), InputArgv("args", cl::Positional, cl::desc("<program arguments>..."),
cl::ZeroOrMore); cl::ZeroOrMore);
enum FileType { AsmFile, CFile };
}
/// AbstractInterpreter Class - Subclasses of this class are used to execute /// AbstractInterpreter Class - Subclasses of this class are used to execute
/// LLVM bytecode in a variety of ways. This abstract interface hides this /// LLVM bytecode in a variety of ways. This abstract interface hides this
/// complexity behind a simple interface. /// complexity behind a simple interface.
@@ -99,19 +99,24 @@ int LLI::ExecuteProgram(const std::string &Bytecode,
exit(1); exit(1);
} }
std::vector<const char*> Args; std::vector<const char*> LLIArgs;
Args.push_back(LLIPath.c_str()); LLIArgs.push_back(LLIPath.c_str());
Args.push_back("-abort-on-exception"); LLIArgs.push_back("-abort-on-exception");
Args.push_back("-quiet"); LLIArgs.push_back("-quiet");
Args.push_back("-force-interpreter=true"); LLIArgs.push_back("-force-interpreter=true");
Args.push_back(Bytecode.c_str()); LLIArgs.push_back(Bytecode.c_str());
// Add optional parameters to the running program from Argv // Add optional parameters to the running program from Argv
for (unsigned i=0, e = InputArgv.size(); i != e; ++i) for (unsigned i=0, e = InputArgv.size(); i != e; ++i)
Args.push_back(InputArgv[i].c_str()); LLIArgs.push_back(InputArgv[i].c_str());
Args.push_back(0); LLIArgs.push_back(0);
std::cout << "<lli>"; std::cout << "<lli>";
return RunProgramWithTimeout(LLIPath, &Args[0], DEBUG(std::cerr << "About to run:\n\t";
for (unsigned i=0, e = LLIArgs.size(); i != e; ++i)
std::cerr << " " << LLIArgs[i];
std::cerr << "\n";
);
return RunProgramWithTimeout(LLIPath, &LLIArgs[0],
InputFile, OutputFile, OutputFile); InputFile, OutputFile, OutputFile);
} }
@@ -186,6 +191,11 @@ int GCC::ExecuteProgram(const std::string &ProgramFile,
// Now that we have a binary, run it! // Now that we have a binary, run it!
std::cout << "<program>"; std::cout << "<program>";
DEBUG(std::cerr << "About to run:\n\t";
for (unsigned i=0, e = ProgramArgs.size(); i != e; ++i)
std::cerr << " " << ProgramArgs[i];
std::cerr << "\n";
);
int ProgramResult = RunProgramWithTimeout(OutputBinary, &ProgramArgs[0], int ProgramResult = RunProgramWithTimeout(OutputBinary, &ProgramArgs[0],
InputFile, OutputFile, OutputFile); InputFile, OutputFile, OutputFile);
std::cout << "\n"; std::cout << "\n";
@@ -348,24 +358,29 @@ public:
int JIT::ExecuteProgram(const std::string &Bytecode, int JIT::ExecuteProgram(const std::string &Bytecode,
const std::string &OutputFile, const std::string &OutputFile,
const std::string &SharedLib) { const std::string &SharedLib) {
const char* ArgsWithoutSO[] = { // Construct a vector of parameters, incorporating those from the command-line
LLIPath.c_str(), "-quiet", "-force-interpreter=false", std::vector<const char*> JITArgs;
Bytecode.c_str(), JITArgs.push_back(LLIPath.c_str());
0 JITArgs.push_back("-quiet");
}; JITArgs.push_back("-force-interpreter=false");
if (!SharedLib.empty()) {
JITArgs.push_back("-load");
JITArgs.push_back(SharedLib.c_str());
}
JITArgs.push_back(Bytecode.c_str());
// Add optional parameters to the running program from Argv
for (unsigned i=0, e = InputArgv.size(); i != e; ++i)
JITArgs.push_back(InputArgv[i].c_str());
JITArgs.push_back(0);
const char* ArgsWithSO[] = { std::cout << "<jit>\n";
LLIPath.c_str(), "-quiet", "-force-interpreter=false", DEBUG(std::cerr << "About to run:\n\t";
"-load", SharedLib.c_str(), for (unsigned i=0, e = JITArgs.size(); i != e; ++i)
Bytecode.c_str(), std::cerr << " " << JITArgs[i];
0 std::cerr << "\n";
}; );
const char** JITArgs = SharedLib.empty() ? ArgsWithoutSO : ArgsWithSO;
std::cout << "<jit>";
DEBUG(std::cerr << "\nSending output to " << OutputFile << "\n"); DEBUG(std::cerr << "\nSending output to " << OutputFile << "\n");
return RunProgramWithTimeout(LLIPath, JITArgs, return RunProgramWithTimeout(LLIPath, &JITArgs[0],
InputFile, OutputFile, OutputFile); InputFile, OutputFile, OutputFile);
} }