Remove CBE related code.
[oota-llvm.git] / tools / bugpoint / ToolRunner.h
1 //===-- tools/bugpoint/ToolRunner.h -----------------------------*- C++ -*-===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 //
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.
14 //
15 //===----------------------------------------------------------------------===//
16
17 #ifndef BUGPOINT_TOOLRUNNER_H
18 #define BUGPOINT_TOOLRUNNER_H
19
20 #include "llvm/ADT/Triple.h"
21 #include "llvm/Support/CommandLine.h"
22 #include "llvm/Support/ErrorHandling.h"
23 #include "llvm/Support/Path.h"
24 #include "llvm/Support/PathV1.h"
25 #include "llvm/Support/SystemUtils.h"
26 #include <exception>
27 #include <vector>
28
29 namespace llvm {
30
31 extern cl::opt<bool> SaveTemps;
32 extern Triple TargetTriple;
33
34 class LLC;
35
36 //===---------------------------------------------------------------------===//
37 // GCC abstraction
38 //
39 class GCC {
40   std::string GCCPath;                // The path to the gcc executable.
41   std::string RemoteClientPath;       // The path to the rsh / ssh executable.
42   std::vector<std::string> gccArgs; // GCC-specific arguments.
43   GCC(StringRef gccPath, StringRef RemotePath,
44       const std::vector<std::string> *GCCArgs)
45     : GCCPath(gccPath), RemoteClientPath(RemotePath) {
46     if (GCCArgs) gccArgs = *GCCArgs;
47   }
48 public:
49   enum FileType { AsmFile, ObjectFile, CFile };
50
51   static GCC *create(std::string &Message,
52                      const std::string &GCCBinary,
53                      const std::vector<std::string> *Args);
54
55   /// ExecuteProgram - Execute the program specified by "ProgramFile" (which is
56   /// either a .s file, or a .c file, specified by FileType), with the specified
57   /// arguments.  Standard input is specified with InputFile, and standard
58   /// Output is captured to the specified OutputFile location.  The SharedLibs
59   /// option specifies optional native shared objects that can be loaded into
60   /// the program for execution.
61   ///
62   int ExecuteProgram(const std::string &ProgramFile,
63                      const std::vector<std::string> &Args,
64                      FileType fileType,
65                      const std::string &InputFile,
66                      const std::string &OutputFile,
67                      std::string *Error = 0,
68                      const std::vector<std::string> &GCCArgs =
69                          std::vector<std::string>(),
70                      unsigned Timeout = 0,
71                      unsigned MemoryLimit = 0);
72
73   /// MakeSharedObject - This compiles the specified file (which is either a .c
74   /// file or a .s file) into a shared object.
75   ///
76   int MakeSharedObject(const std::string &InputFile, FileType fileType,
77                        std::string &OutputFile,
78                        const std::vector<std::string> &ArgsForGCC,
79                        std::string &Error);
80 };
81
82
83 //===---------------------------------------------------------------------===//
84 /// AbstractInterpreter Class - Subclasses of this class are used to execute
85 /// LLVM bitcode in a variety of ways.  This abstract interface hides this
86 /// complexity behind a simple interface.
87 ///
88 class AbstractInterpreter {
89   virtual void anchor();
90 public:
91   static LLC *createLLC(const char *Argv0, std::string &Message,
92                         const std::string              &GCCBinary,
93                         const std::vector<std::string> *Args = 0,
94                         const std::vector<std::string> *GCCArgs = 0,
95                         bool UseIntegratedAssembler = false);
96
97   static AbstractInterpreter* createLLI(const char *Argv0, std::string &Message,
98                                         const std::vector<std::string> *Args=0);
99
100   static AbstractInterpreter* createJIT(const char *Argv0, std::string &Message,
101                                         const std::vector<std::string> *Args=0);
102
103   static AbstractInterpreter*
104   createCustomCompiler(std::string &Message,
105                        const std::string &CompileCommandLine);
106
107   static AbstractInterpreter*
108   createCustomExecutor(std::string &Message,
109                        const std::string &ExecCommandLine);
110
111
112   virtual ~AbstractInterpreter() {}
113
114   /// compileProgram - Compile the specified program from bitcode to executable
115   /// code.  This does not produce any output, it is only used when debugging
116   /// the code generator.  It returns false if the code generator fails.
117   virtual void compileProgram(const std::string &Bitcode, std::string *Error,
118                               unsigned Timeout = 0, unsigned MemoryLimit = 0) {}
119
120   /// OutputCode - Compile the specified program from bitcode to code
121   /// understood by the GCC driver (either C or asm).  If the code generator
122   /// fails, it sets Error, otherwise, this function returns the type of code
123   /// emitted.
124   virtual GCC::FileType OutputCode(const std::string &Bitcode,
125                                    sys::Path &OutFile, std::string &Error,
126                                    unsigned Timeout = 0,
127                                    unsigned MemoryLimit = 0) {
128     Error = "OutputCode not supported by this AbstractInterpreter!";
129     return GCC::AsmFile;
130   }
131
132   /// ExecuteProgram - Run the specified bitcode file, emitting output to the
133   /// specified filename.  This sets RetVal to the exit code of the program or
134   /// returns false if a problem was encountered that prevented execution of
135   /// the program.
136   ///
137   virtual int ExecuteProgram(const std::string &Bitcode,
138                              const std::vector<std::string> &Args,
139                              const std::string &InputFile,
140                              const std::string &OutputFile,
141                              std::string *Error,
142                              const std::vector<std::string> &GCCArgs =
143                                std::vector<std::string>(),
144                              const std::vector<std::string> &SharedLibs =
145                                std::vector<std::string>(),
146                              unsigned Timeout = 0,
147                              unsigned MemoryLimit = 0) = 0;
148 };
149
150 //===---------------------------------------------------------------------===//
151 // LLC Implementation of AbstractIntepreter interface
152 //
153 class LLC : public AbstractInterpreter {
154   std::string LLCPath;               // The path to the LLC executable.
155   std::vector<std::string> ToolArgs; // Extra args to pass to LLC.
156   GCC *gcc;
157   bool UseIntegratedAssembler;
158 public:
159   LLC(const std::string &llcPath, GCC *Gcc,
160       const std::vector<std::string> *Args,
161       bool useIntegratedAssembler)
162     : LLCPath(llcPath), gcc(Gcc),
163       UseIntegratedAssembler(useIntegratedAssembler) {
164     ToolArgs.clear();
165     if (Args) ToolArgs = *Args;
166   }
167   ~LLC() { delete gcc; }
168
169   /// compileProgram - Compile the specified program from bitcode to executable
170   /// code.  This does not produce any output, it is only used when debugging
171   /// the code generator.  Returns false if the code generator fails.
172   virtual void compileProgram(const std::string &Bitcode, std::string *Error,
173                               unsigned Timeout = 0, unsigned MemoryLimit = 0);
174
175   virtual int ExecuteProgram(const std::string &Bitcode,
176                              const std::vector<std::string> &Args,
177                              const std::string &InputFile,
178                              const std::string &OutputFile,
179                              std::string *Error,
180                              const std::vector<std::string> &GCCArgs =
181                                std::vector<std::string>(),
182                              const std::vector<std::string> &SharedLibs =
183                                 std::vector<std::string>(),
184                              unsigned Timeout = 0,
185                              unsigned MemoryLimit = 0);
186
187   /// OutputCode - Compile the specified program from bitcode to code
188   /// understood by the GCC driver (either C or asm).  If the code generator
189   /// fails, it sets Error, otherwise, this function returns the type of code
190   /// emitted.
191   virtual GCC::FileType OutputCode(const std::string &Bitcode,
192                                    sys::Path &OutFile, std::string &Error,
193                                    unsigned Timeout = 0,
194                                    unsigned MemoryLimit = 0);
195 };
196
197 } // End llvm namespace
198
199 #endif