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