1//===- lld/Core/Node.h - Input file class -----------------------*- C++ -*-===//
2//
3//                             The LLVM Linker
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9///
10/// \file
11///
12/// The classes in this file represents inputs to the linker.
13///
14//===----------------------------------------------------------------------===//
15
16#ifndef LLD_CORE_NODE_H
17#define LLD_CORE_NODE_H
18
19#include "lld/Core/File.h"
20#include <algorithm>
21#include <memory>
22
23namespace lld {
24
25// A Node represents a FileNode or other type of Node. In the latter case,
26// the node contains meta information about the input file list.
27// Currently only GroupEnd node is defined as a meta node.
28class Node {
29public:
30  enum class Kind { File, GroupEnd };
31
32  explicit Node(Kind type) : _kind(type) {}
33  virtual ~Node() = default;
34
35  virtual Kind kind() const { return _kind; }
36
37private:
38  Kind _kind;
39};
40
41// This is a marker for --end-group. getSize() returns the number of
42// files between the corresponding --start-group and this marker.
43class GroupEnd : public Node {
44public:
45  explicit GroupEnd(int size) : Node(Kind::GroupEnd), _size(size) {}
46
47  int getSize() const { return _size; }
48
49  static bool classof(const Node *a) {
50    return a->kind() == Kind::GroupEnd;
51  }
52
53private:
54  int _size;
55};
56
57// A container of File.
58class FileNode : public Node {
59public:
60  explicit FileNode(std::unique_ptr<File> f)
61      : Node(Node::Kind::File), _file(std::move(f)) {}
62
63  static bool classof(const Node *a) {
64    return a->kind() == Node::Kind::File;
65  }
66
67  File *getFile() { return _file.get(); }
68
69protected:
70  std::unique_ptr<File> _file;
71};
72
73} // end namespace lld
74
75#endif // LLD_CORE_NODE_H
76