blob: 9e492410b1623436f69d83dfe75ad632c2410d79 [file] [log] [blame]
Sean Silva1b600182013-01-07 02:43:44 +00001===========================
2TableGen Language Reference
3===========================
4
Sean Silva1b600182013-01-07 02:43:44 +00005.. contents::
6 :local:
7
8.. warning::
9 This document is extremely rough. If you find something lacking, please
Tanya Lattner0d28f802015-08-05 03:51:17 +000010 fix it, file a documentation bug, or ask about it on llvm-dev.
Sean Silva1b600182013-01-07 02:43:44 +000011
12Introduction
13============
14
15This document is meant to be a normative spec about the TableGen language
16in and of itself (i.e. how to understand a given construct in terms of how
17it affects the final set of records represented by the TableGen file). If
18you are unsure if this document is really what you are looking for, please
Sean Silva397ee6e2014-04-07 22:46:40 +000019read the :doc:`introduction to TableGen <index>` first.
Sean Silva1b600182013-01-07 02:43:44 +000020
Renato Golin33f973a2014-04-01 09:51:49 +000021Notation
22========
Sean Silva1b600182013-01-07 02:43:44 +000023
Renato Golin33f973a2014-04-01 09:51:49 +000024The lexical and syntax notation used here is intended to imitate
25`Python's`_. In particular, for lexical definitions, the productions
26operate at the character level and there is no implied whitespace between
27elements. The syntax definitions operate at the token level, so there is
28implied whitespace between tokens.
Sean Silva1b600182013-01-07 02:43:44 +000029
Renato Golin33f973a2014-04-01 09:51:49 +000030.. _`Python's`: http://docs.python.org/py3k/reference/introduction.html#notation
Sean Silva1b600182013-01-07 02:43:44 +000031
Renato Golin33f973a2014-04-01 09:51:49 +000032Lexical Analysis
33================
Sean Silva1b600182013-01-07 02:43:44 +000034
Renato Golin33f973a2014-04-01 09:51:49 +000035TableGen supports BCPL (``// ...``) and nestable C-style (``/* ... */``)
36comments.
Sean Silva1b600182013-01-07 02:43:44 +000037
Renato Golin33f973a2014-04-01 09:51:49 +000038The following is a listing of the basic punctuation tokens::
Sean Silva1b600182013-01-07 02:43:44 +000039
Renato Golin33f973a2014-04-01 09:51:49 +000040 - + [ ] { } ( ) < > : ; . = ? #
Sean Silva1b600182013-01-07 02:43:44 +000041
Renato Golin33f973a2014-04-01 09:51:49 +000042Numeric literals take one of the following forms:
Sean Silva1b600182013-01-07 02:43:44 +000043
Renato Golin33f973a2014-04-01 09:51:49 +000044.. 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 Silva1b600182013-01-07 02:43:44 +000047
Renato Golin33f973a2014-04-01 09:51:49 +000048.. 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 Silva1b600182013-01-07 02:43:44 +000053
Renato Golin33f973a2014-04-01 09:51:49 +000054One aspect to note is that the :token:`DecimalInteger` token *includes* the
55``+`` or ``-``, as opposed to having ``+`` and ``-`` be unary operators as
56most languages do.
Sean Silva1b600182013-01-07 02:43:44 +000057
Pete Cooper9b90dc72014-08-07 05:47:13 +000058Also note that :token:`BinInteger` creates a value of type ``bits<n>``
59(where ``n`` is the number of bits). This will implicitly convert to
60integers when needed.
61
Renato Golin33f973a2014-04-01 09:51:49 +000062TableGen has identifier-like tokens:
Sean Silva1b600182013-01-07 02:43:44 +000063
Renato Golin33f973a2014-04-01 09:51:49 +000064.. productionlist::
65 ualpha: "a"..."z" | "A"..."Z" | "_"
66 TokIdentifier: ("0"..."9")* `ualpha` (`ualpha` | "0"..."9")*
67 TokVarName: "$" `ualpha` (`ualpha` | "0"..."9")*
Sean Silva1b600182013-01-07 02:43:44 +000068
Renato Golin33f973a2014-04-01 09:51:49 +000069Note that unlike most languages, TableGen allows :token:`TokIdentifier` to
70begin with a number. In case of ambiguity, a token will be interpreted as a
71numeric literal rather than an identifier.
Sean Silva1b600182013-01-07 02:43:44 +000072
Renato Golin33f973a2014-04-01 09:51:49 +000073TableGen also has two string-like literals:
Sean Silva1b600182013-01-07 02:43:44 +000074
Renato Golin33f973a2014-04-01 09:51:49 +000075.. productionlist::
76 TokString: '"' <non-'"' characters and C-like escapes> '"'
77 TokCodeFragment: "[{" <shortest text not containing "}]"> "}]"
Sean Silva1b600182013-01-07 02:43:44 +000078
Renato Golin33f973a2014-04-01 09:51:49 +000079:token:`TokCodeFragment` is essentially a multiline string literal
80delimited by ``[{`` and ``}]``.
Sean Silvacc373352014-02-09 02:43:50 +000081
Renato Golin33f973a2014-04-01 09:51:49 +000082.. note::
83 The current implementation accepts the following C-like escapes::
Sean Silva543fd7f2013-01-09 02:20:30 +000084
Renato Golin33f973a2014-04-01 09:51:49 +000085 \\ \' \" \t \n
Sean Silva543fd7f2013-01-09 02:20:30 +000086
Renato Golin33f973a2014-04-01 09:51:49 +000087TableGen also has the following keywords::
Sean Silva1b600182013-01-07 02:43:44 +000088
Renato Golin33f973a2014-04-01 09:51:49 +000089 bit bits class code dag
90 def foreach defm field in
91 int let list multiclass string
Sean Silva1b600182013-01-07 02:43:44 +000092
Renato Golin33f973a2014-04-01 09:51:49 +000093TableGen also has "bang operators" which have a
94wide variety of meanings:
Sean Silva1b600182013-01-07 02:43:44 +000095
Renato Golin33f973a2014-04-01 09:51:49 +000096.. productionlist::
97 BangOperator: one of
98 :!eq !if !head !tail !con
Joerg Sonnenberger0a537272014-09-03 13:17:03 +000099 :!add !shl !sra !srl !and
Matt Arsenault1c8d9332016-11-15 06:49:28 +0000100 :!or !empty !subst !foreach !strconcat
Nicolai Haehnled34f6842018-03-06 13:49:16 +0000101 :!cast !listconcat !size !foldl
Nicolai Haehnleaa9ca692018-03-14 11:00:57 +0000102 :!isa !dag !le !lt !ge
103 :!gt !ne
Matt Arsenault1c8d9332016-11-15 06:49:28 +0000104
Sean Silva1b600182013-01-07 02:43:44 +0000105
Renato Golin33f973a2014-04-01 09:51:49 +0000106Syntax
107======
Sean Silva1b600182013-01-07 02:43:44 +0000108
Renato Golin33f973a2014-04-01 09:51:49 +0000109TableGen has an ``include`` mechanism. It does not play a role in the
110syntax per se, since it is lexically replaced with the contents of the
111included file.
Sean Silva1b600182013-01-07 02:43:44 +0000112
Renato Golin33f973a2014-04-01 09:51:49 +0000113.. productionlist::
114 IncludeDirective: "include" `TokString`
Sean Silva1b600182013-01-07 02:43:44 +0000115
Renato Golin33f973a2014-04-01 09:51:49 +0000116TableGen's top-level production consists of "objects".
Sean Silva1b600182013-01-07 02:43:44 +0000117
Renato Golin33f973a2014-04-01 09:51:49 +0000118.. productionlist::
119 TableGenFile: `Object`*
Nicolai Haehnlefcd65252018-03-09 12:24:42 +0000120 Object: `Class` | `Def` | `Defm` | `Defset` | `Let` | `MultiClass` |
121 `Foreach`
Sean Silva1b600182013-01-07 02:43:44 +0000122
Renato Golin33f973a2014-04-01 09:51:49 +0000123``class``\es
124------------
Sean Silva1b600182013-01-07 02:43:44 +0000125
Renato Golin33f973a2014-04-01 09:51:49 +0000126.. productionlist::
127 Class: "class" `TokIdentifier` [`TemplateArgList`] `ObjectBody`
Sean Silva1b600182013-01-07 02:43:44 +0000128
Renato Golin33f973a2014-04-01 09:51:49 +0000129A ``class`` declaration creates a record which other records can inherit
130from. A class can be parametrized by a list of "template arguments", whose
131values can be used in the class body.
Sean Silva1b600182013-01-07 02:43:44 +0000132
Renato Golin33f973a2014-04-01 09:51:49 +0000133A given class can only be defined once. A ``class`` declaration is
134considered to define the class if any of the following is true:
Sean Silva1b600182013-01-07 02:43:44 +0000135
Renato Golin33f973a2014-04-01 09:51:49 +0000136.. break ObjectBody into its consituents so that they are present here?
Sean Silva1b600182013-01-07 02:43:44 +0000137
Renato Golin33f973a2014-04-01 09:51:49 +0000138#. The :token:`TemplateArgList` is present.
139#. The :token:`Body` in the :token:`ObjectBody` is present and is not empty.
140#. The :token:`BaseClassList` in the :token:`ObjectBody` is present.
Sean Silva1b600182013-01-07 02:43:44 +0000141
Renato Golin33f973a2014-04-01 09:51:49 +0000142You can declare an empty class by giving and empty :token:`TemplateArgList`
143and an empty :token:`ObjectBody`. This can serve as a restricted form of
144forward declaration: note that records deriving from the forward-declared
145class will inherit no fields from it since the record expansion is done
146when the record is parsed.
Sean Silva1b600182013-01-07 02:43:44 +0000147
Renato Golin33f973a2014-04-01 09:51:49 +0000148.. productionlist::
149 TemplateArgList: "<" `Declaration` ("," `Declaration`)* ">"
Sean Silva1b600182013-01-07 02:43:44 +0000150
Renato Golin33f973a2014-04-01 09:51:49 +0000151Declarations
152------------
Sean Silva1b600182013-01-07 02:43:44 +0000153
Renato Golin33f973a2014-04-01 09:51:49 +0000154.. Omitting mention of arcane "field" prefix to discourage its use.
Sean Silva1b600182013-01-07 02:43:44 +0000155
Renato Golin33f973a2014-04-01 09:51:49 +0000156The declaration syntax is pretty much what you would expect as a C++
157programmer.
Sean Silva1b600182013-01-07 02:43:44 +0000158
Renato Golin33f973a2014-04-01 09:51:49 +0000159.. productionlist::
160 Declaration: `Type` `TokIdentifier` ["=" `Value`]
Sean Silva1b600182013-01-07 02:43:44 +0000161
Sylvestre Ledru7d540502016-07-02 19:28:40 +0000162It assigns the value to the identifier.
Sean Silva1b600182013-01-07 02:43:44 +0000163
Renato Golin33f973a2014-04-01 09:51:49 +0000164Types
165-----
Sean Silva1b600182013-01-07 02:43:44 +0000166
Renato Golin33f973a2014-04-01 09:51:49 +0000167.. productionlist::
168 Type: "string" | "code" | "bit" | "int" | "dag"
169 :| "bits" "<" `TokInteger` ">"
170 :| "list" "<" `Type` ">"
171 :| `ClassID`
172 ClassID: `TokIdentifier`
Sean Silva1b600182013-01-07 02:43:44 +0000173
Renato Golin33f973a2014-04-01 09:51:49 +0000174Both ``string`` and ``code`` correspond to the string type; the difference
175is purely to indicate programmer intention.
Renato Golinca105642014-03-20 16:08:34 +0000176
Renato Golin33f973a2014-04-01 09:51:49 +0000177The :token:`ClassID` must identify a class that has been previously
178declared or defined.
Renato Golinca105642014-03-20 16:08:34 +0000179
Renato Golin33f973a2014-04-01 09:51:49 +0000180Values
181------
Renato Golinca105642014-03-20 16:08:34 +0000182
Renato Golin33f973a2014-04-01 09:51:49 +0000183.. productionlist::
184 Value: `SimpleValue` `ValueSuffix`*
185 ValueSuffix: "{" `RangeList` "}"
186 :| "[" `RangeList` "]"
187 :| "." `TokIdentifier`
188 RangeList: `RangePiece` ("," `RangePiece`)*
189 RangePiece: `TokInteger`
190 :| `TokInteger` "-" `TokInteger`
191 :| `TokInteger` `TokInteger`
Renato Golinca105642014-03-20 16:08:34 +0000192
Renato Golin33f973a2014-04-01 09:51:49 +0000193The peculiar last form of :token:`RangePiece` is due to the fact that the
194"``-``" is included in the :token:`TokInteger`, hence ``1-5`` gets lexed as
195two consecutive :token:`TokInteger`'s, with values ``1`` and ``-5``,
196instead of "1", "-", and "5".
197The :token:`RangeList` can be thought of as specifying "list slice" in some
198contexts.
Renato Golinca105642014-03-20 16:08:34 +0000199
Renato Golinca105642014-03-20 16:08:34 +0000200
Renato Golin33f973a2014-04-01 09:51:49 +0000201:token:`SimpleValue` has a number of forms:
Renato Golinca105642014-03-20 16:08:34 +0000202
Renato Golinca105642014-03-20 16:08:34 +0000203
Renato Golin33f973a2014-04-01 09:51:49 +0000204.. productionlist::
205 SimpleValue: `TokIdentifier`
Renato Golinca105642014-03-20 16:08:34 +0000206
Renato Golin33f973a2014-04-01 09:51:49 +0000207The value will be the variable referenced by the identifier. It can be one
208of:
Renato Golinca105642014-03-20 16:08:34 +0000209
Renato Golin33f973a2014-04-01 09:51:49 +0000210.. The code for this is exceptionally abstruse. These examples are a
211 best-effort attempt.
Renato Golinca105642014-03-20 16:08:34 +0000212
Renato Golin33f973a2014-04-01 09:51:49 +0000213* name of a ``def``, such as the use of ``Bar`` in::
Renato Golinca105642014-03-20 16:08:34 +0000214
Renato Golin33f973a2014-04-01 09:51:49 +0000215 def Bar : SomeClass {
216 int X = 5;
217 }
Renato Golinca105642014-03-20 16:08:34 +0000218
Renato Golin33f973a2014-04-01 09:51:49 +0000219 def Foo {
220 SomeClass Baz = Bar;
221 }
Renato Golinca105642014-03-20 16:08:34 +0000222
Renato Golin33f973a2014-04-01 09:51:49 +0000223* value local to a ``def``, such as the use of ``Bar`` in::
Renato Golinca105642014-03-20 16:08:34 +0000224
Renato Golin33f973a2014-04-01 09:51:49 +0000225 def Foo {
226 int Bar = 5;
227 int Baz = Bar;
228 }
Renato Golinca105642014-03-20 16:08:34 +0000229
Renato Golin33f973a2014-04-01 09:51:49 +0000230* a template arg of a ``class``, such as the use of ``Bar`` in::
Renato Golinca105642014-03-20 16:08:34 +0000231
Renato Golin33f973a2014-04-01 09:51:49 +0000232 class Foo<int Bar> {
233 int Baz = Bar;
234 }
Renato Golinca105642014-03-20 16:08:34 +0000235
Renato Golin33f973a2014-04-01 09:51:49 +0000236* value local to a ``multiclass``, such as the use of ``Bar`` in::
Renato Golinca105642014-03-20 16:08:34 +0000237
Renato Golin33f973a2014-04-01 09:51:49 +0000238 multiclass Foo {
239 int Bar = 5;
240 int Baz = Bar;
241 }
Renato Golinca105642014-03-20 16:08:34 +0000242
Renato Golin33f973a2014-04-01 09:51:49 +0000243* a template arg to a ``multiclass``, such as the use of ``Bar`` in::
Renato Golinca105642014-03-20 16:08:34 +0000244
Renato Golin33f973a2014-04-01 09:51:49 +0000245 multiclass Foo<int Bar> {
246 int Baz = Bar;
247 }
Renato Golinca105642014-03-20 16:08:34 +0000248
Renato Golin33f973a2014-04-01 09:51:49 +0000249.. productionlist::
250 SimpleValue: `TokInteger`
Renato Golinca105642014-03-20 16:08:34 +0000251
Renato Golin33f973a2014-04-01 09:51:49 +0000252This represents the numeric value of the integer.
Renato Golinca105642014-03-20 16:08:34 +0000253
Renato Golin33f973a2014-04-01 09:51:49 +0000254.. productionlist::
255 SimpleValue: `TokString`+
Renato Golinca105642014-03-20 16:08:34 +0000256
Renato Golin33f973a2014-04-01 09:51:49 +0000257Multiple adjacent string literals are concatenated like in C/C++. The value
258is the concatenation of the strings.
Renato Golinca105642014-03-20 16:08:34 +0000259
Renato Golin33f973a2014-04-01 09:51:49 +0000260.. productionlist::
261 SimpleValue: `TokCodeFragment`
Renato Golinca105642014-03-20 16:08:34 +0000262
Renato Golin33f973a2014-04-01 09:51:49 +0000263The value is the string value of the code fragment.
Renato Golinca105642014-03-20 16:08:34 +0000264
Renato Golin33f973a2014-04-01 09:51:49 +0000265.. productionlist::
266 SimpleValue: "?"
Renato Golinca105642014-03-20 16:08:34 +0000267
Renato Golin33f973a2014-04-01 09:51:49 +0000268``?`` represents an "unset" initializer.
Sean Silva1b600182013-01-07 02:43:44 +0000269
Renato Golin33f973a2014-04-01 09:51:49 +0000270.. productionlist::
271 SimpleValue: "{" `ValueList` "}"
272 ValueList: [`ValueListNE`]
273 ValueListNE: `Value` ("," `Value`)*
Sean Silva1b600182013-01-07 02:43:44 +0000274
Renato Golin33f973a2014-04-01 09:51:49 +0000275This represents a sequence of bits, as would be used to initialize a
276``bits<n>`` field (where ``n`` is the number of bits).
Sean Silva1b600182013-01-07 02:43:44 +0000277
Renato Golin33f973a2014-04-01 09:51:49 +0000278.. productionlist::
279 SimpleValue: `ClassID` "<" `ValueListNE` ">"
Sean Silva1b600182013-01-07 02:43:44 +0000280
Renato Golin33f973a2014-04-01 09:51:49 +0000281This generates a new anonymous record definition (as would be created by an
282unnamed ``def`` inheriting from the given class with the given template
283arguments) and the value is the value of that record definition.
Sean Silva1b600182013-01-07 02:43:44 +0000284
Renato Golin33f973a2014-04-01 09:51:49 +0000285.. productionlist::
286 SimpleValue: "[" `ValueList` "]" ["<" `Type` ">"]
Sean Silva1b600182013-01-07 02:43:44 +0000287
Renato Golin33f973a2014-04-01 09:51:49 +0000288A list initializer. The optional :token:`Type` can be used to indicate a
289specific element type, otherwise the element type will be deduced from the
290given values.
Sean Silva1b600182013-01-07 02:43:44 +0000291
Renato Golin33f973a2014-04-01 09:51:49 +0000292.. The initial `DagArg` of the dag must start with an identifier or
293 !cast, but this is more of an implementation detail and so for now just
294 leave it out.
Sean Silva1b600182013-01-07 02:43:44 +0000295
Renato Golin33f973a2014-04-01 09:51:49 +0000296.. productionlist::
Simon Tatham047c1ab2018-04-23 09:15:47 +0000297 SimpleValue: "(" `DagArg` [`DagArgList`] ")"
Renato Golin33f973a2014-04-01 09:51:49 +0000298 DagArgList: `DagArg` ("," `DagArg`)*
299 DagArg: `Value` [":" `TokVarName`] | `TokVarName`
Sean Silva1b600182013-01-07 02:43:44 +0000300
Renato Golin33f973a2014-04-01 09:51:49 +0000301The initial :token:`DagArg` is called the "operator" of the dag.
Sean Silva1b600182013-01-07 02:43:44 +0000302
Renato Golin33f973a2014-04-01 09:51:49 +0000303.. productionlist::
304 SimpleValue: `BangOperator` ["<" `Type` ">"] "(" `ValueListNE` ")"
Sean Silva1b600182013-01-07 02:43:44 +0000305
Renato Golin33f973a2014-04-01 09:51:49 +0000306Bodies
307------
Sean Silva1b600182013-01-07 02:43:44 +0000308
Renato Golin33f973a2014-04-01 09:51:49 +0000309.. productionlist::
310 ObjectBody: `BaseClassList` `Body`
311 BaseClassList: [":" `BaseClassListNE`]
312 BaseClassListNE: `SubClassRef` ("," `SubClassRef`)*
313 SubClassRef: (`ClassID` | `MultiClassID`) ["<" `ValueList` ">"]
314 DefmID: `TokIdentifier`
Sean Silva1b600182013-01-07 02:43:44 +0000315
Renato Golin33f973a2014-04-01 09:51:49 +0000316The version with the :token:`MultiClassID` is only valid in the
317:token:`BaseClassList` of a ``defm``.
318The :token:`MultiClassID` should be the name of a ``multiclass``.
Sean Silva1b600182013-01-07 02:43:44 +0000319
Renato Golin33f973a2014-04-01 09:51:49 +0000320.. put this somewhere else
Sean Silva1b600182013-01-07 02:43:44 +0000321
Renato Golin33f973a2014-04-01 09:51:49 +0000322It is after parsing the base class list that the "let stack" is applied.
Sean Silva1b600182013-01-07 02:43:44 +0000323
Renato Golin33f973a2014-04-01 09:51:49 +0000324.. productionlist::
325 Body: ";" | "{" BodyList "}"
326 BodyList: BodyItem*
327 BodyItem: `Declaration` ";"
Simon Tatham047c1ab2018-04-23 09:15:47 +0000328 :| "let" `TokIdentifier` [ "{" `RangeList` "}" ] "=" `Value` ";"
Sean Silva1b600182013-01-07 02:43:44 +0000329
Renato Golin33f973a2014-04-01 09:51:49 +0000330The ``let`` form allows overriding the value of an inherited field.
Sean Silva1b600182013-01-07 02:43:44 +0000331
Renato Golin33f973a2014-04-01 09:51:49 +0000332``def``
333-------
Sean Silva1b600182013-01-07 02:43:44 +0000334
Renato Golin33f973a2014-04-01 09:51:49 +0000335.. TODO::
336 There can be pastes in the names here, like ``#NAME#``. Look into that
337 and document it (it boils down to ParseIDValue with IDParseMode ==
338 ParseNameMode). ParseObjectName calls into the general ParseValue, with
339 the only different from "arbitrary expression parsing" being IDParseMode
340 == Mode.
Sean Silva1b600182013-01-07 02:43:44 +0000341
Renato Golin33f973a2014-04-01 09:51:49 +0000342.. productionlist::
343 Def: "def" `TokIdentifier` `ObjectBody`
Sean Silva1b600182013-01-07 02:43:44 +0000344
Renato Golin33f973a2014-04-01 09:51:49 +0000345Defines a record whose name is given by the :token:`TokIdentifier`. The
346fields of the record are inherited from the base classes and defined in the
347body.
Sean Silva1b600182013-01-07 02:43:44 +0000348
Renato Golin33f973a2014-04-01 09:51:49 +0000349Special handling occurs if this ``def`` appears inside a ``multiclass`` or
350a ``foreach``.
Sean Silva1b600182013-01-07 02:43:44 +0000351
Renato Golin33f973a2014-04-01 09:51:49 +0000352``defm``
353--------
Sean Silva1b600182013-01-07 02:43:44 +0000354
Renato Golin33f973a2014-04-01 09:51:49 +0000355.. productionlist::
Simon Tatham047c1ab2018-04-23 09:15:47 +0000356 Defm: "defm" [`TokIdentifier`] ":" `BaseClassListNE` ";"
Sean Silva1b600182013-01-07 02:43:44 +0000357
Renato Golin33f973a2014-04-01 09:51:49 +0000358Note that in the :token:`BaseClassList`, all of the ``multiclass``'s must
359precede any ``class``'s that appear.
Sean Silva1b600182013-01-07 02:43:44 +0000360
Nicolai Haehnlefcd65252018-03-09 12:24:42 +0000361``defset``
362----------
363.. productionlist::
364 Defset: "defset" `Type` `TokIdentifier` "=" "{" `Object`* "}"
365
366All records defined inside the braces via ``def`` and ``defm`` are collected
367in a globally accessible list of the given name (in addition to being added
368to the global collection of records as usual). Anonymous records created inside
369initializier expressions using the ``Class<args...>`` syntax are never collected
370in a defset.
371
372The given type must be ``list<A>``, where ``A`` is some class. It is an error
373to define a record (via ``def`` or ``defm``) inside the braces which doesn't
374derive from ``A``.
375
Renato Golin33f973a2014-04-01 09:51:49 +0000376``foreach``
377-----------
Sean Silva1b600182013-01-07 02:43:44 +0000378
Renato Golin33f973a2014-04-01 09:51:49 +0000379.. productionlist::
Nicolai Haehnle8aa9d582018-03-09 12:24:30 +0000380 Foreach: "foreach" `ForeachDeclaration` "in" "{" `Object`* "}"
381 :| "foreach" `ForeachDeclaration` "in" `Object`
382 ForeachDeclaration: ID "=" ( "{" `RangeList` "}" | `RangePiece` | `Value` )
Sean Silva1b600182013-01-07 02:43:44 +0000383
Renato Golin33f973a2014-04-01 09:51:49 +0000384The value assigned to the variable in the declaration is iterated over and
385the object or object list is reevaluated with the variable set at each
386iterated value.
Sean Silva1b600182013-01-07 02:43:44 +0000387
Nicolai Haehnle8aa9d582018-03-09 12:24:30 +0000388Note that the productions involving RangeList and RangePiece have precedence
389over the more generic value parsing based on the first token.
390
Renato Golin33f973a2014-04-01 09:51:49 +0000391Top-Level ``let``
392-----------------
Sean Silva1b600182013-01-07 02:43:44 +0000393
Renato Golin33f973a2014-04-01 09:51:49 +0000394.. productionlist::
395 Let: "let" `LetList` "in" "{" `Object`* "}"
396 :| "let" `LetList` "in" `Object`
397 LetList: `LetItem` ("," `LetItem`)*
398 LetItem: `TokIdentifier` [`RangeList`] "=" `Value`
Sean Silva1b600182013-01-07 02:43:44 +0000399
Renato Golin33f973a2014-04-01 09:51:49 +0000400This is effectively equivalent to ``let`` inside the body of a record
401except that it applies to multiple records at a time. The bindings are
402applied at the end of parsing the base classes of a record.
Sean Silva1b600182013-01-07 02:43:44 +0000403
Renato Golin33f973a2014-04-01 09:51:49 +0000404``multiclass``
405--------------
Sean Silva1b600182013-01-07 02:43:44 +0000406
Renato Golin33f973a2014-04-01 09:51:49 +0000407.. productionlist::
408 MultiClass: "multiclass" `TokIdentifier` [`TemplateArgList`]
409 : [":" `BaseMultiClassList`] "{" `MultiClassObject`+ "}"
410 BaseMultiClassList: `MultiClassID` ("," `MultiClassID`)*
411 MultiClassID: `TokIdentifier`
412 MultiClassObject: `Def` | `Defm` | `Let` | `Foreach`