@@ -13,44 +13,143 @@ module CIL-STMT
1313 rule
1414 <k> goto L:Label; ~> _ => Ss </k>
1515 <frame-fun-id> F:Ptr </frame-fun-id>
16- <fun>...
17- <fun-id> F </fun-id>
18- <labels>... L |-> Ss:Stmts ...</labels>
19- ...</fun>
16+ <fun-id> F </fun-id>
17+ <labels>... L |-> Ss:Stmts ...</labels>
2018 [computational]
2119
22- rule <k> (. => eval-case-labels)
23- ~> goto $caseLabel(_, _) ;
24- ...</k>
20+ rule
21+ <k> (. => make-goto-table ~> eval-case-labels) ~> goto _:Label ; ...</k>
2522 <frame-fun-id> F:Ptr </frame-fun-id>
2623 <fun-id> F </fun-id>
27- <labels-evaluated > false </labels-evaluated >
24+ <labels-generated > false => true </labels-generated >
2825 [structural]
2926
3027 rule <k> goto $caseLabel(I:Int, V:TypedValue) ;
3128 => goto $defaultLabel(I) ; ...</k>
3229 <frame-fun-id> F:Ptr </frame-fun-id>
3330 <fun-id> F </fun-id>
3431 <labels> Lbls:Map </labels>
35- <labels-evaluated > true </labels-evaluated >
32+ <labels-generated > true </labels-generated >
3633 when notBool ($caseLabel(I, V) in keys Lbls)
3734 [structural]
3835
36+ /*
37+ * Compute the goto table (Map{Label, Stmt}). We do this at "runtime" to
38+ * improve the performance of the interpreter.
39+ */
40+ syntax K ::= "make-goto-table"
41+ rule
42+ <k> make-goto-table ...</k>
43+ <frame-fun-id> F:Ptr </frame-fun-id>
44+ <fun-id> F </fun-id>
45+ <body> { _:VarDecls { Ss:Stmts } } </body>
46+ <make-goto-table-enabled> false => true </make-goto-table-enabled>
47+ <make-goto-table-tasks>
48+ (.Bag =>
49+ <make-goto-table-task>
50+ <make-goto-table-stmts> Ss </make-goto-table-stmts>
51+ <make-goto-table-cont> .Stmts </make-goto-table-cont>
52+ </make-goto-table-task>
53+ )
54+ </make-goto-table-tasks>
55+ [structural]
56+ rule
57+ <make-goto-table-tasks>...
58+ <make-goto-table-task>...
59+ <make-goto-table-stmts> .Stmts </make-goto-table-stmts>
60+ ...</make-goto-table-task>
61+ => .Bag
62+ ...</make-goto-table-tasks>
63+ [structural]
64+ rule
65+ <k> make-goto-table => . ...</k>
66+ <make-goto-table-enabled> true => false </make-goto-table-enabled>
67+ <make-goto-table-tasks> .Bag </make-goto-table-tasks>
68+ [structural]
69+
70+ rule
71+ <frame-fun-id> F:Ptr </frame-fun-id>
72+ <fun-id> F </fun-id>
73+ <labels>... .Map => L |-> (S Ss1 ) @Stmts Cont ...</labels>
74+ <make-goto-table-task>
75+ <make-goto-table-stmts>
76+ L:Label : S:Stmt Ss1 :Stmts => S Ss1
77+ </make-goto-table-stmts>
78+ <make-goto-table-cont>
79+ Cont:Stmts
80+ </make-goto-table-cont>
81+ </make-goto-table-task>
82+ [structural]
83+
84+ rule
85+ <make-goto-table-tasks>...
86+ <make-goto-table-task>
87+ <make-goto-table-stmts>
88+ (if ( _ ) S1 :Stmt else S2 :Stmt) Ss:Stmts => Ss
89+ </make-goto-table-stmts>
90+ <make-goto-table-cont>
91+ Cont:Stmts
92+ </make-goto-table-cont>
93+ </make-goto-table-task>
94+ (.Bag =>
95+ <make-goto-table-task>
96+ <make-goto-table-stmts> S1 (.Stmts) </make-goto-table-stmts>
97+ <make-goto-table-cont> Ss @Stmts Cont </make-goto-table-cont>
98+ </make-goto-table-task>
99+ <make-goto-table-task>
100+ <make-goto-table-stmts> S2 (.Stmts) </make-goto-table-stmts>
101+ <make-goto-table-cont> Ss @Stmts Cont </make-goto-table-cont>
102+ </make-goto-table-task>
103+ )
104+ ...</make-goto-table-tasks>
105+ [structural]
106+ rule
107+ <make-goto-table-tasks>...
108+ <make-goto-table-task>
109+ <make-goto-table-stmts>
110+ while (E:Exp) S:Stmt Ss:Stmts => Ss
111+ </make-goto-table-stmts>
112+ <make-goto-table-cont>
113+ Cont:Stmts
114+ </make-goto-table-cont>
115+ </make-goto-table-task>
116+ (.Bag =>
117+ <make-goto-table-task>
118+ <make-goto-table-stmts> S (.Stmts) </make-goto-table-stmts>
119+ <make-goto-table-cont>
120+ (while (E) S Ss) @Stmts Cont
121+ </make-goto-table-cont>
122+ </make-goto-table-task>
123+ )
124+ ...</make-goto-table-tasks>
125+ [structural]
126+ rule
127+ <make-goto-table-stmts>
128+ { Ss1 :Stmts } Ss2 :Stmts => Ss1 @Stmts Ss2
129+ </make-goto-table-stmts>
130+ [structural]
131+ rule
132+ <make-goto-table-stmts>
133+ KLabel:KLabel(KList:KList) Ss:Stmts => Ss
134+ </make-goto-table-stmts>
135+ when isStmt(KLabel:KLabel(KList:KList))
136+ andBool KLabel =/=KLabel '_:_
137+ andBool KLabel =/=KLabel ' if `(_`)_else_
138+ andBool KLabel =/=KLabel 'while`(_`)_
139+ andBool KLabel =/=KLabel ' `{_`}
140+ [structural]
141+
39142 // This is a somewhat hackish method for evaluating the constant expressions
40143 // in the case labels of switch statements. It seems to slow things down
41144 // quite a bit too.
42145 syntax K ::= "eval-case-labels"
43146 | "eval-case-labels" "(" Map "," Map ")"
44147 | "case-label-freezer" "(" Int "," Stmts ")"
45- rule <k> eval-case-labels => . ...</k>
46- <frame-fun-id> F:Ptr </frame-fun-id>
47- <fun-id> F </fun-id>
48- <labels-evaluated> true </labels-evaluated>
148+
49149 rule <k> eval-case-labels => eval-case-labels(Lbls, .Map) ...</k>
50150 <frame-fun-id> F:Ptr </frame-fun-id>
51151 <fun-id> F </fun-id>
52152 <labels> Lbls:Map </labels>
53- <labels-evaluated> false </labels-evaluated>
54153
55154 rule eval-case-labels(
56155 _:Map (L:Label |-> Ss:Stmts => .Map),
@@ -70,7 +169,6 @@ module CIL-STMT
70169 <frame-fun-id> F:Ptr </frame-fun-id>
71170 <fun-id> F </fun-id>
72171 <labels> _ => Lbls </labels>
73- <labels-evaluated> false => true </labels-evaluated>
74172 [structural]
75173
76174 syntax K ::= "$exp2bool" "(" Exp ")" [strict]
0 commit comments