llvm/llvm/include/llvm/TableGen/Record.h

//===- llvm/TableGen/Record.h - Classes for Table Records -------*- C++ -*-===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
//
// This file defines the main TableGen data structures, including the TableGen
// types, values, and high-level data structures.
//
//===----------------------------------------------------------------------===//

#ifndef LLVM_TABLEGEN_RECORD_H
#define LLVM_TABLEGEN_RECORD_H

#include "llvm/ADT/ArrayRef.h"
#include "llvm/ADT/DenseMap.h"
#include "llvm/ADT/DenseSet.h"
#include "llvm/ADT/FoldingSet.h"
#include "llvm/ADT/PointerIntPair.h"
#include "llvm/ADT/SmallVector.h"
#include "llvm/ADT/StringExtras.h"
#include "llvm/ADT/StringRef.h"
#include "llvm/Support/Casting.h"
#include "llvm/Support/ErrorHandling.h"
#include "llvm/Support/SMLoc.h"
#include "llvm/Support/Timer.h"
#include "llvm/Support/TrailingObjects.h"
#include "llvm/Support/raw_ostream.h"
#include <cassert>
#include <cstddef>
#include <cstdint>
#include <map>
#include <memory>
#include <optional>
#include <string>
#include <utility>
#include <variant>
#include <vector>

namespace llvm {
namespace detail {
struct RecordKeeperImpl;
} // namespace detail

class ListRecTy;
class Record;
class RecordKeeper;
class RecordVal;
class Resolver;
class StringInit;
class TypedInit;

//===----------------------------------------------------------------------===//
//  Type Classes
//===----------------------------------------------------------------------===//

class RecTy {};

inline raw_ostream &operator<<(raw_ostream &OS, const RecTy &Ty) {}

/// 'bit' - Represent a single bit
class BitRecTy : public RecTy {};

/// 'bits<n>' - Represent a fixed number of bits
class BitsRecTy : public RecTy {};

/// 'int' - Represent an integer value of no particular size
class IntRecTy : public RecTy {};

/// 'string' - Represent an string value
class StringRecTy : public RecTy {};

/// 'list<Ty>' - Represent a list of element values, all of which must be of
/// the specified type. The type is stored in ElementTy.
class ListRecTy : public RecTy {};

/// 'dag' - Represent a dag fragment
class DagRecTy : public RecTy {};

/// '[classname]' - Type of record values that have zero or more superclasses.
///
/// The list of superclasses is non-redundant, i.e. only contains classes that
/// are not the superclass of some other listed class.
class RecordRecTy final : public RecTy,
                          public FoldingSetNode,
                          public TrailingObjects<RecordRecTy, const Record *> {};

/// Find a common type that T1 and T2 convert to.
/// Return 0 if no such type exists.
const RecTy *resolveTypes(const RecTy *T1, const RecTy *T2);

//===----------------------------------------------------------------------===//
//  Initializer Classes
//===----------------------------------------------------------------------===//

class Init {};

inline raw_ostream &operator<<(raw_ostream &OS, const Init &I) {}

/// This is the common superclass of types that have a specific,
/// explicit type, stored in ValueTy.
class TypedInit : public Init {};

/// '?' - Represents an uninitialized value.
class UnsetInit : public Init {};

// Represent an argument.
ArgAuxType;
class ArgumentInit : public Init, public FoldingSetNode {};

/// 'true'/'false' - Represent a concrete initializer for a bit.
class BitInit final : public TypedInit {};

/// '{ a, b, c }' - Represents an initializer for a BitsRecTy value.
/// It contains a vector of bits, whose size is determined by the type.
class BitsInit final : public TypedInit, public FoldingSetNode,
                       public TrailingObjects<BitsInit, Init *> {};

/// '7' - Represent an initialization by a literal integer value.
class IntInit : public TypedInit {};

/// "anonymous_n" - Represent an anonymous record name
class AnonymousNameInit : public TypedInit {};

/// "foo" - Represent an initialization by a string value.
class StringInit : public TypedInit {};

/// [AL, AH, CL] - Represent a list of defs
///
class ListInit final : public TypedInit, public FoldingSetNode,
                       public TrailingObjects<ListInit, Init *> {};

/// Base class for operators
///
class OpInit : public TypedInit {};

/// !op (X) - Transform an init.
///
class UnOpInit : public OpInit, public FoldingSetNode {};

/// !op (X, Y) - Combine two inits.
class BinOpInit : public OpInit, public FoldingSetNode {};

/// !op (X, Y, Z) - Combine two inits.
class TernOpInit : public OpInit, public FoldingSetNode {};

/// !cond(condition_1: value1, ... , condition_n: value)
/// Selects the first value for which condition is true.
/// Otherwise reports an error.
class CondOpInit final : public TypedInit, public FoldingSetNode,
                      public TrailingObjects<CondOpInit, Init *> {};

/// !foldl (a, b, expr, start, lst) - Fold over a list.
class FoldOpInit : public TypedInit, public FoldingSetNode {};

/// !isa<type>(expr) - Dynamically determine the type of an expression.
class IsAOpInit : public TypedInit, public FoldingSetNode {};

/// !exists<type>(expr) - Dynamically determine if a record of `type` named
/// `expr` exists.
class ExistsOpInit : public TypedInit, public FoldingSetNode {};

/// 'Opcode' - Represent a reference to an entire variable object.
class VarInit : public TypedInit {};

/// Opcode{0} - Represent access to one bit of a variable or field.
class VarBitInit final : public TypedInit {};

/// AL - Represent a reference to a 'def' in the description
class DefInit : public TypedInit {};

/// classname<targs...> - Represent an uninstantiated anonymous class
/// instantiation.
class VarDefInit final : public TypedInit,
                         public FoldingSetNode,
                         public TrailingObjects<VarDefInit, ArgumentInit *> {};

/// X.Y - Represent a reference to a subfield of a variable
class FieldInit : public TypedInit {};

/// (v a, b) - Represent a DAG tree value.  DAG inits are required
/// to have at least one value then a (possibly empty) list of arguments.  Each
/// argument can have a name associated with it.
class DagInit final : public TypedInit, public FoldingSetNode,
                      public TrailingObjects<DagInit, Init *, StringInit *> {};

//===----------------------------------------------------------------------===//
//  High-Level Classes
//===----------------------------------------------------------------------===//

/// This class represents a field in a record, including its name, type,
/// value, and source location.
class RecordVal {};

inline raw_ostream &operator<<(raw_ostream &OS, const RecordVal &RV) {}

class Record {};

raw_ostream &operator<<(raw_ostream &OS, const Record &R);

class RecordKeeper {};

/// Sorting predicate to sort record pointers by name.
struct LessRecord {};

/// Sorting predicate to sort record pointers by their
/// unique ID. If you just need a deterministic order, use this, since it
/// just compares two `unsigned`; the other sorting predicates require
/// string manipulation.
struct LessRecordByID {};

/// Sorting predicate to sort record pointers by their Name field.
struct LessRecordFieldName {};

struct LessRecordRegister {};

raw_ostream &operator<<(raw_ostream &OS, const RecordKeeper &RK);

//===----------------------------------------------------------------------===//
//  Resolvers
//===----------------------------------------------------------------------===//

/// Interface for looking up the initializer for a variable name, used by
/// Init::resolveReferences.
class Resolver {};

/// Resolve arbitrary mappings.
class MapResolver final : public Resolver {};

/// Resolve all variables from a record except for unset variables.
class RecordResolver final : public Resolver {};

/// Delegate resolving to a sub-resolver, but shadow some variable names.
class ShadowResolver final : public Resolver {};

/// (Optionally) delegate resolving to a sub-resolver, and keep track whether
/// there were unresolved references.
class TrackUnresolvedResolver final : public Resolver {};

/// Do not resolve anything, but keep track of whether a given variable was
/// referenced.
class HasReferenceResolver final : public Resolver {};

void EmitDetailedRecords(const RecordKeeper &RK, raw_ostream &OS);
void EmitJSON(const RecordKeeper &RK, raw_ostream &OS);

} // end namespace llvm

#endif // LLVM_TABLEGEN_RECORD_H