2009-06-02 17:52:33 +00:00
|
|
|
//===- lib/Linker/Linker.cpp - Basic Linker functionality ----------------===//
|
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
|
|
|
// This file contains basic Linker functionality that all usages will need.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#include "llvm/Linker.h"
|
|
|
|
#include "llvm/Bitcode/ReaderWriter.h"
|
2013-04-08 18:41:23 +00:00
|
|
|
#include "llvm/IR/Module.h"
|
2009-06-02 17:52:33 +00:00
|
|
|
#include "llvm/Support/MemoryBuffer.h"
|
2009-10-14 17:57:32 +00:00
|
|
|
#include "llvm/Support/raw_ostream.h"
|
2011-02-20 12:57:14 +00:00
|
|
|
#include "llvm/Support/system_error.h"
|
2009-06-02 17:52:33 +00:00
|
|
|
using namespace llvm;
|
|
|
|
|
2009-11-18 14:58:34 +00:00
|
|
|
Linker::Linker(StringRef progname, StringRef modname,
|
|
|
|
LLVMContext& C, unsigned flags):
|
2009-07-04 13:58:26 +00:00
|
|
|
Context(C),
|
|
|
|
Composite(new Module(modname, C)),
|
|
|
|
Flags(flags),
|
|
|
|
Error(),
|
|
|
|
ProgramName(progname) { }
|
2009-06-02 17:52:33 +00:00
|
|
|
|
2009-11-18 14:58:34 +00:00
|
|
|
Linker::Linker(StringRef progname, Module* aModule, unsigned flags) :
|
2009-07-04 13:58:26 +00:00
|
|
|
Context(aModule->getContext()),
|
|
|
|
Composite(aModule),
|
|
|
|
Flags(flags),
|
|
|
|
Error(),
|
|
|
|
ProgramName(progname) { }
|
2009-06-02 17:52:33 +00:00
|
|
|
|
|
|
|
Linker::~Linker() {
|
|
|
|
delete Composite;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
2009-11-18 14:58:34 +00:00
|
|
|
Linker::error(StringRef message) {
|
2009-06-02 17:52:33 +00:00
|
|
|
Error = message;
|
|
|
|
if (!(Flags&QuietErrors))
|
2009-10-14 17:57:32 +00:00
|
|
|
errs() << ProgramName << ": error: " << message << "\n";
|
2009-06-02 17:52:33 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
2009-11-18 14:58:34 +00:00
|
|
|
Linker::warning(StringRef message) {
|
2009-06-02 17:52:33 +00:00
|
|
|
Error = message;
|
|
|
|
if (!(Flags&QuietWarnings))
|
2009-10-14 17:57:32 +00:00
|
|
|
errs() << ProgramName << ": warning: " << message << "\n";
|
2009-06-02 17:52:33 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2009-11-18 14:58:34 +00:00
|
|
|
Linker::verbose(StringRef message) {
|
2009-06-02 17:52:33 +00:00
|
|
|
if (Flags&Verbose)
|
2009-10-14 17:57:32 +00:00
|
|
|
errs() << " " << message << "\n";
|
2009-06-02 17:52:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
Module*
|
|
|
|
Linker::releaseModule() {
|
|
|
|
Module* result = Composite;
|
|
|
|
Error.clear();
|
|
|
|
Composite = 0;
|
|
|
|
Flags = 0;
|
|
|
|
return result;
|
|
|
|
}
|