Chris Lattner | f474449 | 2003-09-30 18:28:53 +0000 | [diff] [blame] | 1 | //===-- Support/ToolRunner.h ------------------------------------*- C++ -*-===// |
John Criswell | 6fbcc26 | 2003-10-20 20:19:47 +0000 | [diff] [blame] | 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
| 5 | // This file was developed by the LLVM research group and is distributed under |
| 6 | // the University of Illinois Open Source License. See LICENSE.TXT for details. |
| 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
Chris Lattner | f474449 | 2003-09-30 18:28:53 +0000 | [diff] [blame] | 9 | // |
Chris Lattner | 7915a1e | 2003-10-14 21:34:11 +0000 | [diff] [blame] | 10 | // This file exposes an abstraction around a platform C compiler, used to |
| 11 | // compile C and assembly code. It also exposes an "AbstractIntepreter" |
| 12 | // interface, which is used to execute code using one of the LLVM execution |
| 13 | // engines. |
Chris Lattner | f474449 | 2003-09-30 18:28:53 +0000 | [diff] [blame] | 14 | // |
| 15 | //===----------------------------------------------------------------------===// |
| 16 | |
Misha Brukman | 29afb64 | 2003-09-29 22:38:57 +0000 | [diff] [blame] | 17 | #ifndef TOOLRUNNER_H |
| 18 | #define TOOLRUNNER_H |
| 19 | |
Misha Brukman | 29afb64 | 2003-09-29 22:38:57 +0000 | [diff] [blame] | 20 | #include "Support/SystemUtils.h" |
Misha Brukman | 29afb64 | 2003-09-29 22:38:57 +0000 | [diff] [blame] | 21 | #include <vector> |
| 22 | |
Brian Gaeke | d0fde30 | 2003-11-11 22:41:34 +0000 | [diff] [blame] | 23 | namespace llvm { |
| 24 | |
Chris Lattner | 7915a1e | 2003-10-14 21:34:11 +0000 | [diff] [blame] | 25 | class CBE; |
| 26 | class LLC; |
Misha Brukman | 29afb64 | 2003-09-29 22:38:57 +0000 | [diff] [blame] | 27 | |
| 28 | //===---------------------------------------------------------------------===// |
| 29 | // GCC abstraction |
| 30 | // |
Misha Brukman | 29afb64 | 2003-09-29 22:38:57 +0000 | [diff] [blame] | 31 | class GCC { |
| 32 | std::string GCCPath; // The path to the gcc executable |
Misha Brukman | 29afb64 | 2003-09-29 22:38:57 +0000 | [diff] [blame] | 33 | GCC(const std::string &gccPath) : GCCPath(gccPath) { } |
Chris Lattner | 7915a1e | 2003-10-14 21:34:11 +0000 | [diff] [blame] | 34 | public: |
| 35 | enum FileType { AsmFile, CFile }; |
Misha Brukman | 29afb64 | 2003-09-29 22:38:57 +0000 | [diff] [blame] | 36 | |
Chris Lattner | 7915a1e | 2003-10-14 21:34:11 +0000 | [diff] [blame] | 37 | static GCC* create(const std::string &ProgramPath, std::string &Message); |
| 38 | |
Chris Lattner | eeed983 | 2003-10-14 21:52:52 +0000 | [diff] [blame] | 39 | /// ExecuteProgram - Execute the program specified by "ProgramFile" (which is |
| 40 | /// either a .s file, or a .c file, specified by FileType), with the specified |
| 41 | /// arguments. Standard input is specified with InputFile, and standard |
| 42 | /// Output is captured to the specified OutputFile location. The SharedLibs |
| 43 | /// option specifies optional native shared objects that can be loaded into |
| 44 | /// the program for execution. |
| 45 | /// |
Chris Lattner | 7915a1e | 2003-10-14 21:34:11 +0000 | [diff] [blame] | 46 | int ExecuteProgram(const std::string &ProgramFile, |
| 47 | const std::vector<std::string> &Args, |
| 48 | FileType fileType, |
| 49 | const std::string &InputFile, |
| 50 | const std::string &OutputFile, |
Chris Lattner | eeed983 | 2003-10-14 21:52:52 +0000 | [diff] [blame] | 51 | const std::vector<std::string> &SharedLibs = |
| 52 | std::vector<std::string>()); |
Misha Brukman | 29afb64 | 2003-09-29 22:38:57 +0000 | [diff] [blame] | 53 | |
Chris Lattner | eeed983 | 2003-10-14 21:52:52 +0000 | [diff] [blame] | 54 | /// MakeSharedObject - This compiles the specified file (which is either a .c |
| 55 | /// file or a .s file) into a shared object. |
| 56 | /// |
| 57 | int MakeSharedObject(const std::string &InputFile, FileType fileType, |
Misha Brukman | 29afb64 | 2003-09-29 22:38:57 +0000 | [diff] [blame] | 58 | std::string &OutputFile); |
| 59 | |
Chris Lattner | eeed983 | 2003-10-14 21:52:52 +0000 | [diff] [blame] | 60 | private: |
Misha Brukman | 29afb64 | 2003-09-29 22:38:57 +0000 | [diff] [blame] | 61 | void ProcessFailure(const char **Args); |
| 62 | }; |
| 63 | |
Misha Brukman | 29afb64 | 2003-09-29 22:38:57 +0000 | [diff] [blame] | 64 | |
Chris Lattner | 7915a1e | 2003-10-14 21:34:11 +0000 | [diff] [blame] | 65 | //===---------------------------------------------------------------------===// |
Misha Brukman | 29afb64 | 2003-09-29 22:38:57 +0000 | [diff] [blame] | 66 | /// AbstractInterpreter Class - Subclasses of this class are used to execute |
| 67 | /// LLVM bytecode in a variety of ways. This abstract interface hides this |
| 68 | /// complexity behind a simple interface. |
| 69 | /// |
| 70 | struct AbstractInterpreter { |
Chris Lattner | 7915a1e | 2003-10-14 21:34:11 +0000 | [diff] [blame] | 71 | static CBE* createCBE(const std::string &ProgramPath, std::string &Message); |
| 72 | static LLC *createLLC(const std::string &ProgramPath, std::string &Message); |
| 73 | |
| 74 | static AbstractInterpreter* createLLI(const std::string &ProgramPath, |
| 75 | std::string &Message); |
| 76 | |
| 77 | static AbstractInterpreter* createJIT(const std::string &ProgramPath, |
| 78 | std::string &Message); |
| 79 | |
Misha Brukman | 29afb64 | 2003-09-29 22:38:57 +0000 | [diff] [blame] | 80 | |
| 81 | virtual ~AbstractInterpreter() {} |
| 82 | |
| 83 | /// ExecuteProgram - Run the specified bytecode file, emitting output to the |
| 84 | /// specified filename. This returns the exit code of the program. |
| 85 | /// |
| 86 | virtual int ExecuteProgram(const std::string &Bytecode, |
Chris Lattner | 7915a1e | 2003-10-14 21:34:11 +0000 | [diff] [blame] | 87 | const std::vector<std::string> &Args, |
Misha Brukman | 29afb64 | 2003-09-29 22:38:57 +0000 | [diff] [blame] | 88 | const std::string &InputFile, |
| 89 | const std::string &OutputFile, |
Chris Lattner | eeed983 | 2003-10-14 21:52:52 +0000 | [diff] [blame] | 90 | const std::vector<std::string> &SharedLibs = |
| 91 | std::vector<std::string>()) = 0; |
Misha Brukman | 29afb64 | 2003-09-29 22:38:57 +0000 | [diff] [blame] | 92 | }; |
| 93 | |
| 94 | //===---------------------------------------------------------------------===// |
| 95 | // CBE Implementation of AbstractIntepreter interface |
| 96 | // |
| 97 | class CBE : public AbstractInterpreter { |
| 98 | std::string DISPath; // The path to the `llvm-dis' executable |
| 99 | GCC *gcc; |
| 100 | public: |
| 101 | CBE(const std::string &disPath, GCC *Gcc) : DISPath(disPath), gcc(Gcc) { } |
| 102 | ~CBE() { delete gcc; } |
| 103 | |
| 104 | virtual int ExecuteProgram(const std::string &Bytecode, |
Chris Lattner | 7915a1e | 2003-10-14 21:34:11 +0000 | [diff] [blame] | 105 | const std::vector<std::string> &Args, |
Misha Brukman | 29afb64 | 2003-09-29 22:38:57 +0000 | [diff] [blame] | 106 | const std::string &InputFile, |
| 107 | const std::string &OutputFile, |
Chris Lattner | eeed983 | 2003-10-14 21:52:52 +0000 | [diff] [blame] | 108 | const std::vector<std::string> &SharedLibs = |
| 109 | std::vector<std::string>()); |
Misha Brukman | 29afb64 | 2003-09-29 22:38:57 +0000 | [diff] [blame] | 110 | |
Chris Lattner | 7915a1e | 2003-10-14 21:34:11 +0000 | [diff] [blame] | 111 | // Sometimes we just want to go half-way and only generate the .c file, |
| 112 | // not necessarily compile it with GCC and run the program. |
| 113 | // |
| 114 | virtual int OutputC(const std::string &Bytecode, std::string &OutputCFile); |
Misha Brukman | 29afb64 | 2003-09-29 22:38:57 +0000 | [diff] [blame] | 115 | }; |
| 116 | |
Misha Brukman | 29afb64 | 2003-09-29 22:38:57 +0000 | [diff] [blame] | 117 | |
| 118 | //===---------------------------------------------------------------------===// |
| 119 | // LLC Implementation of AbstractIntepreter interface |
| 120 | // |
| 121 | class LLC : public AbstractInterpreter { |
| 122 | std::string LLCPath; // The path to the LLC executable |
| 123 | GCC *gcc; |
| 124 | public: |
| 125 | LLC(const std::string &llcPath, GCC *Gcc) |
| 126 | : LLCPath(llcPath), gcc(Gcc) { } |
| 127 | ~LLC() { delete gcc; } |
| 128 | |
| 129 | virtual int ExecuteProgram(const std::string &Bytecode, |
Chris Lattner | 7915a1e | 2003-10-14 21:34:11 +0000 | [diff] [blame] | 130 | const std::vector<std::string> &Args, |
Misha Brukman | 29afb64 | 2003-09-29 22:38:57 +0000 | [diff] [blame] | 131 | const std::string &InputFile, |
| 132 | const std::string &OutputFile, |
Chris Lattner | eeed983 | 2003-10-14 21:52:52 +0000 | [diff] [blame] | 133 | const std::vector<std::string> &SharedLibs = |
| 134 | std::vector<std::string>()); |
Misha Brukman | 29afb64 | 2003-09-29 22:38:57 +0000 | [diff] [blame] | 135 | |
Chris Lattner | 7915a1e | 2003-10-14 21:34:11 +0000 | [diff] [blame] | 136 | // Sometimes we just want to go half-way and only generate the .s file, |
| 137 | // not necessarily compile it all the way and run the program. |
| 138 | // |
| 139 | int OutputAsm(const std::string &Bytecode, std::string &OutputAsmFile); |
Misha Brukman | 29afb64 | 2003-09-29 22:38:57 +0000 | [diff] [blame] | 140 | }; |
| 141 | |
Brian Gaeke | d0fde30 | 2003-11-11 22:41:34 +0000 | [diff] [blame] | 142 | } // End llvm namespace |
| 143 | |
Misha Brukman | 29afb64 | 2003-09-29 22:38:57 +0000 | [diff] [blame] | 144 | #endif |