Back to home page

EIC code displayed by LXR

 
 

    


Warning, /include/llvm/TableGen/Automaton.td is written in an unsupported language. File is not indexed.

0001 //===- Automaton.td ----------------------------------------*- tablegen -*-===//
0002 //
0003 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
0004 // See https://llvm.org/LICENSE.txt for license information.
0005 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
0006 //
0007 //===----------------------------------------------------------------------===//
0008 //
0009 // This file defines the key top-level classes needed to produce a reasonably
0010 // generic finite-state automaton.
0011 //
0012 //===----------------------------------------------------------------------===//
0013 
0014 // Define a record inheriting from GenericAutomaton to generate a reasonably
0015 // generic finite-state automaton over a set of actions and states.
0016 //
0017 // This automaton is defined by:
0018 //   1) a state space (explicit, always bits<32>).
0019 //   2) a set of input symbols (actions, explicit) and
0020 //   3) a transition function from state + action -> state.
0021 //
0022 // A theoretical automaton is defined by <Q, S, d, q0, F>:
0023 //   Q: A set of possible states.
0024 //   S: (sigma) The input alphabet.
0025 //   d: (delta) The transition function f(q in Q, s in S) -> q' in Q.
0026 //   F: The set of final (accepting) states.
0027 //
0028 // Because generating all possible states is tedious, we instead define the
0029 // transition function only and crawl all reachable states starting from the
0030 // initial state with all inputs under all transitions until termination.
0031 //
0032 // We define F = S, that is, all valid states are accepting.
0033 //
0034 // To ensure the generation of the automaton terminates, the state transitions
0035 // are defined as a lattice (meaning every transitioned-to state is more
0036 // specific than the transitioned-from state, for some definition of specificity).
0037 // Concretely a transition may set one or more bits in the state that were
0038 // previously zero to one. If any bit was not zero, the transition is invalid.
0039 //
0040 // Instead of defining all possible states (which would be cumbersome), the user
0041 // provides a set of possible Transitions from state A, consuming an input
0042 // symbol A to state B. The Transition object transforms state A to state B and
0043 // acts as a predicate. This means the state space can be discovered by crawling
0044 // all the possible transitions until none are valid.
0045 //
0046 // This automaton is considered to be nondeterministic, meaning that multiple
0047 // transitions can occur from any (state, action) pair. The generated automaton
0048 // is determinized, meaning that is executes in O(k) time where k is the input
0049 // sequence length.
0050 //
0051 // In addition to a generated automaton that determines if a sequence of inputs
0052 // is accepted or not, a table is emitted that allows determining a plausible
0053 // sequence of states traversed to accept that input.
0054 class GenericAutomaton {
0055   // Name of a class that inherits from Transition. All records inheriting from
0056   // this class will be considered when constructing the automaton.
0057   string TransitionClass;
0058 
0059   // Names of fields within TransitionClass that define the action symbol. This
0060   // defines the action as an N-tuple.
0061   //
0062   // Each symbol field can be of class, int, string or code type.
0063   //   If the type of a field is a class, the Record's name is used verbatim
0064   //     in C++ and the class name is used as the C++ type name.
0065   //   If the type of a field is a string, code or int, that is also used
0066   //     verbatim in C++.
0067   //
0068   // To override the C++ type name for field F, define a field called TypeOf_F.
0069   // This should be a string that will be used verbatim in C++.
0070   //
0071   // As an example, to define a 2-tuple with an enum and a string, one might:
0072   //   def MyTransition : Transition {
0073   //     MyEnum S1;
0074   //     int S2;
0075   //   }
0076   //   def MyAutomaton : GenericAutomaton }{
0077   //     let TransitionClass = "Transition";
0078   //     let SymbolFields = ["S1", "S2"];
0079   //     let TypeOf_S1 = "MyEnumInCxxKind";
0080   //   }
0081   list<string> SymbolFields;
0082 }
0083 
0084 // All transitions inherit from Transition.
0085 class Transition {
0086   // A transition S' = T(S) is valid if, for every set bit in NewState, the
0087   // corresponding bit in S is clear. That is:
0088   //   def T(S):
0089   //     S' = S | NewState
0090   //     return S' if S' != S else Failure
0091   //
0092   // The automaton generator uses this property to crawl the set of possible
0093   // transitions from a starting state of 0b0.
0094   bits<32> NewState;
0095 }