Node.h revision 305067
1//===- lld/Core/Node.h - Input file class ---------------------------------===// 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 "llvm/Option/ArgList.h" 21#include <memory> 22#include <vector> 23 24namespace lld { 25 26// A Node represents a FileNode or other type of Node. In the latter case, 27// the node contains meta information about the input file list. 28// Currently only GroupEnd node is defined as a meta node. 29class Node { 30public: 31 enum class Kind { File, GroupEnd }; 32 explicit Node(Kind type) : _kind(type) {} 33 virtual ~Node() {} 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} // namespace lld 73 74#endif // LLD_CORE_NODE_H 75