+ // set up the input file name
+ sys::Path inputFilename(OutputPrefix + "-input.bc");
+ if (inputFilename.makeUnique(true, &ErrMsg)) {
+ errs() << getToolName() << ": Error making unique filename: "
+ << ErrMsg << "\n";
+ return(1);
+ }
+
+ std::string ErrInfo;
+ raw_fd_ostream InFile(inputFilename.c_str(), ErrInfo,
+ raw_fd_ostream::F_Binary);
+
+
+ if (!ErrInfo.empty()) {
+ errs() << "Error opening bitcode file: " << inputFilename.str() << "\n";
+ return 1;
+ }
+ WriteBitcodeToFile(Program, InFile);
+ InFile.close();
+
+ // setup the child process' arguments
+ SmallVector<const char*, 8> Args;
+ sys::Path tool = sys::Program::FindProgramByName(ToolName);
+ if (UseValgrind) {
+ Args.push_back("valgrind");
+ Args.push_back("--error-exitcode=1");
+ Args.push_back("-q");
+ Args.push_back(tool.c_str());
+ } else
+ Args.push_back(ToolName);
+
+ Args.push_back("-as-child");
+ Args.push_back("-child-output");
+ Args.push_back(OutputFilename.c_str());
+ std::vector<std::string> pass_args;
+ for (unsigned i = 0, e = PluginLoader::getNumPlugins(); i != e; ++i) {
+ pass_args.push_back( std::string("-load"));
+ pass_args.push_back( PluginLoader::getPlugin(i));