1 //===-- Support/ToolRunner.h ------------------------------------*- C++ -*-===//
5 //===----------------------------------------------------------------------===//
10 #include "Support/CommandLine.h"
11 #include "Support/SystemUtils.h"
17 enum FileType { AsmFile, CFile };
19 //===---------------------------------------------------------------------===//
22 // This is not a *real* AbstractInterpreter as it does not accept bytecode
23 // files, but only input acceptable to GCC, i.e. C, C++, and assembly files
26 std::string GCCPath; // The path to the gcc executable
28 GCC(const std::string &gccPath) : GCCPath(gccPath) { }
31 virtual int ExecuteProgram(const std::string &ProgramFile,
32 const cl::list<std::string> &Args,
34 const std::string &InputFile,
35 const std::string &OutputFile,
36 const std::string &SharedLib = "");
38 int MakeSharedObject(const std::string &InputFile,
40 std::string &OutputFile);
42 void ProcessFailure(const char **Args);
45 GCC* createGCCtool(const std::string &ProgramPath,
46 std::string &Message);
48 /// AbstractInterpreter Class - Subclasses of this class are used to execute
49 /// LLVM bytecode in a variety of ways. This abstract interface hides this
50 /// complexity behind a simple interface.
52 struct AbstractInterpreter {
54 virtual ~AbstractInterpreter() {}
56 /// ExecuteProgram - Run the specified bytecode file, emitting output to the
57 /// specified filename. This returns the exit code of the program.
59 virtual int ExecuteProgram(const std::string &Bytecode,
60 const cl::list<std::string> &Args,
61 const std::string &InputFile,
62 const std::string &OutputFile,
63 const std::string &SharedLib = "") = 0;
66 //===---------------------------------------------------------------------===//
67 // CBE Implementation of AbstractIntepreter interface
69 class CBE : public AbstractInterpreter {
70 std::string DISPath; // The path to the `llvm-dis' executable
73 CBE(const std::string &disPath, GCC *Gcc) : DISPath(disPath), gcc(Gcc) { }
74 ~CBE() { delete gcc; }
76 virtual int ExecuteProgram(const std::string &Bytecode,
77 const cl::list<std::string> &Args,
78 const std::string &InputFile,
79 const std::string &OutputFile,
80 const std::string &SharedLib = "");
82 // Sometimes we just want to go half-way and only generate the C file,
83 // not necessarily compile it with GCC and run the program
84 virtual int OutputC(const std::string &Bytecode,
85 std::string &OutputCFile);
89 CBE* createCBEtool(const std::string &ProgramPath, std::string &Message);
91 //===---------------------------------------------------------------------===//
92 // LLC Implementation of AbstractIntepreter interface
94 class LLC : public AbstractInterpreter {
95 std::string LLCPath; // The path to the LLC executable
98 LLC(const std::string &llcPath, GCC *Gcc)
99 : LLCPath(llcPath), gcc(Gcc) { }
100 ~LLC() { delete gcc; }
102 virtual int ExecuteProgram(const std::string &Bytecode,
103 const cl::list<std::string> &Args,
104 const std::string &InputFile,
105 const std::string &OutputFile,
106 const std::string &SharedLib = "");
108 int OutputAsm(const std::string &Bytecode,
109 std::string &OutputAsmFile);
112 LLC* createLLCtool(const std::string &ProgramPath, std::string &Message);
114 AbstractInterpreter* createLLItool(const std::string &ProgramPath,
115 std::string &Message);
117 AbstractInterpreter* createJITtool(const std::string &ProgramPath,
118 std::string &Message);