|
56 | 56 | import Lexer |
57 | 57 | from Symbols import * |
58 | 58 | import sys |
| 59 | +# Access constants collected by wavgen.py (fallback to empty if not present) |
| 60 | +try: |
| 61 | + from wavgen import Constants |
| 62 | +except Exception: |
| 63 | + Constants = {} |
59 | 64 |
|
60 | 65 | sys.dont_write_bytecode = True |
61 | 66 |
|
@@ -254,18 +259,23 @@ def lvds(slot_number): |
254 | 259 |
|
255 | 260 | lvds_chan = None |
256 | 261 |
|
257 | | - if found(NUMBER): |
| 262 | + if found(IDENTIFIER) and token.cargo in Constants: |
| 263 | + lvds_chan = str(int(float(Constants[token.cargo]))) |
| 264 | + consume(IDENTIFIER) |
| 265 | + elif found(NUMBER): |
258 | 266 | lvds_chan = token.cargo |
259 | | - if module_name.upper() in {"LVDS"}: |
260 | | - if not (1 <= int(lvds_chan) <= 16): |
261 | | - error( |
262 | | - f"LVDS channel {dq(lvds_chan)} outside range {{1:16}} for module: " |
263 | | - f"{module_name.upper()}" |
264 | | - ) |
265 | | - else: |
266 | | - error(f"LVDSL is an invalid keyword for module: {module_name.upper()}") |
| 267 | + consume(NUMBER) |
| 268 | + else: |
| 269 | + error("Expected number or constant for LVDS channel") |
267 | 270 |
|
268 | | - consume(NUMBER) |
| 271 | + if module_name.upper() in {"LVDS"}: |
| 272 | + if not (1 <= int(lvds_chan) <= 16): |
| 273 | + error( |
| 274 | + f"LVDS channel {dq(lvds_chan)} outside range {{1:16}} for module: " |
| 275 | + f"{module_name.upper()}" |
| 276 | + ) |
| 277 | + else: |
| 278 | + error(f"LVDSL is an invalid keyword for module: {module_name.upper()}") |
269 | 279 |
|
270 | 280 | # there can be an optional label, specified as token type=STRING |
271 | 281 | if found(STRING): |
@@ -1909,17 +1919,22 @@ def to(): |
1909 | 1919 | global setLevel |
1910 | 1920 |
|
1911 | 1921 | consume("TO") |
1912 | | - # could be a negative number... |
| 1922 | + # optional leading minus sign |
1913 | 1923 | if found("-"): |
1914 | | - # if so, consume the sign and remember it |
1915 | 1924 | consume("-") |
1916 | 1925 | sign = -1.0 |
1917 | 1926 | else: |
1918 | 1927 | sign = 1.0 |
1919 | | - if found(NUMBER): |
1920 | | - # multiply the value by the sign from above (hehe) |
| 1928 | + |
| 1929 | + # level can be a NUMBER or a defined constant |
| 1930 | + if found(IDENTIFIER) and token.cargo in Constants: |
| 1931 | + setLevel = str(sign * float(Constants[token.cargo])) |
| 1932 | + consume(IDENTIFIER) |
| 1933 | + elif found(NUMBER): |
1921 | 1934 | setLevel = str(sign * float(token.cargo)) |
1922 | | - consume(NUMBER) |
| 1935 | + consume(NUMBER) |
| 1936 | + else: |
| 1937 | + error("Expected level as number or defined constant after TO") |
1923 | 1938 |
|
1924 | 1939 |
|
1925 | 1940 | # ----------------------------------------------------------------------------- |
@@ -2191,6 +2206,7 @@ def generic_sequence(*sequenceName): |
2191 | 2206 | (found(IDENTIFIER)) |
2192 | 2207 | and (token.cargo not in subroutines) |
2193 | 2208 | and (token.cargo not in paramNames) |
| 2209 | + and (token.cargo not in Constants) |
2194 | 2210 | ): |
2195 | 2211 | error( |
2196 | 2212 | "(wdlParser.py::generic_sequence) undefined symbol " |
@@ -2222,14 +2238,18 @@ def generic_sequence(*sequenceName): |
2222 | 2238 | consume(IDENTIFIER) |
2223 | 2239 | consume("(") |
2224 | 2240 | # if next token isn't a closing paren then assume |
2225 | | - # it's a number or param |
| 2241 | + # it's a number, param, or constant |
2226 | 2242 | if not found(")"): |
2227 | | - sequence_line += "(" + token.cargo # + ")" |
2228 | | - # and if it's not a number then it must be a defined param |
2229 | | - if not found(NUMBER) and token.cargo not in paramNames: |
| 2243 | + sequence_line += "(" + token.cargo # keep the name; const is emitted earlier |
| 2244 | + # validate: allow NUMBER, defined param, or defined constant |
| 2245 | + if ( |
| 2246 | + not found(NUMBER) |
| 2247 | + and token.cargo not in paramNames |
| 2248 | + and token.cargo not in constNames |
| 2249 | + ): |
2230 | 2250 | error( |
2231 | 2251 | "(wdlParser.py::generic_sequence) undefined " |
2232 | | - "param " + token.show(align=False) |
| 2252 | + "param or constant " + token.show(align=False) |
2233 | 2253 | ) |
2234 | 2254 | elif found("RETURN"): |
2235 | 2255 | consume("RETURN") |
|
0 commit comments