//
// 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 is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
//
#include "CompilerDriver.h"
#include "ConfigLexer.h"
#include "llvm/Module.h"
-#include "llvm/Bytecode/Reader.h"
+#include "llvm/ModuleProvider.h"
+#include "llvm/Bitcode/ReaderWriter.h"
+#include "llvm/Support/MemoryBuffer.h"
#include "llvm/Support/Timer.h"
#include "llvm/System/Signals.h"
#include "llvm/ADT/SetVector.h"
#include <iostream>
using namespace llvm;
+
namespace {
void WriteAction(CompilerDriver::Action* action ) {
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"
-};
+static bool GetBitcodeDependentLibraries(const std::string &fname,
+ Module::LibraryListType& deplibs,
+ std::string* ErrMsg) {
+ ModuleProvider *MP = 0;
+ if (MemoryBuffer *Buffer = MemoryBuffer::getFileOrSTDIN(fname)) {
+ MP = getBitcodeModuleProvider(Buffer);
+ if (MP == 0) delete Buffer;
+ }
+ if (!MP) {
+ deplibs.clear();
+ return true;
+ }
+ deplibs = MP->getModule()->getLibraries();
+ delete MP;
+ return false;
+}
+
class CompilerDriverImpl : public CompilerDriver {
/// @name Constructors
void cleanup() {
if (!isSet(KEEP_TEMPS_FLAG)) {
- sys::FileStatus Status;
- if (!TempDir.getFileStatus(Status) && Status.isDir)
+ const sys::FileStatus *Status = TempDir.getFileStatus();
+ if (Status && Status->isDir)
TempDir.eraseFromDisk(/*remove_contents=*/true);
} else {
std::cout << "Temporary files are in " << TempDir << "\n";
if (programName[0] == '%' && programName.length() >2) {
switch(programName[1]){
case 'b':
- if (programName.substr(0,8) == "%bindir%") {
- std::string tmp(LLVM_BINDIR);
- tmp.append(programName.substr(8));
- pat->program.set(tmp);
- }
- break;
+ if (programName.substr(0,8) == "%bindir%") {
+ std::string tmp(LLVM_BINDIR);
+ tmp.append(programName.substr(8));
+ pat->program.set(tmp);
+ }
+ break;
case 'l':
- if (programName.substr(0,12) == "%llvmgccdir%"){
- std::string tmp(LLVMGCCDIR);
- tmp.append(programName.substr(12));
- pat->program.set(tmp);
- }else if (programName.substr(0,13) == "%llvmgccarch%"){
- std::string tmp(LLVMGCCARCH);
- tmp.append(programName.substr(13));
- pat->program.set(tmp);
- }else if (programName.substr(0,9) == "%llvmgcc%"){
- std::string tmp(LLVMGCC);
- tmp.append(programName.substr(9));
- pat->program.set(tmp);
- }else if (programName.substr(0,9) == "%llvmgxx%"){
- std::string tmp(LLVMGXX);
- tmp.append(programName.substr(9));
- pat->program.set(tmp);
- }else if (programName.substr(0,9) == "%llvmcc1%"){
- std::string tmp(LLVMCC1);
- tmp.append(programName.substr(9));
- pat->program.set(tmp);
- }else if (programName.substr(0,13) == "%llvmcc1plus%"){
- std::string tmp(LLVMCC1PLUS);
- tmp.append(programName.substr(13));
- pat->program.set(tmp);
- }else if (programName.substr(0,8) == "%libdir%") {
- std::string tmp(LLVM_LIBDIR);
- tmp.append(programName.substr(8));
- pat->program.set(tmp);
- }
- break;
+ if (programName.substr(0,12) == "%llvmgccdir%"){
+ std::string tmp(LLVMGCCDIR);
+ tmp.append(programName.substr(12));
+ pat->program.set(tmp);
+ }else if (programName.substr(0,13) == "%llvmgccarch%"){
+ std::string tmp(LLVMGCCARCH);
+ tmp.append(programName.substr(13));
+ pat->program.set(tmp);
+ }else if (programName.substr(0,9) == "%llvmgcc%"){
+ std::string tmp(LLVMGCC);
+ tmp.append(programName.substr(9));
+ pat->program.set(tmp);
+ }else if (programName.substr(0,9) == "%llvmgxx%"){
+ std::string tmp(LLVMGXX);
+ tmp.append(programName.substr(9));
+ pat->program.set(tmp);
+ }else if (programName.substr(0,9) == "%llvmcc1%"){
+ std::string tmp(LLVMCC1);
+ tmp.append(programName.substr(9));
+ pat->program.set(tmp);
+ }else if (programName.substr(0,13) == "%llvmcc1plus%"){
+ std::string tmp(LLVMCC1PLUS);
+ tmp.append(programName.substr(13));
+ pat->program.set(tmp);
+ }else if (programName.substr(0,8) == "%libdir%") {
+ std::string tmp(LLVM_LIBDIR);
+ tmp.append(programName.substr(8));
+ pat->program.set(tmp);
+ }
+ break;
}
}
action->program = pat->program;
Timer timer(action->program.toString());
timer.startTimer();
int resultCode =
- sys::Program::ExecuteAndWait(action->program, Args,0,0,0,&ErrMsg);
+ sys::Program::ExecuteAndWait(action->program, Args,0,0,0,0, &ErrMsg);
timer.stopTimer();
timer.print(timer,std::cerr);
return resultCode;
}
else
return
- sys::Program::ExecuteAndWait(action->program, Args, 0,0,0, &ErrMsg);
+ sys::Program::ExecuteAndWait(action->program, Args, 0,0,0,0, &ErrMsg);
}
return 0;
}
}
/// This method processes a linkage item. The item could be a
- /// Bytecode file needing translation to native code and that is
- /// dependent on other bytecode libraries, or a native code
+ /// Bitcode file needing translation to native code and that is
+ /// dependent on other bitcode libraries, or a native code
/// library that should just be linked into the program.
bool ProcessLinkageItem(const llvm::sys::Path& link_item,
SetVector<sys::Path>& set,
// If we got here fullpath is the path to the file, and its readable.
set.insert(fullpath);
- // If its an LLVM bytecode file ...
- if (fullpath.isBytecodeFile()) {
+ // If its an LLVM bitcode file ...
+ if (fullpath.isBitcodeFile()) {
// Process the dependent libraries recursively
Module::LibraryListType modlibs;
- if (GetBytecodeDependentLibraries(fullpath.toString(),modlibs,&err)) {
+ if (GetBitcodeDependentLibraries(fullpath.toString(),modlibs, &err)) {
// Traverse the dependent libraries list
Module::lib_iterator LI = modlibs.begin();
Module::lib_iterator LE = modlibs.end();
// Get the suffix of the file name
const std::string& ftype = I->second;
- // If its a library, bytecode file, or object file, save
+ // If its a library, bitcode file, or object file, save
// it for linking below and short circuit the
// pre-processing/translation/assembly phases
if (ftype.empty() || ftype == "o" || ftype == "bc" || ftype=="a") {
// ll -> bc Helper
if (action.isSet(OUTPUT_IS_ASM_FLAG)) {
/// The output of the translator is an LLVM Assembly program
- /// We need to translate it to bytecode
+ /// We need to translate it to bitcode
Action* action = new Action();
action->program.set("llvm-as");
action->args.push_back(InFile.toString());
// ll -> bc Helper
if (action.isSet(OUTPUT_IS_ASM_FLAG)) {
/// The output of the optimizer is an LLVM Assembly program
- /// We need to translate it to bytecode with llvm-as
+ /// We need to translate it to bitcode with llvm-as
Action* action = new Action();
action->program.set("llvm-as");
action->args.push_back(InFile.toString());
PathVector IncludePaths; ///< -I options
PathVector ToolPaths; ///< -B options
StringVector Defines; ///< -D options
- sys::Path TempDir; ///< Name of the temporary directory.
+ sys::PathWithStatus TempDir; ///< Name of the temporary directory.
StringTable AdditionalArgs; ///< The -Txyz options
StringVector fOptions; ///< -f options
StringVector MOptions; ///< -M options