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