[3] | 1 | (* *********************************************************************) |
---|
| 2 | (* *) |
---|
| 3 | (* The Compcert verified compiler *) |
---|
| 4 | (* *) |
---|
| 5 | (* Xavier Leroy, INRIA Paris-Rocquencourt *) |
---|
| 6 | (* *) |
---|
| 7 | (* Copyright Institut National de Recherche en Informatique et en *) |
---|
| 8 | (* Automatique. All rights reserved. This file is distributed *) |
---|
| 9 | (* under the terms of the GNU General Public License as published by *) |
---|
| 10 | (* the Free Software Foundation, either version 2 of the License, or *) |
---|
| 11 | (* (at your option) any later version. This file is also distributed *) |
---|
| 12 | (* under the terms of the INRIA Non-Commercial License Agreement. *) |
---|
| 13 | (* *) |
---|
| 14 | (* *********************************************************************) |
---|
| 15 | |
---|
| 16 | (* * Dynamic semantics for the Clight language *) |
---|
| 17 | |
---|
[474] | 18 | (*include "Coqlib.ma".*) |
---|
| 19 | (*include "Errors.ma".*) |
---|
| 20 | (*include "Integers.ma".*) |
---|
| 21 | (*include "Floats.ma".*) |
---|
| 22 | (*include "Values.ma".*) |
---|
| 23 | (*include "AST.ma".*) |
---|
| 24 | (*include "Mem.ma".*) |
---|
[700] | 25 | include "common/Globalenvs.ma". |
---|
| 26 | include "Clight/Csyntax.ma". |
---|
[474] | 27 | (*include "Events.ma".*) |
---|
[700] | 28 | include "common/Smallstep.ma". |
---|
[1872] | 29 | include "Clight/ClassifyOp.ma". |
---|
[3] | 30 | |
---|
| 31 | (* * * Semantics of type-dependent operations *) |
---|
| 32 | |
---|
| 33 | (* * Interpretation of values as truth values. |
---|
| 34 | Non-zero integers, non-zero floats and non-null pointers are |
---|
| 35 | considered as true. The integer zero (which also represents |
---|
| 36 | the null pointer) and the float 0.0 are false. *) |
---|
| 37 | |
---|
[487] | 38 | inductive is_false: val → type → Prop ≝ |
---|
[3] | 39 | | is_false_int: ∀sz,sg. |
---|
[961] | 40 | is_false (Vint sz (zero ?)) (Tint sz sg) |
---|
[484] | 41 | | is_false_pointer: ∀r,r',t. |
---|
| 42 | is_false (Vnull r) (Tpointer r' t) |
---|
[3] | 43 | | is_false_float: ∀sz. |
---|
| 44 | is_false (Vfloat Fzero) (Tfloat sz). |
---|
| 45 | |
---|
[487] | 46 | inductive is_true: val → type → Prop ≝ |
---|
[961] | 47 | | is_true_int_int: ∀sz,sg,n. |
---|
| 48 | n ≠ (zero ?) → |
---|
| 49 | is_true (Vint sz n) (Tint sz sg) |
---|
[1545] | 50 | | is_true_pointer_pointer: ∀ptr,s,t. |
---|
| 51 | is_true (Vptr ptr) (Tpointer s t) |
---|
[3] | 52 | | is_true_float: ∀f,sz. |
---|
| 53 | f ≠ Fzero → |
---|
| 54 | is_true (Vfloat f) (Tfloat sz). |
---|
| 55 | |
---|
[487] | 56 | inductive bool_of_val : val → type → val → Prop ≝ |
---|
[3] | 57 | | bool_of_val_true: ∀v,ty. |
---|
| 58 | is_true v ty → |
---|
| 59 | bool_of_val v ty Vtrue |
---|
| 60 | | bool_of_val_false: ∀v,ty. |
---|
| 61 | is_false v ty → |
---|
| 62 | bool_of_val v ty Vfalse. |
---|
| 63 | |
---|
| 64 | (* * The following [sem_] functions compute the result of an operator |
---|
| 65 | application. Since operators are overloaded, the result depends |
---|
| 66 | both on the static types of the arguments and on their run-time values. |
---|
| 67 | Unlike in C, automatic conversions between integers and floats |
---|
| 68 | are not performed. For instance, [e1 + e2] is undefined if [e1] |
---|
| 69 | is a float and [e2] an integer. The Clight producer must have explicitly |
---|
| 70 | promoted [e2] to a float. *) |
---|
| 71 | |
---|
[487] | 72 | let rec sem_neg (v: val) (ty: type) : option val ≝ |
---|
[3] | 73 | match ty with |
---|
[961] | 74 | [ Tint sz _ ⇒ |
---|
[3] | 75 | match v with |
---|
[961] | 76 | [ Vint sz' n ⇒ if eq_intsize sz sz' |
---|
| 77 | then Some ? (Vint ? (two_complement_negation ? n)) |
---|
| 78 | else None ? |
---|
[648] | 79 | | _ ⇒ None ? |
---|
[3] | 80 | ] |
---|
| 81 | | Tfloat _ ⇒ |
---|
| 82 | match v with |
---|
| 83 | [ Vfloat f ⇒ Some ? (Vfloat (Fneg f)) |
---|
| 84 | | _ ⇒ None ? |
---|
| 85 | ] |
---|
| 86 | | _ ⇒ None ? |
---|
| 87 | ]. |
---|
| 88 | |
---|
[487] | 89 | let rec sem_notint (v: val) : option val ≝ |
---|
[3] | 90 | match v with |
---|
[961] | 91 | [ Vint sz n ⇒ Some ? (Vint ? (exclusive_disjunction_bv ? n (mone ?))) (* XXX *) |
---|
[3] | 92 | | _ ⇒ None ? |
---|
| 93 | ]. |
---|
| 94 | |
---|
[487] | 95 | let rec sem_notbool (v: val) (ty: type) : option val ≝ |
---|
[3] | 96 | match ty with |
---|
[961] | 97 | [ Tint sz _ ⇒ |
---|
[3] | 98 | match v with |
---|
[961] | 99 | [ Vint sz' n ⇒ if eq_intsize sz sz' |
---|
| 100 | then Some ? (of_bool (eq_bv ? n (zero ?))) |
---|
| 101 | else None ? |
---|
[3] | 102 | | _ ⇒ None ? |
---|
| 103 | ] |
---|
[124] | 104 | | Tpointer _ _ ⇒ |
---|
[3] | 105 | match v with |
---|
[1545] | 106 | [ Vptr _ ⇒ Some ? Vfalse |
---|
[502] | 107 | | Vnull _ ⇒ Some ? Vtrue |
---|
[3] | 108 | | _ ⇒ None ? |
---|
| 109 | ] |
---|
| 110 | | Tfloat _ ⇒ |
---|
| 111 | match v with |
---|
| 112 | [ Vfloat f ⇒ Some ? (of_bool (Fcmp Ceq f Fzero)) |
---|
| 113 | | _ ⇒ None ? |
---|
| 114 | ] |
---|
| 115 | | _ ⇒ None ? |
---|
| 116 | ]. |
---|
| 117 | |
---|
[487] | 118 | let rec sem_add (v1:val) (t1:type) (v2: val) (t2:type) : option val ≝ |
---|
[3] | 119 | match classify_add t1 t2 with |
---|
[1872] | 120 | [ add_case_ii _ _ ⇒ (**r integer addition *) |
---|
[3] | 121 | match v1 with |
---|
[961] | 122 | [ Vint sz1 n1 ⇒ match v2 with |
---|
| 123 | [ Vint sz2 n2 ⇒ intsize_eq_elim ? sz1 sz2 ? n1 |
---|
| 124 | (λn1. Some ? (Vint ? (addition_n ? n1 n2))) (None ?) |
---|
[3] | 125 | | _ ⇒ None ? ] |
---|
| 126 | | _ ⇒ None ? ] |
---|
[1872] | 127 | | add_case_ff _ ⇒ (**r float addition *) |
---|
[3] | 128 | match v1 with |
---|
| 129 | [ Vfloat n1 ⇒ match v2 with |
---|
| 130 | [ Vfloat n2 ⇒ Some ? (Vfloat (Fadd n1 n2)) |
---|
| 131 | | _ ⇒ None ? ] |
---|
| 132 | | _ ⇒ None ? ] |
---|
[1872] | 133 | | add_case_pi _ _ ty _ _ ⇒ (**r pointer plus integer *) |
---|
[3] | 134 | match v1 with |
---|
[1545] | 135 | [ Vptr ptr1 ⇒ match v2 with |
---|
| 136 | [ Vint sz2 n2 ⇒ Some ? (Vptr (shift_pointer_n ? ptr1 (sizeof ty) n2)) |
---|
[3] | 137 | | _ ⇒ None ? ] |
---|
[484] | 138 | | Vnull r ⇒ match v2 with |
---|
[961] | 139 | [ Vint sz2 n2 ⇒ if eq_bv ? n2 (zero ?) then Some ? (Vnull r) else None ? |
---|
[484] | 140 | | _ ⇒ None ? ] |
---|
[3] | 141 | | _ ⇒ None ? ] |
---|
[1872] | 142 | | add_case_ip _ _ _ _ ty ⇒ (**r integer plus pointer *) |
---|
[3] | 143 | match v1 with |
---|
[961] | 144 | [ Vint sz1 n1 ⇒ match v2 with |
---|
[1545] | 145 | [ Vptr ptr2 ⇒ Some ? (Vptr (shift_pointer_n ? ptr2 (sizeof ty) n1)) |
---|
[961] | 146 | | Vnull r ⇒ if eq_bv ? n1 (zero ?) then Some ? (Vnull r) else None ? |
---|
[3] | 147 | | _ ⇒ None ? ] |
---|
| 148 | | _ ⇒ None ? ] |
---|
[1872] | 149 | | add_default _ _ ⇒ None ? |
---|
[3] | 150 | ]. |
---|
| 151 | |
---|
[487] | 152 | let rec sem_sub (v1:val) (t1:type) (v2: val) (t2:type) : option val ≝ |
---|
[3] | 153 | match classify_sub t1 t2 with |
---|
[1872] | 154 | [ sub_case_ii _ _ ⇒ (**r integer subtraction *) |
---|
[3] | 155 | match v1 with |
---|
[961] | 156 | [ Vint sz1 n1 ⇒ match v2 with |
---|
| 157 | [ Vint sz2 n2 ⇒ intsize_eq_elim ? sz1 sz2 ? n1 |
---|
| 158 | (λn1.Some ? (Vint sz2 (subtraction ? n1 n2))) (None ?) |
---|
[3] | 159 | | _ ⇒ None ? ] |
---|
| 160 | | _ ⇒ None ? ] |
---|
[1872] | 161 | | sub_case_ff _ ⇒ (**r float subtraction *) |
---|
[3] | 162 | match v1 with |
---|
| 163 | [ Vfloat f1 ⇒ match v2 with |
---|
| 164 | [ Vfloat f2 ⇒ Some ? (Vfloat (Fsub f1 f2)) |
---|
| 165 | | _ ⇒ None ? ] |
---|
| 166 | | _ ⇒ None ? ] |
---|
[1872] | 167 | | sub_case_pi _ _ ty _ _ ⇒ (**r pointer minus integer *) |
---|
[3] | 168 | match v1 with |
---|
[1545] | 169 | [ Vptr ptr1 ⇒ match v2 with |
---|
| 170 | [ Vint sz2 n2 ⇒ Some ? (Vptr (neg_shift_pointer_n ? ptr1 (sizeof ty) n2)) |
---|
[3] | 171 | | _ ⇒ None ? ] |
---|
[776] | 172 | | Vnull r ⇒ match v2 with |
---|
[961] | 173 | [ Vint sz2 n2 ⇒ if eq_bv ? n2 (zero ?) then Some ? (Vnull r) else None ? |
---|
[776] | 174 | | _ ⇒ None ? ] |
---|
[3] | 175 | | _ ⇒ None ? ] |
---|
[1872] | 176 | | sub_case_pp _ _ _ ty _ _ ⇒ (**r pointer minus pointer *) |
---|
[3] | 177 | match v1 with |
---|
[1545] | 178 | [ Vptr ptr1 ⇒ match v2 with |
---|
| 179 | [ Vptr ptr2 ⇒ |
---|
| 180 | if eq_block (pblock ptr1) (pblock ptr2) then |
---|
[961] | 181 | if eqb (sizeof ty) 0 then None ? |
---|
[1545] | 182 | else match division_u ? (sub_offset ? (poff ptr1) (poff ptr2)) (repr (sizeof ty)) with |
---|
[744] | 183 | [ None ⇒ None ? |
---|
[961] | 184 | | Some v ⇒ Some ? (Vint I32 v) (* XXX choose size from result type? *) |
---|
[744] | 185 | ] |
---|
[3] | 186 | else None ? |
---|
| 187 | | _ ⇒ None ? ] |
---|
[961] | 188 | | Vnull r ⇒ match v2 with [ Vnull r' ⇒ Some ? (Vint I32 (*XXX*) (zero ?)) | _ ⇒ None ? ] |
---|
[3] | 189 | | _ ⇒ None ? ] |
---|
[1872] | 190 | | sub_default _ _ ⇒ None ? |
---|
[3] | 191 | ]. |
---|
[124] | 192 | |
---|
[487] | 193 | let rec sem_mul (v1:val) (t1:type) (v2: val) (t2:type) : option val ≝ |
---|
[1872] | 194 | match classify_aop t1 t2 with |
---|
| 195 | [ aop_case_ii _ _ ⇒ |
---|
[3] | 196 | match v1 with |
---|
[961] | 197 | [ Vint sz1 n1 ⇒ match v2 with |
---|
| 198 | [ Vint sz2 n2 ⇒ intsize_eq_elim ? sz1 sz2 ? n1 |
---|
| 199 | (λn1. Some ? (Vint sz2 (\snd (split ??? (multiplication ? n1 n2))))) (None ?) |
---|
[3] | 200 | | _ ⇒ None ? ] |
---|
| 201 | | _ ⇒ None ? ] |
---|
[1872] | 202 | | aop_case_ff _ ⇒ |
---|
[3] | 203 | match v1 with |
---|
| 204 | [ Vfloat f1 ⇒ match v2 with |
---|
| 205 | [ Vfloat f2 ⇒ Some ? (Vfloat (Fmul f1 f2)) |
---|
| 206 | | _ ⇒ None ? ] |
---|
| 207 | | _ ⇒ None ? ] |
---|
[1872] | 208 | | aop_default _ _ ⇒ |
---|
[3] | 209 | None ? |
---|
| 210 | ]. |
---|
| 211 | |
---|
[487] | 212 | let rec sem_div (v1:val) (t1:type) (v2: val) (t2:type) : option val ≝ |
---|
[1872] | 213 | match classify_aop t1 t2 with |
---|
| 214 | [ aop_case_ii _ sg ⇒ |
---|
[3] | 215 | match v1 with |
---|
[961] | 216 | [ Vint sz1 n1 ⇒ match v2 with |
---|
[1872] | 217 | [ Vint sz2 n2 ⇒ |
---|
| 218 | match sg with |
---|
| 219 | [ Signed ⇒ intsize_eq_elim ? sz1 sz2 ? n1 |
---|
[961] | 220 | (λn1. option_map … (Vint ?) (division_s ? n1 n2)) (None ?) |
---|
[1872] | 221 | | Unsigned ⇒ intsize_eq_elim ? sz1 sz2 ? n1 |
---|
| 222 | (λn1. option_map … (Vint ?) (division_u ? n1 n2)) (None ?) |
---|
| 223 | ] |
---|
[3] | 224 | | _ ⇒ None ? ] |
---|
| 225 | | _ ⇒ None ? ] |
---|
[1872] | 226 | | aop_case_ff _ ⇒ |
---|
[3] | 227 | match v1 with |
---|
| 228 | [ Vfloat f1 ⇒ match v2 with |
---|
| 229 | [ Vfloat f2 ⇒ Some ? (Vfloat(Fdiv f1 f2)) |
---|
| 230 | | _ ⇒ None ? ] |
---|
| 231 | | _ ⇒ None ? ] |
---|
[1872] | 232 | | aop_default _ _ ⇒ |
---|
[3] | 233 | None ? |
---|
| 234 | ]. |
---|
| 235 | |
---|
[487] | 236 | let rec sem_mod (v1:val) (t1:type) (v2: val) (t2:type) : option val ≝ |
---|
[1872] | 237 | match classify_aop t1 t2 with |
---|
| 238 | [ aop_case_ii sz sg ⇒ |
---|
[3] | 239 | match v1 with |
---|
[961] | 240 | [ Vint sz1 n1 ⇒ match v2 with |
---|
[1872] | 241 | [ Vint sz2 n2 ⇒ |
---|
| 242 | match sg with |
---|
| 243 | [ Unsigned ⇒ intsize_eq_elim ? sz1 sz2 ? n1 |
---|
[961] | 244 | (λn1. option_map … (Vint ?) (modulus_u ? n1 n2)) (None ?) |
---|
[1872] | 245 | | Signed ⇒ intsize_eq_elim ? sz1 sz2 ? n1 |
---|
| 246 | (λn1. option_map … (Vint ?) (modulus_s ? n1 n2)) (None ?) |
---|
| 247 | ] |
---|
[3] | 248 | | _ ⇒ None ? ] |
---|
| 249 | | _ ⇒ None ? ] |
---|
[1872] | 250 | | _ ⇒ |
---|
[3] | 251 | None ? |
---|
| 252 | ]. |
---|
| 253 | |
---|
[487] | 254 | let rec sem_and (v1,v2: val) : option val ≝ |
---|
[3] | 255 | match v1 with |
---|
[961] | 256 | [ Vint sz1 n1 ⇒ match v2 with |
---|
| 257 | [ Vint sz2 n2 ⇒ intsize_eq_elim ? sz1 sz2 ? n1 |
---|
| 258 | (λn1. Some ? (Vint ? (conjunction_bv ? n1 n2))) (None ?) |
---|
[3] | 259 | | _ ⇒ None ? ] |
---|
| 260 | | _ ⇒ None ? |
---|
| 261 | ]. |
---|
| 262 | |
---|
[487] | 263 | let rec sem_or (v1,v2: val) : option val ≝ |
---|
[3] | 264 | match v1 with |
---|
[961] | 265 | [ Vint sz1 n1 ⇒ match v2 with |
---|
| 266 | [ Vint sz2 n2 ⇒ intsize_eq_elim ? sz1 sz2 ? n1 |
---|
| 267 | (λn1. Some ? (Vint ? (inclusive_disjunction_bv ? n1 n2))) (None ?) |
---|
[3] | 268 | | _ ⇒ None ? ] |
---|
| 269 | | _ ⇒ None ? |
---|
| 270 | ]. |
---|
| 271 | |
---|
[487] | 272 | let rec sem_xor (v1,v2: val) : option val ≝ |
---|
[3] | 273 | match v1 with |
---|
[961] | 274 | [ Vint sz1 n1 ⇒ match v2 with |
---|
| 275 | [ Vint sz2 n2 ⇒ intsize_eq_elim ? sz1 sz2 ? n1 |
---|
| 276 | (λn1. Some ? (Vint ? (exclusive_disjunction_bv ? n1 n2))) (None ?) |
---|
[3] | 277 | | _ ⇒ None ? ] |
---|
| 278 | | _ ⇒ None ? |
---|
| 279 | ]. |
---|
| 280 | |
---|
[487] | 281 | let rec sem_shl (v1,v2: val): option val ≝ |
---|
[3] | 282 | match v1 with |
---|
[961] | 283 | [ Vint sz1 n1 ⇒ match v2 with |
---|
| 284 | [ Vint sz2 n2 ⇒ |
---|
| 285 | if lt_u ? n2 (bitvector_of_nat … (bitsize_of_intsize sz1)) |
---|
| 286 | then Some ? (Vint sz1 (shift_left ?? (nat_of_bitvector … n2) n1 false)) |
---|
| 287 | else None ? |
---|
[3] | 288 | | _ ⇒ None ? ] |
---|
| 289 | | _ ⇒ None ? ]. |
---|
| 290 | |
---|
[487] | 291 | let rec sem_shr (v1: val) (t1: type) (v2: val) (t2: type): option val ≝ |
---|
[1872] | 292 | match classify_aop t1 t2 with |
---|
| 293 | [ aop_case_ii _ sg ⇒ |
---|
[3] | 294 | match v1 with |
---|
[961] | 295 | [ Vint sz1 n1 ⇒ match v2 with |
---|
| 296 | [ Vint sz2 n2 ⇒ |
---|
[1872] | 297 | match sg with |
---|
| 298 | [ Unsigned ⇒ |
---|
[961] | 299 | if lt_u ? n2 (bitvector_of_nat … (bitsize_of_intsize sz1)) |
---|
| 300 | then Some ? (Vint ? (shift_right ?? (nat_of_bitvector … n2) n1 false)) |
---|
| 301 | else None ? |
---|
[1872] | 302 | | Signed ⇒ |
---|
[961] | 303 | if lt_u ? n2 (bitvector_of_nat … (bitsize_of_intsize sz1)) |
---|
| 304 | then Some ? (Vint ? (shift_right ?? (nat_of_bitvector … n2) n1 (head' … n1))) |
---|
| 305 | else None ? |
---|
[1872] | 306 | ] |
---|
[3] | 307 | | _ ⇒ None ? ] |
---|
| 308 | | _ ⇒ None ? ] |
---|
[1872] | 309 | | _ ⇒ |
---|
[3] | 310 | None ? |
---|
| 311 | ]. |
---|
| 312 | |
---|
[487] | 313 | let rec sem_cmp_mismatch (c: comparison): option val ≝ |
---|
[3] | 314 | match c with |
---|
[1872] | 315 | [ Ceq ⇒ Some ? Vfalse |
---|
| 316 | | Cne ⇒ Some ? Vtrue |
---|
| 317 | | _ ⇒ None ? |
---|
[3] | 318 | ]. |
---|
| 319 | |
---|
[487] | 320 | let rec sem_cmp_match (c: comparison): option val ≝ |
---|
[484] | 321 | match c with |
---|
[1872] | 322 | [ Ceq ⇒ Some ? Vtrue |
---|
| 323 | | Cne ⇒ Some ? Vfalse |
---|
| 324 | | _ ⇒ None ? |
---|
[484] | 325 | ]. |
---|
| 326 | |
---|
[487] | 327 | let rec sem_cmp (c:comparison) |
---|
[3] | 328 | (v1: val) (t1: type) (v2: val) (t2: type) |
---|
| 329 | (m: mem): option val ≝ |
---|
| 330 | match classify_cmp t1 t2 with |
---|
[1872] | 331 | [ cmp_case_ii _ sg ⇒ |
---|
[3] | 332 | match v1 with |
---|
[961] | 333 | [ Vint sz1 n1 ⇒ match v2 with |
---|
[1872] | 334 | [ Vint sz2 n2 ⇒ |
---|
| 335 | match sg with |
---|
| 336 | [ Unsigned ⇒ intsize_eq_elim ? sz1 sz2 ? n1 |
---|
[961] | 337 | (λn1. Some ? (of_bool (cmpu_int ? c n1 n2))) (None ?) |
---|
[1872] | 338 | | Signed ⇒ intsize_eq_elim ? sz1 sz2 ? n1 |
---|
| 339 | (λn1. Some ? (of_bool (cmp_int ? c n1 n2))) (None ?) |
---|
| 340 | ] |
---|
[3] | 341 | | _ ⇒ None ? |
---|
| 342 | ] |
---|
[816] | 343 | | _ ⇒ None ? |
---|
| 344 | ] |
---|
[1872] | 345 | | cmp_case_pp _ _ _ ⇒ |
---|
[816] | 346 | match v1 with |
---|
[1545] | 347 | [ Vptr ptr1 ⇒ |
---|
[3] | 348 | match v2 with |
---|
[1545] | 349 | [ Vptr ptr2 ⇒ |
---|
| 350 | if valid_pointer m ptr1 |
---|
| 351 | ∧ valid_pointer m ptr2 then |
---|
| 352 | if eq_block (pblock ptr1) (pblock ptr2) |
---|
| 353 | then Some ? (of_bool (cmp_offset c (poff ptr1) (poff ptr2))) |
---|
[3] | 354 | else sem_cmp_mismatch c |
---|
| 355 | else None ? |
---|
[484] | 356 | | Vnull r2 ⇒ sem_cmp_mismatch c |
---|
[3] | 357 | | _ ⇒ None ? ] |
---|
[484] | 358 | | Vnull r1 ⇒ |
---|
| 359 | match v2 with |
---|
[1545] | 360 | [ Vptr ptr2 ⇒ sem_cmp_mismatch c |
---|
[484] | 361 | | Vnull r2 ⇒ sem_cmp_match c |
---|
| 362 | | _ ⇒ None ? |
---|
| 363 | ] |
---|
[3] | 364 | | _ ⇒ None ? ] |
---|
[1872] | 365 | | cmp_case_ff _ ⇒ |
---|
[3] | 366 | match v1 with |
---|
| 367 | [ Vfloat f1 ⇒ |
---|
| 368 | match v2 with |
---|
| 369 | [ Vfloat f2 ⇒ Some ? (of_bool (Fcmp c f1 f2)) |
---|
| 370 | | _ ⇒ None ? ] |
---|
| 371 | | _ ⇒ None ? ] |
---|
[1872] | 372 | | cmp_default _ _ ⇒ None ? |
---|
[3] | 373 | ]. |
---|
| 374 | |
---|
[487] | 375 | definition sem_unary_operation |
---|
[3] | 376 | : unary_operation → val → type → option val ≝ |
---|
| 377 | λop,v,ty. |
---|
| 378 | match op with |
---|
| 379 | [ Onotbool => sem_notbool v ty |
---|
| 380 | | Onotint => sem_notint v |
---|
| 381 | | Oneg => sem_neg v ty |
---|
| 382 | ]. |
---|
| 383 | |
---|
[487] | 384 | let rec sem_binary_operation |
---|
[3] | 385 | (op: binary_operation) |
---|
| 386 | (v1: val) (t1: type) (v2: val) (t2:type) |
---|
| 387 | (m: mem): option val ≝ |
---|
| 388 | match op with |
---|
| 389 | [ Oadd ⇒ sem_add v1 t1 v2 t2 |
---|
| 390 | | Osub ⇒ sem_sub v1 t1 v2 t2 |
---|
| 391 | | Omul ⇒ sem_mul v1 t1 v2 t2 |
---|
| 392 | | Omod ⇒ sem_mod v1 t1 v2 t2 |
---|
| 393 | | Odiv ⇒ sem_div v1 t1 v2 t2 |
---|
| 394 | | Oand ⇒ sem_and v1 v2 |
---|
| 395 | | Oor ⇒ sem_or v1 v2 |
---|
| 396 | | Oxor ⇒ sem_xor v1 v2 |
---|
| 397 | | Oshl ⇒ sem_shl v1 v2 |
---|
| 398 | | Oshr ⇒ sem_shr v1 t1 v2 t2 |
---|
| 399 | | Oeq ⇒ sem_cmp Ceq v1 t1 v2 t2 m |
---|
| 400 | | One ⇒ sem_cmp Cne v1 t1 v2 t2 m |
---|
| 401 | | Olt ⇒ sem_cmp Clt v1 t1 v2 t2 m |
---|
| 402 | | Ogt ⇒ sem_cmp Cgt v1 t1 v2 t2 m |
---|
| 403 | | Ole ⇒ sem_cmp Cle v1 t1 v2 t2 m |
---|
| 404 | | Oge ⇒ sem_cmp Cge v1 t1 v2 t2 m |
---|
| 405 | ]. |
---|
| 406 | |
---|
| 407 | (* * Semantic of casts. [cast v1 t1 t2 v2] holds if value [v1], |
---|
| 408 | viewed with static type [t1], can be cast to type [t2], |
---|
| 409 | resulting in value [v2]. *) |
---|
| 410 | |
---|
[964] | 411 | let rec cast_int_int (sz: intsize) (sg: signedness) (dstsz: intsize) (i: BitVector (bitsize_of_intsize sz)) : BitVector (bitsize_of_intsize dstsz) ≝ |
---|
[961] | 412 | match sg with [ Signed ⇒ sign_ext ?? i | Unsigned ⇒ zero_ext ?? i ]. |
---|
[3] | 413 | |
---|
[961] | 414 | let rec cast_int_float (si : signedness) (n:nat) (i: BitVector n) : float ≝ |
---|
[3] | 415 | match si with |
---|
[961] | 416 | [ Signed ⇒ floatofint ? i |
---|
| 417 | | Unsigned ⇒ floatofintu ? i |
---|
[3] | 418 | ]. |
---|
| 419 | |
---|
[961] | 420 | let rec cast_float_int (sz : intsize) (si : signedness) (f: float) : BitVector (bitsize_of_intsize sz) ≝ |
---|
[3] | 421 | match si with |
---|
[961] | 422 | [ Signed ⇒ intoffloat ? f |
---|
| 423 | | Unsigned ⇒ intuoffloat ? f |
---|
[3] | 424 | ]. |
---|
| 425 | |
---|
[487] | 426 | let rec cast_float_float (sz: floatsize) (f: float) : float ≝ |
---|
[3] | 427 | match sz with |
---|
| 428 | [ F32 ⇒ singleoffloat f |
---|
| 429 | | F64 ⇒ f |
---|
| 430 | ]. |
---|
| 431 | |
---|
[487] | 432 | inductive type_region : type → region → Prop ≝ |
---|
[484] | 433 | | type_rgn_pointer : ∀s,t. type_region (Tpointer s t) s |
---|
| 434 | | type_rgn_array : ∀s,t,n. type_region (Tarray s t n) s |
---|
[155] | 435 | (* XXX Is the following necessary? *) |
---|
[484] | 436 | | type_rgn_code : ∀tys,ty. type_region (Tfunction tys ty) Code. |
---|
[124] | 437 | |
---|
[487] | 438 | inductive cast : mem → val → type → type → val → Prop ≝ |
---|
[961] | 439 | | cast_ii: ∀m,sz2,sz1,si1,si2,i. (**r int to int *) |
---|
| 440 | cast m (Vint sz1 i) (Tint sz1 si1) (Tint sz2 si2) |
---|
[964] | 441 | (Vint sz2 (cast_int_int sz1 si1 sz2 i)) |
---|
[124] | 442 | | cast_fi: ∀m,f,sz1,sz2,si2. (**r float to int *) |
---|
| 443 | cast m (Vfloat f) (Tfloat sz1) (Tint sz2 si2) |
---|
[961] | 444 | (Vint sz2 (cast_float_int sz2 si2 f)) |
---|
| 445 | | cast_if: ∀m,sz1,sz2,si1,i. (**r int to float *) |
---|
| 446 | cast m (Vint sz1 i) (Tint sz1 si1) (Tfloat sz2) |
---|
| 447 | (Vfloat (cast_float_float sz2 (cast_int_float si1 ? i))) |
---|
[124] | 448 | | cast_ff: ∀m,f,sz1,sz2. (**r float to float *) |
---|
| 449 | cast m (Vfloat f) (Tfloat sz1) (Tfloat sz2) |
---|
[3] | 450 | (Vfloat (cast_float_float sz2 f)) |
---|
[1545] | 451 | | cast_pp: ∀m,ty,ty',ptr,r'. |
---|
| 452 | type_region ty (ptype ptr) → |
---|
[484] | 453 | type_region ty' r' → |
---|
[1545] | 454 | ∀pc':pointer_compat (pblock ptr) r'. |
---|
| 455 | cast m (Vptr ptr) ty ty' (Vptr (mk_pointer r' (pblock ptr) pc' (poff ptr))) |
---|
[484] | 456 | | cast_ip_z: ∀m,sz,sg,ty',r. |
---|
| 457 | type_region ty' r → |
---|
[961] | 458 | cast m (Vint sz (zero ?)) (Tint sz sg) ty' (Vnull r) |
---|
[484] | 459 | | cast_pp_z: ∀m,ty,ty',r,r'. |
---|
| 460 | type_region ty r → |
---|
| 461 | type_region ty' r' → |
---|
| 462 | cast m (Vnull r) ty ty' (Vnull r'). |
---|
[127] | 463 | |
---|
[3] | 464 | (* * * Operational semantics *) |
---|
| 465 | |
---|
| 466 | (* * The semantics uses two environments. The global environment |
---|
| 467 | maps names of functions and global variables to memory block references, |
---|
| 468 | and function pointers to their definitions. (See module [Globalenvs].) *) |
---|
| 469 | |
---|
[1986] | 470 | definition genv ≝ genv_t clight_fundef. |
---|
[3] | 471 | |
---|
| 472 | (* * The local environment maps local variables to block references. |
---|
| 473 | The current value of the variable is stored in the associated memory |
---|
| 474 | block. *) |
---|
| 475 | |
---|
[1058] | 476 | definition env ≝ identifier_map SymbolTag block. (* map variable -> location *) |
---|
[3] | 477 | |
---|
[1058] | 478 | definition empty_env: env ≝ (empty_map …). |
---|
[3] | 479 | |
---|
| 480 | (* * [load_value_of_type ty m b ofs] computes the value of a datum |
---|
| 481 | of type [ty] residing in memory [m] at block [b], offset [ofs]. |
---|
| 482 | If the type [ty] indicates an access by value, the corresponding |
---|
| 483 | memory load is performed. If the type [ty] indicates an access by |
---|
| 484 | reference, the pointer [Vptr b ofs] is returned. *) |
---|
| 485 | |
---|
[583] | 486 | let rec load_value_of_type (ty: type) (m: mem) (b: block) (ofs: offset) : option val ≝ |
---|
[3] | 487 | match access_mode ty with |
---|
[1545] | 488 | [ By_value chunk ⇒ loadv chunk m (Vptr (mk_pointer Any b ? ofs)) |
---|
[500] | 489 | | By_reference r ⇒ |
---|
| 490 | match pointer_compat_dec b r with |
---|
[1545] | 491 | [ inl p ⇒ Some ? (Vptr (mk_pointer r b p ofs)) |
---|
[500] | 492 | | inr _ ⇒ None ? |
---|
| 493 | ] |
---|
[1872] | 494 | | By_nothing _ ⇒ None ? |
---|
[3] | 495 | ]. |
---|
[500] | 496 | cases b // |
---|
| 497 | qed. |
---|
[3] | 498 | |
---|
| 499 | (* * Symmetrically, [store_value_of_type ty m b ofs v] returns the |
---|
| 500 | memory state after storing the value [v] in the datum |
---|
| 501 | of type [ty] residing in memory [m] at block [b], offset [ofs]. |
---|
| 502 | This is allowed only if [ty] indicates an access by value. *) |
---|
| 503 | |
---|
[583] | 504 | let rec store_value_of_type (ty_dest: type) (m: mem) (loc: block) (ofs: offset) (v: val) : option mem ≝ |
---|
[3] | 505 | match access_mode ty_dest with |
---|
[1545] | 506 | [ By_value chunk ⇒ storev chunk m (Vptr (mk_pointer Any loc ? ofs)) v |
---|
[498] | 507 | | By_reference _ ⇒ None ? |
---|
[1872] | 508 | | By_nothing _ ⇒ None ? |
---|
[3] | 509 | ]. |
---|
[500] | 510 | cases loc // |
---|
| 511 | qed. |
---|
[3] | 512 | |
---|
| 513 | (* * Allocation of function-local variables. |
---|
| 514 | [alloc_variables e1 m1 vars e2 m2] allocates one memory block |
---|
| 515 | for each variable declared in [vars], and associates the variable |
---|
| 516 | name with this block. [e1] and [m1] are the initial local environment |
---|
| 517 | and memory state. [e2] and [m2] are the final local environment |
---|
| 518 | and memory state. *) |
---|
| 519 | |
---|
[487] | 520 | inductive alloc_variables: env → mem → |
---|
[3] | 521 | list (ident × type) → |
---|
| 522 | env → mem → Prop ≝ |
---|
| 523 | | alloc_variables_nil: |
---|
| 524 | ∀e,m. |
---|
| 525 | alloc_variables e m (nil ?) e m |
---|
| 526 | | alloc_variables_cons: |
---|
| 527 | ∀e,m,id,ty,vars,m1,b1,m2,e2. |
---|
[1874] | 528 | alloc becontentT m 0 (sizeof ty) Any = 〈m1, b1〉 → |
---|
| 529 | alloc_variables (add … e id (pi1 … b1)) m1 vars e2 m2 → |
---|
[3] | 530 | alloc_variables e m (〈id, ty〉 :: vars) e2 m2. |
---|
| 531 | |
---|
| 532 | (* * Initialization of local variables that are parameters to a function. |
---|
| 533 | [bind_parameters e m1 params args m2] stores the values [args] |
---|
| 534 | in the memory blocks corresponding to the variables [params]. |
---|
| 535 | [m1] is the initial memory state and [m2] the final memory state. *) |
---|
| 536 | |
---|
[487] | 537 | inductive bind_parameters: env → |
---|
[3] | 538 | mem → list (ident × type) → list val → |
---|
| 539 | mem → Prop ≝ |
---|
| 540 | | bind_parameters_nil: |
---|
| 541 | ∀e,m. |
---|
| 542 | bind_parameters e m (nil ?) (nil ?) m |
---|
| 543 | | bind_parameters_cons: |
---|
[125] | 544 | ∀e,m,id,ty,params,v1,vl,b,m1,m2. |
---|
[1058] | 545 | lookup ?? e id = Some ? b → |
---|
[583] | 546 | store_value_of_type ty m b zero_offset v1 = Some ? m1 → |
---|
[3] | 547 | bind_parameters e m1 params vl m2 → |
---|
| 548 | bind_parameters e m (〈id, ty〉 :: params) (v1 :: vl) m2. |
---|
| 549 | |
---|
| 550 | (* * Return the list of blocks in the codomain of [e]. *) |
---|
| 551 | |
---|
[487] | 552 | definition blocks_of_env : env → list block ≝ λe. |
---|
[1058] | 553 | map ?? (λx. snd ?? x) (elements ?? e). |
---|
[3] | 554 | |
---|
| 555 | (* * Selection of the appropriate case of a [switch], given the value [n] |
---|
| 556 | of the selector expression. *) |
---|
[961] | 557 | (* FIXME: now that we have several sizes of integer, it isn't clear whether we |
---|
| 558 | should allow case labels to be of a different size to the switch expression. *) |
---|
| 559 | let rec select_switch (sz:intsize) (n: BitVector (bitsize_of_intsize sz)) (sl: labeled_statements) |
---|
[3] | 560 | on sl : labeled_statements ≝ |
---|
| 561 | match sl with |
---|
| 562 | [ LSdefault _ ⇒ sl |
---|
[961] | 563 | | LScase sz' c s sl' ⇒ intsize_eq_elim ? sz sz' ? n |
---|
| 564 | (λn. if eq_bv ? c n then sl else select_switch sz' n sl') (select_switch sz n sl') |
---|
[3] | 565 | ]. |
---|
| 566 | |
---|
| 567 | (* * Turn a labeled statement into a sequence *) |
---|
| 568 | |
---|
[487] | 569 | let rec seq_of_labeled_statement (sl: labeled_statements) : statement ≝ |
---|
[3] | 570 | match sl with |
---|
| 571 | [ LSdefault s ⇒ s |
---|
[961] | 572 | | LScase _ c s sl' ⇒ Ssequence s (seq_of_labeled_statement sl') |
---|
[3] | 573 | ]. |
---|
| 574 | |
---|
| 575 | (* |
---|
| 576 | Section SEMANTICS. |
---|
| 577 | |
---|
| 578 | Variable ge: genv. |
---|
| 579 | |
---|
| 580 | (** ** Evaluation of expressions *) |
---|
| 581 | |
---|
| 582 | Section EXPR. |
---|
| 583 | |
---|
| 584 | Variable e: env. |
---|
| 585 | Variable m: mem. |
---|
| 586 | *) |
---|
| 587 | (* * [eval_expr ge e m a v] defines the evaluation of expression [a] |
---|
| 588 | in r-value position. [v] is the value of the expression. |
---|
| 589 | [e] is the current environment and [m] is the current memory state. *) |
---|
| 590 | |
---|
[487] | 591 | inductive eval_expr (ge:genv) (e:env) (m:mem) : expr → val → trace → Prop ≝ |
---|
[961] | 592 | | eval_Econst_int: ∀sz,sg,i. |
---|
| 593 | eval_expr ge e m (Expr (Econst_int sz i) (Tint sz sg)) (Vint sz i) E0 |
---|
[3] | 594 | | eval_Econst_float: ∀f,ty. |
---|
[175] | 595 | eval_expr ge e m (Expr (Econst_float f) ty) (Vfloat f) E0 |
---|
[498] | 596 | | eval_Elvalue: ∀a,ty,loc,ofs,v,tr. |
---|
| 597 | eval_lvalue ge e m (Expr a ty) loc ofs tr → |
---|
| 598 | load_value_of_type ty m loc ofs = Some ? v → |
---|
[175] | 599 | eval_expr ge e m (Expr a ty) v tr |
---|
[496] | 600 | | eval_Eaddrof: ∀a,ty,r,loc,ofs,tr. |
---|
[498] | 601 | eval_lvalue ge e m a loc ofs tr → |
---|
[500] | 602 | ∀pc:pointer_compat loc r. |
---|
[1545] | 603 | eval_expr ge e m (Expr (Eaddrof a) (Tpointer r ty)) (Vptr (mk_pointer r loc pc ofs)) tr |
---|
[961] | 604 | | eval_Esizeof: ∀ty',sz,sg. |
---|
| 605 | eval_expr ge e m (Expr (Esizeof ty') (Tint sz sg)) (Vint sz (repr ? (sizeof ty'))) E0 |
---|
[175] | 606 | | eval_Eunop: ∀op,a,ty,v1,v,tr. |
---|
| 607 | eval_expr ge e m a v1 tr → |
---|
| 608 | sem_unary_operation op v1 (typeof a) = Some ? v → |
---|
| 609 | eval_expr ge e m (Expr (Eunop op a) ty) v tr |
---|
| 610 | | eval_Ebinop: ∀op,a1,a2,ty,v1,v2,v,tr1,tr2. |
---|
| 611 | eval_expr ge e m a1 v1 tr1 → |
---|
| 612 | eval_expr ge e m a2 v2 tr2 → |
---|
| 613 | sem_binary_operation op v1 (typeof a1) v2 (typeof a2) m = Some ? v → |
---|
| 614 | eval_expr ge e m (Expr (Ebinop op a1 a2) ty) v (tr1⧺tr2) |
---|
| 615 | | eval_Econdition_true: ∀a1,a2,a3,ty,v1,v2,tr1,tr2. |
---|
| 616 | eval_expr ge e m a1 v1 tr1 → |
---|
| 617 | is_true v1 (typeof a1) → |
---|
| 618 | eval_expr ge e m a2 v2 tr2 → |
---|
| 619 | eval_expr ge e m (Expr (Econdition a1 a2 a3) ty) v2 (tr1⧺tr2) |
---|
| 620 | | eval_Econdition_false: ∀a1,a2,a3,ty,v1,v3,tr1,tr2. |
---|
| 621 | eval_expr ge e m a1 v1 tr1 → |
---|
| 622 | is_false v1 (typeof a1) → |
---|
| 623 | eval_expr ge e m a3 v3 tr2 → |
---|
| 624 | eval_expr ge e m (Expr (Econdition a1 a2 a3) ty) v3 (tr1⧺tr2) |
---|
| 625 | | eval_Eorbool_1: ∀a1,a2,ty,v1,tr. |
---|
| 626 | eval_expr ge e m a1 v1 tr → |
---|
| 627 | is_true v1 (typeof a1) → |
---|
| 628 | eval_expr ge e m (Expr (Eorbool a1 a2) ty) Vtrue tr |
---|
| 629 | | eval_Eorbool_2: ∀a1,a2,ty,v1,v2,v,tr1,tr2. |
---|
| 630 | eval_expr ge e m a1 v1 tr1 → |
---|
| 631 | is_false v1 (typeof a1) → |
---|
| 632 | eval_expr ge e m a2 v2 tr2 → |
---|
| 633 | bool_of_val v2 (typeof a2) v → |
---|
| 634 | eval_expr ge e m (Expr (Eorbool a1 a2) ty) v (tr1⧺tr2) |
---|
| 635 | | eval_Eandbool_1: ∀a1,a2,ty,v1,tr. |
---|
| 636 | eval_expr ge e m a1 v1 tr → |
---|
| 637 | is_false v1 (typeof a1) → |
---|
| 638 | eval_expr ge e m (Expr (Eandbool a1 a2) ty) Vfalse tr |
---|
| 639 | | eval_Eandbool_2: ∀a1,a2,ty,v1,v2,v,tr1,tr2. |
---|
| 640 | eval_expr ge e m a1 v1 tr1 → |
---|
| 641 | is_true v1 (typeof a1) → |
---|
| 642 | eval_expr ge e m a2 v2 tr2 → |
---|
| 643 | bool_of_val v2 (typeof a2) v → |
---|
| 644 | eval_expr ge e m (Expr (Eandbool a1 a2) ty) v (tr1⧺tr2) |
---|
| 645 | | eval_Ecast: ∀a,ty,ty',v1,v,tr. |
---|
| 646 | eval_expr ge e m a v1 tr → |
---|
| 647 | cast m v1 (typeof a) ty v → |
---|
| 648 | eval_expr ge e m (Expr (Ecast ty a) ty') v tr |
---|
| 649 | | eval_Ecost: ∀a,ty,v,l,tr. |
---|
| 650 | eval_expr ge e m a v tr → |
---|
| 651 | eval_expr ge e m (Expr (Ecost l a) ty) v (tr⧺Echarge l) |
---|
[3] | 652 | |
---|
[496] | 653 | (* * [eval_lvalue ge e m a r b ofs] defines the evaluation of expression [a] |
---|
[3] | 654 | in l-value position. The result is the memory location [b, ofs] |
---|
[496] | 655 | that contains the value of the expression [a]. The memory location should |
---|
| 656 | be representable in a pointer of region r. *) |
---|
[3] | 657 | |
---|
[583] | 658 | with eval_lvalue (*(ge:genv) (e:env) (m:mem)*) : expr → block → offset → trace → Prop ≝ |
---|
[125] | 659 | | eval_Evar_local: ∀id,l,ty. |
---|
[1058] | 660 | (* XXX notation? e!id*) lookup ?? e id = Some ? l → |
---|
[583] | 661 | eval_lvalue ge e m (Expr (Evar id) ty) l zero_offset E0 |
---|
[498] | 662 | | eval_Evar_global: ∀id,l,ty. |
---|
[1058] | 663 | (* XXX e!id *) lookup ?? e id = None ? → |
---|
[1986] | 664 | find_symbol … ge id = Some ? l → |
---|
[583] | 665 | eval_lvalue ge e m (Expr (Evar id) ty) l zero_offset E0 |
---|
[500] | 666 | | eval_Ederef: ∀a,ty,r,l,p,ofs,tr. |
---|
[1545] | 667 | eval_expr ge e m a (Vptr (mk_pointer r l p ofs)) tr → |
---|
[498] | 668 | eval_lvalue ge e m (Expr (Ederef a) ty) l ofs tr |
---|
| 669 | (* Aside: note that each block of memory is entirely contained within one |
---|
| 670 | memory region; hence adding a field offset will not produce a location |
---|
| 671 | outside of the original location's region. *) |
---|
| 672 | | eval_Efield_struct: ∀a,i,ty,l,ofs,id,fList,delta,tr. |
---|
| 673 | eval_lvalue ge e m a l ofs tr → |
---|
[175] | 674 | typeof a = Tstruct id fList → |
---|
| 675 | field_offset i fList = OK ? delta → |
---|
[961] | 676 | eval_lvalue ge e m (Expr (Efield a i) ty) l (shift_offset ? ofs (repr I32 delta)) tr |
---|
[498] | 677 | | eval_Efield_union: ∀a,i,ty,l,ofs,id,fList,tr. |
---|
| 678 | eval_lvalue ge e m a l ofs tr → |
---|
[175] | 679 | typeof a = Tunion id fList → |
---|
[498] | 680 | eval_lvalue ge e m (Expr (Efield a i) ty) l ofs tr. |
---|
[3] | 681 | |
---|
[487] | 682 | let rec eval_expr_ind (ge:genv) (e:env) (m:mem) |
---|
[226] | 683 | (P:∀a,v,tr. eval_expr ge e m a v tr → Prop) |
---|
[961] | 684 | (eci:∀sz,sg,i. P ??? (eval_Econst_int ge e m sz sg i)) |
---|
[226] | 685 | (ecF:∀f,ty. P ??? (eval_Econst_float ge e m f ty)) |
---|
[498] | 686 | (elv:∀a,ty,loc,ofs,v,tr,H1,H2. P ??? (eval_Elvalue ge e m a ty loc ofs v tr H1 H2)) |
---|
[500] | 687 | (ead:∀a,ty,r,loc,pc,ofs,tr,H. P ??? (eval_Eaddrof ge e m a ty r loc pc ofs tr H)) |
---|
[961] | 688 | (esz:∀ty',sz,sg. P ??? (eval_Esizeof ge e m ty' sz sg)) |
---|
[226] | 689 | (eun:∀op,a,ty,v1,v,tr,H1,H2. P a v1 tr H1 → P ??? (eval_Eunop ge e m op a ty v1 v tr H1 H2)) |
---|
| 690 | (ebi:∀op,a1,a2,ty,v1,v2,v,tr1,tr2,H1,H2,H3. P a1 v1 tr1 H1 → P a2 v2 tr2 H2 → P ??? (eval_Ebinop ge e m op a1 a2 ty v1 v2 v tr1 tr2 H1 H2 H3)) |
---|
| 691 | (ect:∀a1,a2,a3,ty,v1,v2,tr1,tr2,H1,H2,H3. P a1 v1 tr1 H1 → P a2 v2 tr2 H3 → P ??? (eval_Econdition_true ge e m a1 a2 a3 ty v1 v2 tr1 tr2 H1 H2 H3)) |
---|
| 692 | (ecf:∀a1,a2,a3,ty,v1,v3,tr1,tr2,H1,H2,H3. P a1 v1 tr1 H1 → P a3 v3 tr2 H3 → P ??? (eval_Econdition_false ge e m a1 a2 a3 ty v1 v3 tr1 tr2 H1 H2 H3)) |
---|
| 693 | (eo1:∀a1,a2,ty,v1,tr,H1,H2. P a1 v1 tr H1 → P ??? (eval_Eorbool_1 ge e m a1 a2 ty v1 tr H1 H2)) |
---|
| 694 | (eo2:∀a1,a2,ty,v1,v2,v,tr1,tr2,H1,H2,H3,H4. P a1 v1 tr1 H1 → P a2 v2 tr2 H3 → P ??? (eval_Eorbool_2 ge e m a1 a2 ty v1 v2 v tr1 tr2 H1 H2 H3 H4)) |
---|
| 695 | (ea1:∀a1,a2,ty,v1,tr,H1,H2. P a1 v1 tr H1 → P ??? (eval_Eandbool_1 ge e m a1 a2 ty v1 tr H1 H2)) |
---|
| 696 | (ea2:∀a1,a2,ty,v1,v2,v,tr1,tr2,H1,H2,H3,H4. P a1 v1 tr1 H1 → P a2 v2 tr2 H3 → P ??? (eval_Eandbool_2 ge e m a1 a2 ty v1 v2 v tr1 tr2 H1 H2 H3 H4)) |
---|
| 697 | (ecs:∀a,ty,ty',v1,v,tr,H1,H2. P a v1 tr H1 → P ??? (eval_Ecast ge e m a ty ty' v1 v tr H1 H2)) |
---|
| 698 | (eco:∀a,ty,v,l,tr,H. P a v tr H → P ??? (eval_Ecost ge e m a ty v l tr H)) |
---|
| 699 | (a:expr) (v:val) (tr:trace) (ev:eval_expr ge e m a v tr) on ev : P a v tr ev ≝ |
---|
| 700 | match ev with |
---|
[961] | 701 | [ eval_Econst_int sz sg i ⇒ eci sz sg i |
---|
[226] | 702 | | eval_Econst_float f ty ⇒ ecF f ty |
---|
[498] | 703 | | eval_Elvalue a ty loc ofs v tr H1 H2 ⇒ elv a ty loc ofs v tr H1 H2 |
---|
[500] | 704 | | eval_Eaddrof a ty r loc pc ofs tr H ⇒ ead a ty r loc pc ofs tr H |
---|
[961] | 705 | | eval_Esizeof ty' sz sg ⇒ esz ty' sz sg |
---|
[226] | 706 | | eval_Eunop op a ty v1 v tr H1 H2 ⇒ eun op a ty v1 v tr H1 H2 (eval_expr_ind ge e m P eci ecF elv ead esz eun ebi ect ecf eo1 eo2 ea1 ea2 ecs eco a v1 tr H1) |
---|
| 707 | | eval_Ebinop op a1 a2 ty v1 v2 v tr1 tr2 H1 H2 H3 ⇒ ebi op a1 a2 ty v1 v2 v tr1 tr2 H1 H2 H3 (eval_expr_ind ge e m P eci ecF elv ead esz eun ebi ect ecf eo1 eo2 ea1 ea2 ecs eco a1 v1 tr1 H1) (eval_expr_ind ge e m P eci ecF elv ead esz eun ebi ect ecf eo1 eo2 ea1 ea2 ecs eco a2 v2 tr2 H2) |
---|
| 708 | | eval_Econdition_true a1 a2 a3 ty v1 v2 tr1 tr2 H1 H2 H3 ⇒ ect a1 a2 a3 ty v1 v2 tr1 tr2 H1 H2 H3 (eval_expr_ind ge e m P eci ecF elv ead esz eun ebi ect ecf eo1 eo2 ea1 ea2 ecs eco a1 v1 tr1 H1) (eval_expr_ind ge e m P eci ecF elv ead esz eun ebi ect ecf eo1 eo2 ea1 ea2 ecs eco a2 v2 tr2 H3) |
---|
| 709 | | eval_Econdition_false a1 a2 a3 ty v1 v3 tr1 tr2 H1 H2 H3 ⇒ ecf a1 a2 a3 ty v1 v3 tr1 tr2 H1 H2 H3 (eval_expr_ind ge e m P eci ecF elv ead esz eun ebi ect ecf eo1 eo2 ea1 ea2 ecs eco a1 v1 tr1 H1) (eval_expr_ind ge e m P eci ecF elv ead esz eun ebi ect ecf eo1 eo2 ea1 ea2 ecs eco a3 v3 tr2 H3) |
---|
| 710 | | eval_Eorbool_1 a1 a2 ty v1 tr H1 H2 ⇒ eo1 a1 a2 ty v1 tr H1 H2 (eval_expr_ind ge e m P eci ecF elv ead esz eun ebi ect ecf eo1 eo2 ea1 ea2 ecs eco a1 v1 tr H1) |
---|
| 711 | | eval_Eorbool_2 a1 a2 ty v1 v2 v tr1 tr2 H1 H2 H3 H4 ⇒ eo2 a1 a2 ty v1 v2 v tr1 tr2 H1 H2 H3 H4 (eval_expr_ind ge e m P eci ecF elv ead esz eun ebi ect ecf eo1 eo2 ea1 ea2 ecs eco a1 v1 tr1 H1) (eval_expr_ind ge e m P eci ecF elv ead esz eun ebi ect ecf eo1 eo2 ea1 ea2 ecs eco a2 v2 tr2 H3) |
---|
| 712 | | eval_Eandbool_1 a1 a2 ty v1 tr H1 H2 ⇒ ea1 a1 a2 ty v1 tr H1 H2 (eval_expr_ind ge e m P eci ecF elv ead esz eun ebi ect ecf eo1 eo2 ea1 ea2 ecs eco a1 v1 tr H1) |
---|
| 713 | | eval_Eandbool_2 a1 a2 ty v1 v2 v tr1 tr2 H1 H2 H3 H4 ⇒ ea2 a1 a2 ty v1 v2 v tr1 tr2 H1 H2 H3 H4 (eval_expr_ind ge e m P eci ecF elv ead esz eun ebi ect ecf eo1 eo2 ea1 ea2 ecs eco a1 v1 tr1 H1) (eval_expr_ind ge e m P eci ecF elv ead esz eun ebi ect ecf eo1 eo2 ea1 ea2 ecs eco a2 v2 tr2 H3) |
---|
| 714 | | eval_Ecast a ty ty' v1 v tr H1 H2 ⇒ ecs a ty ty' v1 v tr H1 H2 (eval_expr_ind ge e m P eci ecF elv ead esz eun ebi ect ecf eo1 eo2 ea1 ea2 ecs eco a v1 tr H1) |
---|
| 715 | | eval_Ecost a ty v l tr H ⇒ eco a ty v l tr H (eval_expr_ind ge e m P eci ecF elv ead esz eun ebi ect ecf eo1 eo2 ea1 ea2 ecs eco a v tr H) |
---|
| 716 | ]. |
---|
[1672] | 717 | (* |
---|
[487] | 718 | inverter eval_expr_inv_ind for eval_expr : Prop. |
---|
[1672] | 719 | *) |
---|
[487] | 720 | let rec eval_lvalue_ind (ge:genv) (e:env) (m:mem) |
---|
[498] | 721 | (P:∀a,loc,ofs,tr. eval_lvalue ge e m a loc ofs tr → Prop) |
---|
| 722 | (lvl:∀id,l,ty,H. P ???? (eval_Evar_local ge e m id l ty H)) |
---|
| 723 | (lvg:∀id,l,ty,H1,H2. P ???? (eval_Evar_global ge e m id l ty H1 H2)) |
---|
[500] | 724 | (lde:∀a,ty,r,l,pc,ofs,tr,H. P ???? (eval_Ederef ge e m a ty r l pc ofs tr H)) |
---|
[498] | 725 | (lfs:∀a,i,ty,l,ofs,id,fList,delta,tr,H1,H2,H3. P a l ofs tr H1 → P ???? (eval_Efield_struct ge e m a i ty l ofs id fList delta tr H1 H2 H3)) |
---|
| 726 | (lfu:∀a,i,ty,l,ofs,id,fList,tr,H1,H2. P a l ofs tr H1 → P ???? (eval_Efield_union ge e m a i ty l ofs id fList tr H1 H2)) |
---|
[583] | 727 | (a:expr) (loc:block) (ofs:offset) (tr:trace) (ev:eval_lvalue ge e m a loc ofs tr) on ev : P a loc ofs tr ev ≝ |
---|
[226] | 728 | match ev with |
---|
| 729 | [ eval_Evar_local id l ty H ⇒ lvl id l ty H |
---|
[498] | 730 | | eval_Evar_global id l ty H1 H2 ⇒ lvg id l ty H1 H2 |
---|
[500] | 731 | | eval_Ederef a ty r l pc ofs tr H ⇒ lde a ty r l pc ofs tr H |
---|
[498] | 732 | | eval_Efield_struct a i ty l ofs id fList delta tr H1 H2 H3 ⇒ lfs a i ty l ofs id fList delta tr H1 H2 H3 (eval_lvalue_ind ge e m P lvl lvg lde lfs lfu a l ofs tr H1) |
---|
| 733 | | eval_Efield_union a i ty l ofs id fList tr H1 H2 ⇒ lfu a i ty l ofs id fList tr H1 H2 (eval_lvalue_ind ge e m P lvl lvg lde lfs lfu a l ofs tr H1) |
---|
[226] | 734 | ]. |
---|
| 735 | |
---|
[3] | 736 | (* |
---|
[226] | 737 | ninverter eval_lvalue_inv_ind for eval_lvalue : Prop. |
---|
| 738 | *) |
---|
[1672] | 739 | (* |
---|
[487] | 740 | definition eval_lvalue_inv_ind : |
---|
[226] | 741 | ∀x1: genv. |
---|
| 742 | ∀x2: env. |
---|
| 743 | ∀x3: mem. |
---|
| 744 | ∀x4: expr. |
---|
| 745 | ∀x6: block. |
---|
[583] | 746 | ∀x7: offset. |
---|
[226] | 747 | ∀x8: trace. |
---|
| 748 | ∀P: |
---|
| 749 | ∀_z1430: expr. |
---|
[583] | 750 | ∀_z1428: block. ∀_z1427: offset. ∀_z1426: trace. Prop. |
---|
[226] | 751 | ∀_H1: ?. |
---|
| 752 | ∀_H2: ?. |
---|
| 753 | ∀_H3: ?. |
---|
| 754 | ∀_H4: ?. |
---|
| 755 | ∀_H5: ?. |
---|
[498] | 756 | ∀_Hterm: eval_lvalue x1 x2 x3 x4 x6 x7 x8. |
---|
| 757 | P x4 x6 x7 x8 |
---|
[226] | 758 | := |
---|
| 759 | (λx1:genv. |
---|
| 760 | (λx2:env. |
---|
| 761 | (λx3:mem. |
---|
| 762 | (λx4:expr. |
---|
| 763 | (λx6:block. |
---|
[583] | 764 | (λx7:offset. |
---|
[226] | 765 | (λx8:trace. |
---|
| 766 | (λP:∀_z1430: expr. |
---|
| 767 | ∀_z1428: block. |
---|
[583] | 768 | ∀_z1427: offset. ∀_z1426: trace. Prop. |
---|
[226] | 769 | (λH1:?. |
---|
| 770 | (λH2:?. |
---|
| 771 | (λH3:?. |
---|
| 772 | (λH4:?. |
---|
| 773 | (λH5:?. |
---|
[498] | 774 | (λHterm:eval_lvalue x1 x2 x3 x4 x6 x7 x8. |
---|
[226] | 775 | ((λHcut:∀z1435: eq expr x4 x4. |
---|
| 776 | ∀z1433: eq block x6 x6. |
---|
[583] | 777 | ∀z1432: eq offset x7 x7. |
---|
[226] | 778 | ∀z1431: eq trace x8 x8. |
---|
[498] | 779 | P x4 x6 x7 x8. |
---|
[226] | 780 | (Hcut (refl expr x4) |
---|
[498] | 781 | (refl block x6) |
---|
[583] | 782 | (refl offset x7) (refl trace x8))) |
---|
[498] | 783 | ?))))))))))))))). |
---|
| 784 | [ @(eval_lvalue_ind x1 x2 x3 (λa,loc,ofs,tr,e. ∀e1:eq ? x4 a. ∀e3:eq ? x6 loc. ∀e4:eq ? x7 ofs. ∀e5:eq ? x8 tr. P a loc ofs tr) … Hterm) |
---|
[487] | 785 | [ @H1 | @H2 | @H3 | @H4 | @H5 ] |
---|
| 786 | | *: skip |
---|
| 787 | ] qed. |
---|
[1672] | 788 | *) |
---|
[487] | 789 | let rec eval_expr_ind2 (ge:genv) (e:env) (m:mem) |
---|
[226] | 790 | (P:∀a,v,tr. eval_expr ge e m a v tr → Prop) |
---|
[498] | 791 | (Q:∀a,loc,ofs,tr. eval_lvalue ge e m a loc ofs tr → Prop) |
---|
[961] | 792 | (eci:∀sz,sg,i. P ??? (eval_Econst_int ge e m sz sg i)) |
---|
[226] | 793 | (ecF:∀f,ty. P ??? (eval_Econst_float ge e m f ty)) |
---|
[498] | 794 | (elv:∀a,ty,loc,ofs,v,tr,H1,H2. Q (Expr a ty) loc ofs tr H1 → P ??? (eval_Elvalue ge e m a ty loc ofs v tr H1 H2)) |
---|
[500] | 795 | (ead:∀a,ty,r,loc,pc,ofs,tr,H. Q a loc ofs tr H → P ??? (eval_Eaddrof ge e m a ty r loc ofs tr H pc)) |
---|
[961] | 796 | (esz:∀ty',sz,sg. P ??? (eval_Esizeof ge e m ty' sz sg)) |
---|
[226] | 797 | (eun:∀op,a,ty,v1,v,tr,H1,H2. P a v1 tr H1 → P ??? (eval_Eunop ge e m op a ty v1 v tr H1 H2)) |
---|
| 798 | (ebi:∀op,a1,a2,ty,v1,v2,v,tr1,tr2,H1,H2,H3. P a1 v1 tr1 H1 → P a2 v2 tr2 H2 → P ??? (eval_Ebinop ge e m op a1 a2 ty v1 v2 v tr1 tr2 H1 H2 H3)) |
---|
| 799 | (ect:∀a1,a2,a3,ty,v1,v2,tr1,tr2,H1,H2,H3. P a1 v1 tr1 H1 → P a2 v2 tr2 H3 → P ??? (eval_Econdition_true ge e m a1 a2 a3 ty v1 v2 tr1 tr2 H1 H2 H3)) |
---|
| 800 | (ecf:∀a1,a2,a3,ty,v1,v3,tr1,tr2,H1,H2,H3. P a1 v1 tr1 H1 → P a3 v3 tr2 H3 → P ??? (eval_Econdition_false ge e m a1 a2 a3 ty v1 v3 tr1 tr2 H1 H2 H3)) |
---|
| 801 | (eo1:∀a1,a2,ty,v1,tr,H1,H2. P a1 v1 tr H1 → P ??? (eval_Eorbool_1 ge e m a1 a2 ty v1 tr H1 H2)) |
---|
| 802 | (eo2:∀a1,a2,ty,v1,v2,v,tr1,tr2,H1,H2,H3,H4. P a1 v1 tr1 H1 → P a2 v2 tr2 H3 → P ??? (eval_Eorbool_2 ge e m a1 a2 ty v1 v2 v tr1 tr2 H1 H2 H3 H4)) |
---|
| 803 | (ea1:∀a1,a2,ty,v1,tr,H1,H2. P a1 v1 tr H1 → P ??? (eval_Eandbool_1 ge e m a1 a2 ty v1 tr H1 H2)) |
---|
| 804 | (ea2:∀a1,a2,ty,v1,v2,v,tr1,tr2,H1,H2,H3,H4. P a1 v1 tr1 H1 → P a2 v2 tr2 H3 → P ??? (eval_Eandbool_2 ge e m a1 a2 ty v1 v2 v tr1 tr2 H1 H2 H3 H4)) |
---|
| 805 | (ecs:∀a,ty,ty',v1,v,tr,H1,H2. P a v1 tr H1 → P ??? (eval_Ecast ge e m a ty ty' v1 v tr H1 H2)) |
---|
| 806 | (eco:∀a,ty,v,l,tr,H. P a v tr H → P ??? (eval_Ecost ge e m a ty v l tr H)) |
---|
[498] | 807 | (lvl:∀id,l,ty,H. Q ???? (eval_Evar_local ge e m id l ty H)) |
---|
| 808 | (lvg:∀id,l,ty,H1,H2. Q ???? (eval_Evar_global ge e m id l ty H1 H2)) |
---|
[1545] | 809 | (lde:∀a,ty,r,l,pc,ofs,tr,H. P a (Vptr (mk_pointer r l pc ofs)) tr H → Q ???? (eval_Ederef ge e m a ty r l pc ofs tr H)) |
---|
[498] | 810 | (lfs:∀a,i,ty,l,ofs,id,fList,delta,tr,H1,H2,H3. Q a l ofs tr H1 → Q ???? (eval_Efield_struct ge e m a i ty l ofs id fList delta tr H1 H2 H3)) |
---|
| 811 | (lfu:∀a,i,ty,l,ofs,id,fList,tr,H1,H2. Q a l ofs tr H1 → Q ???? (eval_Efield_union ge e m a i ty l ofs id fList tr H1 H2)) |
---|
[226] | 812 | |
---|
| 813 | (a:expr) (v:val) (tr:trace) (ev:eval_expr ge e m a v tr) on ev : P a v tr ev ≝ |
---|
| 814 | match ev with |
---|
[961] | 815 | [ eval_Econst_int sz sg i ⇒ eci sz sg i |
---|
[226] | 816 | | eval_Econst_float f ty ⇒ ecF f ty |
---|
[498] | 817 | | eval_Elvalue a ty loc ofs v tr H1 H2 ⇒ elv a ty loc ofs v tr H1 H2 (eval_lvalue_ind2 ge e m P Q eci ecF elv ead esz eun ebi ect ecf eo1 eo2 ea1 ea2 ecs eco lvl lvg lde lfs lfu (Expr a ty) loc ofs tr H1) |
---|
[500] | 818 | | eval_Eaddrof a ty r loc ofs tr H pc ⇒ ead a ty r loc pc ofs tr H (eval_lvalue_ind2 ge e m P Q eci ecF elv ead esz eun ebi ect ecf eo1 eo2 ea1 ea2 ecs eco lvl lvg lde lfs lfu a loc ofs tr H) |
---|
[961] | 819 | | eval_Esizeof ty' sz sg ⇒ esz ty' sz sg |
---|
[226] | 820 | | eval_Eunop op a ty v1 v tr H1 H2 ⇒ eun op a ty v1 v tr H1 H2 (eval_expr_ind2 ge e m P Q eci ecF elv ead esz eun ebi ect ecf eo1 eo2 ea1 ea2 ecs eco lvl lvg lde lfs lfu a v1 tr H1) |
---|
| 821 | | eval_Ebinop op a1 a2 ty v1 v2 v tr1 tr2 H1 H2 H3 ⇒ ebi op a1 a2 ty v1 v2 v tr1 tr2 H1 H2 H3 (eval_expr_ind2 ge e m P Q eci ecF elv ead esz eun ebi ect ecf eo1 eo2 ea1 ea2 ecs eco lvl lvg lde lfs lfu a1 v1 tr1 H1) (eval_expr_ind2 ge e m P Q eci ecF elv ead esz eun ebi ect ecf eo1 eo2 ea1 ea2 ecs eco lvl lvg lde lfs lfu a2 v2 tr2 H2) |
---|
| 822 | | eval_Econdition_true a1 a2 a3 ty v1 v2 tr1 tr2 H1 H2 H3 ⇒ ect a1 a2 a3 ty v1 v2 tr1 tr2 H1 H2 H3 (eval_expr_ind2 ge e m P Q eci ecF elv ead esz eun ebi ect ecf eo1 eo2 ea1 ea2 ecs eco lvl lvg lde lfs lfu a1 v1 tr1 H1) (eval_expr_ind2 ge e m P Q eci ecF elv ead esz eun ebi ect ecf eo1 eo2 ea1 ea2 ecs eco lvl lvg lde lfs lfu a2 v2 tr2 H3) |
---|
| 823 | | eval_Econdition_false a1 a2 a3 ty v1 v3 tr1 tr2 H1 H2 H3 ⇒ ecf a1 a2 a3 ty v1 v3 tr1 tr2 H1 H2 H3 (eval_expr_ind2 ge e m P Q eci ecF elv ead esz eun ebi ect ecf eo1 eo2 ea1 ea2 ecs eco lvl lvg lde lfs lfu a1 v1 tr1 H1) (eval_expr_ind2 ge e m P Q eci ecF elv ead esz eun ebi ect ecf eo1 eo2 ea1 ea2 ecs eco lvl lvg lde lfs lfu a3 v3 tr2 H3) |
---|
| 824 | | eval_Eorbool_1 a1 a2 ty v1 tr H1 H2 ⇒ eo1 a1 a2 ty v1 tr H1 H2 (eval_expr_ind2 ge e m P Q eci ecF elv ead esz eun ebi ect ecf eo1 eo2 ea1 ea2 ecs eco lvl lvg lde lfs lfu a1 v1 tr H1) |
---|
| 825 | | eval_Eorbool_2 a1 a2 ty v1 v2 v tr1 tr2 H1 H2 H3 H4 ⇒ eo2 a1 a2 ty v1 v2 v tr1 tr2 H1 H2 H3 H4 (eval_expr_ind2 ge e m P Q eci ecF elv ead esz eun ebi ect ecf eo1 eo2 ea1 ea2 ecs eco lvl lvg lde lfs lfu a1 v1 tr1 H1) (eval_expr_ind2 ge e m P Q eci ecF elv ead esz eun ebi ect ecf eo1 eo2 ea1 ea2 ecs eco lvl lvg lde lfs lfu a2 v2 tr2 H3) |
---|
| 826 | | eval_Eandbool_1 a1 a2 ty v1 tr H1 H2 ⇒ ea1 a1 a2 ty v1 tr H1 H2 (eval_expr_ind2 ge e m P Q eci ecF elv ead esz eun ebi ect ecf eo1 eo2 ea1 ea2 ecs eco lvl lvg lde lfs lfu a1 v1 tr H1) |
---|
| 827 | | eval_Eandbool_2 a1 a2 ty v1 v2 v tr1 tr2 H1 H2 H3 H4 ⇒ ea2 a1 a2 ty v1 v2 v tr1 tr2 H1 H2 H3 H4 (eval_expr_ind2 ge e m P Q eci ecF elv ead esz eun ebi ect ecf eo1 eo2 ea1 ea2 ecs eco lvl lvg lde lfs lfu a1 v1 tr1 H1) (eval_expr_ind2 ge e m P Q eci ecF elv ead esz eun ebi ect ecf eo1 eo2 ea1 ea2 ecs eco lvl lvg lde lfs lfu a2 v2 tr2 H3) |
---|
| 828 | | eval_Ecast a ty ty' v1 v tr H1 H2 ⇒ ecs a ty ty' v1 v tr H1 H2 (eval_expr_ind2 ge e m P Q eci ecF elv ead esz eun ebi ect ecf eo1 eo2 ea1 ea2 ecs eco lvl lvg lde lfs lfu a v1 tr H1) |
---|
| 829 | | eval_Ecost a ty v l tr H ⇒ eco a ty v l tr H (eval_expr_ind2 ge e m P Q eci ecF elv ead esz eun ebi ect ecf eo1 eo2 ea1 ea2 ecs eco lvl lvg lde lfs lfu a v tr H) |
---|
| 830 | ] |
---|
| 831 | and eval_lvalue_ind2 (ge:genv) (e:env) (m:mem) |
---|
| 832 | (P:∀a,v,tr. eval_expr ge e m a v tr → Prop) |
---|
[498] | 833 | (Q:∀a,loc,ofs,tr. eval_lvalue ge e m a loc ofs tr → Prop) |
---|
[961] | 834 | (eci:∀sz,sg,i. P ??? (eval_Econst_int ge e m sz sg i)) |
---|
[226] | 835 | (ecF:∀f,ty. P ??? (eval_Econst_float ge e m f ty)) |
---|
[498] | 836 | (elv:∀a,ty,loc,ofs,v,tr,H1,H2. Q (Expr a ty) loc ofs tr H1 → P ??? (eval_Elvalue ge e m a ty loc ofs v tr H1 H2)) |
---|
[500] | 837 | (ead:∀a,ty,r,loc,pc,ofs,tr,H. Q a loc ofs tr H → P ??? (eval_Eaddrof ge e m a ty r loc ofs tr H pc)) |
---|
[961] | 838 | (esz:∀ty',sz,sg. P ??? (eval_Esizeof ge e m ty' sz sg)) |
---|
[226] | 839 | (eun:∀op,a,ty,v1,v,tr,H1,H2. P a v1 tr H1 → P ??? (eval_Eunop ge e m op a ty v1 v tr H1 H2)) |
---|
| 840 | (ebi:∀op,a1,a2,ty,v1,v2,v,tr1,tr2,H1,H2,H3. P a1 v1 tr1 H1 → P a2 v2 tr2 H2 → P ??? (eval_Ebinop ge e m op a1 a2 ty v1 v2 v tr1 tr2 H1 H2 H3)) |
---|
| 841 | (ect:∀a1,a2,a3,ty,v1,v2,tr1,tr2,H1,H2,H3. P a1 v1 tr1 H1 → P a2 v2 tr2 H3 → P ??? (eval_Econdition_true ge e m a1 a2 a3 ty v1 v2 tr1 tr2 H1 H2 H3)) |
---|
| 842 | (ecf:∀a1,a2,a3,ty,v1,v3,tr1,tr2,H1,H2,H3. P a1 v1 tr1 H1 → P a3 v3 tr2 H3 → P ??? (eval_Econdition_false ge e m a1 a2 a3 ty v1 v3 tr1 tr2 H1 H2 H3)) |
---|
| 843 | (eo1:∀a1,a2,ty,v1,tr,H1,H2. P a1 v1 tr H1 → P ??? (eval_Eorbool_1 ge e m a1 a2 ty v1 tr H1 H2)) |
---|
| 844 | (eo2:∀a1,a2,ty,v1,v2,v,tr1,tr2,H1,H2,H3,H4. P a1 v1 tr1 H1 → P a2 v2 tr2 H3 → P ??? (eval_Eorbool_2 ge e m a1 a2 ty v1 v2 v tr1 tr2 H1 H2 H3 H4)) |
---|
| 845 | (ea1:∀a1,a2,ty,v1,tr,H1,H2. P a1 v1 tr H1 → P ??? (eval_Eandbool_1 ge e m a1 a2 ty v1 tr H1 H2)) |
---|
| 846 | (ea2:∀a1,a2,ty,v1,v2,v,tr1,tr2,H1,H2,H3,H4. P a1 v1 tr1 H1 → P a2 v2 tr2 H3 → P ??? (eval_Eandbool_2 ge e m a1 a2 ty v1 v2 v tr1 tr2 H1 H2 H3 H4)) |
---|
| 847 | (ecs:∀a,ty,ty',v1,v,tr,H1,H2. P a v1 tr H1 → P ??? (eval_Ecast ge e m a ty ty' v1 v tr H1 H2)) |
---|
| 848 | (eco:∀a,ty,v,l,tr,H. P a v tr H → P ??? (eval_Ecost ge e m a ty v l tr H)) |
---|
[498] | 849 | (lvl:∀id,l,ty,H. Q ???? (eval_Evar_local ge e m id l ty H)) |
---|
| 850 | (lvg:∀id,l,ty,H1,H2. Q ???? (eval_Evar_global ge e m id l ty H1 H2)) |
---|
[1545] | 851 | (lde:∀a,ty,r,l,pc,ofs,tr,H. P a (Vptr (mk_pointer r l pc ofs)) tr H → Q ???? (eval_Ederef ge e m a ty r l pc ofs tr H)) |
---|
[498] | 852 | (lfs:∀a,i,ty,l,ofs,id,fList,delta,tr,H1,H2,H3. Q a l ofs tr H1 → Q ???? (eval_Efield_struct ge e m a i ty l ofs id fList delta tr H1 H2 H3)) |
---|
| 853 | (lfu:∀a,i,ty,l,ofs,id,fList,tr,H1,H2. Q a l ofs tr H1 → Q ???? (eval_Efield_union ge e m a i ty l ofs id fList tr H1 H2)) |
---|
[583] | 854 | (a:expr) (loc:block) (ofs:offset) (tr:trace) (ev:eval_lvalue ge e m a loc ofs tr) on ev : Q a loc ofs tr ev ≝ |
---|
[226] | 855 | match ev with |
---|
| 856 | [ eval_Evar_local id l ty H ⇒ lvl id l ty H |
---|
[498] | 857 | | eval_Evar_global id l ty H1 H2 ⇒ lvg id l ty H1 H2 |
---|
[1545] | 858 | | eval_Ederef a ty r l pc ofs tr H ⇒ lde a ty r l pc ofs tr H (eval_expr_ind2 ge e m P Q eci ecF elv ead esz eun ebi ect ecf eo1 eo2 ea1 ea2 ecs eco lvl lvg lde lfs lfu a (Vptr (mk_pointer r l pc ofs)) tr H) |
---|
[498] | 859 | | eval_Efield_struct a i ty l ofs id fList delta tr H1 H2 H3 ⇒ lfs a i ty l ofs id fList delta tr H1 H2 H3 (eval_lvalue_ind2 ge e m P Q eci ecF elv ead esz eun ebi ect ecf eo1 eo2 ea1 ea2 ecs eco lvl lvg lde lfs lfu a l ofs tr H1) |
---|
| 860 | | eval_Efield_union a i ty l ofs id fList tr H1 H2 ⇒ lfu a i ty l ofs id fList tr H1 H2 (eval_lvalue_ind2 ge e m P Q eci ecF elv ead esz eun ebi ect ecf eo1 eo2 ea1 ea2 ecs eco lvl lvg lde lfs lfu a l ofs tr H1) |
---|
[226] | 861 | ]. |
---|
| 862 | |
---|
[487] | 863 | definition combined_expr_lvalue_ind ≝ |
---|
[226] | 864 | λge,e,m,P,Q,eci,ecF,elv,ead,esz,eun,ebi,ect,ecf,eo1,eo2,ea1,ea2,ecs,eco,lvl,lvg,lde,lfs,lfu. |
---|
| 865 | conj ?? |
---|
| 866 | (eval_expr_ind2 ge e m P Q eci ecF elv ead esz eun ebi ect ecf eo1 eo2 ea1 ea2 ecs eco lvl lvg lde lfs lfu) |
---|
| 867 | (eval_lvalue_ind2 ge e m P Q eci ecF elv ead esz eun ebi ect ecf eo1 eo2 ea1 ea2 ecs eco lvl lvg lde lfs lfu). |
---|
| 868 | |
---|
| 869 | (* * [eval_lvalue ge e m a b ofs] defines the evaluation of expression [a] |
---|
| 870 | in l-value position. The result is the memory location [b, ofs] |
---|
| 871 | that contains the value of the expression [a]. *) |
---|
| 872 | |
---|
| 873 | (* |
---|
| 874 | Scheme eval_expr_ind22 := Minimality for eval_expr Sort Prop |
---|
[3] | 875 | with eval_lvalue_ind2 := Minimality for eval_lvalue Sort Prop. |
---|
| 876 | *) |
---|
| 877 | |
---|
| 878 | (* * [eval_exprlist ge e m al vl] evaluates a list of r-value |
---|
| 879 | expressions [al] to their values [vl]. *) |
---|
| 880 | |
---|
[487] | 881 | inductive eval_exprlist (ge:genv) (e:env) (m:mem) : list expr → list val → trace → Prop ≝ |
---|
[3] | 882 | | eval_Enil: |
---|
[175] | 883 | eval_exprlist ge e m (nil ?) (nil ?) E0 |
---|
| 884 | | eval_Econs: ∀a,bl,v,vl,tr1,tr2. |
---|
| 885 | eval_expr ge e m a v tr1 → |
---|
| 886 | eval_exprlist ge e m bl vl tr2 → |
---|
| 887 | eval_exprlist ge e m (a :: bl) (v :: vl) (tr1⧺tr2). |
---|
[3] | 888 | |
---|
| 889 | (*End EXPR.*) |
---|
| 890 | |
---|
| 891 | (* * ** Transition semantics for statements and functions *) |
---|
| 892 | |
---|
| 893 | (* * Continuations *) |
---|
| 894 | |
---|
[487] | 895 | inductive cont: Type[0] := |
---|
[3] | 896 | | Kstop: cont |
---|
| 897 | | Kseq: statement -> cont -> cont |
---|
| 898 | (**r [Kseq s2 k] = after [s1] in [s1;s2] *) |
---|
| 899 | | Kwhile: expr -> statement -> cont -> cont |
---|
| 900 | (**r [Kwhile e s k] = after [s] in [while (e) s] *) |
---|
| 901 | | Kdowhile: expr -> statement -> cont -> cont |
---|
| 902 | (**r [Kdowhile e s k] = after [s] in [do s while (e)] *) |
---|
| 903 | | Kfor2: expr -> statement -> statement -> cont -> cont |
---|
| 904 | (**r [Kfor2 e2 e3 s k] = after [s] in [for(e1;e2;e3) s] *) |
---|
| 905 | | Kfor3: expr -> statement -> statement -> cont -> cont |
---|
| 906 | (**r [Kfor3 e2 e3 s k] = after [e3] in [for(e1;e2;e3) s] *) |
---|
| 907 | | Kswitch: cont -> cont |
---|
| 908 | (**r catches [break] statements arising out of [switch] *) |
---|
[583] | 909 | | Kcall: option (block × offset × type) -> (**r where to store result *) |
---|
| 910 | function -> (**r calling function *) |
---|
| 911 | env -> (**r local env of calling function *) |
---|
[3] | 912 | cont -> cont. |
---|
| 913 | |
---|
| 914 | (* * Pop continuation until a call or stop *) |
---|
| 915 | |
---|
[487] | 916 | let rec call_cont (k: cont) : cont := |
---|
[3] | 917 | match k with |
---|
| 918 | [ Kseq s k => call_cont k |
---|
| 919 | | Kwhile e s k => call_cont k |
---|
| 920 | | Kdowhile e s k => call_cont k |
---|
| 921 | | Kfor2 e2 e3 s k => call_cont k |
---|
| 922 | | Kfor3 e2 e3 s k => call_cont k |
---|
| 923 | | Kswitch k => call_cont k |
---|
| 924 | | _ => k |
---|
| 925 | ]. |
---|
| 926 | |
---|
[487] | 927 | definition is_call_cont : cont → Prop ≝ λk. |
---|
[3] | 928 | match k with |
---|
| 929 | [ Kstop => True |
---|
| 930 | | Kcall _ _ _ _ => True |
---|
| 931 | | _ => False |
---|
| 932 | ]. |
---|
| 933 | |
---|
| 934 | (* * States *) |
---|
| 935 | |
---|
[487] | 936 | inductive state: Type[0] := |
---|
[3] | 937 | | State: |
---|
| 938 | ∀f: function. |
---|
| 939 | ∀s: statement. |
---|
| 940 | ∀k: cont. |
---|
| 941 | ∀e: env. |
---|
| 942 | ∀m: mem. state |
---|
| 943 | | Callstate: |
---|
[725] | 944 | ∀fd: clight_fundef. |
---|
[3] | 945 | ∀args: list val. |
---|
| 946 | ∀k: cont. |
---|
| 947 | ∀m: mem. state |
---|
| 948 | | Returnstate: |
---|
| 949 | ∀res: val. |
---|
| 950 | ∀k: cont. |
---|
[1713] | 951 | ∀m: mem. state |
---|
| 952 | | Finalstate: |
---|
| 953 | ∀r: int. |
---|
| 954 | state. |
---|
[3] | 955 | |
---|
| 956 | (* * Find the statement and manufacture the continuation |
---|
| 957 | corresponding to a label *) |
---|
| 958 | |
---|
[487] | 959 | let rec find_label (lbl: label) (s: statement) (k: cont) |
---|
[3] | 960 | on s: option (statement × cont) := |
---|
| 961 | match s with |
---|
| 962 | [ Ssequence s1 s2 => |
---|
| 963 | match find_label lbl s1 (Kseq s2 k) with |
---|
| 964 | [ Some sk => Some ? sk |
---|
| 965 | | None => find_label lbl s2 k |
---|
| 966 | ] |
---|
| 967 | | Sifthenelse a s1 s2 => |
---|
| 968 | match find_label lbl s1 k with |
---|
| 969 | [ Some sk => Some ? sk |
---|
| 970 | | None => find_label lbl s2 k |
---|
| 971 | ] |
---|
| 972 | | Swhile a s1 => |
---|
| 973 | find_label lbl s1 (Kwhile a s1 k) |
---|
| 974 | | Sdowhile a s1 => |
---|
| 975 | find_label lbl s1 (Kdowhile a s1 k) |
---|
| 976 | | Sfor a1 a2 a3 s1 => |
---|
| 977 | match find_label lbl a1 (Kseq (Sfor Sskip a2 a3 s1) k) with |
---|
| 978 | [ Some sk => Some ? sk |
---|
| 979 | | None => |
---|
| 980 | match find_label lbl s1 (Kfor2 a2 a3 s1 k) with |
---|
| 981 | [ Some sk => Some ? sk |
---|
| 982 | | None => find_label lbl a3 (Kfor3 a2 a3 s1 k) |
---|
| 983 | ] |
---|
| 984 | ] |
---|
| 985 | | Sswitch e sl => |
---|
| 986 | find_label_ls lbl sl (Kswitch k) |
---|
| 987 | | Slabel lbl' s' => |
---|
| 988 | match ident_eq lbl lbl' with |
---|
| 989 | [ inl _ ⇒ Some ? 〈s', k〉 |
---|
| 990 | | inr _ ⇒ find_label lbl s' k |
---|
| 991 | ] |
---|
[1914] | 992 | | Scost c s' ⇒ |
---|
| 993 | find_label lbl s' k |
---|
[3] | 994 | | _ => None ? |
---|
| 995 | ] |
---|
| 996 | |
---|
| 997 | and find_label_ls (lbl: label) (sl: labeled_statements) (k: cont) |
---|
| 998 | on sl: option (statement × cont) := |
---|
| 999 | match sl with |
---|
| 1000 | [ LSdefault s => find_label lbl s k |
---|
[961] | 1001 | | LScase _ _ s sl' => |
---|
[3] | 1002 | match find_label lbl s (Kseq (seq_of_labeled_statement sl') k) with |
---|
| 1003 | [ Some sk => Some ? sk |
---|
| 1004 | | None => find_label_ls lbl sl' k |
---|
| 1005 | ] |
---|
| 1006 | ]. |
---|
| 1007 | |
---|
| 1008 | (* * Transition relation *) |
---|
| 1009 | |
---|
[457] | 1010 | (* Strip off outer pointer for use when comparing function types. *) |
---|
[487] | 1011 | definition fun_typeof ≝ |
---|
[457] | 1012 | λe. match typeof e with |
---|
| 1013 | [ Tvoid ⇒ Tvoid |
---|
| 1014 | | Tint a b ⇒ Tint a b |
---|
| 1015 | | Tfloat a ⇒ Tfloat a |
---|
| 1016 | | Tpointer _ ty ⇒ ty |
---|
| 1017 | | Tarray a b c ⇒ Tarray a b c |
---|
| 1018 | | Tfunction a b ⇒ Tfunction a b |
---|
| 1019 | | Tstruct a b ⇒ Tstruct a b |
---|
| 1020 | | Tunion a b ⇒ Tunion a b |
---|
[481] | 1021 | | Tcomp_ptr a b ⇒ Tcomp_ptr a b |
---|
[457] | 1022 | ]. |
---|
| 1023 | |
---|
[175] | 1024 | (* XXX: note that cost labels in exprs expose a particular eval order. *) |
---|
[3] | 1025 | |
---|
[487] | 1026 | inductive step (ge:genv) : state → trace → state → Prop ≝ |
---|
[175] | 1027 | |
---|
[498] | 1028 | | step_assign: ∀f,a1,a2,k,e,m,loc,ofs,v2,m',tr1,tr2. |
---|
| 1029 | eval_lvalue ge e m a1 loc ofs tr1 → |
---|
[175] | 1030 | eval_expr ge e m a2 v2 tr2 → |
---|
[498] | 1031 | store_value_of_type (typeof a1) m loc ofs v2 = Some ? m' → |
---|
[3] | 1032 | step ge (State f (Sassign a1 a2) k e m) |
---|
[175] | 1033 | (tr1⧺tr2) (State f Sskip k e m') |
---|
[3] | 1034 | |
---|
[175] | 1035 | | step_call_none: ∀f,a,al,k,e,m,vf,vargs,fd,tr1,tr2. |
---|
| 1036 | eval_expr ge e m a vf tr1 → |
---|
| 1037 | eval_exprlist ge e m al vargs tr2 → |
---|
[1986] | 1038 | find_funct … ge vf = Some ? fd → |
---|
[457] | 1039 | type_of_fundef fd = fun_typeof a → |
---|
[3] | 1040 | step ge (State f (Scall (None ?) a al) k e m) |
---|
[175] | 1041 | (tr1⧺tr2) (Callstate fd vargs (Kcall (None ?) f e k) m) |
---|
[3] | 1042 | |
---|
[498] | 1043 | | step_call_some: ∀f,lhs,a,al,k,e,m,loc,ofs,vf,vargs,fd,tr1,tr2,tr3. |
---|
| 1044 | eval_lvalue ge e m lhs loc ofs tr1 → |
---|
[175] | 1045 | eval_expr ge e m a vf tr2 → |
---|
| 1046 | eval_exprlist ge e m al vargs tr3 → |
---|
[1986] | 1047 | find_funct … ge vf = Some ? fd → |
---|
[457] | 1048 | type_of_fundef fd = fun_typeof a → |
---|
[3] | 1049 | step ge (State f (Scall (Some ? lhs) a al) k e m) |
---|
[498] | 1050 | (tr1⧺tr2⧺tr3) (Callstate fd vargs (Kcall (Some ? 〈〈loc, ofs〉, typeof lhs〉) f e k) m) |
---|
[3] | 1051 | |
---|
| 1052 | | step_seq: ∀f,s1,s2,k,e,m. |
---|
| 1053 | step ge (State f (Ssequence s1 s2) k e m) |
---|
| 1054 | E0 (State f s1 (Kseq s2 k) e m) |
---|
| 1055 | | step_skip_seq: ∀f,s,k,e,m. |
---|
| 1056 | step ge (State f Sskip (Kseq s k) e m) |
---|
| 1057 | E0 (State f s k e m) |
---|
| 1058 | | step_continue_seq: ∀f,s,k,e,m. |
---|
| 1059 | step ge (State f Scontinue (Kseq s k) e m) |
---|
| 1060 | E0 (State f Scontinue k e m) |
---|
| 1061 | | step_break_seq: ∀f,s,k,e,m. |
---|
| 1062 | step ge (State f Sbreak (Kseq s k) e m) |
---|
| 1063 | E0 (State f Sbreak k e m) |
---|
| 1064 | |
---|
[175] | 1065 | | step_ifthenelse_true: ∀f,a,s1,s2,k,e,m,v1,tr. |
---|
| 1066 | eval_expr ge e m a v1 tr → |
---|
| 1067 | is_true v1 (typeof a) → |
---|
[3] | 1068 | step ge (State f (Sifthenelse a s1 s2) k e m) |
---|
[175] | 1069 | tr (State f s1 k e m) |
---|
| 1070 | | step_ifthenelse_false: ∀f,a,s1,s2,k,e,m,v1,tr. |
---|
| 1071 | eval_expr ge e m a v1 tr → |
---|
| 1072 | is_false v1 (typeof a) → |
---|
[3] | 1073 | step ge (State f (Sifthenelse a s1 s2) k e m) |
---|
[175] | 1074 | tr (State f s2 k e m) |
---|
[3] | 1075 | |
---|
[175] | 1076 | | step_while_false: ∀f,a,s,k,e,m,v,tr. |
---|
| 1077 | eval_expr ge e m a v tr → |
---|
| 1078 | is_false v (typeof a) → |
---|
[3] | 1079 | step ge (State f (Swhile a s) k e m) |
---|
[175] | 1080 | tr (State f Sskip k e m) |
---|
| 1081 | | step_while_true: ∀f,a,s,k,e,m,v,tr. |
---|
| 1082 | eval_expr ge e m a v tr → |
---|
| 1083 | is_true v (typeof a) → |
---|
[3] | 1084 | step ge (State f (Swhile a s) k e m) |
---|
[175] | 1085 | tr (State f s (Kwhile a s k) e m) |
---|
[3] | 1086 | | step_skip_or_continue_while: ∀f,x,a,s,k,e,m. |
---|
[175] | 1087 | x = Sskip ∨ x = Scontinue → |
---|
[3] | 1088 | step ge (State f x (Kwhile a s k) e m) |
---|
| 1089 | E0 (State f (Swhile a s) k e m) |
---|
| 1090 | | step_break_while: ∀f,a,s,k,e,m. |
---|
| 1091 | step ge (State f Sbreak (Kwhile a s k) e m) |
---|
| 1092 | E0 (State f Sskip k e m) |
---|
| 1093 | |
---|
| 1094 | | step_dowhile: ∀f,a,s,k,e,m. |
---|
| 1095 | step ge (State f (Sdowhile a s) k e m) |
---|
| 1096 | E0 (State f s (Kdowhile a s k) e m) |
---|
[175] | 1097 | | step_skip_or_continue_dowhile_false: ∀f,x,a,s,k,e,m,v,tr. |
---|
| 1098 | x = Sskip ∨ x = Scontinue → |
---|
| 1099 | eval_expr ge e m a v tr → |
---|
| 1100 | is_false v (typeof a) → |
---|
[3] | 1101 | step ge (State f x (Kdowhile a s k) e m) |
---|
[175] | 1102 | tr (State f Sskip k e m) |
---|
| 1103 | | step_skip_or_continue_dowhile_true: ∀f,x,a,s,k,e,m,v,tr. |
---|
| 1104 | x = Sskip ∨ x = Scontinue → |
---|
| 1105 | eval_expr ge e m a v tr → |
---|
| 1106 | is_true v (typeof a) → |
---|
[3] | 1107 | step ge (State f x (Kdowhile a s k) e m) |
---|
[175] | 1108 | tr (State f (Sdowhile a s) k e m) |
---|
[3] | 1109 | | step_break_dowhile: ∀f,a,s,k,e,m. |
---|
| 1110 | step ge (State f Sbreak (Kdowhile a s k) e m) |
---|
| 1111 | E0 (State f Sskip k e m) |
---|
| 1112 | |
---|
| 1113 | | step_for_start: ∀f,a1,a2,a3,s,k,e,m. |
---|
[175] | 1114 | a1 ≠ Sskip → |
---|
[3] | 1115 | step ge (State f (Sfor a1 a2 a3 s) k e m) |
---|
| 1116 | E0 (State f a1 (Kseq (Sfor Sskip a2 a3 s) k) e m) |
---|
[175] | 1117 | | step_for_false: ∀f,a2,a3,s,k,e,m,v,tr. |
---|
| 1118 | eval_expr ge e m a2 v tr → |
---|
| 1119 | is_false v (typeof a2) → |
---|
[3] | 1120 | step ge (State f (Sfor Sskip a2 a3 s) k e m) |
---|
[175] | 1121 | tr (State f Sskip k e m) |
---|
| 1122 | | step_for_true: ∀f,a2,a3,s,k,e,m,v,tr. |
---|
| 1123 | eval_expr ge e m a2 v tr → |
---|
| 1124 | is_true v (typeof a2) → |
---|
[3] | 1125 | step ge (State f (Sfor Sskip a2 a3 s) k e m) |
---|
[175] | 1126 | tr (State f s (Kfor2 a2 a3 s k) e m) |
---|
[3] | 1127 | | step_skip_or_continue_for2: ∀f,x,a2,a3,s,k,e,m. |
---|
[175] | 1128 | x = Sskip ∨ x = Scontinue → |
---|
[3] | 1129 | step ge (State f x (Kfor2 a2 a3 s k) e m) |
---|
| 1130 | E0 (State f a3 (Kfor3 a2 a3 s k) e m) |
---|
| 1131 | | step_break_for2: ∀f,a2,a3,s,k,e,m. |
---|
| 1132 | step ge (State f Sbreak (Kfor2 a2 a3 s k) e m) |
---|
| 1133 | E0 (State f Sskip k e m) |
---|
| 1134 | | step_skip_for3: ∀f,a2,a3,s,k,e,m. |
---|
| 1135 | step ge (State f Sskip (Kfor3 a2 a3 s k) e m) |
---|
| 1136 | E0 (State f (Sfor Sskip a2 a3 s) k e m) |
---|
| 1137 | |
---|
| 1138 | | step_return_0: ∀f,k,e,m. |
---|
[175] | 1139 | fn_return f = Tvoid → |
---|
[3] | 1140 | step ge (State f (Sreturn (None ?)) k e m) |
---|
[1874] | 1141 | E0 (Returnstate Vundef (call_cont k) (free_list becontentT m (blocks_of_env e))) |
---|
[175] | 1142 | | step_return_1: ∀f,a,k,e,m,v,tr. |
---|
| 1143 | fn_return f ≠ Tvoid → |
---|
| 1144 | eval_expr ge e m a v tr → |
---|
[3] | 1145 | step ge (State f (Sreturn (Some ? a)) k e m) |
---|
[1874] | 1146 | tr (Returnstate v (call_cont k) (free_list becontentT m (blocks_of_env e))) |
---|
[3] | 1147 | | step_skip_call: ∀f,k,e,m. |
---|
[175] | 1148 | is_call_cont k → |
---|
| 1149 | fn_return f = Tvoid → |
---|
[3] | 1150 | step ge (State f Sskip k e m) |
---|
[1874] | 1151 | E0 (Returnstate Vundef k (free_list becontentT m (blocks_of_env e))) |
---|
[3] | 1152 | |
---|
[961] | 1153 | | step_switch: ∀f,a,sl,k,e,m,sz,n,tr. |
---|
| 1154 | eval_expr ge e m a (Vint sz n) tr → |
---|
[3] | 1155 | step ge (State f (Sswitch a sl) k e m) |
---|
[961] | 1156 | tr (State f (seq_of_labeled_statement (select_switch ? n sl)) (Kswitch k) e m) |
---|
[3] | 1157 | | step_skip_break_switch: ∀f,x,k,e,m. |
---|
[175] | 1158 | x = Sskip ∨ x = Sbreak → |
---|
[3] | 1159 | step ge (State f x (Kswitch k) e m) |
---|
| 1160 | E0 (State f Sskip k e m) |
---|
| 1161 | | step_continue_switch: ∀f,k,e,m. |
---|
| 1162 | step ge (State f Scontinue (Kswitch k) e m) |
---|
| 1163 | E0 (State f Scontinue k e m) |
---|
| 1164 | |
---|
| 1165 | | step_label: ∀f,lbl,s,k,e,m. |
---|
| 1166 | step ge (State f (Slabel lbl s) k e m) |
---|
| 1167 | E0 (State f s k e m) |
---|
| 1168 | |
---|
| 1169 | | step_goto: ∀f,lbl,k,e,m,s',k'. |
---|
[175] | 1170 | find_label lbl (fn_body f) (call_cont k) = Some ? 〈s', k'〉 → |
---|
[3] | 1171 | step ge (State f (Sgoto lbl) k e m) |
---|
| 1172 | E0 (State f s' k' e m) |
---|
| 1173 | |
---|
| 1174 | | step_internal_function: ∀f,vargs,k,m,e,m1,m2. |
---|
[175] | 1175 | alloc_variables empty_env m ((fn_params f) @ (fn_vars f)) e m1 → |
---|
| 1176 | bind_parameters e m1 (fn_params f) vargs m2 → |
---|
[725] | 1177 | step ge (Callstate (CL_Internal f) vargs k m) |
---|
[3] | 1178 | E0 (State f (fn_body f) k e m2) |
---|
| 1179 | |
---|
| 1180 | | step_external_function: ∀id,targs,tres,vargs,k,m,vres,t. |
---|
[175] | 1181 | event_match (external_function id targs tres) vargs t vres → |
---|
[725] | 1182 | step ge (Callstate (CL_External id targs tres) vargs k m) |
---|
[3] | 1183 | t (Returnstate vres k m) |
---|
| 1184 | |
---|
| 1185 | | step_returnstate_0: ∀v,f,e,k,m. |
---|
| 1186 | step ge (Returnstate v (Kcall (None ?) f e k) m) |
---|
| 1187 | E0 (State f Sskip k e m) |
---|
| 1188 | |
---|
[498] | 1189 | | step_returnstate_1: ∀v,f,e,k,m,m',loc,ofs,ty. |
---|
| 1190 | store_value_of_type ty m loc ofs v = Some ? m' → |
---|
| 1191 | step ge (Returnstate v (Kcall (Some ? 〈〈loc, ofs〉, ty〉) f e k) m) |
---|
[175] | 1192 | E0 (State f Sskip k e m') |
---|
| 1193 | |
---|
| 1194 | | step_cost: ∀f,lbl,s,k,e,m. |
---|
| 1195 | step ge (State f (Scost lbl s) k e m) |
---|
[1713] | 1196 | (Echarge lbl) (State f s k e m) |
---|
| 1197 | |
---|
| 1198 | | step_final: ∀r,m. |
---|
| 1199 | step ge (Returnstate (Vint I32 r) Kstop m) |
---|
| 1200 | E0 (Finalstate r). |
---|
[1147] | 1201 | |
---|
[3] | 1202 | (* |
---|
| 1203 | End SEMANTICS. |
---|
| 1204 | *) |
---|
[1147] | 1205 | |
---|
[3] | 1206 | (* * * Whole-program semantics *) |
---|
| 1207 | |
---|
| 1208 | (* * Execution of whole programs are described as sequences of transitions |
---|
| 1209 | from an initial state to a final state. An initial state is a [Callstate] |
---|
| 1210 | corresponding to the invocation of the ``main'' function of the program |
---|
| 1211 | without arguments and with an empty continuation. *) |
---|
| 1212 | |
---|
[487] | 1213 | inductive initial_state (p: clight_program): state -> Prop := |
---|
[485] | 1214 | | initial_state_intro: ∀b,f,ge,m0. |
---|
[1986] | 1215 | globalenv … (fst ??) p = ge → |
---|
| 1216 | init_mem … (fst ??) p = OK ? m0 → |
---|
| 1217 | find_symbol … ge (prog_main ?? p) = Some ? b → |
---|
| 1218 | find_funct_ptr … ge b = Some ? f → |
---|
[3] | 1219 | initial_state p (Callstate f (nil ?) Kstop m0). |
---|
| 1220 | |
---|
| 1221 | (* * A final state is a [Returnstate] with an empty continuation. *) |
---|
| 1222 | |
---|
[487] | 1223 | inductive final_state: state -> int -> Prop := |
---|
[1713] | 1224 | | final_state_intro: ∀r. |
---|
| 1225 | final_state (Finalstate r) r. |
---|
[3] | 1226 | |
---|
| 1227 | (* * Execution of a whole program: [exec_program p beh] |
---|
| 1228 | holds if the application of [p]'s main function to no arguments |
---|
| 1229 | in the initial memory state for [p] has [beh] as observable |
---|
| 1230 | behavior. *) |
---|
| 1231 | |
---|
[487] | 1232 | definition exec_program : clight_program → program_behavior → Prop ≝ λp,beh. |
---|
[1986] | 1233 | ∀ge. globalenv … (fst ??) p = ge → |
---|
[485] | 1234 | program_behaves (mk_transrel ?? step) (initial_state p) final_state ge beh. |
---|
[3] | 1235 | |
---|