source: src/Clight/Csem.ma @ 2468

Last change on this file since 2468 was 2468, checked in by garnier, 7 years ago

Floats are gone from the front-end. Some trace amount might remain in RTL/RTLabs, but this should be easily fixable.
Also, work-in-progress in Clight/memoryInjections.ma

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