Debian Codegraph @

lib/mlrisc-lib/MLRISC/Tools/Parser/mdl.grm

raw
1 (* There are 30 shift/reduce errors *)
2
3 structure Ast = AstPP.Ast
4 structure Prec = PrecedenceParser
5 open Ast
6
7 val precStacks= ref [] : PrecedenceParser.precedence_stack list ref
8 fun newScope precStack = precStacks := !precStack :: !precStacks
9 fun oldScope precStack =
10 case !precStacks of
11 h::t => (precStacks := t; precStack := h)
12
13 fun Infix precStack (p,[]) = ()
14 | Infix precStack (p,id::ids) =
15 (precStack := Prec.declare(!precStack,id,Prec.INFIX p);
16 Infix precStack (p,ids))
17
18 fun Infixr precStack (p,[]) = ()
19 | Infixr precStack (p,id::ids) =
20 (precStack := Prec.declare(!precStack,id,Prec.INFIXR p);
21 Infixr precStack (p,ids))
22
23 fun Nonfix precStack ([]) = ()
24 | Nonfix precStack (id::ids) =
25 (precStack := Prec.declare(!precStack,id,Prec.NONFIX);
26 Nonfix precStack (ids))
27
28 fun p2s p = PP.text(AstPP.pat p)
29 fun e2s e = PP.text(AstPP.exp e)
30 fun ps2s ps = PP.text(PP.concat(map AstPP.pat ps))
31
32 fun BOOLexp b = LITexp(BOOLlit b)
33
34 fun precErr err loc msg = err(loc,msg)
35
36 fun parseExp precStack err loc toks =
37 Prec.parse{error=precErr err loc,app=APPexp,tuple=TUPLEexp,
38 id=fn id => IDexp(IDENT([],id)),stack= !precStack,
39 toString=e2s, kind="expression"} toks
40
41 fun parsePat precStack err loc toks =
42 let fun appPat (IDpat id,p) = CONSpat(IDENT([],id),SOME p)
43 | appPat (CONSpat(id,NONE),p) = CONSpat(id,SOME p)
44 | appPat (p1,p2) = (err(loc,"pattern "^p2s p1^" "^p2s p2); p1)
45 in case Prec.parse{error=precErr err loc,app=appPat,tuple=TUPLEpat,
46 id=IDpat, stack= !precStack, kind="pattern",
47 toString=p2s} toks of
48 CONSpat(IDENT([],"not"),SOME p) => NOTpat p
49 | p => p
50 end
51
52 fun parseFunPat precStack err loc toks =
53 let fun pr(SOME f,ps) = f^" "^ps2s ps
54 | pr(NONE, ps) = ps2s ps
55 fun appPat ((f,ps), (NONE,ps')) = (f, ps@ps')
56 | appPat ((f,ps), (SOME g,ps')) = (f, ps@[IDpat g]@ps')
57 (*| appPat (p1,p2) = (err(loc,"fun pattern ("^pr p1^") "^pr p2); p1)*)
58 fun lower(NONE,[p]) = p
59 | lower(SOME f,[]) = IDpat f
60 fun tuple ps = (NONE,[TUPLEpat(map lower ps)])
61 fun id n = (SOME n,[])
62 fun toString(NONE,ps) = ps2s ps
63 | toString(SOME f,ps) = f^" "^ps2s ps
64 in Prec.parse{error=precErr err loc,
65 app=appPat,
66 tuple=tuple,
67 id=id,
68 stack= !precStack,
69 kind="function argument",
70 toString=toString
71 } (map (fn Prec.EXP p => Prec.EXP(NONE,[p])
72 | Prec.ID id => Prec.ID id
73 ) toks)
74 end
75
76
77 fun markdecl srcMap (decl,left,right) =
78 MARKdecl(SourceMapping.location srcMap (left,right), decl)
79 fun markexp srcMap (exp,left,right) =
80 MARKexp(SourceMapping.location srcMap (left,right), exp)
81
82 exception Bad
83
84 fun enumPat(err, loc, id, ps) =
85 map (fn IDpat x => IDpat(id^x)
86 | p => (err(loc,"bad pattern "^PP.text(AstPP.pat p)); p)
87 ) ps
88 fun enumPat'(err, loc, ps, id) =
89 map (fn IDpat x => IDpat(x^id)
90 | p => (err(loc,"bad pattern "^PP.text(AstPP.pat p)); p)
91 ) ps
92
93 fun enumExp(err, loc, id, es) =
94 map (fn IDexp(IDENT([],x)) => IDexp(IDENT([],id^x))
95 | e => (err(loc,"bad expression "^PP.text(AstPP.exp e)); e)
96 ) es
97 fun enumExp'(err, loc, es, id) =
98 map (fn IDexp(IDENT([],x)) => IDexp(IDENT([],x^id))
99 | e => (err(loc,"bad expression "^PP.text(AstPP.exp e)); e)
100 ) es
101
102 fun clause(pats, guard, exn, return_ty, e) =
103 let val e = case exn of NONE => e | SOME x => CONTexp(e, x)
104 val e = case return_ty of NONE => e | SOME ty => TYPEDexp(e,ty)
105 in CLAUSE(pats, guard, e)
106 end
107
108 fun seqdecl [d] = d
109 | seqdecl ds = SEQdecl ds
110
111 fun idty(IDENT([],"unit")) = TUPLEty []
112 | idty x = IDty x
113
114 %%
115 %header (functor MDLParser(structure Token : TOKEN
116 structure AstPP : MDL_AST_PRETTY_PRINTER
117 )
118 )
119
120 %arg (srcMap,err,import,precStack,extraCells)
121 : SourceMapping.sourcemap * (SourceMapping.location * string -> unit) *
122 (SourceMapping.location * string -> decl list) *
123 PrecedenceParser.precedence_stack ref *
124 Ast.storagedecl list
125 %name MDL
126 %term ARCHITECTURE | END | LOCAL | IN | OF | CASE | DATATYPE |
127 TYPE | EQ | DOLLAR | TIMES | AND | DEREF | NOT | CONCAT |
128 LLBRACKET | RRBRACKET | LHASHBRACKET |
129 LPAREN | RPAREN | LBRACKET | RBRACKET | LBRACE | RBRACE | SEMICOLON |
130 LDQUOTE | RDQUOTE | LMETA | RMETA |
131 CELLSET | FN | STORAGE | LOCATIONS | HASH |
132 COMMA | COLON | COLONGREATER |
133 DOT | DOTDOT | AT | BAR | ARROW | DARROW | PAR | BITS |
134 IF | THEN | ELSE | TRUE | FALSE | WILD | RAISE |
135 HANDLE | LET | STRUCTURE | FUNCTOR | SIGNATURE | SIG | STRUCT | WHERE |
136 SHARING | INSTRUCTION | REGISTER | CELL | CELLS | ORDERING |
137 FIELD | FIELDS | VLIW | SUPERSCALAR | SIGNED | UNSIGNED |
138 FORMATS | AS | ENCODING | WITHTYPE | FUN | VAL | INCLUDE | OPEN | OP |
139 LITTLE | BIG | ENDIAN | PIPELINE | PREDICATED |
140 LOWERCASE | UPPERCASE | VERBATIM | WHEN | BRANCHING | TAKEN |
141 ASSEMBLY | RTL | SPAN | DEPENDENT | ASSIGN | DELAYSLOT |
142 FORWARDS | ALWAYS | NEVER | BACKWARDS |
143 CANDIDATE | NONFIX | INFIX | INFIXR | DEBUG |
144 ASM_COLON | MC_COLON | RTL_COLON | DELAYSLOT_COLON | NULLIFIED_COLON |
145 PADDING_COLON | CANDIDATE_COLON | AGGREGABLE | ALIASING |
146 RESOURCE | CPU | RESERVATION | TABLE | LATENCY | EQUATION |
147 EXCEPTION |
148 ID of string |
149 SYMBOL of string |
150 TYVAR of string |
151 WORD of Word32.word |
152 INT of int |
153 INTINF of IntInf.int |
154 REAL of string |
155 STRING of string |
156 CHAR of char |
157 ASMTEXT of string |
158 EOF
159
160 %nonterm architecture of decl list |
161 structexp of structexp |
162 sigcon of sigconstraint |
163 opt_of of unit |
164 id of id |
165 sym of id |
166 symb of id |
167 ident of ident |
168 ident2 of ident |
169 tid of id |
170 tid2 of id |
171 tident of ident |
172 tpath of id list * id |
173 idents of ident list |
174 syms of id list |
175 path of id list |
176 decls of decl list |
177 scopeddecls of decl list |
178 functorarg of decl list |
179 scopedmldecls of decl list |
180 newScope of unit |
181 oldScope of unit |
182 mldecls of decl list |
183 exceptionbind of exceptionbind |
184 exceptionbinds of exceptionbind list |
185 decl of decl |
186 locdecl of loc * decl |
187 loc of loc |
188 mldecl of decl |
189 mymldecl of decl |
190 mddecl of decl |
191 mymddecl of decl |
192 sharingdecl of share |
193 sharingdecls of share list |
194 sharelist of ident list |
195 aexp of exp |
196 aexp2 of exp Prec.token |
197 appexp of exp Prec.token list |
198 exp of exp |
199 typedexp of exp |
200 guard of exp option |
201 funguard of exp option |
202 cont of id option |
203 region of id option |
204 opt_exp of exp option |
205 exps of exp list |
206 exps1 of exp list |
207 exps2 of exp list |
208 expseq of exp list |
209 expseq2 of exp list |
210 labexps0 of (id * exp) list |
211 labexps of (id * exp) list |
212 labexp of id * exp |
213 apat of pat |
214 asapat of pat |
215 apat2 of pat Prec.token |
216 apppat of pat Prec.token list |
217 pat of pat |
218 typedpat of pat |
219 pats of pat list |
220 pats1 of pat list |
221 pats2 of pat list |
222 orpats2 of pat list |
223 andpats2 of pat list |
224 labpat of id * pat |
225 labpats0 of (id * pat) list * bool |
226 labpats of (id * pat) list * bool|
227 of_ty of ty option |
228 ty of ty |
229 return_ty of ty option |
230 aty of ty |
231 appty of ty |
232 tys2 of ty list |
233 labty of id * ty |
234 labtys of (id * ty) list |
235 labtys1 of (id * ty) list |
236 tuplety of ty list |
237 signedness of signedness |
238 word of Word32.word |
239 unsignedint of Word32.word |
240 unsignedint_opt of Word32.word option |
241 width of width |
242 int of int |
243 intopt of int |
244 intinf of IntInf.int |
245 real of string |
246 endianess of endianess |
247 kind of archKind |
248 string of string |
249 char of char |
250 bool of bool |
251 literal of literal |
252 slice of int * int |
253 slices of (int * int) list |
254 storagedecl of storagedecl |
255 aliasing of id option |
256 printcell of exp |
257 storagedecls of storagedecl list |
258 cellcount of int option |
259 locbind of locbind |
260 locbinds of locbind list |
261 field of field |
262 fieldid of id |
263 cnv of cnv |
264 fields of field list |
265 formatbind of formatbind |
266 formatbinds of formatbind list |
267 datatypebinds of datatypebind list |
268 datatypebind of datatypebind |
269 consbinds of consbind list |
270 consbind of consbind |
271 consencoding of mc option |
272 sdi of exp option |
273 latency of exp option |
274 pipeline of exp option |
275 nop of flag |
276 flag of flag |
277 flagguard of exp |
278 nullified of flag |
279 delayslot of exp option |
280 delayslotcandidate of exp option |
281 delay of delayslot |
282 branching of branching |
283 consassembly of assembly option |
284 typebinds of typebind list |
285 withtypeclause of typebind list |
286 typebind of typebind |
287 tyvar of tyvar |
288 tyvars of tyvar list |
289 tyvarseq of tyvar list |
290 clause of clause |
291 clauses of clause list |
292 funclause of id * clause |
293 funclauses of id * clause list |
294 funbind of funbind |
295 funbinds of funbind list |
296 valbind of valbind |
297 valbinds of valbind list |
298 assemblycase of assemblycase |
299 rtl of exp option |
300 rtlterm of rtlterm |
301 rtlterms of rtlterm list |
302 opcodeencoding of int list option |
303 encodingexp of int list |
304 encodingexps of int list |
305 fieldty of id option |
306 asms of asm list |
307 asm_strings of asm list |
308 asm of asm |
309 hasasm of bool |
310 sigsub of sigexp -> sigexp |
311 sigsubs of sigexp -> sigexp |
312 sigexp of sigexp |
313 True of unit |
314 False of unit |
315 default of int * exp |
316 default_list of (int * exp) list |
317 defaults of (int * exp) list |
318 aggregable of bool |
319 bitSize of int * bool |
320 resourcebinds of id list |
321 cpubinds of cpubind list |
322 cpubind of cpubind |
323 aliases of string list |
324 resources of (int * id) list |
325 resource of (int * id) |
326 pipelinebinds of pipelinebind list |
327 pipelinebind of pipelinebind |
328 pipelineclauses of (id * pat * pipelineexp) list |
329 pipelineclause of (id * pat * pipelineexp) |
330 cycles0 of cycle list |
331 cycles of cycle list |
332 cycle of cycle |
333 latencybinds of latencybind list |
334 latencybind of latencybind |
335 latencyclauses of (id * pat * exp) list |
336 latencyclause of (id * pat * exp) |
337 optsemi of unit
338
339
340 %verbose
341 %nodefault
342 %pos int
343 %eop EOF
344
345 %left DARROW
346 %left IF THEN ELSE RAISE HANDLE CASE FN OF SEMICOLON COMMA
347 %left DOT
348 %left EQ
349 %right ARROW
350 %left AT
351 %left TIMES
352 %left DEREF NOT
353 (* %left BITS CELL *)
354 (* %left BAR
355 %left AND*)
356
357 (*%left DARROW *)
358
359 %%
360
361 architecture: decls (decls)
362
363 decls: ([])
364 | decl decls (decl::decls)
365
366 mldecls: ([])
367 | mldecl mldecls (mldecl::mldecls)
368
369 optsemi: ()
370 | SEMICOLON optsemi ()
371
372 decl: mldecl optsemi (mldecl)
373 | mddecl optsemi (mddecl)
374 | INCLUDE string optsemi
375 (seqdecl(import
376 (SourceMapping.location srcMap
377 (INCLUDEleft,stringright), string)))
378
379 mldecl: mymldecl (markdecl srcMap (mymldecl,mymldeclleft,mymldeclright))
380
381 mddecl: mymddecl (markdecl srcMap (mymddecl,mymddeclleft,mymddeclright))
382
383 mymddecl: ARCHITECTURE id EQ STRUCT decls END (ARCHdecl(id,decls))
384 | LITTLE ENDIAN (ENDIANESSdecl LITTLE)
385 | BIG ENDIAN (ENDIANESSdecl BIG)
386 | VLIW (ARCHKINDdecl VLIW)
387 | SUPERSCALAR (ARCHKINDdecl SUPERSCALAR)
388 | assemblycase ASSEMBLY (ASSEMBLYCASEdecl assemblycase)
389 | INSTRUCTION FORMATS int BITS formatbinds
390 (FORMATdecl(SOME int,formatbinds))
391 | INSTRUCTION FORMATS formatbinds
392 (FORMATdecl(NONE,formatbinds))
393 | STORAGE storagedecls
394 (STORAGEdecl(storagedecls @ extraCells))
395 | LOCATIONS locbinds (LOCATIONSdecl locbinds)
396 | INSTRUCTION consbinds (INSTRUCTIONdecl consbinds)
397 | DEBUG id (DEBUGdecl id)
398 | RESOURCE resourcebinds (RESOURCEdecl resourcebinds)
399 | CPU cpubinds (CPUdecl cpubinds)
400 | PIPELINE pipelinebinds (PIPELINEdecl pipelinebinds)
401 | LATENCY latencybinds (LATENCYdecl latencybinds)
402
403 resourcebinds: id ([id])
404 | id AND resourcebinds (id::resourcebinds)
405
406 cpubinds: cpubind ([cpubind])
407 | cpubind AND cpubinds (cpubind::cpubinds)
408
409 cpubind: id aliases int LBRACKET resources RBRACKET
410 (CPUbind{name=id,aliases=aliases,
411 maxIssues=int,resources=resources})
412
413 aliases: ([])
414 | string aliases (string::aliases)
415
416 resources: resource ([resource])
417 | resource COMMA resources (resource::resources)
418
419 resource: int id (int,id)
420 | id (1,id)
421
422 pipelinebinds: pipelinebind ([pipelinebind])
423 | pipelinebind AND pipelinebinds (pipelinebind::pipelinebinds)
424
425 pipelinebind: pipelineclauses
426 (let val name = #1(hd pipelineclauses)
427 val clauses = map (fn (_,x,y) => (x,y)) pipelineclauses
428 in (PIPELINEbind(name, clauses)) end
429 )
430
431 pipelineclauses: pipelineclause ([pipelineclause])
432 | pipelineclause BAR pipelineclauses
433 (pipelineclause::pipelineclauses)
434
435 pipelineclause: id pat EQ LBRACKET cycles0 RBRACKET (id, pat,PIPELINE cycles0)
436
437 cycles0: ([])
438 | cycles (cycles)
439
440 cycles: cycle ([cycle])
441 | cycle COMMA cycles (cycle::cycles)
442
443 cycle: id (IDcycle id)
444 | cycle CONCAT cycle (ORcycle(cycle1,cycle2))
445 | cycle TIMES int (REPEATcycle(cycle, int))
446 | LPAREN cycle RPAREN (cycle)
447
448 latencybinds: latencybind ([latencybind])
449 | latencybind AND latencybinds (latencybind::latencybinds)
450
451 latencybind: latencyclauses
452 (let val name = #1(hd latencyclauses)
453 val clauses = map (fn (_,x,y) => (x,y)) latencyclauses
454 in (LATENCYbind(name, clauses)) end
455 )
456
457 latencyclauses: latencyclause ([latencyclause])
458 | latencyclause BAR latencyclauses
459 (latencyclause::latencyclauses)
460
461 latencyclause: id pat EQ exp (id, pat, exp)
462
463 mymldecl: DATATYPE datatypebinds withtypeclause
464 (DATATYPEdecl(datatypebinds,withtypeclause))
465 | TYPE typebinds (DATATYPEdecl([],typebinds))
466 | FUN funbinds (FUNdecl(funbinds))
467 | RTL id LBRACE labpats0 RBRACE EQ exp
468 (RTLdecl(IDpat id,LAMBDAexp
469 [CLAUSE([RECORDpat labpats0],NONE,exp)],
470 SourceMapping.location srcMap (RTLleft, expright)))
471 | RTL asapat EQ exp
472 (RTLdecl(asapat,exp,
473 SourceMapping.location srcMap (RTLleft,expright)))
474 | RTL syms COLON ty (RTLSIGdecl(syms,ty))
475 | VAL valbinds (VALdecl(valbinds))
476 | VAL syms COLON ty (VALSIGdecl(syms,ty))
477 | TYPE tyvarseq tid (TYPESIGdecl(tid,tyvarseq))
478 | LOCAL scopeddecls IN scopeddecls END
479 (LOCALdecl(scopeddecls1,scopeddecls2))
480 | STRUCTURE id EQ structexp
481 (STRUCTUREdecl(id,[],NONE,structexp))
482 | STRUCTURE id sigcon EQ structexp
483 (STRUCTUREdecl(id,[],SOME sigcon,structexp))
484 | STRUCTURE id COLON sigexp (STRUCTURESIGdecl(id,sigexp))
485 | SIGNATURE id EQ sigexp (SIGNATUREdecl(id,sigexp))
486 | FUNCTOR id LPAREN functorarg RPAREN EQ structexp
487 (STRUCTUREdecl(id,functorarg,NONE,structexp))
488 | FUNCTOR id LPAREN functorarg RPAREN sigcon EQ structexp
489 (STRUCTUREdecl(id,functorarg,SOME sigcon,structexp))
490 | FUNCTOR id EQ structexp
491 (FUNCTORdecl(id,[],NONE,structexp))
492 | SHARING sharingdecls (SHARINGdecl sharingdecls)
493 | INFIX intopt syms (Infix precStack (intopt,syms); INFIXdecl(intopt,syms))
494 | INFIXR intopt syms (Infixr precStack (intopt,syms); INFIXRdecl(intopt,syms))
495 | NONFIX syms (Nonfix precStack (syms); NONFIXdecl(syms))
496 | OPEN idents (OPENdecl(idents))
497 | INCLUDE sigexp (INCLUDESIGdecl sigexp)
498 | EXCEPTION exceptionbinds (EXCEPTIONdecl exceptionbinds)
499
500 exceptionbinds: exceptionbind ([exceptionbind])
501 | exceptionbind AND exceptionbinds (exceptionbind::exceptionbinds)
502
503 exceptionbind: id (EXCEPTIONbind(id,NONE))
504 | id OF ty (EXCEPTIONbind(id,SOME ty))
505 | id EQ ident (EXCEPTIONEQbind(id,ident))
506
507
508 functorarg: scopeddecls (scopeddecls)
509 | id sigcon ([FUNCTORARGdecl(id,sigcon)])
510
511 sigexp: ident (IDsig ident)
512 | SIG decls END (DECLsig decls)
513 | sigexp WHERE sigsubs (sigsubs sigexp)
514
515 sigcon: COLON sigexp ({abstract=false,sigexp=sigexp})
516 | COLONGREATER sigexp ({abstract=true,sigexp=sigexp})
517
518 sigsubs: sigsub (sigsub)
519 | sigsub AND sigsubs (sigsub o sigsubs)
520
521 sigsub: TYPE ident EQ ty (fn s => WHERETYPEsig(s,ident,ty))
522 | ident EQ structexp (fn s => WHEREsig(s,ident,structexp))
523
524 sharingdecls: sharingdecl ([sharingdecl])
525 | sharingdecl AND sharingdecls (sharingdecl::sharingdecls)
526
527 sharingdecl: TYPE sharelist (TYPEshare sharelist)
528 | sharelist (STRUCTshare sharelist)
529
530 sharelist: ident EQ ident ([ident1,ident2])
531 | ident EQ sharelist (ident::sharelist)
532
533 scopedmldecls: newScope mldecls oldScope (mldecls)
534
535 scopeddecls: newScope decls oldScope (decls)
536
537 newScope: (newScope precStack)
538 oldScope: (oldScope precStack)
539
540 syms: sym ([sym])
541 | sym syms (sym::syms)
542
543 idents: ident ([ident])
544 | ident idents (ident::idents)
545
546 assemblycase: LOWERCASE (LOWERCASE)
547 | UPPERCASE (UPPERCASE)
548 | VERBATIM (VERBATIM)
549
550 rtl: RTL_COLON exp (SOME(exp))
551 | (NONE)
552
553 rtlterms: rtlterm ([rtlterm])
554 | rtlterm rtlterms (rtlterm::rtlterms)
555
556 rtlterm: string (LITrtl string)
557 | sym (IDrtl sym)
558 | HASH id (COMPOSITErtl id)
559
560 structexp: ident (IDsexp ident)
561 | STRUCT scopeddecls END (DECLsexp scopeddecls)
562 | structexp LPAREN scopeddecls RPAREN
563 (APPsexp(structexp,DECLsexp scopeddecls))
564 | structexp LPAREN ident RPAREN
565 (APPsexp(structexp,IDsexp ident))
566
567 datatypebinds: datatypebind ([datatypebind])
568 | datatypebind AND datatypebinds (datatypebind::datatypebinds)
569
570 datatypebind: tyvarseq id opcodeencoding fieldty hasasm EQ consbinds
571 (let val a = hasasm orelse
572 List.exists(fn CONSbind{asm=SOME _,...}=>true
573 | _ => false) consbinds
574 in
575 DATATYPEbind{id=id,tyvars=tyvarseq,mc=opcodeencoding,
576 asm=a,field=fieldty,cbs=consbinds}
577 end
578 )
579 | tyvarseq id opcodeencoding fieldty hasasm EQ DATATYPE ty
580 (DATATYPEEQbind{id=id,tyvars=tyvarseq,ty=ty})
581
582 hasasm: DEREF (true)
583 | (false)
584
585 fieldty: (NONE)
586 | COLON id (SOME id)
587
588 opcodeencoding: (NONE)
589 | LBRACKET encodingexps RBRACKET (SOME encodingexps)
590
591 encodingexps: encodingexp (encodingexp)
592 | encodingexp COMMA encodingexps (encodingexp@encodingexps)
593
594 encodingexp: int ([int])
595 | int DOTDOT int
596 (let fun f i = if i > int2 then [] else i::f(i+1)
597 in f int1 end)
598 | int int DOTDOT int
599 (let val inc = int2 - int1
600 fun f i = if i > int3 then [] else i::f(i+inc)
601 in f int1 end)
602
603 consbinds: consbind ([consbind])
604 | consbind BAR consbinds (consbind::consbinds)
605
606 consbind: sym of_ty consassembly consencoding rtl nop
607 nullified delayslot delayslotcandidate sdi latency pipeline
608 (let val cand =
609 case delayslotcandidate of
610 SOME _ => delayslotcandidate
611 | _ => case (nop,nullified) of
612 (FLAGoff,FLAGoff) => NONE
613 | _ => (SOME(BOOLexp false))
614 in
615 CONSbind{id=sym,ty=of_ty,mc=consencoding,
616 asm=consassembly,rtl=rtl,
617 nop=nop,sdi=sdi,nullified=nullified,
618 delayslot=delayslot,
619 delaycand=cand, latency=latency, pipeline=pipeline,
620 loc=SourceMapping.location srcMap (symleft,sdiright)
621 }
622 end
623 )
624
625 latency: LATENCY COLON exp (SOME exp)
626 | (NONE)
627
628 pipeline: PIPELINE COLON exp (SOME exp)
629 | (NONE)
630
631 delayslotcandidate: (NONE)
632 | DELAYSLOT CANDIDATE_COLON exp (SOME exp)
633
634 of_ty: (NONE)
635 | OF ty (SOME ty)
636
637 nop: (FLAGoff)
638 | PADDING_COLON flag (flag)
639 | PADDING_COLON False (FLAGoff)
640 | PADDING_COLON True (FLAGon)
641
642 True: TRUE ()
643 | ALWAYS ()
644
645 False: FALSE ()
646 | NEVER ()
647
648 flag: id flagguard (FLAGid(id,true,flagguard))
649 | NOT id flagguard (FLAGid(id,false,flagguard))
650 | id EQ True flagguard (FLAGid(id,true,flagguard))
651 | id EQ False flagguard (FLAGid(id,false,flagguard))
652
653 flagguard: (BOOLexp true)
654 | AND exp (exp)
655
656 nullified: (FLAGoff)
657 | NULLIFIED_COLON FALSE (FLAGoff)
658 | NULLIFIED_COLON flag (flag)
659
660 delayslot: (NONE)
661 | DELAYSLOT_COLON exp (SOME exp)
662
663 branching: BRANCHING FORWARDS (BRANCHforwards)
664 | BRANCHING BACKWARDS (BRANCHbackwards)
665
666 sdi: (NONE)
667 | SPAN DEPENDENT exp (SOME exp)
668
669 consencoding: (NONE)
670 | unsignedint (SOME(WORDmc(unsignedint)))
671 | LPAREN expseq RPAREN (SOME(EXPmc(SEQexp expseq)))
672 | LPAREN exps2 RPAREN (SOME(EXPmc(TUPLEexp exps2)))
673 | id LBRACE labexps0 RBRACE
674 (SOME(EXPmc(APPexp(IDexp(IDENT([],id)),
675 RECORDexp labexps0))))
676 | MC_COLON exp (SOME(EXPmc exp))
677
678 consassembly: (NONE)
679 | string (SOME(STRINGasm string))
680 | asm_strings (SOME(ASMasm asm_strings))
681 | ASM_COLON exp (SOME(ASMasm[EXPasm exp]))
682
683 asm_strings:
684 LDQUOTE asms RDQUOTE (asms)
685 | LDQUOTE asms RDQUOTE asm_strings (asms@asm_strings)
686
687 asms: asm ([asm])
688 | asm asms (asm::asms)
689
690 asm: LMETA exp RMETA (EXPasm exp)
691 | ASMTEXT (TEXTasm ASMTEXT)
692
693 opt_of: ()
694 | OF ()
695
696 withtypeclause: ([])
697 | WITHTYPE typebinds (typebinds)
698
699
700 typebinds: typebind ([typebind])
701 | typebind AND typebinds (typebind::typebinds)
702
703 typebind: tyvarseq tid EQ ty (TYPEbind(tid,tyvarseq,ty))
704
705 tyvarseq: ([])
706 | tyvar ([tyvar])
707 | LPAREN tyvars RPAREN (tyvars)
708
709 tyvars: tyvar ([tyvar])
710 | tyvar COMMA tyvars (tyvar::tyvars)
711
712 formatbinds: formatbind ([formatbind])
713 | formatbind BAR formatbinds (formatbind::formatbinds)
714
715 formatbind: id opt_of LBRACE fields RBRACE opt_exp
716 (FORMATbind(id,fields,opt_exp))
717
718 opt_exp: (NONE)
719 | EQ exp (SOME exp)
720
721 fields: field ([field])
722 | field COMMA fields (field::fields)
723
724 field: fieldid COLON cnv signedness width unsignedint_opt
725 (FIELD{id=fieldid,cnv=cnv,
726 width=width,sign=signedness,value=unsignedint_opt})
727 | id
728 (FIELD{id=id,cnv=NOcnv,width=WIDTH 0,sign=UNSIGNED,value=NONE})
729
730 fieldid: id (id)
731 | WILD ("")
732
733 cnv: (NOcnv)
734 | id (FUNcnv id)
735 | DOLLAR id (CELLcnv id)
736
737 width: (WIDTH 0)
738 | int (WIDTH int)
739 | int DOTDOT int (RANGE(int1,int2))
740
741 unsignedint: int (Word32.fromInt int)
742 | word (word)
743
744 unsignedint_opt: (NONE)
745 | EQ unsignedint (SOME unsignedint)
746
747 signedness: SIGNED (SIGNED)
748 | UNSIGNED (UNSIGNED)
749 | (UNSIGNED)
750
751 funbinds: funbind ([funbind])
752 | funbind AND funbinds (funbind::funbinds)
753
754 funbind: funclauses (FUNbind funclauses)
755
756 valbinds: valbind ([valbind])
757 | valbind AND valbinds (valbind::valbinds)
758
759 valbind: pat EQ typedexp (VALbind(pat,typedexp))
760
761 literal: word (WORD32lit word)
762 | int (INTlit int)
763 | intinf (INTINFlit intinf)
764 | string (STRINGlit string)
765 | char (CHARlit char)
766 | bool (BOOLlit bool)
767 | real (REALlit real)
768
769 aexp: literal (LITexp literal)
770 | ident2 (IDexp ident2)
771 | HASH id (TYPEexp(TYVARty(INTtv id)))
772 | OP symb (IDexp(IDENT([],symb)))
773 | LPAREN symb RPAREN (IDexp(IDENT([],symb)))
774 (*| LPAREN exp COLON ty RPAREN (TYPEDexp(exp,ty))*)
775 | asm_strings (ASMexp(ASMasm asm_strings))
776 | LPAREN RPAREN (TUPLEexp [])
777 | LPAREN typedexp RPAREN (typedexp)
778 | LPAREN exps2 RPAREN (TUPLEexp exps2)
779 | LPAREN expseq2 RPAREN (SEQexp expseq2)
780 | LBRACKET exps RBRACKET (LISTexp(exps,NONE))
781 | LHASHBRACKET exps RBRACKET (VECTORexp exps)
782 | LBRACE labexps0 RBRACE (RECORDexp labexps0)
783 | DOLLAR id LBRACKET exp region RBRACKET (LOCexp(id,exp,region))
784 | LLBRACKET rtlterms RRBRACKET (RTLexp(rtlterms))
785 | sym CONCAT LBRACKET exps RBRACKET
786 (let val loc = SourceMapping.location srcMap
787 (symleft,RBRACKETright)
788 in LISTexp(enumExp(err,loc,sym,exps),NONE) end
789 )
790 | LBRACKET exps RBRACKET CONCAT sym
791 (let val loc = SourceMapping.location srcMap
792 (symleft,RBRACKETright)
793 in LISTexp(enumExp'(err,loc,exps,sym),NONE) end
794 )
795
796 | sym CONCAT LBRACKET exps RBRACKET CONCAT sym
797 (let val loc = SourceMapping.location srcMap
798 (symleft,RBRACKETright)
799 in LISTexp(enumExp'(err,loc,
800 enumExp(err,loc,sym1,exps),sym2),
801 NONE)
802 end
803 )
804 | LET decls IN expseq END (LETexp(decls,expseq))
805
806 region: (NONE)
807 | COLON id (SOME id)
808
809 aexp2: aexp (Prec.EXP aexp)
810 | sym (Prec.ID sym)
811 | EQ (Prec.ID "=")
812 | aexp2 AT LBRACKET slices RBRACKET
813 (Prec.EXP(BITSLICEexp(
814 case aexp2 of Prec.EXP e => e
815 | Prec.ID x => IDexp(IDENT([],x)),slices)))
816
817 labexps0: ([])
818 | labexps (labexps)
819 labexps: labexp ([labexp])
820 | labexp COMMA labexps (labexp::labexps)
821
822 labexp: id EQ typedexp (id,typedexp)
823 | id (id,IDexp(IDENT([],id)))
824
825 appexp: aexp2 ([aexp2])
826 | appexp aexp2 (appexp @ [aexp2])
827
828 exp: appexp (parseExp precStack err
829 (SourceMapping.location srcMap (appexpleft,appexpright)) appexp)
830 | IF typedexp THEN typedexp ELSE exp
831 (IFexp(typedexp1,typedexp2,exp))
832 | CASE typedexp OF clauses (CASEexp(typedexp,clauses))
833 | FN clauses (LAMBDAexp clauses)
834 | exp HANDLE clauses (HANDLEexp(exp,clauses))
835 | RAISE exp (RAISEexp exp)
836
837 typedexp: exp (exp)
838 | typedexp COLON ty (TYPEDexp(typedexp,ty))
839
840 expseq: typedexp ([typedexp])
841 | typedexp SEMICOLON expseq (typedexp::expseq)
842
843 expseq2: typedexp SEMICOLON expseq (typedexp::expseq)
844
845 exps1: typedexp ([typedexp])
846 | typedexp COMMA exps1 (typedexp::exps1)
847
848 exps2: typedexp COMMA exps1 (typedexp::exps1)
849
850 exps: ([])
851 | exps1 (exps1)
852
853 apat: ident2 (CONSpat(ident2,NONE))
854 | literal (LITpat literal)
855 | WILD (WILDpat)
856 | LPAREN RPAREN (TUPLEpat [])
857 | LBRACKET pats RBRACKET (LISTpat(pats,NONE))
858 | LHASHBRACKET pats RBRACKET (VECTORpat pats)
859 | LPAREN pats2 RPAREN (TUPLEpat pats2)
860 | LPAREN orpats2 RPAREN (ORpat orpats2)
861 | LPAREN andpats2 RPAREN (ANDpat andpats2)
862 | LPAREN typedpat RPAREN (typedpat)
863 | LPAREN typedpat WHERE typedexp RPAREN
864 (WHEREpat(typedpat,typedexp))
865 | LPAREN typedpat WHERE typedexp IN typedpat RPAREN
866 (NESTEDpat(typedpat1,typedexp,typedpat2))
867 | LBRACE labpats0 RBRACE (RECORDpat(labpats0))
868 | sym CONCAT LBRACKET pats RBRACKET
869 (let val loc = SourceMapping.location srcMap
870 (symleft,RBRACKETright)
871 in LISTpat(enumPat(err,loc,sym,pats),NONE) end
872 )
873 | sym CONCAT LBRACKET pats RBRACKET CONCAT sym
874 (let val loc = SourceMapping.location srcMap
875 (symleft,RBRACKETright)
876 in LISTpat(enumPat'(err,loc,
877 enumPat(err,loc,sym1,pats),sym2),NONE) end
878 )
879
880 | LBRACKET pats RBRACKET CONCAT sym
881 (let val loc = SourceMapping.location srcMap
882 (symleft,RBRACKETright)
883 in LISTpat(enumPat'(err,loc,pats,sym),NONE) end
884 )
885
886
887 orpats2: typedpat BAR typedpat ([typedpat1,typedpat2])
888 | typedpat BAR orpats2 (typedpat::orpats2)
889
890 andpats2: typedpat AND typedpat ([typedpat1,typedpat2])
891 | typedpat AND andpats2 (typedpat::andpats2)
892
893 apat2: apat (Prec.EXP apat)
894 | sym (Prec.ID sym)
895 | OP sym (Prec.ID sym)
896
897 apppat: apat2 ([apat2])
898 | apppat apat2 (apppat@[apat2])
899
900 pat: apppat (parsePat precStack err
901 (SourceMapping.location srcMap
902 (apppatleft,apppatright)) apppat)
903 | id AS pat (ASpat(id,pat))
904
905 typedpat: pat (pat)
906 | typedpat COLON ty (TYPEDpat(typedpat,ty))
907
908 asapat: apat (apat)
909 | id AS asapat (ASpat(id,asapat))
910
911 pats: ([])
912 | pats1 (pats1)
913
914 pats1: typedpat ([typedpat])
915 | typedpat COMMA pats1 (typedpat::pats1)
916
917 pats2: typedpat COMMA pats1 (typedpat::pats1)
918
919 labpats0: ([],false)
920 | labpats (labpats)
921
922 labpats: labpat ([labpat],false)
923 | labpat COMMA DOTDOT ([labpat],true)
924 | labpat COMMA labpats (labpat:: #1 labpats, #2 labpats)
925
926 labpat: sym (sym,IDpat sym)
927 | sym EQ typedpat (sym,typedpat)
928 | sym AS typedpat (sym,ASpat(sym,typedpat))
929 | sym WHERE typedexp (sym,WHEREpat(IDpat sym,typedexp))
930 | sym WHERE typedexp IN typedpat
931 (sym,NESTEDpat(IDpat sym,typedexp,typedpat))
932
933 clause: typedpat guard cont DARROW exp
934 (clause([typedpat],guard,cont,NONE,exp))
935
936 cont: (NONE)
937 | EXCEPTION id (SOME id)
938
939 guard: (NONE)
940 | WHERE typedexp (SOME typedexp)
941
942 clauses: clause ([clause])
943 | clause BAR clauses (clause::clauses)
944
945 funclause: apppat funguard return_ty cont EQ typedexp
946 (let val loc = SourceMapping.location srcMap (apppatleft,typedexpright)
947 in case parseFunPat precStack err loc apppat of
948 (SOME f,ps) => (f,clause(ps,funguard,cont,return_ty,typedexp))
949 | (NONE,ps) =>
950 (err(loc,
951 "in clause "^
952 PP.text(AstPP.clause (CLAUSE(ps,funguard,typedexp))));
953 ("dummy",clause(ps,funguard,cont,return_ty,typedexp)))
954 end
955 )
956
957 return_ty: (NONE)
958 | COLON ty (SOME ty)
959
960 funguard: (NONE)
961 | WHERE LPAREN typedexp RPAREN (SOME typedexp)
962
963 funclauses: funclause (#1 funclause,[#2 funclause])
964 | funclause BAR funclauses (#1 funclause,#2 funclause:: #2 funclauses)
965
966 aty: tident (idty(tident))
967 | HASH int (INTVARty int)
968 | tyvar (TYVARty tyvar)
969 | DOLLAR id (CELLty id)
970 | LPAREN RPAREN (TUPLEty [])
971 | LPAREN ty RPAREN (ty)
972 | LBRACE labtys RBRACE (RECORDty labtys)
973
974 appty: aty (aty)
975 | appty tident (APPty(tident,[appty]))
976 | LPAREN tys2 RPAREN tident (APPty(tident,tys2))
977
978 tid: id (id)
979 | tid2 (tid2)
980
981 tid2: BITS ("bits")
982 | CELL ("cell")
983 | INSTRUCTION ("instruction")
984
985 tident: tid (IDENT([],tid))
986 | tpath (IDENT(rev(#1 tpath), #2 tpath))
987
988 tpath: tid DOT tid ([tid1],tid2)
989 | tpath DOT tid (#2 tpath :: #1 tpath,tid)
990
991
992 tys2: ty COMMA ty ([ty1,ty2])
993 | ty COMMA tys2 (ty::tys2)
994
995 ty: ty ARROW ty (FUNty(ty1,ty2))
996 | tuplety (TUPLEty tuplety)
997 | appty (appty)
998
999 labtys: ([])
1000 | labtys1 (labtys1)
1001
1002 labtys1: labty ([labty])
1003 | labty COMMA labtys1 (labty::labtys1)
1004
1005 labty: id COLON ty (id,ty)
1006
1007 tuplety: appty TIMES appty ([appty1,appty2])
1008 | appty TIMES tuplety (appty::tuplety)
1009
1010 storagedecls: storagedecl ([storagedecl])
1011 | storagedecl BAR storagedecls (storagedecl::storagedecls)
1012
1013 storagedecl: id EQ DOLLAR id LBRACKET cellcount RBRACKET bitSize
1014 aliasing defaults printcell
1015 (CELLdecl{id=id1,nickname=id2,
1016 bits= #1 bitSize,count=cellcount,
1017 alias= aliasing, aggregable= #2 bitSize,
1018 from=ref 0,to=ref 0,print=printcell,
1019 defaults=defaults})
1020
1021 aggregable: (false)
1022 | AGGREGABLE (true)
1023
1024 bitSize: OF int aggregable BITS (int,aggregable)
1025 | (0,false)
1026
1027 cellcount: int (SOME int)
1028 | (NONE)
1029
1030 locbind: id EQ exp (LOCbind(id,NONE,exp))
1031 | id pat EQ exp (LOCbind(id,SOME pat,exp))
1032
1033 locbinds: locbind ([locbind])
1034 | locbind AND locbinds (locbind::locbinds)
1035
1036 word: WORD (WORD)
1037
1038 int: INT (INT)
1039
1040 intopt: int (int)
1041 | (0)
1042
1043 intinf: INTINF (INTINF)
1044
1045 real: REAL (REAL)
1046
1047 aliasing: (NONE)
1048 | ALIASING id (SOME id)
1049
1050 printcell: ASM_COLON string
1051 (LAMBDAexp [CLAUSE([WILDpat],NONE,
1052 LITexp(STRINGlit string))])
1053 | ASM_COLON LPAREN exp RPAREN (exp)
1054
1055 defaults: ([])
1056 | WHERE default_list (default_list)
1057
1058 default_list: default ([default])
1059 | default AND default_list (default::default_list)
1060
1061 default: DOLLAR id LBRACKET int RBRACKET EQ exp (int,exp)
1062
1063 slices: slice ([slice])
1064 | slice COMMA slices (slice::slices)
1065
1066 slice: int DOTDOT int (int1,int2)
1067 | int (int1,int1)
1068
1069 id: ID (ID)
1070 | SYMBOL (SYMBOL)
1071 | CELLSET ("cellset")
1072
1073 sym: id (id)
1074 | symb (symb)
1075
1076 symb: TIMES ("*")
1077 | NOT ("not")
1078 | DEREF ("!")
1079
1080 ident: id (IDENT([],id))
1081 | ident2 (ident2)
1082
1083 ident2: path (IDENT(rev(tl path),hd path))
1084
1085 path: id DOT sym ([sym,id])
1086 | path DOT sym (sym::path)
1087
1088 tyvar: TYVAR (VARtv TYVAR)
1089 | HASH id (INTtv id)
1090
1091 string: STRING (STRING)
1092
1093 char: CHAR (CHAR)
1094
1095 bool: False (false)
1096 | True (true)