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 |
| 10 | fix it, file a documentation bug, or ask about it on llvmdev. |
| 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 |
Daniel Sanders | 314e80e | 2014-05-07 10:13:19 +0000 | [diff] [blame] | 100 | :!cast !empty !subst !foreach !listconcat !strconcat |
Sean Silva | 1b60018 | 2013-01-07 02:43:44 +0000 | [diff] [blame] | 101 | |
Renato Golin | 33f973a | 2014-04-01 09:51:49 +0000 | [diff] [blame] | 102 | Syntax |
| 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 | TableGen has an ``include`` mechanism. It does not play a role in the |
| 106 | syntax per se, since it is lexically replaced with the contents of the |
| 107 | included file. |
Sean Silva | 1b60018 | 2013-01-07 02:43:44 +0000 | [diff] [blame] | 108 | |
Renato Golin | 33f973a | 2014-04-01 09:51:49 +0000 | [diff] [blame] | 109 | .. productionlist:: |
| 110 | IncludeDirective: "include" `TokString` |
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 | TableGen's top-level production consists of "objects". |
Sean Silva | 1b60018 | 2013-01-07 02:43:44 +0000 | [diff] [blame] | 113 | |
Renato Golin | 33f973a | 2014-04-01 09:51:49 +0000 | [diff] [blame] | 114 | .. productionlist:: |
| 115 | TableGenFile: `Object`* |
| 116 | Object: `Class` | `Def` | `Defm` | `Let` | `MultiClass` | `Foreach` |
Sean Silva | 1b60018 | 2013-01-07 02:43:44 +0000 | [diff] [blame] | 117 | |
Renato Golin | 33f973a | 2014-04-01 09:51:49 +0000 | [diff] [blame] | 118 | ``class``\es |
| 119 | ------------ |
Sean Silva | 1b60018 | 2013-01-07 02:43:44 +0000 | [diff] [blame] | 120 | |
Renato Golin | 33f973a | 2014-04-01 09:51:49 +0000 | [diff] [blame] | 121 | .. productionlist:: |
| 122 | Class: "class" `TokIdentifier` [`TemplateArgList`] `ObjectBody` |
Sean Silva | 1b60018 | 2013-01-07 02:43:44 +0000 | [diff] [blame] | 123 | |
Renato Golin | 33f973a | 2014-04-01 09:51:49 +0000 | [diff] [blame] | 124 | A ``class`` declaration creates a record which other records can inherit |
| 125 | from. A class can be parametrized by a list of "template arguments", whose |
| 126 | values can be used in the class body. |
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 given class can only be defined once. A ``class`` declaration is |
| 129 | considered to define the class if any of the following is true: |
Sean Silva | 1b60018 | 2013-01-07 02:43:44 +0000 | [diff] [blame] | 130 | |
Renato Golin | 33f973a | 2014-04-01 09:51:49 +0000 | [diff] [blame] | 131 | .. break ObjectBody into its consituents so that they are present here? |
Sean Silva | 1b60018 | 2013-01-07 02:43:44 +0000 | [diff] [blame] | 132 | |
Renato Golin | 33f973a | 2014-04-01 09:51:49 +0000 | [diff] [blame] | 133 | #. The :token:`TemplateArgList` is present. |
| 134 | #. The :token:`Body` in the :token:`ObjectBody` is present and is not empty. |
| 135 | #. The :token:`BaseClassList` in the :token:`ObjectBody` is present. |
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 | You can declare an empty class by giving and empty :token:`TemplateArgList` |
| 138 | and an empty :token:`ObjectBody`. This can serve as a restricted form of |
| 139 | forward declaration: note that records deriving from the forward-declared |
| 140 | class will inherit no fields from it since the record expansion is done |
| 141 | when the record is parsed. |
Sean Silva | 1b60018 | 2013-01-07 02:43:44 +0000 | [diff] [blame] | 142 | |
Renato Golin | 33f973a | 2014-04-01 09:51:49 +0000 | [diff] [blame] | 143 | .. productionlist:: |
| 144 | TemplateArgList: "<" `Declaration` ("," `Declaration`)* ">" |
Sean Silva | 1b60018 | 2013-01-07 02:43:44 +0000 | [diff] [blame] | 145 | |
Renato Golin | 33f973a | 2014-04-01 09:51:49 +0000 | [diff] [blame] | 146 | Declarations |
| 147 | ------------ |
Sean Silva | 1b60018 | 2013-01-07 02:43:44 +0000 | [diff] [blame] | 148 | |
Renato Golin | 33f973a | 2014-04-01 09:51:49 +0000 | [diff] [blame] | 149 | .. Omitting mention of arcane "field" prefix to discourage its use. |
Sean Silva | 1b60018 | 2013-01-07 02:43:44 +0000 | [diff] [blame] | 150 | |
Renato Golin | 33f973a | 2014-04-01 09:51:49 +0000 | [diff] [blame] | 151 | The declaration syntax is pretty much what you would expect as a C++ |
| 152 | programmer. |
Sean Silva | 1b60018 | 2013-01-07 02:43:44 +0000 | [diff] [blame] | 153 | |
Renato Golin | 33f973a | 2014-04-01 09:51:49 +0000 | [diff] [blame] | 154 | .. productionlist:: |
| 155 | Declaration: `Type` `TokIdentifier` ["=" `Value`] |
Sean Silva | 1b60018 | 2013-01-07 02:43:44 +0000 | [diff] [blame] | 156 | |
Renato Golin | 33f973a | 2014-04-01 09:51:49 +0000 | [diff] [blame] | 157 | It assigns the value to the identifer. |
Sean Silva | 1b60018 | 2013-01-07 02:43:44 +0000 | [diff] [blame] | 158 | |
Renato Golin | 33f973a | 2014-04-01 09:51:49 +0000 | [diff] [blame] | 159 | Types |
| 160 | ----- |
Sean Silva | 1b60018 | 2013-01-07 02:43:44 +0000 | [diff] [blame] | 161 | |
Renato Golin | 33f973a | 2014-04-01 09:51:49 +0000 | [diff] [blame] | 162 | .. productionlist:: |
| 163 | Type: "string" | "code" | "bit" | "int" | "dag" |
| 164 | :| "bits" "<" `TokInteger` ">" |
| 165 | :| "list" "<" `Type` ">" |
| 166 | :| `ClassID` |
| 167 | ClassID: `TokIdentifier` |
Sean Silva | 1b60018 | 2013-01-07 02:43:44 +0000 | [diff] [blame] | 168 | |
Renato Golin | 33f973a | 2014-04-01 09:51:49 +0000 | [diff] [blame] | 169 | Both ``string`` and ``code`` correspond to the string type; the difference |
| 170 | is purely to indicate programmer intention. |
Renato Golin | ca10564 | 2014-03-20 16:08:34 +0000 | [diff] [blame] | 171 | |
Renato Golin | 33f973a | 2014-04-01 09:51:49 +0000 | [diff] [blame] | 172 | The :token:`ClassID` must identify a class that has been previously |
| 173 | declared or defined. |
Renato Golin | ca10564 | 2014-03-20 16:08:34 +0000 | [diff] [blame] | 174 | |
Renato Golin | 33f973a | 2014-04-01 09:51:49 +0000 | [diff] [blame] | 175 | Values |
| 176 | ------ |
Renato Golin | ca10564 | 2014-03-20 16:08:34 +0000 | [diff] [blame] | 177 | |
Renato Golin | 33f973a | 2014-04-01 09:51:49 +0000 | [diff] [blame] | 178 | .. productionlist:: |
| 179 | Value: `SimpleValue` `ValueSuffix`* |
| 180 | ValueSuffix: "{" `RangeList` "}" |
| 181 | :| "[" `RangeList` "]" |
| 182 | :| "." `TokIdentifier` |
| 183 | RangeList: `RangePiece` ("," `RangePiece`)* |
| 184 | RangePiece: `TokInteger` |
| 185 | :| `TokInteger` "-" `TokInteger` |
| 186 | :| `TokInteger` `TokInteger` |
Renato Golin | ca10564 | 2014-03-20 16:08:34 +0000 | [diff] [blame] | 187 | |
Renato Golin | 33f973a | 2014-04-01 09:51:49 +0000 | [diff] [blame] | 188 | The peculiar last form of :token:`RangePiece` is due to the fact that the |
| 189 | "``-``" is included in the :token:`TokInteger`, hence ``1-5`` gets lexed as |
| 190 | two consecutive :token:`TokInteger`'s, with values ``1`` and ``-5``, |
| 191 | instead of "1", "-", and "5". |
| 192 | The :token:`RangeList` can be thought of as specifying "list slice" in some |
| 193 | contexts. |
Renato Golin | ca10564 | 2014-03-20 16:08:34 +0000 | [diff] [blame] | 194 | |
Renato Golin | ca10564 | 2014-03-20 16:08:34 +0000 | [diff] [blame] | 195 | |
Renato Golin | 33f973a | 2014-04-01 09:51:49 +0000 | [diff] [blame] | 196 | :token:`SimpleValue` has a number of forms: |
Renato Golin | ca10564 | 2014-03-20 16:08:34 +0000 | [diff] [blame] | 197 | |
Renato Golin | ca10564 | 2014-03-20 16:08:34 +0000 | [diff] [blame] | 198 | |
Renato Golin | 33f973a | 2014-04-01 09:51:49 +0000 | [diff] [blame] | 199 | .. productionlist:: |
| 200 | SimpleValue: `TokIdentifier` |
Renato Golin | ca10564 | 2014-03-20 16:08:34 +0000 | [diff] [blame] | 201 | |
Renato Golin | 33f973a | 2014-04-01 09:51:49 +0000 | [diff] [blame] | 202 | The value will be the variable referenced by the identifier. It can be one |
| 203 | of: |
Renato Golin | ca10564 | 2014-03-20 16:08:34 +0000 | [diff] [blame] | 204 | |
Renato Golin | 33f973a | 2014-04-01 09:51:49 +0000 | [diff] [blame] | 205 | .. The code for this is exceptionally abstruse. These examples are a |
| 206 | best-effort attempt. |
Renato Golin | ca10564 | 2014-03-20 16:08:34 +0000 | [diff] [blame] | 207 | |
Renato Golin | 33f973a | 2014-04-01 09:51:49 +0000 | [diff] [blame] | 208 | * name of a ``def``, such as the use of ``Bar`` in:: |
Renato Golin | ca10564 | 2014-03-20 16:08:34 +0000 | [diff] [blame] | 209 | |
Renato Golin | 33f973a | 2014-04-01 09:51:49 +0000 | [diff] [blame] | 210 | def Bar : SomeClass { |
| 211 | int X = 5; |
| 212 | } |
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 Foo { |
| 215 | SomeClass Baz = Bar; |
| 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 | * value local to a ``def``, such as the use of ``Bar`` in:: |
Renato Golin | ca10564 | 2014-03-20 16:08:34 +0000 | [diff] [blame] | 219 | |
Renato Golin | 33f973a | 2014-04-01 09:51:49 +0000 | [diff] [blame] | 220 | def Foo { |
| 221 | int Bar = 5; |
| 222 | int Baz = Bar; |
| 223 | } |
Renato Golin | ca10564 | 2014-03-20 16:08:34 +0000 | [diff] [blame] | 224 | |
Renato Golin | 33f973a | 2014-04-01 09:51:49 +0000 | [diff] [blame] | 225 | * 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] | 226 | |
Renato Golin | 33f973a | 2014-04-01 09:51:49 +0000 | [diff] [blame] | 227 | class Foo<int Bar> { |
| 228 | int Baz = Bar; |
| 229 | } |
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 | * value local to a ``multiclass``, such as the use of ``Bar`` in:: |
Renato Golin | ca10564 | 2014-03-20 16:08:34 +0000 | [diff] [blame] | 232 | |
Renato Golin | 33f973a | 2014-04-01 09:51:49 +0000 | [diff] [blame] | 233 | multiclass Foo { |
| 234 | int Bar = 5; |
| 235 | int Baz = Bar; |
| 236 | } |
Renato Golin | ca10564 | 2014-03-20 16:08:34 +0000 | [diff] [blame] | 237 | |
Renato Golin | 33f973a | 2014-04-01 09:51:49 +0000 | [diff] [blame] | 238 | * 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] | 239 | |
Renato Golin | 33f973a | 2014-04-01 09:51:49 +0000 | [diff] [blame] | 240 | multiclass Foo<int Bar> { |
| 241 | int Baz = Bar; |
| 242 | } |
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 | .. productionlist:: |
| 245 | SimpleValue: `TokInteger` |
Renato Golin | ca10564 | 2014-03-20 16:08:34 +0000 | [diff] [blame] | 246 | |
Renato Golin | 33f973a | 2014-04-01 09:51:49 +0000 | [diff] [blame] | 247 | This represents the numeric value of the integer. |
Renato Golin | ca10564 | 2014-03-20 16:08:34 +0000 | [diff] [blame] | 248 | |
Renato Golin | 33f973a | 2014-04-01 09:51:49 +0000 | [diff] [blame] | 249 | .. productionlist:: |
| 250 | SimpleValue: `TokString`+ |
Renato Golin | ca10564 | 2014-03-20 16:08:34 +0000 | [diff] [blame] | 251 | |
Renato Golin | 33f973a | 2014-04-01 09:51:49 +0000 | [diff] [blame] | 252 | Multiple adjacent string literals are concatenated like in C/C++. The value |
| 253 | is the concatenation of the strings. |
Renato Golin | ca10564 | 2014-03-20 16:08:34 +0000 | [diff] [blame] | 254 | |
Renato Golin | 33f973a | 2014-04-01 09:51:49 +0000 | [diff] [blame] | 255 | .. productionlist:: |
| 256 | SimpleValue: `TokCodeFragment` |
Renato Golin | ca10564 | 2014-03-20 16:08:34 +0000 | [diff] [blame] | 257 | |
Renato Golin | 33f973a | 2014-04-01 09:51:49 +0000 | [diff] [blame] | 258 | The value is the string value of the code fragment. |
Renato Golin | ca10564 | 2014-03-20 16:08:34 +0000 | [diff] [blame] | 259 | |
Renato Golin | 33f973a | 2014-04-01 09:51:49 +0000 | [diff] [blame] | 260 | .. productionlist:: |
| 261 | SimpleValue: "?" |
Renato Golin | ca10564 | 2014-03-20 16:08:34 +0000 | [diff] [blame] | 262 | |
Renato Golin | 33f973a | 2014-04-01 09:51:49 +0000 | [diff] [blame] | 263 | ``?`` represents an "unset" initializer. |
Sean Silva | 1b60018 | 2013-01-07 02:43:44 +0000 | [diff] [blame] | 264 | |
Renato Golin | 33f973a | 2014-04-01 09:51:49 +0000 | [diff] [blame] | 265 | .. productionlist:: |
| 266 | SimpleValue: "{" `ValueList` "}" |
| 267 | ValueList: [`ValueListNE`] |
| 268 | ValueListNE: `Value` ("," `Value`)* |
Sean Silva | 1b60018 | 2013-01-07 02:43:44 +0000 | [diff] [blame] | 269 | |
Renato Golin | 33f973a | 2014-04-01 09:51:49 +0000 | [diff] [blame] | 270 | This represents a sequence of bits, as would be used to initialize a |
| 271 | ``bits<n>`` field (where ``n`` is the number of bits). |
Sean Silva | 1b60018 | 2013-01-07 02:43:44 +0000 | [diff] [blame] | 272 | |
Renato Golin | 33f973a | 2014-04-01 09:51:49 +0000 | [diff] [blame] | 273 | .. productionlist:: |
| 274 | SimpleValue: `ClassID` "<" `ValueListNE` ">" |
Sean Silva | 1b60018 | 2013-01-07 02:43:44 +0000 | [diff] [blame] | 275 | |
Renato Golin | 33f973a | 2014-04-01 09:51:49 +0000 | [diff] [blame] | 276 | This generates a new anonymous record definition (as would be created by an |
| 277 | unnamed ``def`` inheriting from the given class with the given template |
| 278 | arguments) and the value is the value of that record definition. |
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 | .. productionlist:: |
| 281 | SimpleValue: "[" `ValueList` "]" ["<" `Type` ">"] |
Sean Silva | 1b60018 | 2013-01-07 02:43:44 +0000 | [diff] [blame] | 282 | |
Renato Golin | 33f973a | 2014-04-01 09:51:49 +0000 | [diff] [blame] | 283 | A list initializer. The optional :token:`Type` can be used to indicate a |
| 284 | specific element type, otherwise the element type will be deduced from the |
| 285 | given values. |
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 | .. The initial `DagArg` of the dag must start with an identifier or |
| 288 | !cast, but this is more of an implementation detail and so for now just |
| 289 | leave it out. |
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 | .. productionlist:: |
| 292 | SimpleValue: "(" `DagArg` `DagArgList` ")" |
| 293 | DagArgList: `DagArg` ("," `DagArg`)* |
| 294 | DagArg: `Value` [":" `TokVarName`] | `TokVarName` |
Sean Silva | 1b60018 | 2013-01-07 02:43:44 +0000 | [diff] [blame] | 295 | |
Renato Golin | 33f973a | 2014-04-01 09:51:49 +0000 | [diff] [blame] | 296 | The initial :token:`DagArg` is called the "operator" of the dag. |
Sean Silva | 1b60018 | 2013-01-07 02:43:44 +0000 | [diff] [blame] | 297 | |
Renato Golin | 33f973a | 2014-04-01 09:51:49 +0000 | [diff] [blame] | 298 | .. productionlist:: |
| 299 | SimpleValue: `BangOperator` ["<" `Type` ">"] "(" `ValueListNE` ")" |
Sean Silva | 1b60018 | 2013-01-07 02:43:44 +0000 | [diff] [blame] | 300 | |
Renato Golin | 33f973a | 2014-04-01 09:51:49 +0000 | [diff] [blame] | 301 | Bodies |
| 302 | ------ |
Sean Silva | 1b60018 | 2013-01-07 02:43:44 +0000 | [diff] [blame] | 303 | |
Renato Golin | 33f973a | 2014-04-01 09:51:49 +0000 | [diff] [blame] | 304 | .. productionlist:: |
| 305 | ObjectBody: `BaseClassList` `Body` |
| 306 | BaseClassList: [":" `BaseClassListNE`] |
| 307 | BaseClassListNE: `SubClassRef` ("," `SubClassRef`)* |
| 308 | SubClassRef: (`ClassID` | `MultiClassID`) ["<" `ValueList` ">"] |
| 309 | DefmID: `TokIdentifier` |
Sean Silva | 1b60018 | 2013-01-07 02:43:44 +0000 | [diff] [blame] | 310 | |
Renato Golin | 33f973a | 2014-04-01 09:51:49 +0000 | [diff] [blame] | 311 | The version with the :token:`MultiClassID` is only valid in the |
| 312 | :token:`BaseClassList` of a ``defm``. |
| 313 | The :token:`MultiClassID` should be the name of a ``multiclass``. |
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 | .. put this somewhere else |
Sean Silva | 1b60018 | 2013-01-07 02:43:44 +0000 | [diff] [blame] | 316 | |
Renato Golin | 33f973a | 2014-04-01 09:51:49 +0000 | [diff] [blame] | 317 | 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] | 318 | |
Renato Golin | 33f973a | 2014-04-01 09:51:49 +0000 | [diff] [blame] | 319 | .. productionlist:: |
| 320 | Body: ";" | "{" BodyList "}" |
| 321 | BodyList: BodyItem* |
| 322 | BodyItem: `Declaration` ";" |
| 323 | :| "let" `TokIdentifier` [`RangeList`] "=" `Value` ";" |
Sean Silva | 1b60018 | 2013-01-07 02:43:44 +0000 | [diff] [blame] | 324 | |
Renato Golin | 33f973a | 2014-04-01 09:51:49 +0000 | [diff] [blame] | 325 | The ``let`` form allows overriding the value of an inherited field. |
Sean Silva | 1b60018 | 2013-01-07 02:43:44 +0000 | [diff] [blame] | 326 | |
Renato Golin | 33f973a | 2014-04-01 09:51:49 +0000 | [diff] [blame] | 327 | ``def`` |
| 328 | ------- |
Sean Silva | 1b60018 | 2013-01-07 02:43:44 +0000 | [diff] [blame] | 329 | |
Renato Golin | 33f973a | 2014-04-01 09:51:49 +0000 | [diff] [blame] | 330 | .. TODO:: |
| 331 | There can be pastes in the names here, like ``#NAME#``. Look into that |
| 332 | and document it (it boils down to ParseIDValue with IDParseMode == |
| 333 | ParseNameMode). ParseObjectName calls into the general ParseValue, with |
| 334 | the only different from "arbitrary expression parsing" being IDParseMode |
| 335 | == Mode. |
Sean Silva | 1b60018 | 2013-01-07 02:43:44 +0000 | [diff] [blame] | 336 | |
Renato Golin | 33f973a | 2014-04-01 09:51:49 +0000 | [diff] [blame] | 337 | .. productionlist:: |
| 338 | Def: "def" `TokIdentifier` `ObjectBody` |
Sean Silva | 1b60018 | 2013-01-07 02:43:44 +0000 | [diff] [blame] | 339 | |
Renato Golin | 33f973a | 2014-04-01 09:51:49 +0000 | [diff] [blame] | 340 | Defines a record whose name is given by the :token:`TokIdentifier`. The |
| 341 | fields of the record are inherited from the base classes and defined in the |
| 342 | body. |
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 | Special handling occurs if this ``def`` appears inside a ``multiclass`` or |
| 345 | a ``foreach``. |
Sean Silva | 1b60018 | 2013-01-07 02:43:44 +0000 | [diff] [blame] | 346 | |
Renato Golin | 33f973a | 2014-04-01 09:51:49 +0000 | [diff] [blame] | 347 | ``defm`` |
| 348 | -------- |
Sean Silva | 1b60018 | 2013-01-07 02:43:44 +0000 | [diff] [blame] | 349 | |
Renato Golin | 33f973a | 2014-04-01 09:51:49 +0000 | [diff] [blame] | 350 | .. productionlist:: |
| 351 | Defm: "defm" `TokIdentifier` ":" `BaseClassListNE` ";" |
Sean Silva | 1b60018 | 2013-01-07 02:43:44 +0000 | [diff] [blame] | 352 | |
Renato Golin | 33f973a | 2014-04-01 09:51:49 +0000 | [diff] [blame] | 353 | Note that in the :token:`BaseClassList`, all of the ``multiclass``'s must |
| 354 | precede any ``class``'s that appear. |
Sean Silva | 1b60018 | 2013-01-07 02:43:44 +0000 | [diff] [blame] | 355 | |
Renato Golin | 33f973a | 2014-04-01 09:51:49 +0000 | [diff] [blame] | 356 | ``foreach`` |
| 357 | ----------- |
Sean Silva | 1b60018 | 2013-01-07 02:43:44 +0000 | [diff] [blame] | 358 | |
Renato Golin | 33f973a | 2014-04-01 09:51:49 +0000 | [diff] [blame] | 359 | .. productionlist:: |
| 360 | Foreach: "foreach" `Declaration` "in" "{" `Object`* "}" |
| 361 | :| "foreach" `Declaration` "in" `Object` |
Sean Silva | 1b60018 | 2013-01-07 02:43:44 +0000 | [diff] [blame] | 362 | |
Renato Golin | 33f973a | 2014-04-01 09:51:49 +0000 | [diff] [blame] | 363 | The value assigned to the variable in the declaration is iterated over and |
| 364 | the object or object list is reevaluated with the variable set at each |
| 365 | iterated value. |
Sean Silva | 1b60018 | 2013-01-07 02:43:44 +0000 | [diff] [blame] | 366 | |
Renato Golin | 33f973a | 2014-04-01 09:51:49 +0000 | [diff] [blame] | 367 | Top-Level ``let`` |
| 368 | ----------------- |
Sean Silva | 1b60018 | 2013-01-07 02:43:44 +0000 | [diff] [blame] | 369 | |
Renato Golin | 33f973a | 2014-04-01 09:51:49 +0000 | [diff] [blame] | 370 | .. productionlist:: |
| 371 | Let: "let" `LetList` "in" "{" `Object`* "}" |
| 372 | :| "let" `LetList` "in" `Object` |
| 373 | LetList: `LetItem` ("," `LetItem`)* |
| 374 | LetItem: `TokIdentifier` [`RangeList`] "=" `Value` |
Sean Silva | 1b60018 | 2013-01-07 02:43:44 +0000 | [diff] [blame] | 375 | |
Renato Golin | 33f973a | 2014-04-01 09:51:49 +0000 | [diff] [blame] | 376 | This is effectively equivalent to ``let`` inside the body of a record |
| 377 | except that it applies to multiple records at a time. The bindings are |
| 378 | applied at the end of parsing the base classes of a record. |
Sean Silva | 1b60018 | 2013-01-07 02:43:44 +0000 | [diff] [blame] | 379 | |
Renato Golin | 33f973a | 2014-04-01 09:51:49 +0000 | [diff] [blame] | 380 | ``multiclass`` |
| 381 | -------------- |
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 | .. productionlist:: |
| 384 | MultiClass: "multiclass" `TokIdentifier` [`TemplateArgList`] |
| 385 | : [":" `BaseMultiClassList`] "{" `MultiClassObject`+ "}" |
| 386 | BaseMultiClassList: `MultiClassID` ("," `MultiClassID`)* |
| 387 | MultiClassID: `TokIdentifier` |
| 388 | MultiClassObject: `Def` | `Defm` | `Let` | `Foreach` |