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 //===----------------------------------------------------------------------===//
17 class AbstractInterpreter;
20 const std::string ToolName; // Name of bugpoint
21 Module *Program; // The raw program, linked together
22 std::vector<const PassInfo*> PassesToRun;
23 AbstractInterpreter *Interpreter; // How to run the program
25 BugDriver(const char *toolname)
26 : ToolName(toolname), Program(0), Interpreter(0) {}
28 const std::string &getToolName() const { return ToolName; }
30 // Set up methods... these methods are used to copy information about the
31 // command line arguments into instance variables of BugDriver.
33 bool addSources(const std::vector<std::string> &FileNames);
35 void addPasses(It I, It E) { PassesToRun.insert(PassesToRun.end(), I, E); }
37 /// run - The top level method that is invoked after all of the instance
38 /// variables are set up from command line arguments.
42 /// debugCrash - This method is called when some pass crashes on input. It
43 /// attempts to prune down the testcase to something reasonable, and figure
44 /// out exactly which pass is crashing.
48 /// debugPassCrash - This method is called when the specified pass crashes on
49 /// Program as input. It tries to reduce the testcase to something that still
50 /// crashes, but it smaller.
52 bool debugPassCrash(const PassInfo *PI);
54 /// debugMiscompilation - This method is used when the passes selected are not
55 /// crashing, but the generated output is semantically different from the
57 bool debugMiscompilation();
59 /// debugPassMiscompilation - This method is called when the specified pass
60 /// miscompiles Program as input. It tries to reduce the testcase to
61 /// something that smaller that still miscompiles the program.
62 /// ReferenceOutput contains the filename of the file containing the output we
65 bool debugPassMiscompilation(const PassInfo *ThePass,
66 const std::string &ReferenceOutput);
69 /// ParseInputFile - Given a bytecode or assembly input filename, parse and
70 /// return it, or return null if not possible.
72 Module *ParseInputFile(const std::string &InputFilename) const;
74 /// writeProgramToFile - This writes the current "Program" to the named
75 /// bytecode file. If an error occurs, true is returned.
77 bool writeProgramToFile(const std::string &Filename, Module *M = 0) const;
80 /// EmitProgressBytecode - This function is used to output the current Program
81 /// to a file named "bugpoing-ID.bc".
83 void EmitProgressBytecode(const PassInfo *Pass, const std::string &ID);
85 /// runPasses - Run the specified passes on Program, outputting a bytecode
86 /// file and writting the filename into OutputFile if successful. If the
87 /// optimizations fail for some reason (optimizer crashes), return true,
88 /// otherwise return false. If DeleteOutput is set to true, the bytecode is
89 /// deleted on success, and the filename string is undefined. This prints to
90 /// cout a single line message indicating whether compilation was successful
91 /// or failed, unless Quiet is set.
93 bool runPasses(const std::vector<const PassInfo*> &PassesToRun,
94 std::string &OutputFilename, bool DeleteOutput = false,
95 bool Quiet = false) const;
97 /// runPasses - Just like the method above, but this just returns true or
98 /// false indicating whether or not the optimizer crashed on the specified
99 /// input (true = crashed).
101 bool runPasses(const std::vector<const PassInfo*> &PassesToRun,
102 bool DeleteOutput = true) const {
103 std::string Filename;
104 return runPasses(PassesToRun, Filename, DeleteOutput);
107 /// runPass - Run only the specified pass on the program.
109 bool runPass(const PassInfo *P, bool DeleteOutput = true) const {
110 return runPasses(std::vector<const PassInfo*>(1, P), DeleteOutput);
113 /// extractFunctionFromModule - This method is used to extract the specified
114 /// (non-external) function from the current program, slim down the module,
115 /// and then return it. This does not modify Program at all, it modifies a
116 /// copy, which it returns.
118 Module *extractFunctionFromModule(Function *F) const;
120 /// initializeExecutionEnvironment - This method is used to set up the
121 /// environment for executing LLVM programs.
123 bool initializeExecutionEnvironment();
125 /// executeProgram - This method runs "Program", capturing the output of the
126 /// program to a file, returning the filename of the file. A recommended
127 /// filename may be optionally specified.
129 std::string executeProgram(std::string RequestedOutputFilename = "",
130 std::string Bytecode = "");
132 /// diffProgram - This method executes the specified module and diffs the
133 /// output against the file specified by ReferenceOutputFile. If the output
134 /// is different, true is returned.
136 bool diffProgram(const std::string &ReferenceOutputFile,
137 const std::string &BytecodeFile = "");