summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--lld/include/lld/Core/InputGraph.h44
-rw-r--r--lld/include/lld/Core/LinkingContext.h2
-rw-r--r--lld/lib/Core/Resolver.cpp4
-rw-r--r--lld/lib/Driver/CoreDriver.cpp2
-rw-r--r--lld/lib/Driver/Driver.cpp2
-rw-r--r--lld/lib/Driver/GnuLdDriver.cpp4
-rw-r--r--lld/lib/Driver/WinLinkDriver.cpp4
-rw-r--r--lld/lib/ReaderWriter/MachO/MachOLinkingContext.cpp12
-rw-r--r--lld/lib/ReaderWriter/PECOFF/PECOFFLinkingContext.cpp4
-rw-r--r--lld/unittests/DriverTests/DriverTest.h7
10 files changed, 39 insertions, 46 deletions
diff --git a/lld/include/lld/Core/InputGraph.h b/lld/include/lld/Core/InputGraph.h
index 32b1dfe1847..a2e9c2da95c 100644
--- a/lld/include/lld/Core/InputGraph.h
+++ b/lld/include/lld/Core/InputGraph.h
@@ -30,48 +30,42 @@
namespace lld {
-class InputElement;
+class Node;
class LinkingContext;
class InputGraph {
public:
- std::vector<std::unique_ptr<InputElement>> &members() {
+ std::vector<std::unique_ptr<Node>> &members() {
return _members;
}
protected:
- std::vector<std::unique_ptr<InputElement>> _members;
+ std::vector<std::unique_ptr<Node>> _members;
};
-/// \brief This describes each element in the InputGraph. The Kind
-/// determines what the current node contains.
-class InputElement {
+// A Node represents a FileNode or other type of Node. In the latter case,
+// the node contains meta information about the input file list.
+// Currently only GroupEnd node is defined as a meta node.
+class Node {
public:
- /// Each input element in the graph can be a File or a control
- enum class Kind : uint8_t {
- File, // Represents a type associated with File Nodes
- GroupEnd,
- };
-
- InputElement(Kind type) : _kind(type) {}
- virtual ~InputElement() {}
-
- /// Return the Element Type for an Input Element
+ enum class Kind { File, GroupEnd };
+ Node(Kind type) : _kind(type) {}
+ virtual ~Node() {}
virtual Kind kind() const { return _kind; }
-protected:
- Kind _kind; // The type of the Element
+private:
+ Kind _kind;
};
// This is a marker for --end-group. getSize() returns the number of
// files between the corresponding --start-group and this marker.
-class GroupEnd : public InputElement {
+class GroupEnd : public Node {
public:
- GroupEnd(int size) : InputElement(Kind::GroupEnd), _size(size) {}
+ GroupEnd(int size) : Node(Kind::GroupEnd), _size(size) {}
int getSize() const { return _size; }
- static inline bool classof(const InputElement *a) {
+ static inline bool classof(const Node *a) {
return a->kind() == Kind::GroupEnd;
}
@@ -80,15 +74,15 @@ private:
};
// A container of File.
-class FileNode : public InputElement {
+class FileNode : public Node {
public:
explicit FileNode(std::unique_ptr<File> f)
- : InputElement(InputElement::Kind::File), _file(std::move(f)) {}
+ : Node(Node::Kind::File), _file(std::move(f)) {}
virtual ~FileNode() {}
- static inline bool classof(const InputElement *a) {
- return a->kind() == InputElement::Kind::File;
+ static inline bool classof(const Node *a) {
+ return a->kind() == Node::Kind::File;
}
File *getFile() { return _file.get(); }
diff --git a/lld/include/lld/Core/LinkingContext.h b/lld/include/lld/Core/LinkingContext.h
index fb1e9daf0ee..9528b1714a2 100644
--- a/lld/include/lld/Core/LinkingContext.h
+++ b/lld/include/lld/Core/LinkingContext.h
@@ -26,7 +26,7 @@ class PassManager;
class File;
class Writer;
class InputGraph;
-class InputElement;
+class Node;
class SharedLibraryFile;
/// \brief The LinkingContext class encapsulates "what and how" to link.
diff --git a/lld/lib/Core/Resolver.cpp b/lld/lib/Core/Resolver.cpp
index ce398ff1af1..1af8233a796 100644
--- a/lld/lib/Core/Resolver.cpp
+++ b/lld/lib/Core/Resolver.cpp
@@ -232,7 +232,7 @@ void Resolver::addAtoms(const std::vector<const DefinedAtom *> &newAtoms) {
// Returns true if at least one of N previous files has created an
// undefined symbol.
bool Resolver::undefinesAdded(int begin, int end) {
- std::vector<std::unique_ptr<InputElement>> &inputs =
+ std::vector<std::unique_ptr<Node>> &inputs =
_context.getInputGraph().members();
for (int i = begin; i < end; ++i)
if (FileNode *node = dyn_cast<FileNode>(inputs[i].get()))
@@ -242,7 +242,7 @@ bool Resolver::undefinesAdded(int begin, int end) {
}
File *Resolver::getFile(int &index, int &groupLevel) {
- std::vector<std::unique_ptr<InputElement>> &inputs
+ std::vector<std::unique_ptr<Node>> &inputs
= _context.getInputGraph().members();
if ((size_t)index >= inputs.size())
return nullptr;
diff --git a/lld/lib/Driver/CoreDriver.cpp b/lld/lib/Driver/CoreDriver.cpp
index 4a16b0202f4..1a495771789 100644
--- a/lld/lib/Driver/CoreDriver.cpp
+++ b/lld/lib/Driver/CoreDriver.cpp
@@ -153,7 +153,7 @@ bool CoreDriver::parse(int argc, const char *argv[], CoreLinkingContext &ctx,
std::vector<std::unique_ptr<File>> files
= loadFile(ctx, inputArg->getValue(), false);
for (std::unique_ptr<File> &file : files) {
- inputGraph->members().push_back(std::unique_ptr<InputElement>(
+ inputGraph->members().push_back(std::unique_ptr<Node>(
new FileNode(std::move(file))));
}
break;
diff --git a/lld/lib/Driver/Driver.cpp b/lld/lib/Driver/Driver.cpp
index eac75bfc6aa..c9058cc2fad 100644
--- a/lld/lib/Driver/Driver.cpp
+++ b/lld/lib/Driver/Driver.cpp
@@ -84,7 +84,7 @@ bool Driver::link(LinkingContext &context, raw_ostream &diagnostics) {
ScopedTask readTask(getDefaultDomain(), "Read Args");
TaskGroup tg;
std::mutex diagnosticsMutex;
- for (std::unique_ptr<InputElement> &ie : inputGraph.members()) {
+ for (std::unique_ptr<Node> &ie : inputGraph.members()) {
tg.spawn([&] {
// Writes to the same output stream is not guaranteed to be thread-safe.
// We buffer the diagnostics output to a separate string-backed output
diff --git a/lld/lib/Driver/GnuLdDriver.cpp b/lld/lib/Driver/GnuLdDriver.cpp
index 2e7ef175db5..7c6982cf61a 100644
--- a/lld/lib/Driver/GnuLdDriver.cpp
+++ b/lld/lib/Driver/GnuLdDriver.cpp
@@ -275,7 +275,7 @@ evaluateLinkerScript(ELFLinkingContext &ctx, InputGraph *inputGraph,
if (ctx.logInputFiles())
diag << file->path() << "\n";
inputGraph->members().push_back(
- std::unique_ptr<InputElement>(new FileNode(std::move(file))));
+ std::unique_ptr<Node>(new FileNode(std::move(file))));
++numfiles;
}
}
@@ -616,7 +616,7 @@ bool GnuLdDriver::parse(int argc, const char *argv[],
if (ctx->logInputFiles())
diagnostics << file->path() << "\n";
inputGraph->members().push_back(
- std::unique_ptr<InputElement>(new FileNode(std::move(file))));
+ std::unique_ptr<Node>(new FileNode(std::move(file))));
}
numfiles += files.size();
break;
diff --git a/lld/lib/Driver/WinLinkDriver.cpp b/lld/lib/Driver/WinLinkDriver.cpp
index 77f3a229b08..9aa447ac1ec 100644
--- a/lld/lib/Driver/WinLinkDriver.cpp
+++ b/lld/lib/Driver/WinLinkDriver.cpp
@@ -801,7 +801,7 @@ parseArgs(int argc, const char **argv, PECOFFLinkingContext &ctx,
// graph.
static bool hasLibrary(const PECOFFLinkingContext &ctx, File *file) {
StringRef path = file->path();
- for (std::unique_ptr<InputElement> &p : ctx.getInputGraph().members())
+ for (std::unique_ptr<Node> &p : ctx.getInputGraph().members())
if (auto *f = dyn_cast<FileNode>(p.get()))
if (f->getFile()->path() == path)
return true;
@@ -1417,7 +1417,7 @@ bool WinLinkDriver::parse(int argc, const char *argv[],
return false;
ctx.getResolvableSymsFile()->add(file.get());
ctx.getInputGraph().members().push_back(
- std::unique_ptr<InputElement>(new FileNode(std::move(file))));
+ std::unique_ptr<Node>(new FileNode(std::move(file))));
}
// Add the library group to the input graph.
diff --git a/lld/lib/ReaderWriter/MachO/MachOLinkingContext.cpp b/lld/lib/ReaderWriter/MachO/MachOLinkingContext.cpp
index ca1e11a4ff7..7d6587f2188 100644
--- a/lld/lib/ReaderWriter/MachO/MachOLinkingContext.cpp
+++ b/lld/lib/ReaderWriter/MachO/MachOLinkingContext.cpp
@@ -928,12 +928,12 @@ bool MachOLinkingContext::customAtomOrderer(const DefinedAtom *left,
return true;
}
-static File *getFirstFile(const std::unique_ptr<InputElement> &elem) {
- FileNode *e = dyn_cast<FileNode>(const_cast<InputElement *>(elem.get()));
+static File *getFirstFile(const std::unique_ptr<Node> &elem) {
+ FileNode *e = dyn_cast<FileNode>(const_cast<Node *>(elem.get()));
return e ? e->getFile() : nullptr;
}
-static bool isLibrary(const std::unique_ptr<InputElement> &elem) {
+static bool isLibrary(const std::unique_ptr<Node> &elem) {
File *f = getFirstFile(elem);
return f && (isa<SharedLibraryFile>(f) || isa<ArchiveLibraryFile>(f));
}
@@ -946,11 +946,11 @@ static bool isLibrary(const std::unique_ptr<InputElement> &elem) {
// so that the Resolver will reiterate over the libraries as long as we find
// new undefines from libraries.
void MachOLinkingContext::maybeSortInputFiles() {
- std::vector<std::unique_ptr<InputElement>> &elements
+ std::vector<std::unique_ptr<Node>> &elements
= getInputGraph().members();
std::stable_sort(elements.begin(), elements.end(),
- [](const std::unique_ptr<InputElement> &a,
- const std::unique_ptr<InputElement> &b) {
+ [](const std::unique_ptr<Node> &a,
+ const std::unique_ptr<Node> &b) {
return !isLibrary(a) && isLibrary(b);
});
size_t numLibs = std::count_if(elements.begin(), elements.end(), isLibrary);
diff --git a/lld/lib/ReaderWriter/PECOFF/PECOFFLinkingContext.cpp b/lld/lib/ReaderWriter/PECOFF/PECOFFLinkingContext.cpp
index de4ddca44b7..76ab8521c2c 100644
--- a/lld/lib/ReaderWriter/PECOFF/PECOFFLinkingContext.cpp
+++ b/lld/lib/ReaderWriter/PECOFF/PECOFFLinkingContext.cpp
@@ -90,7 +90,7 @@ std::unique_ptr<File> PECOFFLinkingContext::createUndefinedSymbolFile() const {
void PECOFFLinkingContext::addLibraryFile(std::unique_ptr<FileNode> file) {
GroupEnd *currentGroupEnd;
int pos = -1;
- std::vector<std::unique_ptr<InputElement>> &elements
+ std::vector<std::unique_ptr<Node>> &elements
= getInputGraph().members();
for (int i = 0, e = elements.size(); i < e; ++i) {
if ((currentGroupEnd = dyn_cast<GroupEnd>(elements[i].get()))) {
@@ -107,7 +107,7 @@ void PECOFFLinkingContext::addLibraryFile(std::unique_ptr<FileNode> file) {
bool PECOFFLinkingContext::createImplicitFiles(
std::vector<std::unique_ptr<File>> &) {
pecoff::ResolvableSymbols* syms = getResolvableSymsFile();
- std::vector<std::unique_ptr<InputElement>> &members
+ std::vector<std::unique_ptr<Node>> &members
= getInputGraph().members();
// Create a file for the entry point function.
diff --git a/lld/unittests/DriverTests/DriverTest.h b/lld/unittests/DriverTests/DriverTest.h
index 41c5bc525ee..c854e382aed 100644
--- a/lld/unittests/DriverTests/DriverTest.h
+++ b/lld/unittests/DriverTests/DriverTest.h
@@ -32,10 +32,9 @@ protected:
// Convenience method for getting i'th input files name.
std::string inputFile(int index) {
- InputElement &inputElement =
- *linkingContext()->getInputGraph().members()[index];
- if (inputElement.kind() == InputElement::Kind::File)
- return cast<FileNode>(&inputElement)->getFile()->path();
+ Node &node = *linkingContext()->getInputGraph().members()[index];
+ if (node.kind() == Node::Kind::File)
+ return cast<FileNode>(&node)->getFile()->path();
llvm_unreachable("not handling other types of input files");
}
OpenPOWER on IntegriCloud