X-Git-Url: http://demsky.eecs.uci.edu/git/?a=blobdiff_plain;f=tools%2Fllvm-link%2Fllvm-link.cpp;h=3fb7ba42cd05727e12e08222954b11bca1806596;hb=adf01b3f18442ae8db6b8948e70d82d9df415119;hp=a287c479a741a96606d47af38077394dd3edfef2;hpb=ac95cc79ac0b899d566cc29c0f646f39c2fa35c0;p=oota-llvm.git diff --git a/tools/llvm-link/llvm-link.cpp b/tools/llvm-link/llvm-link.cpp index a287c479a74..3fb7ba42cd0 100644 --- a/tools/llvm-link/llvm-link.cpp +++ b/tools/llvm-link/llvm-link.cpp @@ -19,10 +19,12 @@ #include "llvm/Bitcode/ReaderWriter.h" #include "llvm/Support/CommandLine.h" #include "llvm/Support/ManagedStatic.h" -#include "llvm/Support/MemoryBuffer.h" #include "llvm/Support/PrettyStackTrace.h" -#include "llvm/System/Signals.h" -#include "llvm/System/Path.h" +#include "llvm/Support/ToolOutputFile.h" +#include "llvm/Support/SystemUtils.h" +#include "llvm/Support/IRReader.h" +#include "llvm/Support/Signals.h" +#include "llvm/Support/Path.h" #include using namespace llvm; @@ -34,7 +36,12 @@ static cl::opt OutputFilename("o", cl::desc("Override output filename"), cl::init("-"), cl::value_desc("filename")); -static cl::opt Force("f", cl::desc("Overwrite output files")); +static cl::opt +Force("f", cl::desc("Enable binary output on terminals")); + +static cl::opt +OutputAssembly("S", + cl::desc("Write output as LLVM assembly"), cl::Hidden); static cl::opt Verbose("v", cl::desc("Print information about actions taken")); @@ -45,7 +52,8 @@ DumpAsm("d", cl::desc("Print assembly as linked"), cl::Hidden); // LoadFile - Read the specified bitcode file in and return it. This routine // searches the link path for the specified file to try to find it... // -static inline std::auto_ptr LoadFile(const std::string &FN, +static inline std::auto_ptr LoadFile(const char *argv0, + const std::string &FN, LLVMContext& Context) { sys::Path Filename; if (!Filename.set(FN)) { @@ -53,28 +61,15 @@ static inline std::auto_ptr LoadFile(const std::string &FN, return std::auto_ptr(); } - std::string ErrorMessage; - if (Filename.exists()) { - if (Verbose) errs() << "Loading '" << Filename.c_str() << "'\n"; - Module* Result = 0; - - const std::string &FNStr = Filename.toString(); - if (MemoryBuffer *Buffer = MemoryBuffer::getFileOrSTDIN(FNStr, - &ErrorMessage)) { - Result = ParseBitcodeFile(Buffer, Context, &ErrorMessage); - delete Buffer; - } - if (Result) return std::auto_ptr(Result); // Load successful! - - if (Verbose) { - errs() << "Error opening bitcode file: '" << Filename.c_str() << "'"; - if (ErrorMessage.size()) errs() << ": " << ErrorMessage; - errs() << "\n"; - } - } else { - errs() << "Bitcode file: '" << Filename.c_str() << "' does not exist.\n"; - } + SMDiagnostic Err; + if (Verbose) errs() << "Loading '" << Filename.c_str() << "'\n"; + Module* Result = 0; + + const std::string &FNStr = Filename.str(); + Result = ParseIRFile(FNStr, Err, Context); + if (Result) return std::auto_ptr(Result); // Load successful! + Err.Print(argv0, errs()); return std::auto_ptr(); } @@ -90,7 +85,8 @@ int main(int argc, char **argv) { unsigned BaseArg = 0; std::string ErrorMessage; - std::auto_ptr Composite(LoadFile(InputFilenames[BaseArg], Context)); + std::auto_ptr Composite(LoadFile(argv[0], + InputFilenames[BaseArg], Context)); if (Composite.get() == 0) { errs() << argv[0] << ": error loading file '" << InputFilenames[BaseArg] << "'\n"; @@ -98,7 +94,8 @@ int main(int argc, char **argv) { } for (unsigned i = BaseArg+1; i < InputFilenames.size(); ++i) { - std::auto_ptr M(LoadFile(InputFilenames[i], Context)); + std::auto_ptr M(LoadFile(argv[0], + InputFilenames[i], Context)); if (M.get() == 0) { errs() << argv[0] << ": error loading file '" <