(* *********************************************************************)
(*                                                                     *)
(*              The Compcert verified compiler                         *)
(*                                                                     *)
(*          Xavier Leroy, INRIA Paris-Rocquencourt                     *)
(*                                                                     *)
(*  Copyright Institut National de Recherche en Informatique et en     *)
(*  Automatique.  All rights reserved.  This file is distributed       *)
(*  under the terms of the GNU General Public License as published by  *)
(*  the Free Software Foundation, either version 2 of the License, or  *)
(*  (at your option) any later version.  This file is also distributed *)
(*  under the terms of the INRIA Non-Commercial License Agreement.     *)
(*                                                                     *)
(* *********************************************************************)
(** This module defines the type of values that is used in the dynamic semantics of all our intermediate languages. *)
Definition block : Type := positive.
Definition eq_block := peq.
(** A value is either: - a machine integer; - a floating-point number; - a pointer: a pair of a memory address and an integer offset with respect to this address; - the [Vundef] value denoting an arbitrary bit pattern, such as the value of an uninitialized variable. *)
Inductive val: Type :=
| Vundef: val
| Vint: int -> val
| Vlong: int64 -> val
| Vfloat: float -> val
| Vsingle: float32 -> val
| Vptr: block -> ptrofs -> val.
Definition Vzero: val := Vint Int.zero.
Definition Vone: val := Vint Int.one.
Definition Vmone: val := Vint Int.mone.
Definition Vtrue: val := Vint Int.one.
Definition Vfalse: val := Vint Int.zero.
Definition Vnullptr :=
if Archi.ptr64 then Vlong Int64.zero else Vint Int.zero.
Definition Vptrofs (n: ptrofs) :=
if Archi.ptr64 then Vlong (Ptrofs.to_int64 n) else Vint (Ptrofs.to_int n).
(** * Operations over values *)
(** The module [Val] defines a number of arithmetic and logical operations over type [val].  Most of these operations are straightforward extensions of the corresponding integer or floating-point operations. *)
Module Val.
Definition eq (x y: val): {x=y} + {x<>y}.

(* Specifications: *)
Lemma Vnullptr_has_type:
has_type Vnullptr Tptr.
Lemma has_subtype:
forall ty1 ty2 v,
subtype ty1 ty2 = true -> has_type v ty1 -> has_type v ty2.
Lemma has_subtype_list:
forall tyl1 tyl2 vl,
subtype_list tyl1 tyl2 = true -> has_type_list vl tyl1 -> has_type_list vl tyl2.
Lemma Vnullptr_has_type:
has_type Vnullptr Tptr.
Lemma has_subtype:
forall ty1 ty2 v,
subtype ty1 ty2 = true -> has_type v ty1 -> has_type v ty2.
Lemma has_subtype_list:
forall tyl1 tyl2 vl,
subtype_list tyl1 tyl2 = true -> has_type_list vl tyl1 -> has_type_list vl tyl2.