//===- CompilerDriver.cpp - The LLVM Compiler Driver ------------*- C++ -*-===//
//
//
// 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 implements the bulk of the LLVM Compiler Driver (llvmc).
//
//===------------------------------------------------------------------------===
#include "CompilerDriver.h"
#include "ConfigLexer.h"
#include "llvm/Module.h"
#include "llvm/Bytecode/Reader.h"
#include "llvm/Support/Timer.h"
#include "llvm/System/Signals.h"
#include "llvm/ADT/SetVector.h"
#include "llvm/ADT/StringExtras.h"
#include <iostream>
using namespace llvm;
namespace {
void WriteAction(CompilerDriver::Action* action ) {
std::cerr << action->program.c_str();
std::vector<std::string>::iterator I = action->args.begin();
while (I != action->args.end()) {
std::cerr << " " + *I;
++I;
}
std::cerr << "\n";
}
void DumpAction(CompilerDriver::Action* action) {
std::cerr << "command = " << action->program.c_str();
std::vector<std::string>::iterator I = action->args.begin();
while (I != action->args.end()) {
std::cerr << " " + *I;
++I;
}
std::cerr << "\n";
std::cerr << "flags = " << action->flags << "\n";
}
void DumpConfigData(CompilerDriver::ConfigData* cd, const std::string& type ){
std::cerr << "Configuration Data For '" << cd->langName << "' (" << type
<< ")\n";
std::cerr << "PreProcessor: ";
DumpAction(&cd->PreProcessor);
std::cerr << "Translator: ";
DumpAction(&cd->Translator);
std::cerr << "Optimizer: ";
DumpAction(&cd->Optimizer);
std::cerr << "Assembler: ";
DumpAction(&cd->Assembler);
std::cerr << "Linker: ";
DumpAction(&cd->Linker);
}
/// This specifies the passes to run for OPT_FAST_COMPILE (-O1)
/// which should reduce the volume of code and make compilation
/// faster. This is also safe on any llvm module.
static const char* DefaultFastCompileOptimizations[] = {
"-simplifycfg", "-mem2reg", "-instcombine"
};
class CompilerDriverImpl : public CompilerDriver {
/// @name Constructors
/// @{
public:
CompilerDriverImpl(ConfigDataProvider& confDatProv )
: cdp(&confDatProv)
, finalPhase(LINKING)
, optLevel(OPT_FAST_COMPILE)
, Flags(0)
, machine()
, LibraryPaths()
, TempDir()
, AdditionalArgs()
{
TempDir = sys::Path::GetTemporaryDirectory();
sys::RemoveDirectoryOnSignal(TempDir);
AdditionalArgs.reserve(NUM_PHASES);
StringVector emptyVec;
for (unsigned i = 0; i < NUM_PHASES; ++i)
AdditionalArgs.push_back(emptyVec);
}
virtual ~CompilerDriverImpl() {
cleanup();
cdp = 0;
LibraryPaths.clear();
IncludePaths.clear();
Defines.clear();
TempDir.clear();
AdditionalArgs.clear();
fOptions.clear();
MOptions.clear();
WOptions.clear();
}
/// @}
/// @name Methods
/// @{
public:
virtual void setFinalPhase( Phases phase ) {
finalPhase = phase;
}
virtual void setOptimization( OptimizationLevels level ) {
optLevel = level;
}
virtual void setDriverFlags( unsigned flags ) {
Flags = flags & DRIVER_FLAGS_MASK;
}
virtual void setOutputMachine( const std::string& machineName ) {
machine = machineName;
}
virtual void setPhaseArgs(Phases phase, const StringVector& opts) {
assert(phase <= LINKING && phase >= PREPROCESSING);
AdditionalArgs[phase] = opts;
}
virtual void setIncludePaths(const StringVector& paths) {
StringVector::const_iterator I = paths.begin();
StringVector::const_iterator E = paths.end();
while (I != E) {
sys::Path tmp;
tmp.setDirectory(*I);
IncludePaths.push_back(tmp);
++I;
}
}
virtual void setSymbolDefines