1 //===- BugDriver.h - Top-Level BugPoint class -------------------*- C++ -*-===//
3 // This class contains all of the shared state and information that is used by
4 // the BugPoint tool to track down errors in optimizations. This class is the
5 // main driver class that invokes all sub-functionality.
7 //===----------------------------------------------------------------------===//
19 const std::string ToolName; // Name of bugpoint
20 Module *Program; // The raw program, linked together
21 std::vector<const PassInfo*> PassesToRun;
23 BugDriver(const char *toolname) : ToolName(toolname), Program(0) {}
25 // Set up methods... these methods are used to copy information about the
26 // command line arguments into instance variables of BugDriver.
28 bool addSources(const std::vector<std::string> &FileNames);
30 void addPasses(It I, It E) { PassesToRun.insert(PassesToRun.end(), I, E); }
32 /// run - The top level method that is invoked after all of the instance
33 /// variables are set up from command line arguments.
37 /// debugCrash - This method is called when some pass crashes on input. It
38 /// attempts to prune down the testcase to something reasonable, and figure
39 /// out exactly which pass is crashing.
43 /// debugPassCrash - This method is called when the specified pass crashes on
44 /// Program as input. It tries to reduce the testcase to something that still
45 /// crashes, but it smaller.
47 bool debugPassCrash(const PassInfo *PI);
49 /// debugMiscompilation - This method is used when the passes selected are not
50 /// crashing, but the generated output is semantically different from the
52 bool debugMiscompilation();
55 /// ParseInputFile - Given a bytecode or assembly input filename, parse and
56 /// return it, or return null if not possible.
58 Module *ParseInputFile(const std::string &InputFilename) const;
60 /// removeFile - Delete the specified file
62 void removeFile(const std::string &Filename) const;
64 /// writeProgramToFile - This writes the current "Program" to the named
65 /// bytecode file. If an error occurs, true is returned.
67 bool writeProgramToFile(const std::string &Filename) const;
70 /// EmitProgressBytecode - This function is used to output the current Program
71 /// to a file named "bugpoing-ID.bc".
73 void EmitProgressBytecode(const PassInfo *Pass, const std::string &ID);
75 /// runPasses - Run the specified passes on Program, outputting a bytecode
76 /// file and writting the filename into OutputFile if successful. If the
77 /// optimizations fail for some reason (optimizer crashes), return true,
78 /// otherwise return false. If DeleteOutput is set to true, the bytecode is
79 /// deleted on success, and the filename string is undefined. This prints to
80 /// cout a single line message indicating whether compilation was successful
83 bool runPasses(const std::vector<const PassInfo*> &PassesToRun,
84 std::string &OutputFilename, bool DeleteOutput = false) const;
86 /// runPasses - Just like the method above, but this just returns true or
87 /// false indicating whether or not the optimizer crashed on the specified
88 /// input (true = crashed).
90 bool runPasses(const std::vector<const PassInfo*> &PassesToRun,
91 bool DeleteOutput = true) const {
93 return runPasses(PassesToRun, Filename, DeleteOutput);
96 /// runPass - Run only the specified pass on the program.
97 bool runPass(const PassInfo *P, bool DeleteOutput = true) const {
98 return runPasses(std::vector<const PassInfo*>(1, P), DeleteOutput);
101 /// extractFunctionFromModule - This method is used to extract the specified
102 /// (non-external) function from the current program, slim down the module,
103 /// and then return it. This does not modify Program at all, it modifies a
104 /// copy, which it returns.
105 Module *extractFunctionFromModule(Function *F) const;