Files
clang-p2996/lld/lib/Driver/InputGraph.cpp
Joerg Sonnenberger 5e235de9d3 Change the parseFile argument from MemoryBuffer pointer to LinkerInput
reference. Move readFile logic into FileNode::createLinkerInput.

llvm-svn: 190253
2013-09-07 17:55:28 +00:00

72 lines
1.9 KiB
C++

//===- lib/Driver/InputGraph.cpp ------------------------------------------===//
//
// The LLVM Linker
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
#include "lld/Driver/InputGraph.h"
using namespace lld;
namespace {
bool sortInputElements(const std::unique_ptr<InputElement> &a,
const std::unique_ptr<InputElement> &b) {
return a->getOrdinal() < b->getOrdinal();
}
}
bool InputGraph::addInputElement(std::unique_ptr<InputElement> ie) {
switch (ie->kind()) {
case InputElement::Kind::Control:
++_numElements;
break;
case InputElement::Kind::File:
++_numElements;
++_numFiles;
break;
}
_inputArgs.push_back(std::move(ie));
return true;
}
bool InputGraph::assignOrdinals() {
for (auto &ie : _inputArgs)
ie->setOrdinal(++_ordinal);
return true;
}
void InputGraph::doPostProcess() {
std::stable_sort(_inputArgs.begin(), _inputArgs.end(), sortInputElements);
}
bool InputGraph::validate() {
for (auto &ie : _inputArgs)
if (!ie->validate())
return false;
return true;
}
bool InputGraph::dump(raw_ostream &diagnostics) {
for (auto &ie : _inputArgs)
if (!ie->dump(diagnostics))
return false;
return true;
}
llvm::ErrorOr<std::unique_ptr<lld::LinkerInput> >
FileNode::createLinkerInput(const LinkingContext &ctx) {
auto filePath = path(ctx);
if (!filePath &&
error_code(filePath) == llvm::errc::no_such_file_or_directory)
return make_error_code(llvm::errc::no_such_file_or_directory);
OwningPtr<llvm::MemoryBuffer> opmb;
if (error_code ec = llvm::MemoryBuffer::getFileOrSTDIN(*filePath, opmb))
return ec;
std::unique_ptr<MemoryBuffer> mb(opmb.take());
return std::unique_ptr<LinkerInput>(new LinkerInput(std::move(mb), *filePath));
}