]>
git.proxmox.com Git - rustc.git/blob - src/llvm/tools/bugpoint/ToolRunner.h
1 //===-- tools/bugpoint/ToolRunner.h -----------------------------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
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
15 //===----------------------------------------------------------------------===//
17 #ifndef LLVM_TOOLS_BUGPOINT_TOOLRUNNER_H
18 #define LLVM_TOOLS_BUGPOINT_TOOLRUNNER_H
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/SystemUtils.h"
30 extern cl::opt
<bool> SaveTemps
;
31 extern Triple TargetTriple
;
35 //===---------------------------------------------------------------------===//
39 std::string GCCPath
; // The path to the gcc executable.
40 std::string RemoteClientPath
; // The path to the rsh / ssh executable.
41 std::vector
<std::string
> gccArgs
; // GCC-specific arguments.
42 GCC(StringRef gccPath
, StringRef RemotePath
,
43 const std::vector
<std::string
> *GCCArgs
)
44 : GCCPath(gccPath
), RemoteClientPath(RemotePath
) {
45 if (GCCArgs
) gccArgs
= *GCCArgs
;
48 enum FileType
{ AsmFile
, ObjectFile
, CFile
};
50 static GCC
*create(std::string
&Message
,
51 const std::string
&GCCBinary
,
52 const std::vector
<std::string
> *Args
);
54 /// ExecuteProgram - Execute the program specified by "ProgramFile" (which is
55 /// either a .s file, or a .c file, specified by FileType), with the specified
56 /// arguments. Standard input is specified with InputFile, and standard
57 /// Output is captured to the specified OutputFile location. The SharedLibs
58 /// option specifies optional native shared objects that can be loaded into
59 /// the program for execution.
61 int ExecuteProgram(const std::string
&ProgramFile
,
62 const std::vector
<std::string
> &Args
,
64 const std::string
&InputFile
,
65 const std::string
&OutputFile
,
66 std::string
*Error
= nullptr,
67 const std::vector
<std::string
> &GCCArgs
=
68 std::vector
<std::string
>(),
70 unsigned MemoryLimit
= 0);
72 /// MakeSharedObject - This compiles the specified file (which is either a .c
73 /// file or a .s file) into a shared object.
75 int MakeSharedObject(const std::string
&InputFile
, FileType fileType
,
76 std::string
&OutputFile
,
77 const std::vector
<std::string
> &ArgsForGCC
,
82 //===---------------------------------------------------------------------===//
83 /// AbstractInterpreter Class - Subclasses of this class are used to execute
84 /// LLVM bitcode in a variety of ways. This abstract interface hides this
85 /// complexity behind a simple interface.
87 class AbstractInterpreter
{
88 virtual void anchor();
90 static LLC
*createLLC(const char *Argv0
, std::string
&Message
,
91 const std::string
&GCCBinary
,
92 const std::vector
<std::string
> *Args
= nullptr,
93 const std::vector
<std::string
> *GCCArgs
= nullptr,
94 bool UseIntegratedAssembler
= false);
96 static AbstractInterpreter
*
97 createLLI(const char *Argv0
, std::string
&Message
,
98 const std::vector
<std::string
> *Args
= nullptr);
100 static AbstractInterpreter
*
101 createJIT(const char *Argv0
, std::string
&Message
,
102 const std::vector
<std::string
> *Args
= nullptr);
104 static AbstractInterpreter
*
105 createCustomCompiler(std::string
&Message
,
106 const std::string
&CompileCommandLine
);
108 static AbstractInterpreter
*
109 createCustomExecutor(std::string
&Message
,
110 const std::string
&ExecCommandLine
);
113 virtual ~AbstractInterpreter() {}
115 /// compileProgram - Compile the specified program from bitcode to executable
116 /// code. This does not produce any output, it is only used when debugging
117 /// the code generator. It returns false if the code generator fails.
118 virtual void compileProgram(const std::string
&Bitcode
, std::string
*Error
,
119 unsigned Timeout
= 0, unsigned MemoryLimit
= 0) {}
121 /// OutputCode - Compile the specified program from bitcode to code
122 /// understood by the GCC driver (either C or asm). If the code generator
123 /// fails, it sets Error, otherwise, this function returns the type of code
125 virtual GCC::FileType
OutputCode(const std::string
&Bitcode
,
126 std::string
&OutFile
, std::string
&Error
,
127 unsigned Timeout
= 0,
128 unsigned MemoryLimit
= 0) {
129 Error
= "OutputCode not supported by this AbstractInterpreter!";
133 /// ExecuteProgram - Run the specified bitcode file, emitting output to the
134 /// specified filename. This sets RetVal to the exit code of the program or
135 /// returns false if a problem was encountered that prevented execution of
138 virtual int ExecuteProgram(const std::string
&Bitcode
,
139 const std::vector
<std::string
> &Args
,
140 const std::string
&InputFile
,
141 const std::string
&OutputFile
,
143 const std::vector
<std::string
> &GCCArgs
=
144 std::vector
<std::string
>(),
145 const std::vector
<std::string
> &SharedLibs
=
146 std::vector
<std::string
>(),
147 unsigned Timeout
= 0,
148 unsigned MemoryLimit
= 0) = 0;
151 //===---------------------------------------------------------------------===//
152 // LLC Implementation of AbstractIntepreter interface
154 class LLC
: public AbstractInterpreter
{
155 std::string LLCPath
; // The path to the LLC executable.
156 std::vector
<std::string
> ToolArgs
; // Extra args to pass to LLC.
158 bool UseIntegratedAssembler
;
160 LLC(const std::string
&llcPath
, GCC
*Gcc
,
161 const std::vector
<std::string
> *Args
,
162 bool useIntegratedAssembler
)
163 : LLCPath(llcPath
), gcc(Gcc
),
164 UseIntegratedAssembler(useIntegratedAssembler
) {
166 if (Args
) ToolArgs
= *Args
;
168 ~LLC() { delete gcc
; }
170 /// compileProgram - Compile the specified program from bitcode to executable
171 /// code. This does not produce any output, it is only used when debugging
172 /// the code generator. Returns false if the code generator fails.
173 void compileProgram(const std::string
&Bitcode
, std::string
*Error
,
174 unsigned Timeout
= 0, unsigned MemoryLimit
= 0) override
;
176 int ExecuteProgram(const std::string
&Bitcode
,
177 const std::vector
<std::string
> &Args
,
178 const std::string
&InputFile
,
179 const std::string
&OutputFile
,
181 const std::vector
<std::string
> &GCCArgs
=
182 std::vector
<std::string
>(),
183 const std::vector
<std::string
> &SharedLibs
=
184 std::vector
<std::string
>(),
185 unsigned Timeout
= 0,
186 unsigned MemoryLimit
= 0) override
;
188 /// OutputCode - Compile the specified program from bitcode to code
189 /// understood by the GCC driver (either C or asm). If the code generator
190 /// fails, it sets Error, otherwise, this function returns the type of code
192 GCC::FileType
OutputCode(const std::string
&Bitcode
,
193 std::string
&OutFile
, std::string
&Error
,
194 unsigned Timeout
= 0,
195 unsigned MemoryLimit
= 0) override
;
198 } // End llvm namespace