1 //===- lib/Linker/Linker.cpp - Basic Linker functionality ----------------===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This file contains basic Linker functionality that all usages will need.
12 //===----------------------------------------------------------------------===//
14 #include "llvm/Linker.h"
15 #include "llvm/Bitcode/ReaderWriter.h"
16 #include "llvm/IR/Module.h"
17 #include "llvm/Support/MemoryBuffer.h"
18 #include "llvm/Support/Path.h"
19 #include "llvm/Support/raw_ostream.h"
20 #include "llvm/Support/system_error.h"
23 Linker::Linker(StringRef progname, StringRef modname,
24 LLVMContext& C, unsigned flags):
26 Composite(new Module(modname, C)),
30 ProgramName(progname) { }
32 Linker::Linker(StringRef progname, Module* aModule, unsigned flags) :
33 Context(aModule->getContext()),
38 ProgramName(progname) { }
45 Linker::error(StringRef message) {
47 if (!(Flags&QuietErrors))
48 errs() << ProgramName << ": error: " << message << "\n";
53 Linker::warning(StringRef message) {
55 if (!(Flags&QuietWarnings))
56 errs() << ProgramName << ": warning: " << message << "\n";
61 Linker::verbose(StringRef message) {
63 errs() << " " << message << "\n";
67 Linker::addPath(const sys::Path& path) {
68 LibPaths.push_back(path);
72 Linker::addPaths(const std::vector<std::string>& paths) {
73 for (unsigned i = 0, e = paths.size(); i != e; ++i)
74 LibPaths.push_back(sys::Path(paths[i]));
78 Linker::addSystemPaths() {
79 sys::Path::GetBitcodeLibraryPaths(LibPaths);
80 LibPaths.insert(LibPaths.begin(),sys::Path("./"));
84 Linker::releaseModule() {
85 Module* result = Composite;