@@ -13,44 +13,143 @@ module CIL-STMT
13
13
rule
14
14
<k> goto L:Label; ~> _ => Ss </k>
15
15
<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>
20
18
[computational]
21
19
22
- rule <k> (. => eval-case-labels)
23
- ~> goto $caseLabel(_, _) ;
24
- ...</k>
20
+ rule
21
+ <k> (. => make-goto-table ~> eval-case-labels) ~> goto _:Label ; ...</k>
25
22
<frame-fun-id> F:Ptr </frame-fun-id>
26
23
<fun-id> F </fun-id>
27
- <labels-evaluated > false </labels-evaluated >
24
+ <labels-generated > false => true </labels-generated >
28
25
[structural]
29
26
30
27
rule <k> goto $caseLabel(I:Int, V:TypedValue) ;
31
28
=> goto $defaultLabel(I) ; ...</k>
32
29
<frame-fun-id> F:Ptr </frame-fun-id>
33
30
<fun-id> F </fun-id>
34
31
<labels> Lbls:Map </labels>
35
- <labels-evaluated > true </labels-evaluated >
32
+ <labels-generated > true </labels-generated >
36
33
when notBool ($caseLabel(I, V) in keys Lbls)
37
34
[structural]
38
35
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
+
39
142
// This is a somewhat hackish method for evaluating the constant expressions
40
143
// in the case labels of switch statements. It seems to slow things down
41
144
// quite a bit too.
42
145
syntax K ::= "eval-case-labels"
43
146
| "eval-case-labels" "(" Map "," Map ")"
44
147
| "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
+
49
149
rule <k> eval-case-labels => eval-case-labels(Lbls, .Map) ...</k>
50
150
<frame-fun-id> F:Ptr </frame-fun-id>
51
151
<fun-id> F </fun-id>
52
152
<labels> Lbls:Map </labels>
53
- <labels-evaluated> false </labels-evaluated>
54
153
55
154
rule eval-case-labels(
56
155
_:Map (L:Label |-> Ss:Stmts => .Map),
@@ -70,7 +169,6 @@ module CIL-STMT
70
169
<frame-fun-id> F:Ptr </frame-fun-id>
71
170
<fun-id> F </fun-id>
72
171
<labels> _ => Lbls </labels>
73
- <labels-evaluated> false => true </labels-evaluated>
74
172
[structural]
75
173
76
174
syntax K ::= "$exp2bool" "(" Exp ")" [strict]
0 commit comments