aboutsummaryrefslogtreecommitdiff
path: root/lib/Linker
diff options
context:
space:
mode:
authorRoman Divacky <rdivacky@FreeBSD.org>2009-10-14 17:57:32 +0000
committerRoman Divacky <rdivacky@FreeBSD.org>2009-10-14 17:57:32 +0000
commit59850d0874429601812bc13408cb1f776649027c (patch)
treeb21f6de4e08b89bb7931806bab798fc2a5e3a686 /lib/Linker
parent18f153bdb9db52e7089a2d5293b96c45a3124a26 (diff)
downloadsrc-59850d0874429601812bc13408cb1f776649027c.tar.gz
src-59850d0874429601812bc13408cb1f776649027c.zip
Update llvm to r84119.vendor/llvm/llvm-r84119
Notes
Notes: svn path=/vendor/llvm/dist/; revision=198090 svn path=/vendor/llvm/llvm-84119/; revision=198091; tag=vendor/llvm/llvm-r84119
Diffstat (limited to 'lib/Linker')
-rw-r--r--lib/Linker/LinkArchives.cpp11
-rw-r--r--lib/Linker/LinkItems.cpp33
-rw-r--r--lib/Linker/LinkModules.cpp121
-rw-r--r--lib/Linker/Linker.cpp45
4 files changed, 122 insertions, 88 deletions
diff --git a/lib/Linker/LinkArchives.cpp b/lib/Linker/LinkArchives.cpp
index faf01af127e9..76d81c219426 100644
--- a/lib/Linker/LinkArchives.cpp
+++ b/lib/Linker/LinkArchives.cpp
@@ -96,10 +96,10 @@ bool
Linker::LinkInArchive(const sys::Path &Filename, bool &is_native) {
// Make sure this is an archive file we're dealing with
if (!Filename.isArchive())
- return error("File '" + Filename.toString() + "' is not an archive.");
+ return error("File '" + Filename.str() + "' is not an archive.");
// Open the archive file
- verbose("Linking archive file '" + Filename.toString() + "'");
+ verbose("Linking archive file '" + Filename.str() + "'");
// Find all of the symbols currently undefined in the bitcode program.
// If all the symbols are defined, the program is complete, and there is
@@ -108,8 +108,7 @@ Linker::LinkInArchive(const sys::Path &Filename, bool &is_native) {
GetAllUndefinedSymbols(Composite, UndefinedSymbols);
if (UndefinedSymbols.empty()) {
- verbose("No symbols undefined, skipping library '" +
- Filename.toString() + "'");
+ verbose("No symbols undefined, skipping library '" + Filename.str() + "'");
return false; // No need to link anything in!
}
@@ -120,7 +119,7 @@ Linker::LinkInArchive(const sys::Path &Filename, bool &is_native) {
Archive* arch = AutoArch.get();
if (!arch)
- return error("Cannot read archive '" + Filename.toString() +
+ return error("Cannot read archive '" + Filename.str() +
"': " + ErrMsg);
if (!arch->isBitcodeArchive()) {
is_native = true;
@@ -143,7 +142,7 @@ Linker::LinkInArchive(const sys::Path &Filename, bool &is_native) {
// Find the modules we need to link into the target module
std::set<ModuleProvider*> Modules;
if (!arch->findModulesDefiningSymbols(UndefinedSymbols, Modules, &ErrMsg))
- return error("Cannot find symbols in '" + Filename.toString() +
+ return error("Cannot find symbols in '" + Filename.str() +
"': " + ErrMsg);
// If we didn't find any more modules to link this time, we are done
diff --git a/lib/Linker/LinkItems.cpp b/lib/Linker/LinkItems.cpp
index dc0f7c17bf42..61f3c26c6a1c 100644
--- a/lib/Linker/LinkItems.cpp
+++ b/lib/Linker/LinkItems.cpp
@@ -14,9 +14,10 @@
#include "llvm/Linker.h"
#include "llvm/Module.h"
-#include "llvm/Support/MemoryBuffer.h"
#include "llvm/Bitcode/ReaderWriter.h"
-
+#include "llvm/System/Path.h"
+#include "llvm/Support/ErrorHandling.h"
+#include "llvm/Support/MemoryBuffer.h"
using namespace llvm;
// LinkItems - This function is the main entry point into linking. It takes a
@@ -69,20 +70,20 @@ Linker::LinkInItems(const ItemList& Items, ItemList& NativeItems) {
/// LinkInLibrary - links one library into the HeadModule.
///
-bool Linker::LinkInLibrary(const std::string& Lib, bool& is_native) {
+bool Linker::LinkInLibrary(const StringRef &Lib, bool& is_native) {
is_native = false;
// Determine where this library lives.
sys::Path Pathname = FindLib(Lib);
if (Pathname.isEmpty())
- return error("Cannot find library '" + Lib + "'");
+ return error("Cannot find library '" + Lib.str() + "'");
// If its an archive, try to link it in
std::string Magic;
Pathname.getMagicNumber(Magic, 64);
switch (sys::IdentifyFileType(Magic.c_str(), 64)) {
- default: assert(0 && "Bad file type identification");
+ default: llvm_unreachable("Bad file type identification");
case sys::Unknown_FileType:
- return warning("Supposed library '" + Lib + "' isn't a library.");
+ return warning("Supposed library '" + Lib.str() + "' isn't a library.");
case sys::Bitcode_FileType:
// LLVM ".so" file.
@@ -92,7 +93,7 @@ bool Linker::LinkInLibrary(const std::string& Lib, bool& is_native) {
case sys::Archive_FileType:
if (LinkInArchive(Pathname, is_native))
- return error("Cannot link archive '" + Pathname.toString() + "'");
+ return error("Cannot link archive '" + Pathname.str() + "'");
break;
case sys::ELF_Relocatable_FileType:
@@ -157,7 +158,7 @@ bool Linker::LinkInFile(const sys::Path &File, bool &is_native) {
is_native = false;
// Check for a file of name "-", which means "read standard input"
- if (File.toString() == "-") {
+ if (File.str() == "-") {
std::auto_ptr<Module> M;
if (MemoryBuffer *Buffer = MemoryBuffer::getSTDIN()) {
M.reset(ParseBitcodeFile(Buffer, Context, &Error));
@@ -172,34 +173,34 @@ bool Linker::LinkInFile(const sys::Path &File, bool &is_native) {
// Make sure we can at least read the file
if (!File.canRead())
- return error("Cannot find linker input '" + File.toString() + "'");
+ return error("Cannot find linker input '" + File.str() + "'");
// If its an archive, try to link it in
std::string Magic;
File.getMagicNumber(Magic, 64);
switch (sys::IdentifyFileType(Magic.c_str(), 64)) {
- default: assert(0 && "Bad file type identification");
+ default: llvm_unreachable("Bad file type identification");
case sys::Unknown_FileType:
- return warning("Ignoring file '" + File.toString() +
+ return warning("Ignoring file '" + File.str() +
"' because does not contain bitcode.");
case sys::Archive_FileType:
// A user may specify an ar archive without -l, perhaps because it
// is not installed as a library. Detect that and link the archive.
- verbose("Linking archive file '" + File.toString() + "'");
+ verbose("Linking archive file '" + File.str() + "'");
if (LinkInArchive(File, is_native))
return true;
break;
case sys::Bitcode_FileType: {
- verbose("Linking bitcode file '" + File.toString() + "'");
+ verbose("Linking bitcode file '" + File.str() + "'");
std::auto_ptr<Module> M(LoadObject(File));
if (M.get() == 0)
- return error("Cannot load file '" + File.toString() + "': " + Error);
+ return error("Cannot load file '" + File.str() + "': " + Error);
if (LinkInModule(M.get(), &Error))
- return error("Cannot link file '" + File.toString() + "': " + Error);
+ return error("Cannot link file '" + File.str() + "': " + Error);
- verbose("Linked in file '" + File.toString() + "'");
+ verbose("Linked in file '" + File.str() + "'");
break;
}
diff --git a/lib/Linker/LinkModules.cpp b/lib/Linker/LinkModules.cpp
index 4a15d88d8f36..e64c200cf632 100644
--- a/lib/Linker/LinkModules.cpp
+++ b/lib/Linker/LinkModules.cpp
@@ -19,21 +19,22 @@
#include "llvm/Linker.h"
#include "llvm/Constants.h"
#include "llvm/DerivedTypes.h"
+#include "llvm/LLVMContext.h"
#include "llvm/Module.h"
#include "llvm/TypeSymbolTable.h"
#include "llvm/ValueSymbolTable.h"
#include "llvm/Instructions.h"
#include "llvm/Assembly/Writer.h"
-#include "llvm/Support/Streams.h"
+#include "llvm/Support/ErrorHandling.h"
+#include "llvm/Support/raw_ostream.h"
#include "llvm/System/Path.h"
#include "llvm/ADT/DenseMap.h"
-#include <sstream>
using namespace llvm;
// Error - Simple wrapper function to conditionally assign to E and return true.
// This just makes error return conditions a little bit simpler...
-static inline bool Error(std::string *E, const std::string &Message) {
- if (E) *E = Message;
+static inline bool Error(std::string *E, const Twine &Message) {
+ if (E) *E = Message.str();
return true;
}
@@ -143,7 +144,7 @@ protected:
// for debugging...
virtual void dump() const {
- cerr << "AbstractTypeSet!\n";
+ errs() << "AbstractTypeSet!\n";
}
};
}
@@ -336,11 +337,11 @@ static bool LinkTypes(Module *Dest, const Module *Src, std::string *Err) {
static void PrintMap(const std::map<const Value*, Value*> &M) {
for (std::map<const Value*, Value*>::const_iterator I = M.begin(), E =M.end();
I != E; ++I) {
- cerr << " Fr: " << (void*)I->first << " ";
+ errs() << " Fr: " << (void*)I->first << " ";
I->first->dump();
- cerr << " To: " << (void*)I->second << " ";
+ errs() << " To: " << (void*)I->second << " ";
I->second->dump();
- cerr << "\n";
+ errs() << "\n";
}
}
#endif
@@ -348,7 +349,8 @@ static void PrintMap(const std::map<const Value*, Value*> &M) {
// RemapOperand - Use ValueMap to convert constants from one module to another.
static Value *RemapOperand(const Value *In,
- std::map<const Value*, Value*> &ValueMap) {
+ std::map<const Value*, Value*> &ValueMap,
+ LLVMContext &Context) {
std::map<const Value*,Value*>::const_iterator I = ValueMap.find(In);
if (I != ValueMap.end())
return I->second;
@@ -363,29 +365,37 @@ static Value *RemapOperand(const Value *In,
if (const ConstantArray *CPA = dyn_cast<ConstantArray>(CPV)) {
std::vector<Constant*> Operands(CPA->getNumOperands());
for (unsigned i = 0, e = CPA->getNumOperands(); i != e; ++i)
- Operands[i] =cast<Constant>(RemapOperand(CPA->getOperand(i), ValueMap));
- Result = ConstantArray::get(cast<ArrayType>(CPA->getType()), Operands);
+ Operands[i] =cast<Constant>(RemapOperand(CPA->getOperand(i), ValueMap,
+ Context));
+ Result =
+ ConstantArray::get(cast<ArrayType>(CPA->getType()), Operands);
} else if (const ConstantStruct *CPS = dyn_cast<ConstantStruct>(CPV)) {
std::vector<Constant*> Operands(CPS->getNumOperands());
for (unsigned i = 0, e = CPS->getNumOperands(); i != e; ++i)
- Operands[i] =cast<Constant>(RemapOperand(CPS->getOperand(i), ValueMap));
- Result = ConstantStruct::get(cast<StructType>(CPS->getType()), Operands);
+ Operands[i] =cast<Constant>(RemapOperand(CPS->getOperand(i), ValueMap,
+ Context));
+ Result =
+ ConstantStruct::get(cast<StructType>(CPS->getType()), Operands);
} else if (isa<ConstantPointerNull>(CPV) || isa<UndefValue>(CPV)) {
Result = const_cast<Constant*>(CPV);
} else if (const ConstantVector *CP = dyn_cast<ConstantVector>(CPV)) {
std::vector<Constant*> Operands(CP->getNumOperands());
for (unsigned i = 0, e = CP->getNumOperands(); i != e; ++i)
- Operands[i] = cast<Constant>(RemapOperand(CP->getOperand(i), ValueMap));
+ Operands[i] = cast<Constant>(RemapOperand(CP->getOperand(i), ValueMap,
+ Context));
Result = ConstantVector::get(Operands);
} else if (const ConstantExpr *CE = dyn_cast<ConstantExpr>(CPV)) {
std::vector<Constant*> Ops;
for (unsigned i = 0, e = CE->getNumOperands(); i != e; ++i)
- Ops.push_back(cast<Constant>(RemapOperand(CE->getOperand(i),ValueMap)));
+ Ops.push_back(cast<Constant>(RemapOperand(CE->getOperand(i),ValueMap,
+ Context)));
Result = CE->getWithOperands(Ops);
} else {
assert(!isa<GlobalValue>(CPV) && "Unmapped global?");
- assert(0 && "Unknown type of derived type constant value!");
+ llvm_unreachable("Unknown type of derived type constant value!");
}
+ } else if (isa<MetadataBase>(In)) {
+ Result = const_cast<Value*>(In);
} else if (isa<InlineAsm>(In)) {
Result = const_cast<Value*>(In);
}
@@ -397,11 +407,11 @@ static Value *RemapOperand(const Value *In,
}
#ifndef NDEBUG
- cerr << "LinkModules ValueMap: \n";
+ errs() << "LinkModules ValueMap: \n";
PrintMap(ValueMap);
- cerr << "Couldn't remap value: " << (void*)In << " " << *In << "\n";
- assert(0 && "Couldn't remap value!");
+ errs() << "Couldn't remap value: " << (void*)In << " " << *In << "\n";
+ llvm_unreachable("Couldn't remap value!");
#endif
return 0;
}
@@ -521,6 +531,22 @@ static bool GetLinkageResult(GlobalValue *Dest, const GlobalValue *Src,
return false;
}
+// Insert all of the named mdnoes in Src into the Dest module.
+static void LinkNamedMDNodes(Module *Dest, Module *Src) {
+ for (Module::const_named_metadata_iterator I = Src->named_metadata_begin(),
+ E = Src->named_metadata_end(); I != E; ++I) {
+ const NamedMDNode *SrcNMD = I;
+ NamedMDNode *DestNMD = Dest->getNamedMetadata(SrcNMD->getName());
+ if (!DestNMD)
+ NamedMDNode::Create(SrcNMD, Dest);
+ else {
+ // Add Src elements into Dest node.
+ for (unsigned i = 0, e = SrcNMD->getNumElements(); i != e; ++i)
+ DestNMD->addElement(SrcNMD->getElement(i));
+ }
+ }
+}
+
// LinkGlobals - Loop through the global variables in the src module and merge
// them into the dest module.
static bool LinkGlobals(Module *Dest, const Module *Src,
@@ -538,8 +564,7 @@ static bool LinkGlobals(Module *Dest, const Module *Src,
// Check to see if may have to link the global with the global, alias or
// function.
if (SGV->hasName() && !SGV->hasLocalLinkage())
- DGV = cast_or_null<GlobalValue>(DestSymTab.lookup(SGV->getNameStart(),
- SGV->getNameEnd()));
+ DGV = cast_or_null<GlobalValue>(DestSymTab.lookup(SGV->getName()));
// If we found a global with the same name in the dest module, but it has
// internal linkage, we are really not doing any linkage here.
@@ -564,9 +589,9 @@ static bool LinkGlobals(Module *Dest, const Module *Src,
// symbol over in the dest module... the initializer will be filled in
// later by LinkGlobalInits.
GlobalVariable *NewDGV =
- new GlobalVariable(SGV->getType()->getElementType(),
+ new GlobalVariable(*Dest, SGV->getType()->getElementType(),
SGV->isConstant(), SGV->getLinkage(), /*init*/0,
- SGV->getName(), Dest, false,
+ SGV->getName(), 0, false,
SGV->getType()->getAddressSpace());
// Propagate alignment, visibility and section info.
CopyGVAttributes(NewDGV, SGV);
@@ -597,9 +622,9 @@ static bool LinkGlobals(Module *Dest, const Module *Src,
// AppendingVars map. The name is cleared out so that no linkage is
// performed.
GlobalVariable *NewDGV =
- new GlobalVariable(SGV->getType()->getElementType(),
+ new GlobalVariable(*Dest, SGV->getType()->getElementType(),
SGV->isConstant(), SGV->getLinkage(), /*init*/0,
- "", Dest, false,
+ "", 0, false,
SGV->getType()->getAddressSpace());
// Set alignment allowing CopyGVAttributes merge it with alignment of SGV.
@@ -625,13 +650,15 @@ static bool LinkGlobals(Module *Dest, const Module *Src,
// we are replacing may be a function (if a prototype, weak, etc) or a
// global variable.
GlobalVariable *NewDGV =
- new GlobalVariable(SGV->getType()->getElementType(), SGV->isConstant(),
- NewLinkage, /*init*/0, DGV->getName(), Dest, false,
+ new GlobalVariable(*Dest, SGV->getType()->getElementType(),
+ SGV->isConstant(), NewLinkage, /*init*/0,
+ DGV->getName(), 0, false,
SGV->getType()->getAddressSpace());
// Propagate alignment, section, and visibility info.
CopyGVAttributes(NewDGV, SGV);
- DGV->replaceAllUsesWith(ConstantExpr::getBitCast(NewDGV, DGV->getType()));
+ DGV->replaceAllUsesWith(ConstantExpr::getBitCast(NewDGV,
+ DGV->getType()));
// DGV will conflict with NewDGV because they both had the same
// name. We must erase this now so ForceRenaming doesn't assert
@@ -697,6 +724,9 @@ CalculateAliasLinkage(const GlobalValue *SGV, const GlobalValue *DGV) {
else if (SL == GlobalValue::InternalLinkage &&
DL == GlobalValue::InternalLinkage)
return GlobalValue::InternalLinkage;
+ else if (SL == GlobalValue::LinkerPrivateLinkage &&
+ DL == GlobalValue::LinkerPrivateLinkage)
+ return GlobalValue::LinkerPrivateLinkage;
else {
assert (SL == GlobalValue::PrivateLinkage &&
DL == GlobalValue::PrivateLinkage && "Unexpected linkage type");
@@ -866,7 +896,8 @@ static bool LinkGlobalInits(Module *Dest, const Module *Src,
if (SGV->hasInitializer()) { // Only process initialized GV's
// Figure out what the initializer looks like in the dest module...
Constant *SInit =
- cast<Constant>(RemapOperand(SGV->getInitializer(), ValueMap));
+ cast<Constant>(RemapOperand(SGV->getInitializer(), ValueMap,
+ Dest->getContext()));
// Grab destination global variable or alias.
GlobalValue *DGV = cast<GlobalValue>(ValueMap[SGV]->stripPointerCasts());
@@ -885,9 +916,9 @@ static bool LinkGlobalInits(Module *Dest, const Module *Src,
// Nothing is required, mapped values will take the new global
// automatically.
} else if (DGVar->hasAppendingLinkage()) {
- assert(0 && "Appending linkage unimplemented!");
+ llvm_unreachable("Appending linkage unimplemented!");
} else {
- assert(0 && "Unknown linkage!");
+ llvm_unreachable("Unknown linkage!");
}
} else {
// Copy the initializer over now...
@@ -923,8 +954,7 @@ static bool LinkFunctionProtos(Module *Dest, const Module *Src,
// Check to see if may have to link the function with the global, alias or
// function.
if (SF->hasName() && !SF->hasLocalLinkage())
- DGV = cast_or_null<GlobalValue>(DestSymTab.lookup(SF->getNameStart(),
- SF->getNameEnd()));
+ DGV = cast_or_null<GlobalValue>(DestSymTab.lookup(SF->getName()));
// If we found a global with the same name in the dest module, but it has
// internal linkage, we are really not doing any linkage here.
@@ -979,7 +1009,8 @@ static bool LinkFunctionProtos(Module *Dest, const Module *Src,
CopyGVAttributes(NewDF, SF);
// Any uses of DF need to change to NewDF, with cast
- DGV->replaceAllUsesWith(ConstantExpr::getBitCast(NewDF, DGV->getType()));
+ DGV->replaceAllUsesWith(ConstantExpr::getBitCast(NewDF,
+ DGV->getType()));
// DF will conflict with NewDF because they both had the same. We must
// erase this now so ForceRenaming doesn't assert because DF might
@@ -1053,7 +1084,7 @@ static bool LinkFunctionBody(Function *Dest, Function *Src,
for (Instruction::op_iterator OI = I->op_begin(), OE = I->op_end();
OI != OE; ++OI)
if (!isa<Instruction>(*OI) && !isa<BasicBlock>(*OI))
- *OI = RemapOperand(*OI, ValueMap);
+ *OI = RemapOperand(*OI, ValueMap, Dest->getContext());
// There is no need to map the arguments anymore.
for (Function::arg_iterator I = Src->arg_begin(), E = Src->arg_end();
@@ -1132,14 +1163,15 @@ static bool LinkAppendingVars(Module *M,
"Appending variables with different section name need to be linked!");
unsigned NewSize = T1->getNumElements() + T2->getNumElements();
- ArrayType *NewType = ArrayType::get(T1->getElementType(), NewSize);
+ ArrayType *NewType = ArrayType::get(T1->getElementType(),
+ NewSize);
G1->setName(""); // Clear G1's name in case of a conflict!
// Create the new global variable...
GlobalVariable *NG =
- new GlobalVariable(NewType, G1->isConstant(), G1->getLinkage(),
- /*init*/0, First->first, M, G1->isThreadLocal(),
+ new GlobalVariable(*M, NewType, G1->isConstant(), G1->getLinkage(),
+ /*init*/0, First->first, 0, G1->isThreadLocal(),
G1->getType()->getAddressSpace());
// Propagate alignment, visibility and section info.
@@ -1173,8 +1205,10 @@ static bool LinkAppendingVars(Module *M,
// FIXME: This should rewrite simple/straight-forward uses such as
// getelementptr instructions to not use the Cast!
- G1->replaceAllUsesWith(ConstantExpr::getBitCast(NG, G1->getType()));
- G2->replaceAllUsesWith(ConstantExpr::getBitCast(NG, G2->getType()));
+ G1->replaceAllUsesWith(ConstantExpr::getBitCast(NG,
+ G1->getType()));
+ G2->replaceAllUsesWith(ConstantExpr::getBitCast(NG,
+ G2->getType()));
// Remove the two globals from the module now...
M->getGlobalList().erase(G1);
@@ -1239,10 +1273,10 @@ Linker::LinkModules(Module *Dest, Module *Src, std::string *ErrorMsg) {
if (!Src->getDataLayout().empty() && !Dest->getDataLayout().empty() &&
Src->getDataLayout() != Dest->getDataLayout())
- cerr << "WARNING: Linking two modules of different data layouts!\n";
+ errs() << "WARNING: Linking two modules of different data layouts!\n";
if (!Src->getTargetTriple().empty() &&
Dest->getTargetTriple() != Src->getTargetTriple())
- cerr << "WARNING: Linking two modules of different target triples!\n";
+ errs() << "WARNING: Linking two modules of different target triples!\n";
// Append the module inline asm string.
if (!Src->getModuleInlineAsm().empty()) {
@@ -1282,6 +1316,9 @@ Linker::LinkModules(Module *Dest, Module *Src, std::string *ErrorMsg) {
AppendingVars.insert(std::make_pair(I->getName(), I));
}
+ // Insert all of the named mdnoes in Src into the Dest module.
+ LinkNamedMDNodes(Dest, Src);
+
// Insert all of the globals in src into the Dest module... without linking
// initializers (which could refer to functions not yet mapped over).
if (LinkGlobals(Dest, Src, ValueMap, AppendingVars, ErrorMsg))
diff --git a/lib/Linker/Linker.cpp b/lib/Linker/Linker.cpp
index 6e0b760b85de..aef79d08f423 100644
--- a/lib/Linker/Linker.cpp
+++ b/lib/Linker/Linker.cpp
@@ -14,12 +14,13 @@
#include "llvm/Linker.h"
#include "llvm/Module.h"
#include "llvm/Bitcode/ReaderWriter.h"
-#include "llvm/Config/config.h"
+#include "llvm/System/Path.h"
#include "llvm/Support/MemoryBuffer.h"
-#include "llvm/Support/Streams.h"
+#include "llvm/Support/raw_ostream.h"
+#include "llvm/Config/config.h"
using namespace llvm;
-Linker::Linker(const std::string& progname, const std::string& modname,
+Linker::Linker(const StringRef &progname, const StringRef &modname,
LLVMContext& C, unsigned flags):
Context(C),
Composite(new Module(modname, C)),
@@ -28,7 +29,7 @@ Linker::Linker(const std::string& progname, const std::string& modname,
Error(),
ProgramName(progname) { }
-Linker::Linker(const std::string& progname, Module* aModule, unsigned flags) :
+Linker::Linker(const StringRef &progname, Module* aModule, unsigned flags) :
Context(aModule->getContext()),
Composite(aModule),
LibPaths(),
@@ -41,25 +42,25 @@ Linker::~Linker() {
}
bool
-Linker::error(const std::string& message) {
+Linker::error(const StringRef &message) {
Error = message;
if (!(Flags&QuietErrors))
- cerr << ProgramName << ": error: " << message << "\n";
+ errs() << ProgramName << ": error: " << message << "\n";
return true;
}
bool
-Linker::warning(const std::string& message) {
+Linker::warning(const StringRef &message) {
Error = message;
if (!(Flags&QuietWarnings))
- cerr << ProgramName << ": warning: " << message << "\n";
+ errs() << ProgramName << ": warning: " << message << "\n";
return false;
}
void
-Linker::verbose(const std::string& message) {
+Linker::verbose(const StringRef &message) {
if (Flags&Verbose)
- cerr << " " << message << "\n";
+ errs() << " " << message << "\n";
}
void
@@ -69,11 +70,8 @@ Linker::addPath(const sys::Path& path) {
void
Linker::addPaths(const std::vector<std::string>& paths) {
- for (unsigned i = 0; i != paths.size(); ++i) {
- sys::Path aPath;
- aPath.set(paths[i]);
- LibPaths.push_back(aPath);
- }
+ for (unsigned i = 0, e = paths.size(); i != e; ++i)
+ LibPaths.push_back(sys::Path(paths[i]));
}
void
@@ -100,16 +98,15 @@ Linker::LoadObject(const sys::Path &FN) {
std::string ParseErrorMessage;
Module *Result = 0;
- const std::string &FNS = FN.toString();
- std::auto_ptr<MemoryBuffer> Buffer(MemoryBuffer::getFileOrSTDIN(FNS.c_str()));
+ std::auto_ptr<MemoryBuffer> Buffer(MemoryBuffer::getFileOrSTDIN(FN.c_str()));
if (Buffer.get())
Result = ParseBitcodeFile(Buffer.get(), Context, &ParseErrorMessage);
else
- ParseErrorMessage = "Error reading file '" + FNS + "'";
+ ParseErrorMessage = "Error reading file '" + FN.str() + "'";
if (Result)
return std::auto_ptr<Module>(Result);
- Error = "Bitcode file '" + FN.toString() + "' could not be loaded";
+ Error = "Bitcode file '" + FN.str() + "' could not be loaded";
if (ParseErrorMessage.size())
Error += ": " + ParseErrorMessage;
return std::auto_ptr<Module>();
@@ -117,13 +114,13 @@ Linker::LoadObject(const sys::Path &FN) {
// IsLibrary - Determine if "Name" is a library in "Directory". Return
// a non-empty sys::Path if its found, an empty one otherwise.
-static inline sys::Path IsLibrary(const std::string& Name,
- const sys::Path& Directory) {
+static inline sys::Path IsLibrary(const StringRef &Name,
+ const sys::Path &Directory) {
sys::Path FullPath(Directory);
// Try the libX.a form
- FullPath.appendComponent("lib" + Name);
+ FullPath.appendComponent(("lib" + Name).str());
FullPath.appendSuffix("a");
if (FullPath.isArchive())
return FullPath;
@@ -156,7 +153,7 @@ static inline sys::Path IsLibrary(const std::string& Name,
/// Path if no matching file can be found.
///
sys::Path
-Linker::FindLib(const std::string &Filename) {
+Linker::FindLib(const StringRef &Filename) {
// Determine if the pathname can be found as it stands.
sys::Path FilePath(Filename);
if (FilePath.canRead() &&
@@ -167,7 +164,7 @@ Linker::FindLib(const std::string &Filename) {
// there.
for (unsigned Index = 0; Index != LibPaths.size(); ++Index) {
sys::Path Directory(LibPaths[Index]);
- sys::Path FullPath = IsLibrary(Filename,Directory);
+ sys::Path FullPath = IsLibrary(Filename, Directory);
if (!FullPath.isEmpty())
return FullPath;
}