-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrt_counter.v
203 lines (169 loc) · 6.09 KB
/
rt_counter.v
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
(**
_AUTHOR_
<<
Zhi Zhang
Department of Computer and Information Sciences
Kansas State University
>>
*)
Require Export rt_gen.
(** * Count Number of Run-Time Checks *)
Section Check_Count.
Record cks_infor_t: Type := cks_infor {
num_of_cks : nat;
division_cks: nat;
overflow_cks: nat;
range_cks : nat
}.
Function conj_cks_infor (x1 x2 : cks_infor_t): cks_infor_t :=
match x1, x2 with
| cks_infor cksNum d o r, cks_infor cksNum1 d1 o1 r1 =>
cks_infor (cksNum + cksNum1) (d + d1) (o + o1) (r + r1)
end.
Function compute_cks_infor (cks: check_flags) : cks_infor_t :=
match cks with
| nil => cks_infor 0 0 0 0
| ck :: cks' =>
let r := compute_cks_infor cks' in
match ck with
| DivCheck =>
cks_infor (r.(num_of_cks) + 1) (r.(division_cks) + 1) r.(overflow_cks) r.(range_cks)
| OverflowCheck =>
cks_infor (r.(num_of_cks) + 1) r.(division_cks) (r.(overflow_cks) + 1) r.(range_cks)
| RangeCheck =>
cks_infor (r.(num_of_cks) + 1) r.(division_cks) r.(overflow_cks) (r.(range_cks) + 1)
| RangeCheckOnReturn =>
cks_infor (r.(num_of_cks) + 1) r.(division_cks) r.(overflow_cks) (r.(range_cks) + 1)
| _ => r
end
end.
(** ** Check Counter for Expression *)
Function count_exp_check_flags (e: expRT): cks_infor_t :=
match e with
| LiteralRT n l in_cks ex_cks =>
compute_cks_infor (in_cks ++ ex_cks)
| NameRT n nm =>
count_name_check_flags nm
| BinOpRT n op e1 e2 in_cks ex_cks =>
conj_cks_infor (compute_cks_infor (in_cks ++ ex_cks))
(conj_cks_infor
(count_exp_check_flags e1)
(count_exp_check_flags e2)
)
| UnOpRT n op e in_cks ex_cks =>
conj_cks_infor (compute_cks_infor (in_cks ++ ex_cks))
(count_exp_check_flags e)
end
(** ** Check Counter for Name *)
with count_name_check_flags (n: nameRT): cks_infor_t :=
match n with
| IdentifierRT n x ex_cks =>
compute_cks_infor ex_cks
| IndexedComponentRT n x e ex_cks =>
conj_cks_infor (compute_cks_infor ex_cks)
(conj_cks_infor
(count_name_check_flags x)
(count_exp_check_flags e)
)
| SelectedComponentRT n x f ex_cks =>
conj_cks_infor (compute_cks_infor ex_cks)
(count_name_check_flags x)
end.
Function count_args_check_flags (le: list expRT): cks_infor_t :=
match le with
| nil => cks_infor 0 0 0 0
| (e1 :: le1') =>
conj_cks_infor (count_exp_check_flags e1)
(count_args_check_flags le1')
end.
(** ** Check Counter for Statement *)
Function count_stmt_check_flags (c: stmtRT): cks_infor_t :=
match c with
| NullRT => cks_infor 0 0 0 0
| AssignRT n x e =>
conj_cks_infor (count_name_check_flags x)
(count_exp_check_flags e)
| IfRT n e c1 c2 =>
conj_cks_infor (count_exp_check_flags e)
(conj_cks_infor
(count_stmt_check_flags c1)
(count_stmt_check_flags c2)
)
| WhileRT n e c =>
conj_cks_infor (count_exp_check_flags e)
(count_stmt_check_flags c)
| CallRT n pn p args =>
(count_args_check_flags args)
| SeqRT n c1 c2 =>
conj_cks_infor (count_stmt_check_flags c1)
(count_stmt_check_flags c2)
end.
Function count_type_decl_check_flags (t: typeDeclRT): cks_infor_t :=
match t with
| SubtypeDeclRT n tn t (RangeRT l u) =>
cks_infor 0 0 0 0
| DerivedTypeDeclRT n tn t (RangeRT l u) =>
cks_infor 0 0 0 0
| IntegerTypeDeclRT n tn (RangeRT l u) =>
cks_infor 0 0 0 0
| ArrayTypeDeclRT n tn tm t =>
cks_infor 0 0 0 0
| RecordTypeDeclRT n tn fs =>
cks_infor 0 0 0 0
end.
Function count_object_decl_check_flags (o: objDeclRT): cks_infor_t :=
match o with
| mkobjDeclRT n x t None =>
cks_infor 0 0 0 0
| mkobjDeclRT n x t (Some e) =>
count_exp_check_flags e
end.
Function count_object_decls_check_flags (lo: list objDeclRT): cks_infor_t :=
match lo with
| nil => cks_infor 0 0 0 0
| o1 :: lo1' =>
conj_cks_infor (count_object_decl_check_flags o1)
(count_object_decls_check_flags lo1')
end.
Function count_param_spec_check_flags (param: paramSpecRT): cks_infor_t :=
match param with
| mkparamSpecRT n x m t =>
cks_infor 0 0 0 0
end.
Function count_param_specs_check_flags (lparam: list paramSpecRT): cks_infor_t :=
match lparam with
| nil => cks_infor 0 0 0 0
| param1 :: lparam1' =>
conj_cks_infor (count_param_spec_check_flags param1)
(count_param_specs_check_flags lparam1')
end.
(** ** Check Counter for Declaration *)
Function count_declaration_check_flags (d: declRT): cks_infor_t :=
match d with
| NullDeclRT => cks_infor 0 0 0 0
| TypeDeclRT n t =>
count_type_decl_check_flags t
| ObjDeclRT n o =>
count_object_decl_check_flags o
| ProcBodyDeclRT n p =>
count_procedure_body_check_flags p
| SeqDeclRT n d1 d2 =>
conj_cks_infor (count_declaration_check_flags d1) (count_declaration_check_flags d2)
end
(** ** Check Counter for Procedure *)
with count_procedure_body_check_flags (p: procBodyDeclRT): cks_infor_t :=
match p with
| mkprocBodyDeclRT n p params decls stmt =>
conj_cks_infor (count_param_specs_check_flags params)
(conj_cks_infor
(count_declaration_check_flags decls)
(count_stmt_check_flags stmt)
)
end.
Definition count_option_declaration_check_flags (x: option declRT): cks_infor_t :=
match x with
| Some ast => count_declaration_check_flags ast
| None => cks_infor 0 0 0 0
end.
End Check_Count.