Changeset 1369 for src/common


Ignore:
Timestamp:
Oct 14, 2011, 10:56:45 AM (8 years ago)
Author:
campbell
Message:

Put type information into front-end unary ops.
Slight change to semantics: booleans produced by Onotbool can be any given
integer size.

Location:
src/common
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • src/common/FrontEndOps.ma

    r962 r1369  
    2626  | Oaddrstack: nat → constant.            (**r stack pointer plus the given offset *)
    2727
    28 inductive unary_operation : Type[0] ≝
    29   | Ocastint: signedness → intsize → unary_operation (**r integer casts *)
    30   | Onegint: unary_operation               (**r integer opposite *)
    31   | Onotbool: unary_operation              (**r boolean negation  *)
    32   | Onotint: unary_operation               (**r bitwise complement  *)
    33   | Onegf: unary_operation                 (**r float opposite *)
    34   | Oabsf: unary_operation                 (**r float absolute value *)
    35   | Osingleoffloat: unary_operation        (**r float truncation *)
    36   | Ointoffloat: intsize → unary_operation (**r signed integer to float *)
    37   | Ointuoffloat: intsize → unary_operation (**r unsigned integer to float *)
    38   | Ofloatofint: unary_operation           (**r float to signed integer *)
    39   | Ofloatofintu: unary_operation          (**r float to unsigned integer *)
    40   | Oid: unary_operation                   (**r identity (used to move between registers *)
    41   | Optrofint: region → unary_operation    (**r int to pointer with given representation *)
    42   | Ointofptr: intsize → unary_operation.  (**r pointer to int *)
     28definition boolsrc : typ → Prop ≝ λt. match t with [ ASTint _ _ ⇒ True | ASTptr _ ⇒ True | _ ⇒ False ].
     29
     30inductive unary_operation : typ → typ → Type[0] ≝
     31  | Ocastint: ∀sz,sg,sz',sg'. unary_operation (ASTint sz sg) (ASTint sz' sg')  (**r integer casts *)
     32  | Onegint:  ∀sz,sg. unary_operation (ASTint sz sg) (ASTint sz sg)            (**r integer opposite *)
     33  | Onotbool: ∀t,sz,sg. boolsrc t → unary_operation t (ASTint sz sg)           (**r boolean negation  *)
     34  | Onotint:  ∀sz,sg. unary_operation (ASTint sz sg) (ASTint sz sg)            (**r bitwise complement  *)
     35  | Onegf: ∀sz. unary_operation (ASTfloat sz) (ASTfloat sz)                    (**r float opposite *)
     36  | Oabsf: ∀sz. unary_operation (ASTfloat sz) (ASTfloat sz)                    (**r float absolute value *)
     37  | Osingleoffloat: unary_operation (ASTfloat F64) (ASTfloat F32)              (**r float truncation *)
     38  | Ointoffloat:  ∀fsz,sz. unary_operation (ASTfloat fsz) (ASTint sz Signed)   (**r signed integer to float *)
     39  | Ointuoffloat: ∀fsz,sz. unary_operation (ASTfloat fsz) (ASTint sz Unsigned) (**r unsigned integer to float *)
     40  | Ofloatofint:  ∀fsz,sz. unary_operation (ASTint sz Signed) (ASTfloat fsz)   (**r float to signed integer *)
     41  | Ofloatofintu: ∀fsz,sz. unary_operation (ASTint sz Unsigned) (ASTfloat fsz) (**r float to unsigned integer *)
     42  | Oid: ∀t. unary_operation t t                                               (**r identity (used to move between registers *)
     43  | Optrofint: ∀sz,sg,r. unary_operation (ASTint sz sg) (ASTptr r)             (**r int to pointer with given representation *)
     44  | Ointofptr: ∀sz,sg,r. unary_operation (ASTptr r) (ASTint sz sg).            (**r pointer to int *)
    4345
    4446inductive binary_operation : Type[0] ≝
     
    8890  ]. cases sp // qed.
    8991
    90 definition eval_unop : unary_operation → val → option val ≝
    91 λop,arg.
     92definition eval_unop : ∀t,t'. unary_operation t t' → val → option val ≝
     93λt,t',op,arg.
    9294  match op with
    93   [ Ocastint sg sz
     95  [ Ocastint sz sg sz' sg'
    9496      match sg with
    95       [ Unsigned ⇒ Some ? (zero_ext sz arg)
    96       |   Signed ⇒ Some ? (sign_ext sz arg)
     97      [ Unsigned ⇒ Some ? (zero_ext sz' arg)
     98      |   Signed ⇒ Some ? (sign_ext sz' arg)
    9799      ]
    98   | Onegint ⇒ match arg with [ Vint sz1 n1 ⇒ Some ? (Vint sz1 (two_complement_negation ? n1)) | _ ⇒ None ? ]
    99   | Onotbool ⇒ match arg with [ Vint sz1 n1 ⇒ Some ? (of_bool (eq_bv ? n1 (zero ?)))
    100                               | Vptr _ _ _ _ ⇒ Some ? Vfalse
    101                               | Vnull _ ⇒ Some ? Vtrue
    102                               | _ ⇒ None ?
    103                               ]
    104   | Onotint ⇒ match arg with [ Vint sz1 n1 ⇒ Some ? (Vint sz1 (exclusive_disjunction_bv ? n1 (mone ?))) | _ ⇒ None ? ]
    105   | Onegf ⇒ match arg with [ Vfloat f1 ⇒ Some ? (Vfloat (Fneg f1)) | _ ⇒ None ? ]
    106   | Oabsf ⇒ match arg with [ Vfloat f1 ⇒ Some ? (Vfloat (Fabs f1)) | _ ⇒ None ? ]
     100  | Onegint sz sg ⇒ match arg with [ Vint sz1 n1 ⇒ Some ? (Vint sz1 (two_complement_negation ? n1)) | _ ⇒ None ? ]
     101  | Onotbool t sz sg _ ⇒
     102      match arg with
     103      [ Vint sz1 n1 ⇒ Some ? (Vint sz (if (eq_bv ? n1 (zero ?)) then (repr ? 1) else (zero ?)))
     104      | Vptr _ _ _ _ ⇒ Some ? (Vint sz (zero ?))
     105      | Vnull _ ⇒ Some ? (Vint sz (repr ? 1))
     106      | _ ⇒ None ?
     107      ]
     108  | Onotint sz sg ⇒ match arg with [ Vint sz1 n1 ⇒ Some ? (Vint sz1 (exclusive_disjunction_bv ? n1 (mone ?))) | _ ⇒ None ? ]
     109  | Onegf _ ⇒ match arg with [ Vfloat f1 ⇒ Some ? (Vfloat (Fneg f1)) | _ ⇒ None ? ]
     110  | Oabsf _ ⇒ match arg with [ Vfloat f1 ⇒ Some ? (Vfloat (Fabs f1)) | _ ⇒ None ? ]
    107111  | Osingleoffloat ⇒ Some ? (singleoffloat arg)
    108   | Ointoffloat sz ⇒ match arg with [ Vfloat f1 ⇒ Some ? (Vint sz (intoffloat ? f1)) | _ ⇒ None ? ]
    109   | Ointuoffloat sz ⇒ match arg with [ Vfloat f1 ⇒ Some ? (Vint sz (intuoffloat ? f1)) | _ ⇒ None ? ]
    110   | Ofloatofint ⇒ match arg with [ Vint sz1 n1 ⇒ Some ? (Vfloat (floatofint ? n1)) | _ ⇒ None ? ]
    111   | Ofloatofintu ⇒ match arg with [ Vint sz1 n1 ⇒ Some ? (Vfloat (floatofintu ? n1)) | _ ⇒ None ? ]
    112   | Oid ⇒ Some ? arg (* XXX should we restricted the values allowed? *)
     112  | Ointoffloat _ sz ⇒ match arg with [ Vfloat f1 ⇒ Some ? (Vint sz (intoffloat ? f1)) | _ ⇒ None ? ]
     113  | Ointuoffloat _ sz ⇒ match arg with [ Vfloat f1 ⇒ Some ? (Vint sz (intuoffloat ? f1)) | _ ⇒ None ? ]
     114  | Ofloatofint _ _ ⇒ match arg with [ Vint sz1 n1 ⇒ Some ? (Vfloat (floatofint ? n1)) | _ ⇒ None ? ]
     115  | Ofloatofintu _ _ ⇒ match arg with [ Vint sz1 n1 ⇒ Some ? (Vfloat (floatofintu ? n1)) | _ ⇒ None ? ]
     116  | Oid t ⇒ Some ? arg (* XXX should we restricted the values allowed? *)
    113117  (* Only conversion of null pointers is specified. *)
    114   | Optrofint r ⇒ match arg with [ Vint sz1 n1 ⇒ if eq_bv ? n1 (zero ?) then Some ? (Vnull r) else None ? | _ ⇒ None ? ]
    115   | Ointofptr sz ⇒ match arg with [ Vnull _ ⇒ Some ? (Vint sz (zero ?)) | _ ⇒ None ? ]
    116   ].
    117 
     118  | Optrofint sz sg r ⇒ match arg with [ Vint sz1 n1 ⇒ if eq_bv ? n1 (zero ?) then Some ? (Vnull r) else None ? | _ ⇒ None ? ]
     119  | Ointofptr sz sg r ⇒ match arg with [ Vnull _ ⇒ Some ? (Vint sz (zero ?)) | _ ⇒ None ? ]
     120  ].
     121
     122lemma elim_val_typ : ∀v,t. ∀P:val → Prop.
     123val_typ v t →
     124match t with
     125[ ASTint sz sg ⇒ ∀i.P (Vint sz i)
     126| ASTfloat sz ⇒ ∀f.P (Vfloat f)
     127| ASTptr r ⇒ P (Vnull r) ∧ ∀b,c,o. P (Vptr r b c o)
     128] →
     129P v.
     130#v #t #P *
     131[ 1,2: //
     132| #r * //
     133| #r #b #c #o * //
     134] qed.
     135
     136lemma eval_unop_typ_correct : ∀t,t',op,v,v'.
     137  val_typ v t →
     138  eval_unop t t' op v = Some ? v' →
     139  val_typ v' t'.
     140#t #t' #op elim op
     141[ #sz #sg #sz' #sg' #v #v' #H @(elim_val_typ … H) #i whd in ⊢ (??%? → ?)
     142  cases sg whd in ⊢ (??%? → ?) #E' destruct %
     143| #sz #sg #v #v' #H @(elim_val_typ … H) #i whd in ⊢ (??%? → ?) #E' destruct %
     144| #t'' #sz #sg cases t''
     145  [ #sz' #sg' #H #v #v' #H1 @(elim_val_typ … H1) #i whd in ⊢ (??%? → ?) #E' destruct cases (eq_bv ???) whd in ⊢ (?%?) %
     146  | #r #H #v #v' #H1 @(elim_val_typ … H1) whd %
     147    [ whd in ⊢ (??%? → ?) #E'
     148      (* XXX need to normalize or destruct is intractable *)
     149      normalize in E'; destruct (E') ; %
     150    | #b #c #o whd in ⊢ (??%? → ?) #E' destruct %
     151    ]
     152  | #f *
     153  ]
     154| #sz #sg #v #v' #H @(elim_val_typ … H) #i whd in ⊢ (??%? → ?) #E destruct %
     155| #sz #v #v' #H @(elim_val_typ … H) #f whd in ⊢ (??%? → ?) #E destruct %2
     156| #sz #v #v' #H @(elim_val_typ … H) #f whd in ⊢ (??%? → ?) #E destruct %2
     157| #v #v' #H @(elim_val_typ … H) #f whd in ⊢ (??%? → ?) #E destruct %2
     158| #fsz #sz #v #v' #H @(elim_val_typ … H) #f whd in ⊢ (??%? → ?) #E destruct %
     159| #fsz #sz #v #v' #H @(elim_val_typ … H) #f whd in ⊢ (??%? → ?) #E destruct %
     160| #fsz #sz #v #v' #H @(elim_val_typ … H) #i whd in ⊢ (??%? → ?) #E destruct %2
     161| #fsz #sz #v #v' #H @(elim_val_typ … H) #i whd in ⊢ (??%? → ?) #E destruct %2
     162| #t'' #v #v' #H whd in ⊢ (??%? → ?) #E destruct @H
     163| #sz #sg #r #v #v' #H @(elim_val_typ … H) #i whd in ⊢ (??%? → ?) cases (eq_bv ???)
     164  whd in ⊢ (??%? → ?) #E destruct //
     165| #sz #sg #r #v #v' #H @(elim_val_typ … H) %
     166  [ whd in ⊢ (??%? → ?) #E destruct %
     167  | #b #c #o whd in ⊢ (??%? → ?) #E destruct
     168  ]
     169] qed.
     170 
    118171(* I think this is duplicated somewhere else *)
    119172definition eval_compare_mismatch : comparison → option val ≝
  • src/common/Values.ma

    r1347 r1369  
    4949definition Vtrue: val ≝ Vone I32.
    5050definition Vfalse: val ≝ Vzero I32.
     51
     52inductive val_typ : val → typ → Prop ≝
     53  | VTint: ∀sz,sg,i. val_typ (Vint sz i) (ASTint sz sg)
     54  | VTfloat: ∀sz,f. val_typ (Vfloat f) (ASTfloat sz)
     55  | VTnull: ∀r. val_typ (Vnull r) (ASTptr r)
     56  | VTptr: ∀r,b,c,o. val_typ (Vptr r b c o) (ASTptr r).
    5157
    5258(*
Note: See TracChangeset for help on using the changeset viewer.