2004-12-13 03:50:50 +00:00
|
|
|
//===- lib/Linker/Linker.cpp - Basic Linker functionality ----------------===//
|
2005-04-21 22:55:34 +00:00
|
|
|
//
|
2004-12-13 03:00:28 +00:00
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
2007-12-29 20:36:04 +00:00
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
2005-04-21 22:55:34 +00:00
|
|
|
//
|
2004-12-13 03:00:28 +00:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
2004-12-13 03:50:50 +00:00
|
|
|
// This file contains basic Linker functionality that all usages will need.
|
2004-12-13 03:00:28 +00:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#include "llvm/Linker.h"
|
2007-05-06 06:02:13 +00:00
|
|
|
#include "llvm/Bitcode/ReaderWriter.h"
|
2013-01-02 11:36:10 +00:00
|
|
|
#include "llvm/IR/Module.h"
|
2007-05-06 06:02:13 +00:00
|
|
|
#include "llvm/Support/MemoryBuffer.h"
|
2009-07-25 06:02:13 +00:00
|
|
|
#include "llvm/Support/raw_ostream.h"
|
2010-12-09 17:36:48 +00:00
|
|
|
#include "llvm/Support/system_error.h"
|
2004-12-13 03:00:28 +00:00
|
|
|
using namespace llvm;
|
|
|
|
|
2009-11-06 10:58:06 +00:00
|
|
|
Linker::Linker(StringRef progname, StringRef modname,
|
|
|
|
LLVMContext& C, unsigned flags):
|
2009-07-01 16:58:40 +00:00
|
|
|
Context(C),
|
|
|
|
Composite(new Module(modname, C)),
|
|
|
|
Flags(flags),
|
|
|
|
Error(),
|
|
|
|
ProgramName(progname) { }
|
2004-12-13 03:00:28 +00:00
|
|
|
|
2009-11-06 10:58:06 +00:00
|
|
|
Linker::Linker(StringRef progname, Module* aModule, unsigned flags) :
|
2009-07-01 16:58:40 +00:00
|
|
|
Context(aModule->getContext()),
|
|
|
|
Composite(aModule),
|
|
|
|
Flags(flags),
|
|
|
|
Error(),
|
|
|
|
ProgramName(progname) { }
|
2004-12-13 03:00:28 +00:00
|
|
|
|
|
|
|
Linker::~Linker() {
|
|
|
|
delete Composite;
|
|
|
|
}
|
|
|
|
|
2005-04-21 22:55:34 +00:00
|
|
|
bool
|
2009-11-06 10:58:06 +00:00
|
|
|
Linker::error(StringRef message) {
|
2004-12-13 03:00:28 +00:00
|
|
|
Error = message;
|
2006-11-27 10:09:12 +00:00
|
|
|
if (!(Flags&QuietErrors))
|
2009-07-25 06:02:13 +00:00
|
|
|
errs() << ProgramName << ": error: " << message << "\n";
|
2004-12-13 03:00:28 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
2009-11-06 10:58:06 +00:00
|
|
|
Linker::warning(StringRef message) {
|
2004-12-13 03:00:28 +00:00
|
|
|
Error = message;
|
2008-10-25 17:57:20 +00:00
|
|
|
if (!(Flags&QuietWarnings))
|
2009-07-25 06:02:13 +00:00
|
|
|
errs() << ProgramName << ": warning: " << message << "\n";
|
2004-12-13 03:00:28 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2009-11-06 10:58:06 +00:00
|
|
|
Linker::verbose(StringRef message) {
|
2006-11-27 10:09:12 +00:00
|
|
|
if (Flags&Verbose)
|
2010-01-05 01:55:22 +00:00
|
|
|
errs() << " " << message << "\n";
|
2004-12-13 03:00:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
Module*
|
|
|
|
Linker::releaseModule() {
|
|
|
|
Module* result = Composite;
|
|
|
|
Error.clear();
|
2004-12-13 03:50:50 +00:00
|
|
|
Composite = 0;
|
2004-12-13 03:00:28 +00:00
|
|
|
Flags = 0;
|
|
|
|
return result;
|
|
|
|
}
|