4 #include "Support/CommandLine.h"
5 #include "Support/SystemUtils.h"
11 enum FileType { AsmFile, CFile };
13 //===---------------------------------------------------------------------===//
16 // This is not a *real* AbstractInterpreter as it does not accept bytecode
17 // files, but only input acceptable to GCC, i.e. C, C++, and assembly files
20 std::string GCCPath; // The path to the gcc executable
22 GCC(const std::string &gccPath) : GCCPath(gccPath) { }
25 virtual int ExecuteProgram(const std::string &ProgramFile,
26 const cl::list<std::string> &Args,
28 const std::string &InputFile,
29 const std::string &OutputFile,
30 const std::string &SharedLib = "");
32 int MakeSharedObject(const std::string &InputFile,
34 std::string &OutputFile);
36 void ProcessFailure(const char **Args);
39 GCC* createGCCtool(const std::string &ProgramPath,
40 std::string &Message);
42 /// AbstractInterpreter Class - Subclasses of this class are used to execute
43 /// LLVM bytecode in a variety of ways. This abstract interface hides this
44 /// complexity behind a simple interface.
46 struct AbstractInterpreter {
48 virtual ~AbstractInterpreter() {}
50 /// ExecuteProgram - Run the specified bytecode file, emitting output to the
51 /// specified filename. This returns the exit code of the program.
53 virtual int ExecuteProgram(const std::string &Bytecode,
54 const cl::list<std::string> &Args,
55 const std::string &InputFile,
56 const std::string &OutputFile,
57 const std::string &SharedLib = "") = 0;
60 //===---------------------------------------------------------------------===//
61 // CBE Implementation of AbstractIntepreter interface
63 class CBE : public AbstractInterpreter {
64 std::string DISPath; // The path to the `llvm-dis' executable
67 CBE(const std::string &disPath, GCC *Gcc) : DISPath(disPath), gcc(Gcc) { }
68 ~CBE() { delete gcc; }
70 virtual int ExecuteProgram(const std::string &Bytecode,
71 const cl::list<std::string> &Args,
72 const std::string &InputFile,
73 const std::string &OutputFile,
74 const std::string &SharedLib = "");
76 // Sometimes we just want to go half-way and only generate the C file,
77 // not necessarily compile it with GCC and run the program
78 virtual int OutputC(const std::string &Bytecode,
79 std::string &OutputCFile);
83 CBE* createCBEtool(const std::string &ProgramPath, std::string &Message);
85 //===---------------------------------------------------------------------===//
86 // LLC Implementation of AbstractIntepreter interface
88 class LLC : public AbstractInterpreter {
89 std::string LLCPath; // The path to the LLC executable
92 LLC(const std::string &llcPath, GCC *Gcc)
93 : LLCPath(llcPath), gcc(Gcc) { }
94 ~LLC() { delete gcc; }
96 virtual int ExecuteProgram(const std::string &Bytecode,
97 const cl::list<std::string> &Args,
98 const std::string &InputFile,
99 const std::string &OutputFile,
100 const std::string &SharedLib = "");
102 int OutputAsm(const std::string &Bytecode,
103 std::string &OutputAsmFile);
106 LLC* createLLCtool(const std::string &ProgramPath, std::string &Message);
108 AbstractInterpreter* createLLItool(const std::string &ProgramPath,
109 std::string &Message);
111 AbstractInterpreter* createJITtool(const std::string &ProgramPath,
112 std::string &Message);