[lld] r194641 - Move InputGraph from Driver to Core. LinkingContext depends on it.

Michael J. Spencer bigcheesegs at gmail.com
Wed Nov 13 16:51:34 PST 2013


Author: mspencer
Date: Wed Nov 13 18:51:33 2013
New Revision: 194641

URL: http://llvm.org/viewvc/llvm-project?rev=194641&view=rev
Log:
Move InputGraph from Driver to Core. LinkingContext depends on it.

Added:
    lld/trunk/include/lld/Core/InputGraph.h
      - copied, changed from r194624, lld/trunk/include/lld/Driver/InputGraph.h
    lld/trunk/lib/Core/InputGraph.cpp
      - copied, changed from r194624, lld/trunk/lib/Driver/InputGraph.cpp
Removed:
    lld/trunk/include/lld/Driver/InputGraph.h
    lld/trunk/lib/Driver/InputGraph.cpp
Modified:
    lld/trunk/include/lld/Core/LinkingContext.h
    lld/trunk/include/lld/Driver/CoreInputGraph.h
    lld/trunk/include/lld/Driver/DarwinInputGraph.h
    lld/trunk/include/lld/Driver/Driver.h
    lld/trunk/include/lld/Driver/GnuLdInputGraph.h
    lld/trunk/include/lld/Driver/WinLinkInputGraph.h
    lld/trunk/lib/Core/CMakeLists.txt
    lld/trunk/lib/Driver/CMakeLists.txt

Copied: lld/trunk/include/lld/Core/InputGraph.h (from r194624, lld/trunk/include/lld/Driver/InputGraph.h)
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/include/lld/Core/InputGraph.h?p2=lld/trunk/include/lld/Core/InputGraph.h&p1=lld/trunk/include/lld/Driver/InputGraph.h&r1=194624&r2=194641&rev=194641&view=diff
==============================================================================
--- lld/trunk/include/lld/Driver/InputGraph.h (original)
+++ lld/trunk/include/lld/Core/InputGraph.h Wed Nov 13 18:51:33 2013
@@ -13,8 +13,8 @@
 ///
 //===----------------------------------------------------------------------===//
 
-#ifndef LLD_DRIVER_INPUT_GRAPH_H
-#define LLD_DRIVER_INPUT_GRAPH_H
+#ifndef LLD_CORE_INPUT_GRAPH_H
+#define LLD_CORE_INPUT_GRAPH_H
 
 #include "lld/Core/File.h"
 #include "llvm/ADT/StringRef.h"

Modified: lld/trunk/include/lld/Core/LinkingContext.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/include/lld/Core/LinkingContext.h?rev=194641&r1=194640&r2=194641&view=diff
==============================================================================
--- lld/trunk/include/lld/Core/LinkingContext.h (original)
+++ lld/trunk/include/lld/Core/LinkingContext.h Wed Nov 13 18:51:33 2013
@@ -11,11 +11,11 @@
 #define LLD_CORE_TARGET_INFO_H
 
 #include "lld/Core/Error.h"
+#include "lld/Core/InputGraph.h"
 #include "lld/Core/LLVM.h"
 #include "lld/Core/range.h"
 #include "lld/Core/Reference.h"
 
-#include "lld/Driver/InputGraph.h"
 #include "lld/ReaderWriter/Reader.h"
 
 #include "llvm/Support/ErrorOr.h"

Modified: lld/trunk/include/lld/Driver/CoreInputGraph.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/include/lld/Driver/CoreInputGraph.h?rev=194641&r1=194640&r2=194641&view=diff
==============================================================================
--- lld/trunk/include/lld/Driver/CoreInputGraph.h (original)
+++ lld/trunk/include/lld/Driver/CoreInputGraph.h Wed Nov 13 18:51:33 2013
@@ -17,7 +17,7 @@
 #ifndef LLD_DRIVER_CORE_INPUT_GRAPH_H
 #define LLD_DRIVER_CORE_INPUT_GRAPH_H
 
-#include "lld/Driver/InputGraph.h"
+#include "lld/Core/InputGraph.h"
 #include "lld/ReaderWriter/CoreLinkingContext.h"
 
 #include <map>

Modified: lld/trunk/include/lld/Driver/DarwinInputGraph.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/include/lld/Driver/DarwinInputGraph.h?rev=194641&r1=194640&r2=194641&view=diff
==============================================================================
--- lld/trunk/include/lld/Driver/DarwinInputGraph.h (original)
+++ lld/trunk/include/lld/Driver/DarwinInputGraph.h Wed Nov 13 18:51:33 2013
@@ -17,7 +17,7 @@
 #ifndef LLD_DRIVER_DARWIN_INPUT_GRAPH_H
 #define LLD_DRIVER_DARWIN_INPUT_GRAPH_H
 
-#include "lld/Driver/InputGraph.h"
+#include "lld/Core/InputGraph.h"
 #include "lld/ReaderWriter/MachOLinkingContext.h"
 
 #include <map>

Modified: lld/trunk/include/lld/Driver/Driver.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/include/lld/Driver/Driver.h?rev=194641&r1=194640&r2=194641&view=diff
==============================================================================
--- lld/trunk/include/lld/Driver/Driver.h (original)
+++ lld/trunk/include/lld/Driver/Driver.h Wed Nov 13 18:51:33 2013
@@ -17,8 +17,8 @@
 #ifndef LLD_DRIVER_DRIVER_H
 #define LLD_DRIVER_DRIVER_H
 
+#include "lld/Core/InputGraph.h"
 #include "lld/Core/LLVM.h"
-#include "lld/Driver/InputGraph.h"
 
 #include "llvm/ADT/Triple.h"
 #include "llvm/Support/raw_ostream.h"

Modified: lld/trunk/include/lld/Driver/GnuLdInputGraph.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/include/lld/Driver/GnuLdInputGraph.h?rev=194641&r1=194640&r2=194641&view=diff
==============================================================================
--- lld/trunk/include/lld/Driver/GnuLdInputGraph.h (original)
+++ lld/trunk/include/lld/Driver/GnuLdInputGraph.h Wed Nov 13 18:51:33 2013
@@ -17,8 +17,8 @@
 #ifndef LLD_DRIVER_GNU_LD_INPUT_GRAPH_H
 #define LLD_DRIVER_GNU_LD_INPUT_GRAPH_H
 
+#include "lld/Core/InputGraph.h"
 #include "lld/Core/Resolver.h"
-#include "lld/Driver/InputGraph.h"
 #include "lld/ReaderWriter/ELFLinkingContext.h"
 #include "lld/ReaderWriter/FileArchive.h"
 

Removed: lld/trunk/include/lld/Driver/InputGraph.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/include/lld/Driver/InputGraph.h?rev=194640&view=auto
==============================================================================
--- lld/trunk/include/lld/Driver/InputGraph.h (original)
+++ lld/trunk/include/lld/Driver/InputGraph.h (removed)
@@ -1,411 +0,0 @@
-//===- lld/Core/InputGraph.h - Input Graph --------------------------------===//
-//
-//                             The LLVM Linker
-//
-// This file is distributed under the University of Illinois Open Source
-// License. See LICENSE.TXT for details.
-//
-//===----------------------------------------------------------------------===//
-///
-/// \file
-///
-/// Inputs to the linker in the form of a Graph.
-///
-//===----------------------------------------------------------------------===//
-
-#ifndef LLD_DRIVER_INPUT_GRAPH_H
-#define LLD_DRIVER_INPUT_GRAPH_H
-
-#include "lld/Core/File.h"
-#include "llvm/ADT/StringRef.h"
-#include "llvm/Option/ArgList.h"
-
-#include "llvm/Support/ErrorOr.h"
-#include "llvm/Support/MemoryBuffer.h"
-#include "llvm/Support/raw_ostream.h"
-
-#include <memory>
-#include <stack>
-#include <vector>
-
-namespace lld {
-
-class InputElement;
-class LinkingContext;
-
-/// \brief The inputs to the linker are represented by an InputGraph. The
-/// nodes in the input graph contains Input elements. The InputElements are
-/// either Input Files or Control Options. The Input Files represent each Input
-/// File to the linker and the control option specify what the linker needs
-/// to do when it processes the option.
-/// Each InputElement that is part of the Graph has an Ordinal value
-/// associated with it. The ordinal value is needed for the Writer to figure out
-/// the relative position of the arguments that appeared in the Command Line.
-/// InputElements have a weight function that can be used to determine the
-/// weight of the file, for statistical purposes.
-class InputGraph {
-public:
-  typedef std::vector<std::unique_ptr<InputElement> > InputElementVectorT;
-  typedef InputElementVectorT::iterator InputElementIterT;
-  typedef std::vector<std::unique_ptr<File> > FileVectorT;
-  typedef FileVectorT::iterator FileIterT;
-
-  /// Where do we want to insert the input element when calling the
-  /// insertElementAt, insertOneElementAt API's.
-  enum Position : uint8_t {
-    ANY,
-    BEGIN,
-    END
-  };
-
-  /// \brief Initialize the inputgraph
-  InputGraph() : _ordinal(0), _nextElementIndex(0) {}
-
-  /// \brief Adds a node into the InputGraph
-  virtual bool addInputElement(std::unique_ptr<InputElement>);
-
-  /// \brief Set Ordinals for all the InputElements that form the InputGraph
-  virtual bool assignOrdinals();
-
-  /// Destructor
-  virtual ~InputGraph() {}
-
-  /// \brief Do postprocessing of the InputGraph if there is a need for the
-  /// to provide additional information to the user, also rearranges
-  /// InputElements by their ordinals. If an user wants to place an input file
-  /// at the desired position, the user can do that
-  virtual void doPostProcess();
-
-  range<InputElementIterT> inputElements() {
-    return make_range(_inputArgs.begin(), _inputArgs.end());
-  }
-
-  /// \brief Validate the input graph
-  virtual bool validate();
-
-  // \brief Does the inputGraph contain any elements
-  size_t size() const { return _inputArgs.size(); }
-
-  /// \brief Dump the input Graph
-  virtual bool dump(raw_ostream &diagnostics = llvm::errs());
-
-  InputElement &operator[](size_t index) const {
-    return (*_inputArgs[index]);
-  }
-
-  /// \brief Insert a vector of elements into the input graph at position.
-  virtual void insertElementsAt(std::vector<std::unique_ptr<InputElement> >,
-                                Position position, size_t pos = 0);
-
-  /// \brief Insert an element into the input graph at position.
-  virtual void insertOneElementAt(std::unique_ptr<InputElement>,
-                                  Position position, size_t pos = 0);
-
-  /// \brief Helper functions for the resolver
-  virtual ErrorOr<InputElement *> getNextInputElement();
-
-  /// \brief Set the index on what inputElement has to be returned
-  virtual error_code setNextElementIndex(uint32_t index = 0);
-
-  /// \brief Reset the inputGraph for the inputGraph to start processing
-  /// files from the beginning
-  virtual error_code reset() { return setNextElementIndex(0); }
-
-protected:
-  // Input arguments
-  InputElementVectorT _inputArgs;
-  // Ordinals
-  int64_t _ordinal;
-  // Index of the next element to be processed
-  uint32_t _nextElementIndex;
-};
-
-/// \brief This describes each element in the InputGraph. The Kind
-/// determines what the current node contains.
-class InputElement {
-public:
-  /// Each input element in the graph can be a File or a control
-  enum class Kind : uint8_t {
-    Control,    // Represents a type associated with ControlNodes
-    SimpleFile, // Represents a type reserved for internal files
-    File        // Represents a type associated with File Nodes
-  };
-
-  /// \brief Initialize the Input Element, The ordinal value of an input Element
-  /// is initially set to -1, if the user wants to override its ordinal,
-  /// let the user do it
-  InputElement(Kind type, int64_t ordinal = -1);
-
-  virtual ~InputElement() {}
-
-  /// Return the Element Type for an Input Element
-  virtual Kind kind() const { return _kind; }
-
-  virtual void setOrdinal(int64_t ordinal) {
-    if (_ordinal != -1)
-      _ordinal = ordinal;
-  }
-
-  virtual int64_t getOrdinal() const { return _ordinal; }
-
-  virtual int64_t weight() const { return _weight; }
-
-  virtual void setWeight(int64_t weight) { _weight = weight; }
-
-  /// \brief validates the Input Element
-  virtual bool validate() = 0;
-
-  /// \brief Dump the Input Element
-  virtual bool dump(raw_ostream &diagnostics) = 0;
-
-  /// \brief parse the input element
-  virtual error_code parse(const LinkingContext &, raw_ostream &) = 0;
-
-  /// \brief functions for the resolver to use
-
-  /// Get the next file to be processed by the resolver
-  virtual ErrorOr<File &> getNextFile() = 0;
-
-  /// \brief Set the resolve state for the element
-  virtual void setResolveState(uint32_t state) = 0;
-
-  /// \brief Get the resolve state for the element
-  virtual uint32_t getResolveState() const = 0;
-
-  /// \brief Reset the next index
-  virtual void resetNextIndex() = 0;
-
-protected:
-  Kind _kind;              // The type of the Element
-  int64_t _ordinal;        // The ordinal value
-  int64_t _weight;         // Weight of the file
-};
-
-/// \brief The Control class represents a control node in the InputGraph
-class ControlNode : public InputElement {
-public:
-  /// A control node could be of several types supported by InputGraph
-  /// Future kinds of Control node could be added
-  enum class ControlKind : uint8_t{
-    Simple, // Represents a simple control node
-    Group   // Represents a type associated with ControlNodes
-  };
-
-  ControlNode(ControlNode::ControlKind controlKind =
-                  ControlNode::ControlKind::Simple,
-              int64_t _ordinal = -1)
-      : InputElement(InputElement::Kind::Control, _ordinal),
-        _controlKind(controlKind), _currentElementIndex(0),
-        _nextElementIndex(0) {}
-
-  virtual ~ControlNode() {}
-
-  /// \brief Return the kind of control node
-  virtual ControlNode::ControlKind controlKind() { return _controlKind; }
-
-  /// \brief Process control start/exit
-  virtual bool processControlEnter() { return true; }
-
-  /// \brief Process control start/exit
-  virtual bool processControlExit() { return true; }
-
-  /// Process the input Elemenet
-  virtual bool processInputElement(std::unique_ptr<InputElement> element) = 0;
-
-  /// \brief Casting support
-  static inline bool classof(const InputElement *a) {
-    return a->kind() == InputElement::Kind::Control;
-  }
-
-  range<InputGraph::InputElementIterT> elements() {
-    return make_range(_elements.begin(), _elements.end());
-  }
-
-  virtual void resetNextIndex() {
-    _currentElementIndex = _nextElementIndex = 0;
-    for (auto &elem : _elements)
-      elem->resetNextIndex();
-  }
-
-  virtual uint32_t getResolveState() const;
-
-  virtual void setResolveState(uint32_t);
-
-protected:
-  ControlKind _controlKind;
-  InputGraph::InputElementVectorT _elements;
-  uint32_t _currentElementIndex;
-  uint32_t _nextElementIndex;
-};
-
-/// \brief Represents an Input file in the graph
-///
-/// This class represents an input to the linker. It create the MemoryBuffer
-/// lazily when needed based on the file path. It can also take a MemoryBuffer
-/// directly.
-class FileNode : public InputElement {
-public:
-  FileNode(StringRef path, int64_t ordinal = -1);
-
-  virtual ErrorOr<StringRef> getPath(const LinkingContext &) const {
-    return _path;
-  }
-
-  // The saved input path thats used when a file is not found while
-  // trying to parse a file
-  StringRef getUserPath() const { return _path; }
-
-  virtual ~FileNode() {}
-
-  /// \brief Casting support
-  static inline bool classof(const InputElement *a) {
-    return a->kind() == InputElement::Kind::File;
-  }
-
-  /// \brief create an error string for printing purposes
-  virtual std::string errStr(error_code errc) {
-    std::string msg = errc.message();
-    Twine twine = Twine("Cannot open ") + _path + ": " + msg;
-    return twine.str();
-  }
-
-  /// \brief Get the list of files
-  range<InputGraph::FileIterT> files() {
-    return make_range(_files.begin(), _files.end());
-  }
-
-  /// \brief  number of files.
-  size_t numFiles() const { return _files.size(); }
-
-  /// \brief add a file to the list of files
-  virtual void addFiles(InputGraph::FileVectorT files) {
-    for (auto &ai : files)
-      _files.push_back(std::move(ai));
-  }
-
-  /// \brief Reset the file index if the resolver needs to process
-  /// the node again.
-  virtual void resetNextIndex();
-
-  /// \brief Set the resolve state for the FileNode.
-  virtual void setResolveState(uint32_t resolveState) {
-    _resolveState = resolveState;
-  }
-
-  /// \brief Retrieve the resolve state of the FileNode.
-  virtual uint32_t getResolveState() const { return _resolveState; }
-
-protected:
-  /// \brief Read the file into _buffer.
-  error_code getBuffer(StringRef filePath);
-
-  StringRef _path;                             // The path of the Input file
-  InputGraph::FileVectorT _files;              // A vector of lld File objects
-  std::unique_ptr<MemoryBuffer> _buffer; // Memory buffer to actual
-                                               // contents
-  uint32_t _resolveState;                      // The resolve state of the file
-  uint32_t _nextFileIndex; // The next file that would be processed by the
-                           // resolver
-};
-
-/// \brief A Control node which contains a group of InputElements
-/// This affects the resolver so that it resolves undefined symbols
-/// in the group completely before looking at other input files that
-/// follow the group
-class Group : public ControlNode {
-public:
-  Group(int64_t ordinal)
-      : ControlNode(ControlNode::ControlKind::Group, ordinal) {}
-
-  static inline bool classof(const InputElement *a) {
-    return a->kind() == InputElement::Kind::Control;
-  }
-
-  /// \brief Process input element and add it to the group
-  virtual bool processInputElement(std::unique_ptr<InputElement> element) {
-    _elements.push_back(std::move(element));
-    return true;
-  }
-
-  virtual ErrorOr<File &> getNextFile();
-};
-
-/// \brief Represents Internal Input files
-class SimpleFileNode : public InputElement {
-public:
-  SimpleFileNode(StringRef path, int64_t ordinal = -1);
-
-  virtual ErrorOr<StringRef> path(const LinkingContext &) const {
-    return _path;
-  }
-
-  // The saved input path thats used when a file is not found while
-  // trying to parse a file
-  StringRef getUserPath() const { return _path; }
-
-  virtual ~SimpleFileNode() {}
-
-  /// \brief Casting support
-  static inline bool classof(const InputElement *a) {
-    return a->kind() == InputElement::Kind::SimpleFile;
-  }
-
-  /// \brief Get the list of files
-  range<InputGraph::FileIterT> files() {
-    return make_range(_files.begin(), _files.end());
-  }
-
-  /// \brief  number of files.
-  size_t numFiles() const { return _files.size(); }
-
-  /// \brief add a file to the list of files
-  virtual void appendInputFile(std::unique_ptr<File> f) {
-    _files.push_back(std::move(f));
-  }
-
-  /// \brief add a file to the list of files
-  virtual void appendInputFiles(InputGraph::FileVectorT files) {
-    for (auto &ai : files)
-      _files.push_back(std::move(ai));
-  }
-
-  /// \brief validates the Input Element
-  virtual bool validate() { return true; }
-
-  /// \brief Dump the Input Element
-  virtual bool dump(raw_ostream &) { return true; }
-
-  /// \brief parse the input element
-  virtual error_code parse(const LinkingContext &, raw_ostream &) {
-    return error_code::success();
-  }
-
-  /// \brief Return the next File thats part of this node to the
-  /// resolver.
-  virtual ErrorOr<File &> getNextFile() {
-    if (_nextFileIndex == _files.size())
-      return make_error_code(InputGraphError::no_more_files);
-    return *_files[_nextFileIndex++];
-  }
-
-  /// \brief Set the resolver state.
-  virtual void setResolveState(uint32_t resolveState) {
-    _resolveState = resolveState;
-  }
-
-  /// \brief Retrieve the resolve state.
-  virtual uint32_t getResolveState() const { return _resolveState; }
-
-  // Do nothing here.
-  virtual void resetNextIndex() {}
-
-protected:
-  StringRef _path;                // A string associated with this file.
-  InputGraph::FileVectorT _files; // Vector of lld::File objects
-  uint32_t _nextFileIndex; // The next file that would be processed by the
-                           // resolver
-  uint32_t _resolveState;  // The resolve state associated with this Node
-};
-} // namespace lld
-
-#endif // LLD_DRIVER_INPUT_GRAPH_H

Modified: lld/trunk/include/lld/Driver/WinLinkInputGraph.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/include/lld/Driver/WinLinkInputGraph.h?rev=194641&r1=194640&r2=194641&view=diff
==============================================================================
--- lld/trunk/include/lld/Driver/WinLinkInputGraph.h (original)
+++ lld/trunk/include/lld/Driver/WinLinkInputGraph.h Wed Nov 13 18:51:33 2013
@@ -17,7 +17,7 @@
 #ifndef LLD_DRIVER_WIN_LINK_INPUT_GRAPH_H
 #define LLD_DRIVER_WIN_LINK_INPUT_GRAPH_H
 
-#include "lld/Driver/InputGraph.h"
+#include "lld/Core/InputGraph.h"
 #include "lld/ReaderWriter/PECOFFLinkingContext.h"
 #include "lld/ReaderWriter/FileArchive.h"
 

Modified: lld/trunk/lib/Core/CMakeLists.txt
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/Core/CMakeLists.txt?rev=194641&r1=194640&r2=194641&view=diff
==============================================================================
--- lld/trunk/lib/Core/CMakeLists.txt (original)
+++ lld/trunk/lib/Core/CMakeLists.txt Wed Nov 13 18:51:33 2013
@@ -4,6 +4,7 @@ add_lld_library(lldCore
   DefinedAtom.cpp
   Error.cpp
   File.cpp
+  InputGraph.cpp
   LinkingContext.cpp
   PassManager.cpp
   Resolver.cpp

Copied: lld/trunk/lib/Core/InputGraph.cpp (from r194624, lld/trunk/lib/Driver/InputGraph.cpp)
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/Core/InputGraph.cpp?p2=lld/trunk/lib/Core/InputGraph.cpp&p1=lld/trunk/lib/Driver/InputGraph.cpp&r1=194624&r2=194641&rev=194641&view=diff
==============================================================================
--- lld/trunk/lib/Driver/InputGraph.cpp (original)
+++ lld/trunk/lib/Core/InputGraph.cpp Wed Nov 13 18:51:33 2013
@@ -1,4 +1,4 @@
-//===- lib/Driver/InputGraph.cpp ------------------------------------------===//
+//===- lib/Core/InputGraph.cpp --------------------------------------------===//
 //
 //                             The LLVM Linker
 //
@@ -6,8 +6,10 @@
 // License. See LICENSE.TXT for details.
 //
 //===----------------------------------------------------------------------===//
+
+#include "lld/Core/InputGraph.h"
+
 #include "lld/Core/Resolver.h"
-#include "lld/Driver/InputGraph.h"
 
 using namespace lld;
 

Modified: lld/trunk/lib/Driver/CMakeLists.txt
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/Driver/CMakeLists.txt?rev=194641&r1=194640&r2=194641&view=diff
==============================================================================
--- lld/trunk/lib/Driver/CMakeLists.txt (original)
+++ lld/trunk/lib/Driver/CMakeLists.txt Wed Nov 13 18:51:33 2013
@@ -11,7 +11,6 @@ tablegen(LLVM WinLinkOptions.inc -gen-op
 add_public_tablegen_target(DriverOptionsTableGen)
 
 add_lld_library(lldDriver
-  InputGraph.cpp
   CoreDriver.cpp
   DarwinLdDriver.cpp
   Driver.cpp

Removed: lld/trunk/lib/Driver/InputGraph.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/Driver/InputGraph.cpp?rev=194640&view=auto
==============================================================================
--- lld/trunk/lib/Driver/InputGraph.cpp (original)
+++ lld/trunk/lib/Driver/InputGraph.cpp (removed)
@@ -1,176 +0,0 @@
-//===- 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/Core/Resolver.h"
-#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) {
-  _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;
-}
-
-/// \brief Insert element at position
-void InputGraph::insertElementsAt(
-    std::vector<std::unique_ptr<InputElement> > inputElements,
-    Position position, size_t pos) {
-  if (position == InputGraph::Position::BEGIN)
-    pos = 0;
-  else if (position == InputGraph::Position::END)
-    pos = _inputArgs.size();
-  _inputArgs.insert(_inputArgs.begin() + pos,
-                    std::make_move_iterator(inputElements.begin()),
-                    std::make_move_iterator(inputElements.end()));
-}
-
-void InputGraph::insertOneElementAt(std::unique_ptr<InputElement> element,
-                                    Position position, size_t pos) {
-  if (position == InputGraph::Position::BEGIN)
-    pos = 0;
-  else if (position == InputGraph::Position::END)
-    pos = _inputArgs.size();
-  _inputArgs.insert(_inputArgs.begin() + pos, std::move(element));
-}
-
-/// \brief Helper functions for the resolver
-ErrorOr<InputElement *> InputGraph::getNextInputElement() {
-  if (_nextElementIndex >= _inputArgs.size())
-    return make_error_code(InputGraphError::no_more_elements);
-  return _inputArgs[_nextElementIndex++].get();
-}
-
-/// \brief Set the index on what inputElement has to be returned
-error_code InputGraph::setNextElementIndex(uint32_t index) {
-  if (index > _inputArgs.size())
-    return make_error_code(llvm::errc::invalid_argument);
-  _nextElementIndex = index;
-  return error_code::success();
-}
-
-/// InputElement
-
-/// \brief Initialize the Input Element, The ordinal value of an input Element
-/// is initially set to -1, if the user wants to override its ordinal,
-/// let the user do it
-InputElement::InputElement(Kind type, int64_t ordinal)
-    : _kind(type), _ordinal(ordinal), _weight(0) {}
-
-/// FileNode
-FileNode::FileNode(StringRef path, int64_t ordinal)
-    : InputElement(InputElement::Kind::File, ordinal), _path(path),
-      _resolveState(Resolver::StateNoChange), _nextFileIndex(0) {}
-
-/// \brief Read the file into _buffer.
-error_code FileNode::getBuffer(StringRef filePath) {
-  // Create a memory buffer
-  OwningPtr<MemoryBuffer> opmb;
-
-  if (error_code ec = MemoryBuffer::getFileOrSTDIN(filePath, opmb))
-    return ec;
-
-  std::unique_ptr<MemoryBuffer> mb(opmb.take());
-  _buffer = std::move(mb);
-
-  return error_code::success();
-}
-
-// Reset the next file that would be be processed by the resolver.
-// Reset the resolve state too.
-void FileNode::resetNextIndex() {
-  _nextFileIndex = 0;
-  setResolveState(Resolver::StateNoChange);
-}
-
-/// ControlNode
-
-/// \brief Get the resolver State. The return value of the resolve
-/// state for a control node is the or'ed value of the resolve states
-/// contained in it.
-uint32_t ControlNode::getResolveState() const {
-  uint32_t resolveState = Resolver::StateNoChange;
-  for (auto &elem : _elements)
-    resolveState |= elem->getResolveState();
-  return resolveState;
-}
-
-/// \brief Set the resolve state for the current element
-/// thats processed by the resolver.
-void ControlNode::setResolveState(uint32_t resolveState) {
-  if (_elements.empty())
-    return;
-  _elements[_currentElementIndex]->setResolveState(resolveState);
-}
-
-/// SimpleFileNode
-
-SimpleFileNode::SimpleFileNode(StringRef path, int64_t ordinal)
-    : InputElement(InputElement::Kind::SimpleFile, ordinal), _path(path),
-      _nextFileIndex(0), _resolveState(Resolver::StateNoChange) {}
-
-/// Group
-
-/// \brief Return the next file that need to be processed by the resolver.
-/// This also processes input elements depending on the resolve status
-/// of the input elements contained in the group.
-ErrorOr<File &> Group::getNextFile() {
-  // If there are no elements, move on to the next input element
-  if (_elements.empty())
-    return make_error_code(InputGraphError::no_more_files);
-
-  for (;;) {
-    // If we have processed all the elements as part of this node
-    // check the resolver status for each input element and if the status
-    // has not changed, move onto the next file.
-    if (_nextElementIndex == _elements.size()) {
-      if (getResolveState() == Resolver::StateNoChange)
-        return make_error_code(InputGraphError::no_more_files);
-      resetNextIndex();
-    }
-    _currentElementIndex = _nextElementIndex;
-    auto file = _elements[_nextElementIndex]->getNextFile();
-    // Move on to the next element if we have finished processing all
-    // the files in the input element
-    if (error_code(file) == InputGraphError::no_more_files) {
-      _nextElementIndex++;
-      continue;
-    }
-    return *file;
-  }
-}





More information about the llvm-commits mailing list