2004-08-13 20:22:43 +00:00
|
|
|
//===--- llvmc.cpp - The LLVM Compiler Driver -------------------*- C++ -*-===//
|
2005-04-22 00:00:37 +00:00
|
|
|
//
|
2004-08-10 16:26:01 +00:00
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
2004-08-13 20:22:43 +00:00
|
|
|
// This file was developed by Reid Spencer and is distributed under the
|
2004-08-10 16:26:01 +00:00
|
|
|
// University of Illinois Open Source License. See LICENSE.TXT for details.
|
2005-04-22 00:00:37 +00:00
|
|
|
//
|
2004-08-10 16:26:01 +00:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
|
|
|
// This tool provides a single point of access to the LLVM compilation tools.
|
|
|
|
// It has many options. To discover the options supported please refer to the
|
|
|
|
// tools' manual page (docs/CommandGuide/html/llvmc.html) or run the tool with
|
|
|
|
// the --help option.
|
2005-04-22 00:00:37 +00:00
|
|
|
//
|
2006-05-29 18:52:05 +00:00
|
|
|
//===----------------------------------------------------------------------===//
|
2004-08-10 16:26:01 +00:00
|
|
|
|
2004-08-10 16:29:18 +00:00
|
|
|
#include "CompilerDriver.h"
|
2004-08-19 21:52:49 +00:00
|
|
|
#include "Configuration.h"
|
2004-08-24 17:54:26 +00:00
|
|
|
#include "llvm/Pass.h"
|
2004-09-01 22:55:40 +00:00
|
|
|
#include "llvm/Support/CommandLine.h"
|
2006-12-06 01:18:01 +00:00
|
|
|
#include "llvm/Support/ManagedStatic.h"
|
|
|
|
#include "llvm/System/Signals.h"
|
2004-08-10 16:26:01 +00:00
|
|
|
#include <iostream>
|
|
|
|
using namespace llvm;
|
|
|
|
|
2006-05-29 18:52:05 +00:00
|
|
|
//===----------------------------------------------------------------------===//
|
2004-08-10 16:26:01 +00:00
|
|
|
//=== PHASE OPTIONS
|
2006-05-29 18:52:05 +00:00
|
|
|
//===----------------------------------------------------------------------===//
|
2006-12-06 01:18:01 +00:00
|
|
|
static cl::opt<CompilerDriver::Phases> FinalPhase(cl::Optional,
|
2005-04-22 00:00:37 +00:00
|
|
|
cl::desc("Choose final phase of compilation:"),
|
2004-08-13 20:22:43 +00:00
|
|
|
cl::init(CompilerDriver::LINKING),
|
2004-08-10 16:26:01 +00:00
|
|
|
cl::values(
|
|
|
|
clEnumValN(CompilerDriver::PREPROCESSING,"E",
|
2004-08-13 20:22:43 +00:00
|
|
|
"Stop compilation after pre-processing phase"),
|
|
|
|
clEnumValN(CompilerDriver::TRANSLATION, "t",
|
|
|
|
"Stop compilation after translation phase"),
|
2004-08-10 16:26:01 +00:00
|
|
|
clEnumValN(CompilerDriver::OPTIMIZATION,"c",
|
2004-08-13 20:22:43 +00:00
|
|
|
"Stop compilation after optimization phase"),
|
2004-08-10 16:26:01 +00:00
|
|
|
clEnumValN(CompilerDriver::ASSEMBLY,"S",
|
2004-08-13 20:22:43 +00:00
|
|
|
"Stop compilation after assembly phase"),
|
2004-08-10 16:26:01 +00:00
|
|
|
clEnumValEnd
|
|
|
|
)
|
|
|
|
);
|
|
|
|
|
2006-05-29 18:52:05 +00:00
|
|
|
//===----------------------------------------------------------------------===//
|
2004-08-10 16:26:01 +00:00
|
|
|
//=== OPTIMIZATION OPTIONS
|
2006-05-29 18:52:05 +00:00
|
|
|
//===----------------------------------------------------------------------===//
|
2006-12-06 01:18:01 +00:00
|
|
|
static cl::opt<CompilerDriver::OptimizationLevels> OptLevel(cl::ZeroOrMore,
|
2004-08-10 16:26:01 +00:00
|
|
|
cl::desc("Choose level of optimization to apply:"),
|
2004-08-13 20:22:43 +00:00
|
|
|
cl::init(CompilerDriver::OPT_FAST_COMPILE),
|
2004-08-10 16:26:01 +00:00
|
|
|
cl::values(
|
|
|
|
clEnumValN(CompilerDriver::OPT_FAST_COMPILE,"O0",
|
2005-05-03 05:36:14 +00:00
|
|
|
"An alias for the -O1 option"),
|
2004-08-10 16:26:01 +00:00
|
|
|
clEnumValN(CompilerDriver::OPT_FAST_COMPILE,"O1",
|
2005-05-03 05:36:14 +00:00
|
|
|
"Optimize for compilation speed, not execution speed"),
|
2004-08-10 16:26:01 +00:00
|
|
|
clEnumValN(CompilerDriver::OPT_SIMPLE,"O2",
|
|
|
|
"Perform simple translation time optimizations"),
|
|
|
|
clEnumValN(CompilerDriver::OPT_AGGRESSIVE,"O3",
|
|
|
|
"Perform aggressive translation time optimizations"),
|
|
|
|
clEnumValN(CompilerDriver::OPT_LINK_TIME,"O4",
|
|
|
|
"Perform link time optimizations"),
|
|
|
|
clEnumValN(CompilerDriver::OPT_AGGRESSIVE_LINK_TIME,"O5",
|
|
|
|
"Perform aggressive link time optimizations"),
|
|
|
|
clEnumValEnd
|
|
|
|
)
|
|
|
|
);
|
|
|
|
|
2006-05-29 18:52:05 +00:00
|
|
|
//===----------------------------------------------------------------------===//
|
2004-08-10 16:26:01 +00:00
|
|
|
//=== TOOL OPTIONS
|
2006-05-29 18:52:05 +00:00
|
|
|
//===----------------------------------------------------------------------===//
|
2004-08-10 16:26:01 +00:00
|
|
|
|
2006-12-06 01:18:01 +00:00
|
|
|
static cl::list<std::string> PreprocessorToolOpts("Tpre", cl::ZeroOrMore,
|
2005-04-22 00:00:37 +00:00
|
|
|
cl::desc("Pass specific options to the pre-processor"),
|
2004-08-13 20:22:43 +00:00
|
|
|
cl::value_desc("option"));
|
2004-08-10 16:26:01 +00:00
|
|
|
|
2006-12-06 01:18:01 +00:00
|
|
|
static cl::alias PreprocessorToolOptsAlias("Wp,", cl::ZeroOrMore,
|
2004-10-28 03:56:16 +00:00
|
|
|
cl::desc("Alias for -Tpre"), cl::aliasopt(PreprocessorToolOpts));
|
|
|
|
|
2006-12-06 01:18:01 +00:00
|
|
|
static cl::list<std::string> TranslatorToolOpts("Ttrn", cl::ZeroOrMore,
|
2004-08-13 20:22:43 +00:00
|
|
|
cl::desc("Pass specific options to the assembler"),
|
|
|
|
cl::value_desc("option"));
|
2004-08-10 16:26:01 +00:00
|
|
|
|
2006-12-06 01:18:01 +00:00
|
|
|
static cl::list<std::string> AssemblerToolOpts("Tasm", cl::ZeroOrMore,
|
2004-08-15 08:19:46 +00:00
|
|
|
cl::desc("Pass specific options to the assembler"),
|
|
|
|
cl::value_desc("option"));
|
|
|
|
|
2006-12-06 01:18:01 +00:00
|
|
|
static cl::alias AssemblerToolOptsAlias("Wa,", cl::ZeroOrMore,
|
2004-10-28 03:56:16 +00:00
|
|
|
cl::desc("Alias for -Tasm"), cl::aliasopt(AssemblerToolOpts));
|
|
|
|
|
2006-12-06 01:18:01 +00:00
|
|
|
static cl::list<std::string> OptimizerToolOpts("Topt", cl::ZeroOrMore,
|
2004-08-13 20:22:43 +00:00
|
|
|
cl::desc("Pass specific options to the optimizer"),
|
|
|
|
cl::value_desc("option"));
|
2004-08-10 16:26:01 +00:00
|
|
|
|
2006-12-06 01:18:01 +00:00
|
|
|
static cl::list<std::string> LinkerToolOpts("Tlnk", cl::ZeroOrMore,
|
2004-08-13 20:22:43 +00:00
|
|
|
cl::desc("Pass specific options to the linker"),
|
|
|
|
cl::value_desc("option"));
|
2004-08-10 16:26:01 +00:00
|
|
|
|
2006-12-06 01:18:01 +00:00
|
|
|
static cl::alias LinkerToolOptsAlias("Wl,", cl::ZeroOrMore,
|
2004-10-28 03:56:16 +00:00
|
|
|
cl::desc("Alias for -Tlnk"), cl::aliasopt(LinkerToolOpts));
|
|
|
|
|
2006-12-06 01:18:01 +00:00
|
|
|
static cl::list<std::string> fOpts("f", cl::ZeroOrMore, cl::Prefix,
|
2004-09-14 01:58:45 +00:00
|
|
|
cl::desc("Pass through -f options to compiler tools"),
|
2005-02-18 20:00:05 +00:00
|
|
|
cl::value_desc("option"));
|
2004-09-14 01:58:45 +00:00
|
|
|
|
2006-12-06 01:18:01 +00:00
|
|
|
static cl::list<std::string> MOpts("M", cl::ZeroOrMore, cl::Prefix,
|
2004-09-14 01:58:45 +00:00
|
|
|
cl::desc("Pass through -M options to compiler tools"),
|
2005-02-18 20:00:05 +00:00
|
|
|
cl::value_desc("option"));
|
2004-09-14 01:58:45 +00:00
|
|
|
|
2006-12-06 01:18:01 +00:00
|
|
|
static cl::list<std::string> WOpts("W", cl::ZeroOrMore, cl::Prefix,
|
2004-09-14 01:58:45 +00:00
|
|
|
cl::desc("Pass through -W options to compiler tools"),
|
2005-02-18 20:00:05 +00:00
|
|
|
cl::value_desc("option"));
|
2004-09-14 01:58:45 +00:00
|
|
|
|
2006-12-06 01:18:01 +00:00
|
|
|
static cl::list<std::string> BOpt("B", cl::ZeroOrMore, cl::Prefix,
|
2005-02-18 20:00:05 +00:00
|
|
|
cl::desc("Specify path to find llvmc sub-tools"),
|
|
|
|
cl::value_desc("dir"));
|
2004-11-05 22:15:36 +00:00
|
|
|
|
2006-05-29 18:52:05 +00:00
|
|
|
//===----------------------------------------------------------------------===//
|
2004-08-10 16:26:01 +00:00
|
|
|
//=== INPUT OPTIONS
|
2006-05-29 18:52:05 +00:00
|
|
|
//===----------------------------------------------------------------------===//
|
2004-08-10 16:26:01 +00:00
|
|
|
|
2006-12-06 01:18:01 +00:00
|
|
|
static cl::list<std::string> LibPaths("L", cl::Prefix,
|
2005-02-18 20:00:05 +00:00
|
|
|
cl::desc("Specify a library search path"), cl::value_desc("dir"));
|
2004-11-20 20:45:33 +00:00
|
|
|
|
2006-12-06 01:18:01 +00:00
|
|
|
static cl::list<std::string> Libraries("l", cl::Prefix,
|
2005-02-18 20:00:05 +00:00
|
|
|
cl::desc("Specify base name of libraries to link to"), cl::value_desc("lib"));
|
2004-08-10 16:26:01 +00:00
|
|
|
|
2006-12-06 01:18:01 +00:00
|
|
|
static cl::list<std::string> Includes("I", cl::Prefix,
|
2005-04-22 00:00:37 +00:00
|
|
|
cl::desc("Specify location to search for included source"),
|
2005-02-18 20:00:05 +00:00
|
|
|
cl::value_desc("dir"));
|
2004-08-30 06:27:32 +00:00
|
|
|
|
2006-12-06 01:18:01 +00:00
|
|
|
static cl::list<std::string> Defines("D", cl::Prefix,
|
2005-02-18 20:00:05 +00:00
|
|
|
cl::desc("Specify a pre-processor symbol to define"),
|
|
|
|
cl::value_desc("symbol"));
|
2004-08-30 06:27:32 +00:00
|
|
|
|
2006-05-29 18:52:05 +00:00
|
|
|
//===----------------------------------------------------------------------===//
|
2004-08-10 16:26:01 +00:00
|
|
|
//=== OUTPUT OPTIONS
|
2006-05-29 18:52:05 +00:00
|
|
|
//===----------------------------------------------------------------------===//
|
2004-08-10 16:26:01 +00:00
|
|
|
|
2006-12-06 01:18:01 +00:00
|
|
|
static cl::opt<std::string> OutputFilename("o",
|
2005-02-18 20:00:05 +00:00
|
|
|
cl::desc("Override output filename"), cl::value_desc("file"));
|
2004-08-10 16:26:01 +00:00
|
|
|
|
2006-12-06 01:18:01 +00:00
|
|
|
static cl::opt<std::string> OutputMachine("m", cl::Prefix,
|
2004-08-10 16:26:01 +00:00
|
|
|
cl::desc("Specify a target machine"), cl::value_desc("machine"));
|
2004-10-28 03:56:16 +00:00
|
|
|
|
2006-12-06 01:18:01 +00:00
|
|
|
static cl::opt<bool> Native("native", cl::init(false),
|
2007-07-05 17:07:56 +00:00
|
|
|
cl::desc("Generative native code instead of bitcode"));
|
2004-08-10 16:26:01 +00:00
|
|
|
|
2006-12-06 01:18:01 +00:00
|
|
|
static cl::opt<bool> DebugOutput("g", cl::init(false),
|
2004-08-30 06:27:32 +00:00
|
|
|
cl::desc("Generate objects that include debug symbols"));
|
|
|
|
|
2006-12-06 01:18:01 +00:00
|
|
|
static cl::opt<bool> StripOutput("strip", cl::init(false),
|
2004-09-14 01:58:45 +00:00
|
|
|
cl::desc("Strip all symbols from linked output file"));
|
|
|
|
|
2006-12-06 01:18:01 +00:00
|
|
|
static cl::opt<std::string> PrintFileName("print-fname", cl::Optional,
|
2005-02-18 20:00:05 +00:00
|
|
|
cl::value_desc("file"),
|
2004-11-23 23:47:58 +00:00
|
|
|
cl::desc("Print the full path for the option's value"));
|
|
|
|
|
2006-05-29 18:52:05 +00:00
|
|
|
//===----------------------------------------------------------------------===//
|
2004-08-10 16:26:01 +00:00
|
|
|
//=== INFORMATION OPTIONS
|
2006-05-29 18:52:05 +00:00
|
|
|
//===----------------------------------------------------------------------===//
|
2004-08-10 16:26:01 +00:00
|
|
|
|
2006-12-06 01:18:01 +00:00
|
|
|
static cl::opt<bool> DryRun("dry-run", cl::Optional, cl::init(false),
|
2004-08-13 20:22:43 +00:00
|
|
|
cl::desc("Do everything but perform the compilation actions"));
|
2004-08-10 16:26:01 +00:00
|
|
|
|
2006-12-06 01:18:01 +00:00
|
|
|
static cl::alias DryRunAlias("y", cl::Optional,
|
2004-08-13 20:22:43 +00:00
|
|
|
cl::desc("Alias for -dry-run"), cl::aliasopt(DryRun));
|
2004-08-10 16:26:01 +00:00
|
|
|
|
2006-12-06 01:18:01 +00:00
|
|
|
static cl::opt<bool> Verbose("verbose", cl::Optional, cl::init(false),
|
2004-08-10 16:26:01 +00:00
|
|
|
cl::desc("Print out each action taken"));
|
|
|
|
|
2006-12-06 01:18:01 +00:00
|
|
|
static cl::alias VerboseAlias("v", cl::Optional,
|
2004-08-10 16:26:01 +00:00
|
|
|
cl::desc("Alias for -verbose"), cl::aliasopt(Verbose));
|
|
|
|
|
2006-12-06 01:18:01 +00:00
|
|
|
static cl::opt<bool> Debug("debug", cl::Optional, cl::init(false),
|
2004-08-13 20:22:43 +00:00
|
|
|
cl::Hidden, cl::desc("Print out debugging information"));
|
|
|
|
|
2006-12-06 01:18:01 +00:00
|
|
|
static cl::alias DebugAlias("d", cl::Optional,
|
2004-08-13 20:22:43 +00:00
|
|
|
cl::desc("Alias for -debug"), cl::aliasopt(Debug));
|
|
|
|
|
2006-12-06 01:18:01 +00:00
|
|
|
static cl::opt<bool> TimeActions("time-actions", cl::Optional, cl::init(false),
|
2004-08-10 16:26:01 +00:00
|
|
|
cl::desc("Print execution time for each action taken"));
|
|
|
|
|
2006-12-06 01:18:01 +00:00
|
|
|
static cl::opt<bool> ShowStats("stats", cl::Optional, cl::init(false),
|
2004-08-19 04:49:47 +00:00
|
|
|
cl::desc("Print statistics accumulated during optimization"));
|
|
|
|
|
2006-05-29 18:52:05 +00:00
|
|
|
//===----------------------------------------------------------------------===//
|
2004-08-10 16:26:01 +00:00
|
|
|
//=== ADVANCED OPTIONS
|
2006-05-29 18:52:05 +00:00
|
|
|
//===----------------------------------------------------------------------===//
|
2004-08-10 16:26:01 +00:00
|
|
|
|
2004-08-13 20:22:43 +00:00
|
|
|
static cl::opt<std::string> ConfigDir("config-dir", cl::Optional,
|
2005-02-18 20:00:05 +00:00
|
|
|
cl::desc("Specify configuration directory to override defaults"),
|
|
|
|
cl::value_desc("dir"));
|
2004-08-10 16:26:01 +00:00
|
|
|
|
2004-08-15 08:19:46 +00:00
|
|
|
static cl::opt<bool> EmitRawCode("emit-raw-code", cl::Hidden, cl::Optional,
|
2004-08-10 16:26:01 +00:00
|
|
|
cl::desc("Emit raw, unoptimized code"));
|
|
|
|
|
2004-08-15 08:19:46 +00:00
|
|
|
static cl::opt<bool> PipeCommands("pipe", cl::Optional,
|
|
|
|
cl::desc("Invoke sub-commands by linking input/output with pipes"));
|
|
|
|
|
2004-08-29 19:26:56 +00:00
|
|
|
static cl::opt<bool> KeepTemps("keep-temps", cl::Optional,
|
2005-02-18 20:00:05 +00:00
|
|
|
cl::desc("Don't delete temporary files created by llvmc"));
|
2004-08-19 04:49:47 +00:00
|
|
|
|
2006-05-29 18:52:05 +00:00
|
|
|
//===----------------------------------------------------------------------===//
|
2004-08-10 16:26:01 +00:00
|
|
|
//=== POSITIONAL OPTIONS
|
2006-05-29 18:52:05 +00:00
|
|
|
//===----------------------------------------------------------------------===//
|
2004-08-10 16:26:01 +00:00
|
|
|
|
2004-11-23 23:47:58 +00:00
|
|
|
static cl::list<std::string> Files(cl::Positional, cl::ZeroOrMore,
|
2004-08-13 20:22:43 +00:00
|
|
|
cl::desc("[Sources/objects/libraries]"));
|
|
|
|
|
|
|
|
static cl::list<std::string> Languages("x", cl::ZeroOrMore,
|
|
|
|
cl::desc("Specify the source language for subsequent files"),
|
|
|
|
cl::value_desc("language"));
|
|
|
|
|
2006-05-29 18:52:05 +00:00
|
|
|
//===----------------------------------------------------------------------===//
|
2004-08-13 20:22:43 +00:00
|
|
|
//=== GetFileType - determine type of a file
|
2006-05-29 18:52:05 +00:00
|
|
|
//===----------------------------------------------------------------------===//
|
2006-12-06 01:18:01 +00:00
|
|
|
static const std::string GetFileType(const std::string& fname, unsigned pos) {
|
2004-08-13 20:22:43 +00:00
|
|
|
static std::vector<std::string>::iterator langIt = Languages.begin();
|
|
|
|
static std::string CurrLang = "";
|
|
|
|
|
|
|
|
// If a -x LANG option has been specified ..
|
2005-05-05 22:38:21 +00:00
|
|
|
if (langIt != Languages.end())
|
2004-08-13 20:22:43 +00:00
|
|
|
// If the -x LANG option came before the current file on command line
|
2005-05-05 22:38:21 +00:00
|
|
|
if (Languages.getPosition( langIt - Languages.begin() ) < pos) {
|
2004-08-13 20:22:43 +00:00
|
|
|
// use that language
|
|
|
|
CurrLang = *langIt++;
|
|
|
|
return CurrLang;
|
|
|
|
}
|
|
|
|
|
|
|
|
// If there's a current language in effect
|
|
|
|
if (!CurrLang.empty())
|
|
|
|
return CurrLang; // use that language
|
|
|
|
|
|
|
|
// otherwise just determine lang from the filename's suffix
|
2005-05-05 22:38:21 +00:00
|
|
|
return fname.substr(fname.rfind('.', fname.size()) + 1);
|
2004-08-13 20:22:43 +00:00
|
|
|
}
|
|
|
|
|
2006-12-06 01:18:01 +00:00
|
|
|
static void handleTerminatingOptions(CompilerDriver* CD) {
|
2004-11-23 23:47:58 +00:00
|
|
|
if (!PrintFileName.empty()) {
|
2005-05-05 22:38:21 +00:00
|
|
|
sys::Path path = CD->GetPathForLinkageItem(PrintFileName, false);
|
2004-12-11 00:14:15 +00:00
|
|
|
std::string p = path.toString();
|
2004-11-23 23:47:58 +00:00
|
|
|
if (p.empty())
|
2005-05-05 22:38:21 +00:00
|
|
|
std::cout << "Can't locate `" << PrintFileName << "'.\n";
|
2004-11-23 23:47:58 +00:00
|
|
|
else
|
2005-05-05 22:38:21 +00:00
|
|
|
std::cout << p << '\n';
|
2004-11-23 23:47:58 +00:00
|
|
|
exit(0);
|
|
|
|
}
|
|
|
|
}
|
2004-08-10 16:26:01 +00:00
|
|
|
|
|
|
|
/// @brief The main program for llvmc
|
|
|
|
int main(int argc, char **argv) {
|
2006-12-06 01:18:01 +00:00
|
|
|
llvm_shutdown_obj X; // Call llvm_shutdown() on exit.
|
2004-08-29 19:26:56 +00:00
|
|
|
// Make sure we print stack trace if we get bad signals
|
|
|
|
sys::PrintStackTraceOnErrorSignal();
|
|
|
|
|
2004-08-19 04:49:47 +00:00
|
|
|
try {
|
|
|
|
|
|
|
|
// Parse the command line options
|
2005-04-22 00:00:37 +00:00
|
|
|
cl::ParseCommandLineOptions(argc, argv,
|
2004-08-29 19:26:56 +00:00
|
|
|
" LLVM Compiler Driver (llvmc)\n\n"
|
2004-08-19 04:49:47 +00:00
|
|
|
" This program provides easy invocation of the LLVM tool set\n"
|
2004-08-29 19:26:56 +00:00
|
|
|
" and other compiler tools.\n"
|
2004-08-19 04:49:47 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
// Deal with unimplemented options.
|
|
|
|
if (PipeCommands)
|
2004-08-30 00:06:52 +00:00
|
|
|
throw std::string("Not implemented yet: -pipe");
|
2004-08-24 14:05:30 +00:00
|
|
|
|
|
|
|
if (OutputFilename.empty())
|
|
|
|
if (OptLevel == CompilerDriver::LINKING)
|
|
|
|
OutputFilename = "a.out";
|
2004-08-19 04:49:47 +00:00
|
|
|
|
|
|
|
// Construct the ConfigDataProvider object
|
|
|
|
LLVMC_ConfigDataProvider Provider;
|
2004-08-29 19:26:56 +00:00
|
|
|
Provider.setConfigDir(sys::Path(ConfigDir));
|
2004-08-19 04:49:47 +00:00
|
|
|
|
|
|
|
// Construct the CompilerDriver object
|
2004-08-29 19:26:56 +00:00
|
|
|
CompilerDriver* CD = CompilerDriver::Get(Provider);
|
2004-08-19 04:49:47 +00:00
|
|
|
|
2004-08-24 22:53:13 +00:00
|
|
|
// If the LLVM_LIB_SEARCH_PATH environment variable is
|
|
|
|
// set, append it to the list of places to search for libraries
|
2005-05-03 06:10:51 +00:00
|
|
|
char *srchPath = getenv("LLVM_LIB_SEARCH_PATH");
|
|
|
|
if (srchPath != NULL && strlen(srchPath) != 0)
|
|
|
|
LibPaths.push_back(std::string(srchPath));
|
2004-08-24 22:53:13 +00:00
|
|
|
|
2004-08-29 19:26:56 +00:00
|
|
|
// Set the driver flags based on command line options
|
|
|
|
unsigned flags = 0;
|
|
|
|
if (Verbose) flags |= CompilerDriver::VERBOSE_FLAG;
|
|
|
|
if (Debug) flags |= CompilerDriver::DEBUG_FLAG;
|
|
|
|
if (DryRun) flags |= CompilerDriver::DRY_RUN_FLAG;
|
|
|
|
if (Native) flags |= CompilerDriver::EMIT_NATIVE_FLAG;
|
|
|
|
if (EmitRawCode) flags |= CompilerDriver::EMIT_RAW_FLAG;
|
|
|
|
if (KeepTemps) flags |= CompilerDriver::KEEP_TEMPS_FLAG;
|
|
|
|
if (ShowStats) flags |= CompilerDriver::SHOW_STATS_FLAG;
|
|
|
|
if (TimeActions) flags |= CompilerDriver::TIME_ACTIONS_FLAG;
|
2004-09-14 01:58:45 +00:00
|
|
|
if (StripOutput) flags |= CompilerDriver::STRIP_OUTPUT_FLAG;
|
2004-08-29 19:26:56 +00:00
|
|
|
CD->setDriverFlags(flags);
|
|
|
|
|
2005-05-05 22:38:21 +00:00
|
|
|
// Specify required parameters
|
2004-08-29 19:26:56 +00:00
|
|
|
CD->setFinalPhase(FinalPhase);
|
|
|
|
CD->setOptimization(OptLevel);
|
|
|
|
CD->setOutputMachine(OutputMachine);
|
2004-08-30 06:27:32 +00:00
|
|
|
CD->setIncludePaths(Includes);
|
|
|
|
CD->setSymbolDefines(Defines);
|
2004-08-29 19:26:56 +00:00
|
|
|
CD->setLibraryPaths(LibPaths);
|
2004-09-14 01:58:45 +00:00
|
|
|
CD->setfPassThrough(fOpts);
|
|
|
|
CD->setMPassThrough(MOpts);
|
|
|
|
CD->setWPassThrough(WOpts);
|
2004-08-29 19:26:56 +00:00
|
|
|
|
|
|
|
// Provide additional tool arguments
|
2004-08-19 04:49:47 +00:00
|
|
|
if (!PreprocessorToolOpts.empty())
|
2004-08-29 19:26:56 +00:00
|
|
|
CD->setPhaseArgs(CompilerDriver::PREPROCESSING, PreprocessorToolOpts);
|
2004-08-19 04:49:47 +00:00
|
|
|
if (!TranslatorToolOpts.empty())
|
2004-08-29 19:26:56 +00:00
|
|
|
CD->setPhaseArgs(CompilerDriver::TRANSLATION, TranslatorToolOpts);
|
2004-08-19 04:49:47 +00:00
|
|
|
if (!OptimizerToolOpts.empty())
|
2004-08-29 19:26:56 +00:00
|
|
|
CD->setPhaseArgs(CompilerDriver::OPTIMIZATION, OptimizerToolOpts);
|
2004-08-19 04:49:47 +00:00
|
|
|
if (!AssemblerToolOpts.empty())
|
2004-08-29 19:26:56 +00:00
|
|
|
CD->setPhaseArgs(CompilerDriver::ASSEMBLY,AssemblerToolOpts);
|
2004-08-19 04:49:47 +00:00
|
|
|
if (!LinkerToolOpts.empty())
|
2004-08-29 19:26:56 +00:00
|
|
|
CD->setPhaseArgs(CompilerDriver::LINKING, LinkerToolOpts);
|
2004-08-19 04:49:47 +00:00
|
|
|
|
2004-11-23 23:47:58 +00:00
|
|
|
// Check for options that cause us to terminate before any significant work
|
|
|
|
// is done.
|
|
|
|
handleTerminatingOptions(CD);
|
|
|
|
|
2004-08-19 04:49:47 +00:00
|
|
|
// Prepare the list of files to be compiled by the CompilerDriver.
|
|
|
|
CompilerDriver::InputList InpList;
|
|
|
|
std::vector<std::string>::iterator fileIt = Files.begin();
|
|
|
|
std::vector<std::string>::iterator libIt = Libraries.begin();
|
|
|
|
unsigned libPos = 0, filePos = 0;
|
|
|
|
while ( 1 ) {
|
2005-05-05 22:38:21 +00:00
|
|
|
if (libIt != Libraries.end())
|
2004-08-19 04:49:47 +00:00
|
|
|
libPos = Libraries.getPosition( libIt - Libraries.begin() );
|
|
|
|
else
|
|
|
|
libPos = 0;
|
2005-05-05 22:38:21 +00:00
|
|
|
if (fileIt != Files.end())
|
|
|
|
filePos = Files.getPosition(fileIt - Files.begin());
|
2004-08-19 04:49:47 +00:00
|
|
|
else
|
|
|
|
filePos = 0;
|
|
|
|
|
2005-05-05 22:38:21 +00:00
|
|
|
if (filePos != 0 && (libPos == 0 || filePos < libPos)) {
|
2004-08-19 04:49:47 +00:00
|
|
|
// Add a source file
|
2005-07-27 06:12:32 +00:00
|
|
|
InpList.push_back(std::make_pair(*fileIt,
|
2005-05-05 22:38:21 +00:00
|
|
|
GetFileType(*fileIt, filePos)));
|
2004-08-19 04:49:47 +00:00
|
|
|
++fileIt;
|
2005-05-05 22:38:21 +00:00
|
|
|
} else if ( libPos != 0 && (filePos == 0 || libPos < filePos) ) {
|
2004-08-19 04:49:47 +00:00
|
|
|
// Add a library
|
2005-05-05 22:38:21 +00:00
|
|
|
InpList.push_back(std::make_pair(*libIt++, ""));
|
2004-08-19 04:49:47 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
break; // we're done with the list
|
2004-08-13 20:22:43 +00:00
|
|
|
}
|
2004-08-19 04:49:47 +00:00
|
|
|
|
|
|
|
// Tell the driver to do its thing
|
2006-08-21 06:04:45 +00:00
|
|
|
std::string ErrMsg;
|
|
|
|
int result = CD->execute(InpList, sys::Path(OutputFilename), ErrMsg);
|
2004-08-19 04:49:47 +00:00
|
|
|
if (result != 0) {
|
2006-08-21 06:04:45 +00:00
|
|
|
std::cerr << argv[0] << ": " << ErrMsg << '\n';
|
2004-08-19 04:49:47 +00:00
|
|
|
return result;
|
2004-08-13 20:22:43 +00:00
|
|
|
}
|
2004-08-10 16:26:01 +00:00
|
|
|
|
2004-08-19 04:49:47 +00:00
|
|
|
// All is good, return success
|
|
|
|
return 0;
|
2004-09-03 22:59:32 +00:00
|
|
|
} catch (const std::string& msg) {
|
2005-05-05 22:38:21 +00:00
|
|
|
std::cerr << argv[0] << ": " << msg << '\n';
|
2004-08-19 04:49:47 +00:00
|
|
|
} catch (...) {
|
2004-08-24 14:05:30 +00:00
|
|
|
std::cerr << argv[0] << ": Unexpected unknown exception occurred.\n";
|
2004-08-10 16:26:01 +00:00
|
|
|
}
|
2004-12-30 05:36:08 +00:00
|
|
|
return 1;
|
2004-08-10 16:26:01 +00:00
|
|
|
}
|