Chris Lattner | f474449 | 2003-09-30 18:28:53 +0000 | [diff] [blame] | 1 | //===-- Support/ToolRunner.h ------------------------------------*- C++ -*-===// |
| 2 | // |
Chris Lattner | 7915a1e | 2003-10-14 21:34:11 +0000 | [diff] [blame^] | 3 | // This file exposes an abstraction around a platform C compiler, used to |
| 4 | // compile C and assembly code. It also exposes an "AbstractIntepreter" |
| 5 | // interface, which is used to execute code using one of the LLVM execution |
| 6 | // engines. |
Chris Lattner | f474449 | 2003-09-30 18:28:53 +0000 | [diff] [blame] | 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | |
Misha Brukman | 29afb64 | 2003-09-29 22:38:57 +0000 | [diff] [blame] | 10 | #ifndef TOOLRUNNER_H |
| 11 | #define TOOLRUNNER_H |
| 12 | |
Misha Brukman | 29afb64 | 2003-09-29 22:38:57 +0000 | [diff] [blame] | 13 | #include "Support/SystemUtils.h" |
Misha Brukman | 29afb64 | 2003-09-29 22:38:57 +0000 | [diff] [blame] | 14 | #include <vector> |
| 15 | |
Chris Lattner | 7915a1e | 2003-10-14 21:34:11 +0000 | [diff] [blame^] | 16 | class CBE; |
| 17 | class LLC; |
Misha Brukman | 29afb64 | 2003-09-29 22:38:57 +0000 | [diff] [blame] | 18 | |
| 19 | //===---------------------------------------------------------------------===// |
| 20 | // GCC abstraction |
| 21 | // |
Misha Brukman | 29afb64 | 2003-09-29 22:38:57 +0000 | [diff] [blame] | 22 | class GCC { |
| 23 | std::string GCCPath; // The path to the gcc executable |
Misha Brukman | 29afb64 | 2003-09-29 22:38:57 +0000 | [diff] [blame] | 24 | GCC(const std::string &gccPath) : GCCPath(gccPath) { } |
Chris Lattner | 7915a1e | 2003-10-14 21:34:11 +0000 | [diff] [blame^] | 25 | public: |
| 26 | enum FileType { AsmFile, CFile }; |
Misha Brukman | 29afb64 | 2003-09-29 22:38:57 +0000 | [diff] [blame] | 27 | |
Chris Lattner | 7915a1e | 2003-10-14 21:34:11 +0000 | [diff] [blame^] | 28 | static GCC* create(const std::string &ProgramPath, std::string &Message); |
| 29 | |
| 30 | |
| 31 | int ExecuteProgram(const std::string &ProgramFile, |
| 32 | const std::vector<std::string> &Args, |
| 33 | FileType fileType, |
| 34 | const std::string &InputFile, |
| 35 | const std::string &OutputFile, |
| 36 | const std::string &SharedLib = ""); |
Misha Brukman | 29afb64 | 2003-09-29 22:38:57 +0000 | [diff] [blame] | 37 | |
| 38 | int MakeSharedObject(const std::string &InputFile, |
| 39 | FileType fileType, |
| 40 | std::string &OutputFile); |
| 41 | |
| 42 | void ProcessFailure(const char **Args); |
| 43 | }; |
| 44 | |
Misha Brukman | 29afb64 | 2003-09-29 22:38:57 +0000 | [diff] [blame] | 45 | |
Chris Lattner | 7915a1e | 2003-10-14 21:34:11 +0000 | [diff] [blame^] | 46 | //===---------------------------------------------------------------------===// |
Misha Brukman | 29afb64 | 2003-09-29 22:38:57 +0000 | [diff] [blame] | 47 | /// AbstractInterpreter Class - Subclasses of this class are used to execute |
| 48 | /// LLVM bytecode in a variety of ways. This abstract interface hides this |
| 49 | /// complexity behind a simple interface. |
| 50 | /// |
| 51 | struct AbstractInterpreter { |
Chris Lattner | 7915a1e | 2003-10-14 21:34:11 +0000 | [diff] [blame^] | 52 | static CBE* createCBE(const std::string &ProgramPath, std::string &Message); |
| 53 | static LLC *createLLC(const std::string &ProgramPath, std::string &Message); |
| 54 | |
| 55 | static AbstractInterpreter* createLLI(const std::string &ProgramPath, |
| 56 | std::string &Message); |
| 57 | |
| 58 | static AbstractInterpreter* createJIT(const std::string &ProgramPath, |
| 59 | std::string &Message); |
| 60 | |
Misha Brukman | 29afb64 | 2003-09-29 22:38:57 +0000 | [diff] [blame] | 61 | |
| 62 | virtual ~AbstractInterpreter() {} |
| 63 | |
| 64 | /// ExecuteProgram - Run the specified bytecode file, emitting output to the |
| 65 | /// specified filename. This returns the exit code of the program. |
| 66 | /// |
| 67 | virtual int ExecuteProgram(const std::string &Bytecode, |
Chris Lattner | 7915a1e | 2003-10-14 21:34:11 +0000 | [diff] [blame^] | 68 | const std::vector<std::string> &Args, |
Misha Brukman | 29afb64 | 2003-09-29 22:38:57 +0000 | [diff] [blame] | 69 | const std::string &InputFile, |
| 70 | const std::string &OutputFile, |
| 71 | const std::string &SharedLib = "") = 0; |
| 72 | }; |
| 73 | |
| 74 | //===---------------------------------------------------------------------===// |
| 75 | // CBE Implementation of AbstractIntepreter interface |
| 76 | // |
| 77 | class CBE : public AbstractInterpreter { |
| 78 | std::string DISPath; // The path to the `llvm-dis' executable |
| 79 | GCC *gcc; |
| 80 | public: |
| 81 | CBE(const std::string &disPath, GCC *Gcc) : DISPath(disPath), gcc(Gcc) { } |
| 82 | ~CBE() { delete gcc; } |
| 83 | |
| 84 | virtual int ExecuteProgram(const std::string &Bytecode, |
Chris Lattner | 7915a1e | 2003-10-14 21:34:11 +0000 | [diff] [blame^] | 85 | const std::vector<std::string> &Args, |
Misha Brukman | 29afb64 | 2003-09-29 22:38:57 +0000 | [diff] [blame] | 86 | const std::string &InputFile, |
| 87 | const std::string &OutputFile, |
| 88 | const std::string &SharedLib = ""); |
| 89 | |
Chris Lattner | 7915a1e | 2003-10-14 21:34:11 +0000 | [diff] [blame^] | 90 | // Sometimes we just want to go half-way and only generate the .c file, |
| 91 | // not necessarily compile it with GCC and run the program. |
| 92 | // |
| 93 | virtual int OutputC(const std::string &Bytecode, std::string &OutputCFile); |
Misha Brukman | 29afb64 | 2003-09-29 22:38:57 +0000 | [diff] [blame] | 94 | }; |
| 95 | |
Misha Brukman | 29afb64 | 2003-09-29 22:38:57 +0000 | [diff] [blame] | 96 | |
| 97 | //===---------------------------------------------------------------------===// |
| 98 | // LLC Implementation of AbstractIntepreter interface |
| 99 | // |
| 100 | class LLC : public AbstractInterpreter { |
| 101 | std::string LLCPath; // The path to the LLC executable |
| 102 | GCC *gcc; |
| 103 | public: |
| 104 | LLC(const std::string &llcPath, GCC *Gcc) |
| 105 | : LLCPath(llcPath), gcc(Gcc) { } |
| 106 | ~LLC() { delete gcc; } |
| 107 | |
| 108 | virtual int ExecuteProgram(const std::string &Bytecode, |
Chris Lattner | 7915a1e | 2003-10-14 21:34:11 +0000 | [diff] [blame^] | 109 | const std::vector<std::string> &Args, |
Misha Brukman | 29afb64 | 2003-09-29 22:38:57 +0000 | [diff] [blame] | 110 | const std::string &InputFile, |
| 111 | const std::string &OutputFile, |
| 112 | const std::string &SharedLib = ""); |
| 113 | |
Chris Lattner | 7915a1e | 2003-10-14 21:34:11 +0000 | [diff] [blame^] | 114 | // Sometimes we just want to go half-way and only generate the .s file, |
| 115 | // not necessarily compile it all the way and run the program. |
| 116 | // |
| 117 | int OutputAsm(const std::string &Bytecode, std::string &OutputAsmFile); |
Misha Brukman | 29afb64 | 2003-09-29 22:38:57 +0000 | [diff] [blame] | 118 | }; |
| 119 | |
Misha Brukman | 29afb64 | 2003-09-29 22:38:57 +0000 | [diff] [blame] | 120 | #endif |