Sean Silva | 1b60018 | 2013-01-07 02:43:44 +0000 | [diff] [blame] | 1 | =========================== |
| 2 | TableGen Language Reference |
| 3 | =========================== |
| 4 | |
Sean Silva | 1b60018 | 2013-01-07 02:43:44 +0000 | [diff] [blame] | 5 | .. contents:: |
| 6 | :local: |
| 7 | |
| 8 | .. warning:: |
| 9 | This document is extremely rough. If you find something lacking, please |
Tanya Lattner | 0d28f80 | 2015-08-05 03:51:17 +0000 | [diff] [blame] | 10 | fix it, file a documentation bug, or ask about it on llvm-dev. |
Sean Silva | 1b60018 | 2013-01-07 02:43:44 +0000 | [diff] [blame] | 11 | |
| 12 | Introduction |
| 13 | ============ |
| 14 | |
| 15 | This document is meant to be a normative spec about the TableGen language |
| 16 | in and of itself (i.e. how to understand a given construct in terms of how |
| 17 | it affects the final set of records represented by the TableGen file). If |
| 18 | you are unsure if this document is really what you are looking for, please |
Sean Silva | 397ee6e | 2014-04-07 22:46:40 +0000 | [diff] [blame] | 19 | read the :doc:`introduction to TableGen <index>` first. |
Sean Silva | 1b60018 | 2013-01-07 02:43:44 +0000 | [diff] [blame] | 20 | |
Renato Golin | 33f973a | 2014-04-01 09:51:49 +0000 | [diff] [blame] | 21 | Notation |
| 22 | ======== |
Sean Silva | 1b60018 | 2013-01-07 02:43:44 +0000 | [diff] [blame] | 23 | |
Renato Golin | 33f973a | 2014-04-01 09:51:49 +0000 | [diff] [blame] | 24 | The lexical and syntax notation used here is intended to imitate |
| 25 | `Python's`_. In particular, for lexical definitions, the productions |
| 26 | operate at the character level and there is no implied whitespace between |
| 27 | elements. The syntax definitions operate at the token level, so there is |
| 28 | implied whitespace between tokens. |
Sean Silva | 1b60018 | 2013-01-07 02:43:44 +0000 | [diff] [blame] | 29 | |
Renato Golin | 33f973a | 2014-04-01 09:51:49 +0000 | [diff] [blame] | 30 | .. _`Python's`: http://docs.python.org/py3k/reference/introduction.html#notation |
Sean Silva | 1b60018 | 2013-01-07 02:43:44 +0000 | [diff] [blame] | 31 | |
Renato Golin | 33f973a | 2014-04-01 09:51:49 +0000 | [diff] [blame] | 32 | Lexical Analysis |
| 33 | ================ |
Sean Silva | 1b60018 | 2013-01-07 02:43:44 +0000 | [diff] [blame] | 34 | |
Renato Golin | 33f973a | 2014-04-01 09:51:49 +0000 | [diff] [blame] | 35 | TableGen supports BCPL (``// ...``) and nestable C-style (``/* ... */``) |
| 36 | comments. |
Sean Silva | 1b60018 | 2013-01-07 02:43:44 +0000 | [diff] [blame] | 37 | |
Renato Golin | 33f973a | 2014-04-01 09:51:49 +0000 | [diff] [blame] | 38 | The following is a listing of the basic punctuation tokens:: |
Sean Silva | 1b60018 | 2013-01-07 02:43:44 +0000 | [diff] [blame] | 39 | |
Renato Golin | 33f973a | 2014-04-01 09:51:49 +0000 | [diff] [blame] | 40 | - + [ ] { } ( ) < > : ; . = ? # |
Sean Silva | 1b60018 | 2013-01-07 02:43:44 +0000 | [diff] [blame] | 41 | |
Renato Golin | 33f973a | 2014-04-01 09:51:49 +0000 | [diff] [blame] | 42 | Numeric literals take one of the following forms: |
Sean Silva | 1b60018 | 2013-01-07 02:43:44 +0000 | [diff] [blame] | 43 | |
Renato Golin | 33f973a | 2014-04-01 09:51:49 +0000 | [diff] [blame] | 44 | .. TableGen actually will lex some pretty strange sequences an interpret |
| 45 | them as numbers. What is shown here is an attempt to approximate what it |
| 46 | "should" accept. |
Sean Silva | 1b60018 | 2013-01-07 02:43:44 +0000 | [diff] [blame] | 47 | |
Renato Golin | 33f973a | 2014-04-01 09:51:49 +0000 | [diff] [blame] | 48 | .. productionlist:: |
| 49 | TokInteger: `DecimalInteger` | `HexInteger` | `BinInteger` |
| 50 | DecimalInteger: ["+" | "-"] ("0"..."9")+ |
| 51 | HexInteger: "0x" ("0"..."9" | "a"..."f" | "A"..."F")+ |
| 52 | BinInteger: "0b" ("0" | "1")+ |
Sean Silva | 1b60018 | 2013-01-07 02:43:44 +0000 | [diff] [blame] | 53 | |
Renato Golin | 33f973a | 2014-04-01 09:51:49 +0000 | [diff] [blame] | 54 | One aspect to note is that the :token:`DecimalInteger` token *includes* the |
| 55 | ``+`` or ``-``, as opposed to having ``+`` and ``-`` be unary operators as |
| 56 | most languages do. |
Sean Silva | 1b60018 | 2013-01-07 02:43:44 +0000 | [diff] [blame] | 57 | |
Pete Cooper | 9b90dc7 | 2014-08-07 05:47:13 +0000 | [diff] [blame] | 58 | Also note that :token:`BinInteger` creates a value of type ``bits<n>`` |
| 59 | (where ``n`` is the number of bits). This will implicitly convert to |
| 60 | integers when needed. |
| 61 | |
Renato Golin | 33f973a | 2014-04-01 09:51:49 +0000 | [diff] [blame] | 62 | TableGen has identifier-like tokens: |
Sean Silva | 1b60018 | 2013-01-07 02:43:44 +0000 | [diff] [blame] | 63 | |
Renato Golin | 33f973a | 2014-04-01 09:51:49 +0000 | [diff] [blame] | 64 | .. productionlist:: |
| 65 | ualpha: "a"..."z" | "A"..."Z" | "_" |
| 66 | TokIdentifier: ("0"..."9")* `ualpha` (`ualpha` | "0"..."9")* |
| 67 | TokVarName: "$" `ualpha` (`ualpha` | "0"..."9")* |
Sean Silva | 1b60018 | 2013-01-07 02:43:44 +0000 | [diff] [blame] | 68 | |
Renato Golin | 33f973a | 2014-04-01 09:51:49 +0000 | [diff] [blame] | 69 | Note that unlike most languages, TableGen allows :token:`TokIdentifier` to |
| 70 | begin with a number. In case of ambiguity, a token will be interpreted as a |
| 71 | numeric literal rather than an identifier. |
Sean Silva | 1b60018 | 2013-01-07 02:43:44 +0000 | [diff] [blame] | 72 | |
Renato Golin | 33f973a | 2014-04-01 09:51:49 +0000 | [diff] [blame] | 73 | TableGen also has two string-like literals: |
Sean Silva | 1b60018 | 2013-01-07 02:43:44 +0000 | [diff] [blame] | 74 | |
Renato Golin | 33f973a | 2014-04-01 09:51:49 +0000 | [diff] [blame] | 75 | .. productionlist:: |
| 76 | TokString: '"' <non-'"' characters and C-like escapes> '"' |
| 77 | TokCodeFragment: "[{" <shortest text not containing "}]"> "}]" |
Sean Silva | 1b60018 | 2013-01-07 02:43:44 +0000 | [diff] [blame] | 78 | |
Renato Golin | 33f973a | 2014-04-01 09:51:49 +0000 | [diff] [blame] | 79 | :token:`TokCodeFragment` is essentially a multiline string literal |
| 80 | delimited by ``[{`` and ``}]``. |
Sean Silva | cc37335 | 2014-02-09 02:43:50 +0000 | [diff] [blame] | 81 | |
Renato Golin | 33f973a | 2014-04-01 09:51:49 +0000 | [diff] [blame] | 82 | .. note:: |
| 83 | The current implementation accepts the following C-like escapes:: |
Sean Silva | 543fd7f | 2013-01-09 02:20:30 +0000 | [diff] [blame] | 84 | |
Renato Golin | 33f973a | 2014-04-01 09:51:49 +0000 | [diff] [blame] | 85 | \\ \' \" \t \n |
Sean Silva | 543fd7f | 2013-01-09 02:20:30 +0000 | [diff] [blame] | 86 | |
Renato Golin | 33f973a | 2014-04-01 09:51:49 +0000 | [diff] [blame] | 87 | TableGen also has the following keywords:: |
Sean Silva | 1b60018 | 2013-01-07 02:43:44 +0000 | [diff] [blame] | 88 | |
Renato Golin | 33f973a | 2014-04-01 09:51:49 +0000 | [diff] [blame] | 89 | bit bits class code dag |
| 90 | def foreach defm field in |
| 91 | int let list multiclass string |
Sean Silva | 1b60018 | 2013-01-07 02:43:44 +0000 | [diff] [blame] | 92 | |
Renato Golin | 33f973a | 2014-04-01 09:51:49 +0000 | [diff] [blame] | 93 | TableGen also has "bang operators" which have a |
| 94 | wide variety of meanings: |
Sean Silva | 1b60018 | 2013-01-07 02:43:44 +0000 | [diff] [blame] | 95 | |
Renato Golin | 33f973a | 2014-04-01 09:51:49 +0000 | [diff] [blame] | 96 | .. productionlist:: |
| 97 | BangOperator: one of |
| 98 | :!eq !if !head !tail !con |
Joerg Sonnenberger | 0a53727 | 2014-09-03 13:17:03 +0000 | [diff] [blame] | 99 | :!add !shl !sra !srl !and |
Matt Arsenault | 1c8d933 | 2016-11-15 06:49:28 +0000 | [diff] [blame] | 100 | :!or !empty !subst !foreach !strconcat |
Nicolai Haehnle | d34f684 | 2018-03-06 13:49:16 +0000 | [diff] [blame] | 101 | :!cast !listconcat !size !foldl |
Nicolai Haehnle | b537605 | 2018-03-09 12:24:06 +0000 | [diff] [blame] | 102 | :!isa |
Matt Arsenault | 1c8d933 | 2016-11-15 06:49:28 +0000 | [diff] [blame] | 103 | |
Sean Silva | 1b60018 | 2013-01-07 02:43:44 +0000 | [diff] [blame] | 104 | |
Renato Golin | 33f973a | 2014-04-01 09:51:49 +0000 | [diff] [blame] | 105 | Syntax |
| 106 | ====== |
Sean Silva | 1b60018 | 2013-01-07 02:43:44 +0000 | [diff] [blame] | 107 | |
Renato Golin | 33f973a | 2014-04-01 09:51:49 +0000 | [diff] [blame] | 108 | TableGen has an ``include`` mechanism. It does not play a role in the |
| 109 | syntax per se, since it is lexically replaced with the contents of the |
| 110 | included file. |
Sean Silva | 1b60018 | 2013-01-07 02:43:44 +0000 | [diff] [blame] | 111 | |
Renato Golin | 33f973a | 2014-04-01 09:51:49 +0000 | [diff] [blame] | 112 | .. productionlist:: |
| 113 | IncludeDirective: "include" `TokString` |
Sean Silva | 1b60018 | 2013-01-07 02:43:44 +0000 | [diff] [blame] | 114 | |
Renato Golin | 33f973a | 2014-04-01 09:51:49 +0000 | [diff] [blame] | 115 | TableGen's top-level production consists of "objects". |
Sean Silva | 1b60018 | 2013-01-07 02:43:44 +0000 | [diff] [blame] | 116 | |
Renato Golin | 33f973a | 2014-04-01 09:51:49 +0000 | [diff] [blame] | 117 | .. productionlist:: |
| 118 | TableGenFile: `Object`* |
Nicolai Haehnle | fcd6525 | 2018-03-09 12:24:42 +0000 | [diff] [blame^] | 119 | Object: `Class` | `Def` | `Defm` | `Defset` | `Let` | `MultiClass` | |
| 120 | `Foreach` |
Sean Silva | 1b60018 | 2013-01-07 02:43:44 +0000 | [diff] [blame] | 121 | |
Renato Golin | 33f973a | 2014-04-01 09:51:49 +0000 | [diff] [blame] | 122 | ``class``\es |
| 123 | ------------ |
Sean Silva | 1b60018 | 2013-01-07 02:43:44 +0000 | [diff] [blame] | 124 | |
Renato Golin | 33f973a | 2014-04-01 09:51:49 +0000 | [diff] [blame] | 125 | .. productionlist:: |
| 126 | Class: "class" `TokIdentifier` [`TemplateArgList`] `ObjectBody` |
Sean Silva | 1b60018 | 2013-01-07 02:43:44 +0000 | [diff] [blame] | 127 | |
Renato Golin | 33f973a | 2014-04-01 09:51:49 +0000 | [diff] [blame] | 128 | A ``class`` declaration creates a record which other records can inherit |
| 129 | from. A class can be parametrized by a list of "template arguments", whose |
| 130 | values can be used in the class body. |
Sean Silva | 1b60018 | 2013-01-07 02:43:44 +0000 | [diff] [blame] | 131 | |
Renato Golin | 33f973a | 2014-04-01 09:51:49 +0000 | [diff] [blame] | 132 | A given class can only be defined once. A ``class`` declaration is |
| 133 | considered to define the class if any of the following is true: |
Sean Silva | 1b60018 | 2013-01-07 02:43:44 +0000 | [diff] [blame] | 134 | |
Renato Golin | 33f973a | 2014-04-01 09:51:49 +0000 | [diff] [blame] | 135 | .. break ObjectBody into its consituents so that they are present here? |
Sean Silva | 1b60018 | 2013-01-07 02:43:44 +0000 | [diff] [blame] | 136 | |
Renato Golin | 33f973a | 2014-04-01 09:51:49 +0000 | [diff] [blame] | 137 | #. The :token:`TemplateArgList` is present. |
| 138 | #. The :token:`Body` in the :token:`ObjectBody` is present and is not empty. |
| 139 | #. The :token:`BaseClassList` in the :token:`ObjectBody` is present. |
Sean Silva | 1b60018 | 2013-01-07 02:43:44 +0000 | [diff] [blame] | 140 | |
Renato Golin | 33f973a | 2014-04-01 09:51:49 +0000 | [diff] [blame] | 141 | You can declare an empty class by giving and empty :token:`TemplateArgList` |
| 142 | and an empty :token:`ObjectBody`. This can serve as a restricted form of |
| 143 | forward declaration: note that records deriving from the forward-declared |
| 144 | class will inherit no fields from it since the record expansion is done |
| 145 | when the record is parsed. |
Sean Silva | 1b60018 | 2013-01-07 02:43:44 +0000 | [diff] [blame] | 146 | |
Renato Golin | 33f973a | 2014-04-01 09:51:49 +0000 | [diff] [blame] | 147 | .. productionlist:: |
| 148 | TemplateArgList: "<" `Declaration` ("," `Declaration`)* ">" |
Sean Silva | 1b60018 | 2013-01-07 02:43:44 +0000 | [diff] [blame] | 149 | |
Renato Golin | 33f973a | 2014-04-01 09:51:49 +0000 | [diff] [blame] | 150 | Declarations |
| 151 | ------------ |
Sean Silva | 1b60018 | 2013-01-07 02:43:44 +0000 | [diff] [blame] | 152 | |
Renato Golin | 33f973a | 2014-04-01 09:51:49 +0000 | [diff] [blame] | 153 | .. Omitting mention of arcane "field" prefix to discourage its use. |
Sean Silva | 1b60018 | 2013-01-07 02:43:44 +0000 | [diff] [blame] | 154 | |
Renato Golin | 33f973a | 2014-04-01 09:51:49 +0000 | [diff] [blame] | 155 | The declaration syntax is pretty much what you would expect as a C++ |
| 156 | programmer. |
Sean Silva | 1b60018 | 2013-01-07 02:43:44 +0000 | [diff] [blame] | 157 | |
Renato Golin | 33f973a | 2014-04-01 09:51:49 +0000 | [diff] [blame] | 158 | .. productionlist:: |
| 159 | Declaration: `Type` `TokIdentifier` ["=" `Value`] |
Sean Silva | 1b60018 | 2013-01-07 02:43:44 +0000 | [diff] [blame] | 160 | |
Sylvestre Ledru | 7d54050 | 2016-07-02 19:28:40 +0000 | [diff] [blame] | 161 | It assigns the value to the identifier. |
Sean Silva | 1b60018 | 2013-01-07 02:43:44 +0000 | [diff] [blame] | 162 | |
Renato Golin | 33f973a | 2014-04-01 09:51:49 +0000 | [diff] [blame] | 163 | Types |
| 164 | ----- |
Sean Silva | 1b60018 | 2013-01-07 02:43:44 +0000 | [diff] [blame] | 165 | |
Renato Golin | 33f973a | 2014-04-01 09:51:49 +0000 | [diff] [blame] | 166 | .. productionlist:: |
| 167 | Type: "string" | "code" | "bit" | "int" | "dag" |
| 168 | :| "bits" "<" `TokInteger` ">" |
| 169 | :| "list" "<" `Type` ">" |
| 170 | :| `ClassID` |
| 171 | ClassID: `TokIdentifier` |
Sean Silva | 1b60018 | 2013-01-07 02:43:44 +0000 | [diff] [blame] | 172 | |
Renato Golin | 33f973a | 2014-04-01 09:51:49 +0000 | [diff] [blame] | 173 | Both ``string`` and ``code`` correspond to the string type; the difference |
| 174 | is purely to indicate programmer intention. |
Renato Golin | ca10564 | 2014-03-20 16:08:34 +0000 | [diff] [blame] | 175 | |
Renato Golin | 33f973a | 2014-04-01 09:51:49 +0000 | [diff] [blame] | 176 | The :token:`ClassID` must identify a class that has been previously |
| 177 | declared or defined. |
Renato Golin | ca10564 | 2014-03-20 16:08:34 +0000 | [diff] [blame] | 178 | |
Renato Golin | 33f973a | 2014-04-01 09:51:49 +0000 | [diff] [blame] | 179 | Values |
| 180 | ------ |
Renato Golin | ca10564 | 2014-03-20 16:08:34 +0000 | [diff] [blame] | 181 | |
Renato Golin | 33f973a | 2014-04-01 09:51:49 +0000 | [diff] [blame] | 182 | .. productionlist:: |
| 183 | Value: `SimpleValue` `ValueSuffix`* |
| 184 | ValueSuffix: "{" `RangeList` "}" |
| 185 | :| "[" `RangeList` "]" |
| 186 | :| "." `TokIdentifier` |
| 187 | RangeList: `RangePiece` ("," `RangePiece`)* |
| 188 | RangePiece: `TokInteger` |
| 189 | :| `TokInteger` "-" `TokInteger` |
| 190 | :| `TokInteger` `TokInteger` |
Renato Golin | ca10564 | 2014-03-20 16:08:34 +0000 | [diff] [blame] | 191 | |
Renato Golin | 33f973a | 2014-04-01 09:51:49 +0000 | [diff] [blame] | 192 | The peculiar last form of :token:`RangePiece` is due to the fact that the |
| 193 | "``-``" is included in the :token:`TokInteger`, hence ``1-5`` gets lexed as |
| 194 | two consecutive :token:`TokInteger`'s, with values ``1`` and ``-5``, |
| 195 | instead of "1", "-", and "5". |
| 196 | The :token:`RangeList` can be thought of as specifying "list slice" in some |
| 197 | contexts. |
Renato Golin | ca10564 | 2014-03-20 16:08:34 +0000 | [diff] [blame] | 198 | |
Renato Golin | ca10564 | 2014-03-20 16:08:34 +0000 | [diff] [blame] | 199 | |
Renato Golin | 33f973a | 2014-04-01 09:51:49 +0000 | [diff] [blame] | 200 | :token:`SimpleValue` has a number of forms: |
Renato Golin | ca10564 | 2014-03-20 16:08:34 +0000 | [diff] [blame] | 201 | |
Renato Golin | ca10564 | 2014-03-20 16:08:34 +0000 | [diff] [blame] | 202 | |
Renato Golin | 33f973a | 2014-04-01 09:51:49 +0000 | [diff] [blame] | 203 | .. productionlist:: |
| 204 | SimpleValue: `TokIdentifier` |
Renato Golin | ca10564 | 2014-03-20 16:08:34 +0000 | [diff] [blame] | 205 | |
Renato Golin | 33f973a | 2014-04-01 09:51:49 +0000 | [diff] [blame] | 206 | The value will be the variable referenced by the identifier. It can be one |
| 207 | of: |
Renato Golin | ca10564 | 2014-03-20 16:08:34 +0000 | [diff] [blame] | 208 | |
Renato Golin | 33f973a | 2014-04-01 09:51:49 +0000 | [diff] [blame] | 209 | .. The code for this is exceptionally abstruse. These examples are a |
| 210 | best-effort attempt. |
Renato Golin | ca10564 | 2014-03-20 16:08:34 +0000 | [diff] [blame] | 211 | |
Renato Golin | 33f973a | 2014-04-01 09:51:49 +0000 | [diff] [blame] | 212 | * name of a ``def``, such as the use of ``Bar`` in:: |
Renato Golin | ca10564 | 2014-03-20 16:08:34 +0000 | [diff] [blame] | 213 | |
Renato Golin | 33f973a | 2014-04-01 09:51:49 +0000 | [diff] [blame] | 214 | def Bar : SomeClass { |
| 215 | int X = 5; |
| 216 | } |
Renato Golin | ca10564 | 2014-03-20 16:08:34 +0000 | [diff] [blame] | 217 | |
Renato Golin | 33f973a | 2014-04-01 09:51:49 +0000 | [diff] [blame] | 218 | def Foo { |
| 219 | SomeClass Baz = Bar; |
| 220 | } |
Renato Golin | ca10564 | 2014-03-20 16:08:34 +0000 | [diff] [blame] | 221 | |
Renato Golin | 33f973a | 2014-04-01 09:51:49 +0000 | [diff] [blame] | 222 | * value local to a ``def``, such as the use of ``Bar`` in:: |
Renato Golin | ca10564 | 2014-03-20 16:08:34 +0000 | [diff] [blame] | 223 | |
Renato Golin | 33f973a | 2014-04-01 09:51:49 +0000 | [diff] [blame] | 224 | def Foo { |
| 225 | int Bar = 5; |
| 226 | int Baz = Bar; |
| 227 | } |
Renato Golin | ca10564 | 2014-03-20 16:08:34 +0000 | [diff] [blame] | 228 | |
Renato Golin | 33f973a | 2014-04-01 09:51:49 +0000 | [diff] [blame] | 229 | * a template arg of a ``class``, such as the use of ``Bar`` in:: |
Renato Golin | ca10564 | 2014-03-20 16:08:34 +0000 | [diff] [blame] | 230 | |
Renato Golin | 33f973a | 2014-04-01 09:51:49 +0000 | [diff] [blame] | 231 | class Foo<int Bar> { |
| 232 | int Baz = Bar; |
| 233 | } |
Renato Golin | ca10564 | 2014-03-20 16:08:34 +0000 | [diff] [blame] | 234 | |
Renato Golin | 33f973a | 2014-04-01 09:51:49 +0000 | [diff] [blame] | 235 | * value local to a ``multiclass``, such as the use of ``Bar`` in:: |
Renato Golin | ca10564 | 2014-03-20 16:08:34 +0000 | [diff] [blame] | 236 | |
Renato Golin | 33f973a | 2014-04-01 09:51:49 +0000 | [diff] [blame] | 237 | multiclass Foo { |
| 238 | int Bar = 5; |
| 239 | int Baz = Bar; |
| 240 | } |
Renato Golin | ca10564 | 2014-03-20 16:08:34 +0000 | [diff] [blame] | 241 | |
Renato Golin | 33f973a | 2014-04-01 09:51:49 +0000 | [diff] [blame] | 242 | * a template arg to a ``multiclass``, such as the use of ``Bar`` in:: |
Renato Golin | ca10564 | 2014-03-20 16:08:34 +0000 | [diff] [blame] | 243 | |
Renato Golin | 33f973a | 2014-04-01 09:51:49 +0000 | [diff] [blame] | 244 | multiclass Foo<int Bar> { |
| 245 | int Baz = Bar; |
| 246 | } |
Renato Golin | ca10564 | 2014-03-20 16:08:34 +0000 | [diff] [blame] | 247 | |
Renato Golin | 33f973a | 2014-04-01 09:51:49 +0000 | [diff] [blame] | 248 | .. productionlist:: |
| 249 | SimpleValue: `TokInteger` |
Renato Golin | ca10564 | 2014-03-20 16:08:34 +0000 | [diff] [blame] | 250 | |
Renato Golin | 33f973a | 2014-04-01 09:51:49 +0000 | [diff] [blame] | 251 | This represents the numeric value of the integer. |
Renato Golin | ca10564 | 2014-03-20 16:08:34 +0000 | [diff] [blame] | 252 | |
Renato Golin | 33f973a | 2014-04-01 09:51:49 +0000 | [diff] [blame] | 253 | .. productionlist:: |
| 254 | SimpleValue: `TokString`+ |
Renato Golin | ca10564 | 2014-03-20 16:08:34 +0000 | [diff] [blame] | 255 | |
Renato Golin | 33f973a | 2014-04-01 09:51:49 +0000 | [diff] [blame] | 256 | Multiple adjacent string literals are concatenated like in C/C++. The value |
| 257 | is the concatenation of the strings. |
Renato Golin | ca10564 | 2014-03-20 16:08:34 +0000 | [diff] [blame] | 258 | |
Renato Golin | 33f973a | 2014-04-01 09:51:49 +0000 | [diff] [blame] | 259 | .. productionlist:: |
| 260 | SimpleValue: `TokCodeFragment` |
Renato Golin | ca10564 | 2014-03-20 16:08:34 +0000 | [diff] [blame] | 261 | |
Renato Golin | 33f973a | 2014-04-01 09:51:49 +0000 | [diff] [blame] | 262 | The value is the string value of the code fragment. |
Renato Golin | ca10564 | 2014-03-20 16:08:34 +0000 | [diff] [blame] | 263 | |
Renato Golin | 33f973a | 2014-04-01 09:51:49 +0000 | [diff] [blame] | 264 | .. productionlist:: |
| 265 | SimpleValue: "?" |
Renato Golin | ca10564 | 2014-03-20 16:08:34 +0000 | [diff] [blame] | 266 | |
Renato Golin | 33f973a | 2014-04-01 09:51:49 +0000 | [diff] [blame] | 267 | ``?`` represents an "unset" initializer. |
Sean Silva | 1b60018 | 2013-01-07 02:43:44 +0000 | [diff] [blame] | 268 | |
Renato Golin | 33f973a | 2014-04-01 09:51:49 +0000 | [diff] [blame] | 269 | .. productionlist:: |
| 270 | SimpleValue: "{" `ValueList` "}" |
| 271 | ValueList: [`ValueListNE`] |
| 272 | ValueListNE: `Value` ("," `Value`)* |
Sean Silva | 1b60018 | 2013-01-07 02:43:44 +0000 | [diff] [blame] | 273 | |
Renato Golin | 33f973a | 2014-04-01 09:51:49 +0000 | [diff] [blame] | 274 | This represents a sequence of bits, as would be used to initialize a |
| 275 | ``bits<n>`` field (where ``n`` is the number of bits). |
Sean Silva | 1b60018 | 2013-01-07 02:43:44 +0000 | [diff] [blame] | 276 | |
Renato Golin | 33f973a | 2014-04-01 09:51:49 +0000 | [diff] [blame] | 277 | .. productionlist:: |
| 278 | SimpleValue: `ClassID` "<" `ValueListNE` ">" |
Sean Silva | 1b60018 | 2013-01-07 02:43:44 +0000 | [diff] [blame] | 279 | |
Renato Golin | 33f973a | 2014-04-01 09:51:49 +0000 | [diff] [blame] | 280 | This generates a new anonymous record definition (as would be created by an |
| 281 | unnamed ``def`` inheriting from the given class with the given template |
| 282 | arguments) and the value is the value of that record definition. |
Sean Silva | 1b60018 | 2013-01-07 02:43:44 +0000 | [diff] [blame] | 283 | |
Renato Golin | 33f973a | 2014-04-01 09:51:49 +0000 | [diff] [blame] | 284 | .. productionlist:: |
| 285 | SimpleValue: "[" `ValueList` "]" ["<" `Type` ">"] |
Sean Silva | 1b60018 | 2013-01-07 02:43:44 +0000 | [diff] [blame] | 286 | |
Renato Golin | 33f973a | 2014-04-01 09:51:49 +0000 | [diff] [blame] | 287 | A list initializer. The optional :token:`Type` can be used to indicate a |
| 288 | specific element type, otherwise the element type will be deduced from the |
| 289 | given values. |
Sean Silva | 1b60018 | 2013-01-07 02:43:44 +0000 | [diff] [blame] | 290 | |
Renato Golin | 33f973a | 2014-04-01 09:51:49 +0000 | [diff] [blame] | 291 | .. The initial `DagArg` of the dag must start with an identifier or |
| 292 | !cast, but this is more of an implementation detail and so for now just |
| 293 | leave it out. |
Sean Silva | 1b60018 | 2013-01-07 02:43:44 +0000 | [diff] [blame] | 294 | |
Renato Golin | 33f973a | 2014-04-01 09:51:49 +0000 | [diff] [blame] | 295 | .. productionlist:: |
| 296 | SimpleValue: "(" `DagArg` `DagArgList` ")" |
| 297 | DagArgList: `DagArg` ("," `DagArg`)* |
| 298 | DagArg: `Value` [":" `TokVarName`] | `TokVarName` |
Sean Silva | 1b60018 | 2013-01-07 02:43:44 +0000 | [diff] [blame] | 299 | |
Renato Golin | 33f973a | 2014-04-01 09:51:49 +0000 | [diff] [blame] | 300 | The initial :token:`DagArg` is called the "operator" of the dag. |
Sean Silva | 1b60018 | 2013-01-07 02:43:44 +0000 | [diff] [blame] | 301 | |
Renato Golin | 33f973a | 2014-04-01 09:51:49 +0000 | [diff] [blame] | 302 | .. productionlist:: |
| 303 | SimpleValue: `BangOperator` ["<" `Type` ">"] "(" `ValueListNE` ")" |
Sean Silva | 1b60018 | 2013-01-07 02:43:44 +0000 | [diff] [blame] | 304 | |
Renato Golin | 33f973a | 2014-04-01 09:51:49 +0000 | [diff] [blame] | 305 | Bodies |
| 306 | ------ |
Sean Silva | 1b60018 | 2013-01-07 02:43:44 +0000 | [diff] [blame] | 307 | |
Renato Golin | 33f973a | 2014-04-01 09:51:49 +0000 | [diff] [blame] | 308 | .. productionlist:: |
| 309 | ObjectBody: `BaseClassList` `Body` |
| 310 | BaseClassList: [":" `BaseClassListNE`] |
| 311 | BaseClassListNE: `SubClassRef` ("," `SubClassRef`)* |
| 312 | SubClassRef: (`ClassID` | `MultiClassID`) ["<" `ValueList` ">"] |
| 313 | DefmID: `TokIdentifier` |
Sean Silva | 1b60018 | 2013-01-07 02:43:44 +0000 | [diff] [blame] | 314 | |
Renato Golin | 33f973a | 2014-04-01 09:51:49 +0000 | [diff] [blame] | 315 | The version with the :token:`MultiClassID` is only valid in the |
| 316 | :token:`BaseClassList` of a ``defm``. |
| 317 | The :token:`MultiClassID` should be the name of a ``multiclass``. |
Sean Silva | 1b60018 | 2013-01-07 02:43:44 +0000 | [diff] [blame] | 318 | |
Renato Golin | 33f973a | 2014-04-01 09:51:49 +0000 | [diff] [blame] | 319 | .. put this somewhere else |
Sean Silva | 1b60018 | 2013-01-07 02:43:44 +0000 | [diff] [blame] | 320 | |
Renato Golin | 33f973a | 2014-04-01 09:51:49 +0000 | [diff] [blame] | 321 | It is after parsing the base class list that the "let stack" is applied. |
Sean Silva | 1b60018 | 2013-01-07 02:43:44 +0000 | [diff] [blame] | 322 | |
Renato Golin | 33f973a | 2014-04-01 09:51:49 +0000 | [diff] [blame] | 323 | .. productionlist:: |
| 324 | Body: ";" | "{" BodyList "}" |
| 325 | BodyList: BodyItem* |
| 326 | BodyItem: `Declaration` ";" |
| 327 | :| "let" `TokIdentifier` [`RangeList`] "=" `Value` ";" |
Sean Silva | 1b60018 | 2013-01-07 02:43:44 +0000 | [diff] [blame] | 328 | |
Renato Golin | 33f973a | 2014-04-01 09:51:49 +0000 | [diff] [blame] | 329 | The ``let`` form allows overriding the value of an inherited field. |
Sean Silva | 1b60018 | 2013-01-07 02:43:44 +0000 | [diff] [blame] | 330 | |
Renato Golin | 33f973a | 2014-04-01 09:51:49 +0000 | [diff] [blame] | 331 | ``def`` |
| 332 | ------- |
Sean Silva | 1b60018 | 2013-01-07 02:43:44 +0000 | [diff] [blame] | 333 | |
Renato Golin | 33f973a | 2014-04-01 09:51:49 +0000 | [diff] [blame] | 334 | .. TODO:: |
| 335 | There can be pastes in the names here, like ``#NAME#``. Look into that |
| 336 | and document it (it boils down to ParseIDValue with IDParseMode == |
| 337 | ParseNameMode). ParseObjectName calls into the general ParseValue, with |
| 338 | the only different from "arbitrary expression parsing" being IDParseMode |
| 339 | == Mode. |
Sean Silva | 1b60018 | 2013-01-07 02:43:44 +0000 | [diff] [blame] | 340 | |
Renato Golin | 33f973a | 2014-04-01 09:51:49 +0000 | [diff] [blame] | 341 | .. productionlist:: |
| 342 | Def: "def" `TokIdentifier` `ObjectBody` |
Sean Silva | 1b60018 | 2013-01-07 02:43:44 +0000 | [diff] [blame] | 343 | |
Renato Golin | 33f973a | 2014-04-01 09:51:49 +0000 | [diff] [blame] | 344 | Defines a record whose name is given by the :token:`TokIdentifier`. The |
| 345 | fields of the record are inherited from the base classes and defined in the |
| 346 | body. |
Sean Silva | 1b60018 | 2013-01-07 02:43:44 +0000 | [diff] [blame] | 347 | |
Renato Golin | 33f973a | 2014-04-01 09:51:49 +0000 | [diff] [blame] | 348 | Special handling occurs if this ``def`` appears inside a ``multiclass`` or |
| 349 | a ``foreach``. |
Sean Silva | 1b60018 | 2013-01-07 02:43:44 +0000 | [diff] [blame] | 350 | |
Renato Golin | 33f973a | 2014-04-01 09:51:49 +0000 | [diff] [blame] | 351 | ``defm`` |
| 352 | -------- |
Sean Silva | 1b60018 | 2013-01-07 02:43:44 +0000 | [diff] [blame] | 353 | |
Renato Golin | 33f973a | 2014-04-01 09:51:49 +0000 | [diff] [blame] | 354 | .. productionlist:: |
| 355 | Defm: "defm" `TokIdentifier` ":" `BaseClassListNE` ";" |
Sean Silva | 1b60018 | 2013-01-07 02:43:44 +0000 | [diff] [blame] | 356 | |
Renato Golin | 33f973a | 2014-04-01 09:51:49 +0000 | [diff] [blame] | 357 | Note that in the :token:`BaseClassList`, all of the ``multiclass``'s must |
| 358 | precede any ``class``'s that appear. |
Sean Silva | 1b60018 | 2013-01-07 02:43:44 +0000 | [diff] [blame] | 359 | |
Nicolai Haehnle | fcd6525 | 2018-03-09 12:24:42 +0000 | [diff] [blame^] | 360 | ``defset`` |
| 361 | ---------- |
| 362 | .. productionlist:: |
| 363 | Defset: "defset" `Type` `TokIdentifier` "=" "{" `Object`* "}" |
| 364 | |
| 365 | All records defined inside the braces via ``def`` and ``defm`` are collected |
| 366 | in a globally accessible list of the given name (in addition to being added |
| 367 | to the global collection of records as usual). Anonymous records created inside |
| 368 | initializier expressions using the ``Class<args...>`` syntax are never collected |
| 369 | in a defset. |
| 370 | |
| 371 | The given type must be ``list<A>``, where ``A`` is some class. It is an error |
| 372 | to define a record (via ``def`` or ``defm``) inside the braces which doesn't |
| 373 | derive from ``A``. |
| 374 | |
Renato Golin | 33f973a | 2014-04-01 09:51:49 +0000 | [diff] [blame] | 375 | ``foreach`` |
| 376 | ----------- |
Sean Silva | 1b60018 | 2013-01-07 02:43:44 +0000 | [diff] [blame] | 377 | |
Renato Golin | 33f973a | 2014-04-01 09:51:49 +0000 | [diff] [blame] | 378 | .. productionlist:: |
Nicolai Haehnle | 8aa9d58 | 2018-03-09 12:24:30 +0000 | [diff] [blame] | 379 | Foreach: "foreach" `ForeachDeclaration` "in" "{" `Object`* "}" |
| 380 | :| "foreach" `ForeachDeclaration` "in" `Object` |
| 381 | ForeachDeclaration: ID "=" ( "{" `RangeList` "}" | `RangePiece` | `Value` ) |
Sean Silva | 1b60018 | 2013-01-07 02:43:44 +0000 | [diff] [blame] | 382 | |
Renato Golin | 33f973a | 2014-04-01 09:51:49 +0000 | [diff] [blame] | 383 | The value assigned to the variable in the declaration is iterated over and |
| 384 | the object or object list is reevaluated with the variable set at each |
| 385 | iterated value. |
Sean Silva | 1b60018 | 2013-01-07 02:43:44 +0000 | [diff] [blame] | 386 | |
Nicolai Haehnle | 8aa9d58 | 2018-03-09 12:24:30 +0000 | [diff] [blame] | 387 | Note that the productions involving RangeList and RangePiece have precedence |
| 388 | over the more generic value parsing based on the first token. |
| 389 | |
Renato Golin | 33f973a | 2014-04-01 09:51:49 +0000 | [diff] [blame] | 390 | Top-Level ``let`` |
| 391 | ----------------- |
Sean Silva | 1b60018 | 2013-01-07 02:43:44 +0000 | [diff] [blame] | 392 | |
Renato Golin | 33f973a | 2014-04-01 09:51:49 +0000 | [diff] [blame] | 393 | .. productionlist:: |
| 394 | Let: "let" `LetList` "in" "{" `Object`* "}" |
| 395 | :| "let" `LetList` "in" `Object` |
| 396 | LetList: `LetItem` ("," `LetItem`)* |
| 397 | LetItem: `TokIdentifier` [`RangeList`] "=" `Value` |
Sean Silva | 1b60018 | 2013-01-07 02:43:44 +0000 | [diff] [blame] | 398 | |
Renato Golin | 33f973a | 2014-04-01 09:51:49 +0000 | [diff] [blame] | 399 | This is effectively equivalent to ``let`` inside the body of a record |
| 400 | except that it applies to multiple records at a time. The bindings are |
| 401 | applied at the end of parsing the base classes of a record. |
Sean Silva | 1b60018 | 2013-01-07 02:43:44 +0000 | [diff] [blame] | 402 | |
Renato Golin | 33f973a | 2014-04-01 09:51:49 +0000 | [diff] [blame] | 403 | ``multiclass`` |
| 404 | -------------- |
Sean Silva | 1b60018 | 2013-01-07 02:43:44 +0000 | [diff] [blame] | 405 | |
Renato Golin | 33f973a | 2014-04-01 09:51:49 +0000 | [diff] [blame] | 406 | .. productionlist:: |
| 407 | MultiClass: "multiclass" `TokIdentifier` [`TemplateArgList`] |
| 408 | : [":" `BaseMultiClassList`] "{" `MultiClassObject`+ "}" |
| 409 | BaseMultiClassList: `MultiClassID` ("," `MultiClassID`)* |
| 410 | MultiClassID: `TokIdentifier` |
| 411 | MultiClassObject: `Def` | `Defm` | `Let` | `Foreach` |