2004-08-13 20:22:43 +00:00
|
|
|
//===- CompilerDriver.h - Compiler Driver -----------------------*- C++ -*-===//
|
2004-08-10 16:29:18 +00:00
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file was developed by Reid Spencer and is distributed under the
|
|
|
|
// University of Illinois Open Source License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
|
|
|
// This file declares the CompilerDriver class which implements the bulk of the
|
|
|
|
// LLVM Compiler Driver program (llvmc).
|
|
|
|
//
|
|
|
|
//===------------------------------------------------------------------------===
|
2004-08-13 20:22:43 +00:00
|
|
|
#ifndef LLVM_TOOLS_LLVMC_COMPILERDRIVER_H
|
|
|
|
#define LLVM_TOOLS_LLVMC_COMPILERDRIVER_H
|
|
|
|
|
|
|
|
#include <string>
|
|
|
|
#include <vector>
|
2004-08-29 19:26:56 +00:00
|
|
|
#include "llvm/System/Program.h"
|
2004-08-10 16:29:18 +00:00
|
|
|
|
|
|
|
namespace llvm {
|
|
|
|
/// This class provides the high level interface to the LLVM Compiler Driver.
|
|
|
|
/// The driver's purpose is to make it easier for compiler writers and users
|
|
|
|
/// of LLVM to utilize the compiler toolkits and LLVM toolset by learning only
|
|
|
|
/// the interface of one program (llvmc).
|
|
|
|
///
|
|
|
|
/// @see llvmc.cpp
|
|
|
|
/// @brief The interface to the LLVM Compiler Driver.
|
|
|
|
class CompilerDriver {
|
|
|
|
/// @name Types
|
|
|
|
/// @{
|
|
|
|
public:
|
2004-08-29 19:26:56 +00:00
|
|
|
/// @brief A vector of strings, used for argument lists
|
2004-08-15 08:19:46 +00:00
|
|
|
typedef std::vector<std::string> StringVector;
|
|
|
|
|
2004-08-29 19:26:56 +00:00
|
|
|
/// @brief A vector of sys::Path, used for path lists
|
|
|
|
typedef std::vector<sys::Path> PathVector;
|
|
|
|
|
2004-08-19 04:49:47 +00:00
|
|
|
/// @brief A table of strings, indexed typically by Phases
|
|
|
|
typedef std::vector<StringVector> StringTable;
|
|
|
|
|
2004-08-15 08:19:46 +00:00
|
|
|
/// @brief The phases of processing that llvmc understands
|
2004-08-10 16:29:18 +00:00
|
|
|
enum Phases {
|
|
|
|
PREPROCESSING, ///< Source language combining, filtering, substitution
|
|
|
|
TRANSLATION, ///< Translate source -> LLVM bytecode/assembly
|
|
|
|
OPTIMIZATION, ///< Optimize translation result
|
|
|
|
ASSEMBLY, ///< Convert program to executable
|
2004-08-19 04:49:47 +00:00
|
|
|
LINKING, ///< Link bytecode and native code
|
|
|
|
NUM_PHASES ///< Always last!
|
2004-08-10 16:29:18 +00:00
|
|
|
};
|
|
|
|
|
2004-08-15 08:19:46 +00:00
|
|
|
/// @brief The levels of optimization llvmc understands
|
2004-08-10 16:29:18 +00:00
|
|
|
enum OptimizationLevels {
|
2004-08-13 20:22:43 +00:00
|
|
|
OPT_FAST_COMPILE, ///< Optimize to make >compile< go faster
|
|
|
|
OPT_SIMPLE, ///< Standard/simple optimizations
|
|
|
|
OPT_AGGRESSIVE, ///< Aggressive optimizations
|
|
|
|
OPT_LINK_TIME, ///< Aggressive + LinkTime optimizations
|
2004-08-15 08:19:46 +00:00
|
|
|
OPT_AGGRESSIVE_LINK_TIME, ///< Make it go way fast!
|
|
|
|
OPT_NONE ///< No optimizations. Keep this at the end!
|
|
|
|
};
|
|
|
|
|
|
|
|
/// @brief Action specific flags
|
|
|
|
enum ConfigurationFlags {
|
|
|
|
REQUIRED_FLAG = 0x0001, ///< Should the action always be run?
|
2004-08-24 13:49:57 +00:00
|
|
|
PREPROCESSES_FLAG = 0x0002, ///< Does this action preprocess?
|
|
|
|
TRANSLATES_FLAG = 0x0004, ///< Does this action translate?
|
|
|
|
OUTPUT_IS_ASM_FLAG = 0x0008, ///< Action produces .ll files?
|
|
|
|
FLAGS_MASK = 0x000F, ///< Union of all flags
|
2004-08-13 20:22:43 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/// This type is the input list to the CompilerDriver. It provides
|
2004-08-29 19:26:56 +00:00
|
|
|
/// a vector of pathname/filetype pairs. The filetype is used to look up
|
2004-08-13 20:22:43 +00:00
|
|
|
/// the configuration of the actions to be taken by the driver.
|
|
|
|
/// @brief The Input Data to the execute method
|
2004-08-29 19:26:56 +00:00
|
|
|
typedef std::vector<std::pair<sys::Path,std::string> > InputList;
|
2004-08-13 20:22:43 +00:00
|
|
|
|
|
|
|
/// This type is read from configuration files or otherwise provided to
|
|
|
|
/// the CompilerDriver through a "ConfigDataProvider". It serves as both
|
|
|
|
/// the template of what to do and the actual Action to be executed.
|
|
|
|
/// @brief A structure to hold the action data for a given source
|
|
|
|
/// language.
|
|
|
|
struct Action {
|
2004-08-19 04:49:47 +00:00
|
|
|
Action() : flags(0) {}
|
2004-12-19 18:00:56 +00:00
|
|
|
sys::Path program; ///< The program to execve
|
|
|
|
StringVector args; ///< Arguments to the program
|
|
|
|
unsigned flags; ///< Action specific flags
|
2004-08-15 08:19:46 +00:00
|
|
|
void set(unsigned fl ) { flags |= fl; }
|
|
|
|
void clear(unsigned fl) { flags &= (FLAGS_MASK ^ fl); }
|
2004-08-19 04:49:47 +00:00
|
|
|
bool isSet(unsigned fl) { return (flags&fl) != 0; }
|
2004-08-13 20:22:43 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
struct ConfigData {
|
2004-08-19 04:49:47 +00:00
|
|
|
ConfigData();
|
2004-08-22 18:03:25 +00:00
|
|
|
std::string version; ///< The version number.
|
2004-08-19 04:49:47 +00:00
|
|
|
std::string langName; ///< The name of the source language
|
|
|
|
StringTable opts; ///< The o10n options for each level
|
2004-11-23 23:40:06 +00:00
|
|
|
StringVector libpaths; ///< The library paths
|
2004-08-19 04:49:47 +00:00
|
|
|
Action PreProcessor; ///< PreProcessor command line
|
|
|
|
Action Translator; ///< Translator command line
|
|
|
|
Action Optimizer; ///< Optimizer command line
|
|
|
|
Action Assembler; ///< Assembler command line
|
|
|
|
Action Linker; ///< Linker command line
|
2004-08-13 20:22:43 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/// This pure virtual interface class defines the interface between the
|
|
|
|
/// CompilerDriver and other software that provides ConfigData objects to
|
|
|
|
/// it. The CompilerDriver must be configured to use an object of this
|
|
|
|
/// type so it can obtain the configuration data.
|
|
|
|
/// @see setConfigDataProvider
|
|
|
|
/// @brief Configuration Data Provider interface
|
|
|
|
class ConfigDataProvider {
|
|
|
|
public:
|
|
|
|
virtual ConfigData* ProvideConfigData(const std::string& filetype) = 0;
|
2004-08-29 19:26:56 +00:00
|
|
|
virtual void setConfigDir(const sys::Path& dirName) = 0;
|
2004-08-10 16:29:18 +00:00
|
|
|
};
|
|
|
|
|
2004-09-14 01:58:45 +00:00
|
|
|
/// These flags control various actions of the compiler driver. They are
|
|
|
|
/// used by adding the needed flag values together and passing them to the
|
|
|
|
/// compiler driver's setDriverFlags method.
|
|
|
|
/// @see setDriverFlags
|
|
|
|
/// @brief Driver specific flags
|
|
|
|
enum DriverFlags {
|
|
|
|
DRY_RUN_FLAG = 0x0001, ///< Do everything but execute actions
|
2004-10-28 04:04:38 +00:00
|
|
|
VERBOSE_FLAG = 0x0002, ///< Print each action
|
|
|
|
DEBUG_FLAG = 0x0004, ///< Print debug information
|
|
|
|
TIME_PASSES_FLAG = 0x0008, ///< Time the passes as they execute
|
|
|
|
TIME_ACTIONS_FLAG = 0x0010, ///< Time the actions as they execute
|
|
|
|
SHOW_STATS_FLAG = 0x0020, ///< Show pass statistics
|
|
|
|
EMIT_NATIVE_FLAG = 0x0040, ///< Emit native code instead of bc
|
|
|
|
EMIT_RAW_FLAG = 0x0080, ///< Emit raw, unoptimized bytecode
|
|
|
|
KEEP_TEMPS_FLAG = 0x0100, ///< Don't delete temporary files
|
|
|
|
STRIP_OUTPUT_FLAG = 0x0200, ///< Strip symbols from linked output
|
|
|
|
DRIVER_FLAGS_MASK = 0x03FF, ///< Union of the above flags
|
2004-09-14 01:58:45 +00:00
|
|
|
};
|
|
|
|
|
2004-08-10 16:29:18 +00:00
|
|
|
/// @}
|
|
|
|
/// @name Constructors
|
|
|
|
/// @{
|
|
|
|
public:
|
2004-08-29 19:26:56 +00:00
|
|
|
/// @brief Static Constructor
|
|
|
|
static CompilerDriver* Get(ConfigDataProvider& CDP);
|
|
|
|
|
|
|
|
/// @brief Virtual destructor
|
2004-08-13 20:22:43 +00:00
|
|
|
virtual ~CompilerDriver();
|
2004-08-10 16:29:18 +00:00
|
|
|
|
|
|
|
/// @}
|
2004-08-13 20:22:43 +00:00
|
|
|
/// @name Methods
|
2004-08-10 16:29:18 +00:00
|
|
|
/// @{
|
|
|
|
public:
|
2004-08-13 20:22:43 +00:00
|
|
|
/// @brief Execute the actions requested for the given input list.
|
2004-08-29 19:26:56 +00:00
|
|
|
virtual int execute(const InputList& list, const sys::Path& output) = 0;
|
2004-08-10 16:29:18 +00:00
|
|
|
|
2004-08-13 20:22:43 +00:00
|
|
|
/// @brief Set the final phase at which compilation terminates
|
2004-08-29 19:26:56 +00:00
|
|
|
virtual void setFinalPhase(Phases phase) = 0;
|
2004-08-13 20:22:43 +00:00
|
|
|
|
2004-08-10 16:29:18 +00:00
|
|
|
/// @brief Set the optimization level for the compilation
|
2004-08-29 19:26:56 +00:00
|
|
|
virtual void setOptimization(OptimizationLevels level) = 0;
|
2004-08-19 04:49:47 +00:00
|
|
|
|
2004-08-29 19:26:56 +00:00
|
|
|
/// @brief Set the driver flags.
|
|
|
|
virtual void setDriverFlags(unsigned flags) = 0;
|
2004-08-19 04:49:47 +00:00
|
|
|
|
2004-08-13 20:22:43 +00:00
|
|
|
/// @brief Set the output machine name.
|
2004-08-29 19:26:56 +00:00
|
|
|
virtual void setOutputMachine(const std::string& machineName) = 0;
|
2004-08-13 20:22:43 +00:00
|
|
|
|
2004-11-05 22:15:36 +00:00
|
|
|
/// @brief Set the options for a given phase.
|
2004-08-29 19:26:56 +00:00
|
|
|
virtual void setPhaseArgs(Phases phase, const StringVector& opts) = 0;
|
2004-08-15 08:19:46 +00:00
|
|
|
|
2004-08-30 06:29:06 +00:00
|
|
|
/// @brief Set Library Paths
|
|
|
|
virtual void setIncludePaths(const StringVector& paths) = 0;
|
|
|
|
|
|
|
|
/// @brief Set Library Paths
|
|
|
|
virtual void setSymbolDefines(const StringVector& paths) = 0;
|
|
|
|
|
2004-08-15 08:19:46 +00:00
|
|
|
/// @brief Set Library Paths
|
2004-08-29 19:26:56 +00:00
|
|
|
virtual void setLibraryPaths(const StringVector& paths) = 0;
|
2004-08-15 08:19:46 +00:00
|
|
|
|
2004-11-05 22:15:36 +00:00
|
|
|
/// @brief Add a path to the list of library paths
|
2004-08-29 19:26:56 +00:00
|
|
|
virtual void addLibraryPath( const sys::Path& libPath ) = 0;
|
2004-08-13 20:22:43 +00:00
|
|
|
|
2004-11-05 22:15:36 +00:00
|
|
|
/// @brief Add a path to the list of paths in which to find tools
|
|
|
|
virtual void addToolPath( const sys::Path& toolPath) = 0;
|
|
|
|
|
2004-09-14 01:58:45 +00:00
|
|
|
/// @brief Set the list of -f options to be passed through
|
|
|
|
virtual void setfPassThrough(const StringVector& fOpts) = 0;
|
|
|
|
|
|
|
|
/// @brief Set the list of -M options to be passed through
|
|
|
|
virtual void setMPassThrough(const StringVector& fOpts) = 0;
|
|
|
|
|
|
|
|
/// @brief Set the list of -W options to be passed through
|
|
|
|
virtual void setWPassThrough(const StringVector& fOpts) = 0;
|
|
|
|
|
2004-11-23 23:40:06 +00:00
|
|
|
/// @brief Determine where a linkage file is located in the file system
|
|
|
|
virtual sys::Path GetPathForLinkageItem(
|
|
|
|
const std::string& link_item, ///< Item to be sought
|
|
|
|
bool native = false ///< Looking for native?
|
|
|
|
) = 0;
|
|
|
|
|
2004-08-13 20:22:43 +00:00
|
|
|
/// @}
|
2004-08-10 16:29:18 +00:00
|
|
|
};
|
|
|
|
}
|
2004-08-13 20:22:43 +00:00
|
|
|
|
|
|
|
// vim: sw=2 smartindent smarttab tw=80 autoindent expandtab
|
|
|
|
#endif
|