blob: 77ae10904bb10675c601e7e803ae3d11f8d4f961 [file] [log] [blame]
Chris Lattnerf4744492003-09-30 18:28:53 +00001//===-- Support/ToolRunner.h ------------------------------------*- C++ -*-===//
2//
Chris Lattner7915a1e2003-10-14 21:34:11 +00003// 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 Lattnerf4744492003-09-30 18:28:53 +00007//
8//===----------------------------------------------------------------------===//
9
Misha Brukman29afb642003-09-29 22:38:57 +000010#ifndef TOOLRUNNER_H
11#define TOOLRUNNER_H
12
Misha Brukman29afb642003-09-29 22:38:57 +000013#include "Support/SystemUtils.h"
Misha Brukman29afb642003-09-29 22:38:57 +000014#include <vector>
15
Chris Lattner7915a1e2003-10-14 21:34:11 +000016class CBE;
17class LLC;
Misha Brukman29afb642003-09-29 22:38:57 +000018
19//===---------------------------------------------------------------------===//
20// GCC abstraction
21//
Misha Brukman29afb642003-09-29 22:38:57 +000022class GCC {
23 std::string GCCPath; // The path to the gcc executable
Misha Brukman29afb642003-09-29 22:38:57 +000024 GCC(const std::string &gccPath) : GCCPath(gccPath) { }
Chris Lattner7915a1e2003-10-14 21:34:11 +000025public:
26 enum FileType { AsmFile, CFile };
Misha Brukman29afb642003-09-29 22:38:57 +000027
Chris Lattner7915a1e2003-10-14 21:34:11 +000028 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 Brukman29afb642003-09-29 22:38:57 +000037
38 int MakeSharedObject(const std::string &InputFile,
39 FileType fileType,
40 std::string &OutputFile);
41
42 void ProcessFailure(const char **Args);
43};
44
Misha Brukman29afb642003-09-29 22:38:57 +000045
Chris Lattner7915a1e2003-10-14 21:34:11 +000046//===---------------------------------------------------------------------===//
Misha Brukman29afb642003-09-29 22:38:57 +000047/// 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///
51struct AbstractInterpreter {
Chris Lattner7915a1e2003-10-14 21:34:11 +000052 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 Brukman29afb642003-09-29 22:38:57 +000061
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 Lattner7915a1e2003-10-14 21:34:11 +000068 const std::vector<std::string> &Args,
Misha Brukman29afb642003-09-29 22:38:57 +000069 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//
77class CBE : public AbstractInterpreter {
78 std::string DISPath; // The path to the `llvm-dis' executable
79 GCC *gcc;
80public:
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 Lattner7915a1e2003-10-14 21:34:11 +000085 const std::vector<std::string> &Args,
Misha Brukman29afb642003-09-29 22:38:57 +000086 const std::string &InputFile,
87 const std::string &OutputFile,
88 const std::string &SharedLib = "");
89
Chris Lattner7915a1e2003-10-14 21:34:11 +000090 // 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 Brukman29afb642003-09-29 22:38:57 +000094};
95
Misha Brukman29afb642003-09-29 22:38:57 +000096
97//===---------------------------------------------------------------------===//
98// LLC Implementation of AbstractIntepreter interface
99//
100class LLC : public AbstractInterpreter {
101 std::string LLCPath; // The path to the LLC executable
102 GCC *gcc;
103public:
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 Lattner7915a1e2003-10-14 21:34:11 +0000109 const std::vector<std::string> &Args,
Misha Brukman29afb642003-09-29 22:38:57 +0000110 const std::string &InputFile,
111 const std::string &OutputFile,
112 const std::string &SharedLib = "");
113
Chris Lattner7915a1e2003-10-14 21:34:11 +0000114 // 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 Brukman29afb642003-09-29 22:38:57 +0000118};
119
Misha Brukman29afb642003-09-29 22:38:57 +0000120#endif