[639] | 1 | (* Operations common to the Cminor and RTLabs front end stages. *) |
---|
| 2 | |
---|
| 3 | (* Adapted from CompCert's Cminor.ma: *) |
---|
| 4 | |
---|
| 5 | (* *********************************************************************) |
---|
| 6 | (* *) |
---|
| 7 | (* The Compcert verified compiler *) |
---|
| 8 | (* *) |
---|
| 9 | (* Xavier Leroy, INRIA Paris-Rocquencourt *) |
---|
| 10 | (* *) |
---|
| 11 | (* Copyright Institut National de Recherche en Informatique et en *) |
---|
| 12 | (* Automatique. All rights reserved. This file is distributed *) |
---|
| 13 | (* under the terms of the GNU General Public License as published by *) |
---|
| 14 | (* the Free Software Foundation, either version 2 of the License, or *) |
---|
| 15 | (* (at your option) any later version. This file is also distributed *) |
---|
| 16 | (* under the terms of the INRIA Non-Commercial License Agreement. *) |
---|
| 17 | (* *) |
---|
| 18 | (* *********************************************************************) |
---|
| 19 | |
---|
[702] | 20 | include "common/Values.ma". |
---|
[639] | 21 | |
---|
| 22 | inductive constant : Type[0] ≝ |
---|
[961] | 23 | | Ointconst: ∀sz. bvint sz → constant (**r integer constant *) |
---|
| 24 | | Ofloatconst: float → constant (**r floating-point constant *) |
---|
| 25 | | Oaddrsymbol: ident → nat → constant (**r address of the symbol plus the offset *) |
---|
| 26 | | Oaddrstack: nat → constant. (**r stack pointer plus the given offset *) |
---|
[639] | 27 | |
---|
| 28 | inductive unary_operation : Type[0] ≝ |
---|
[961] | 29 | | Ocastint: intsize → signedness → unary_operation (**r 8-bit zero extension *) |
---|
[639] | 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 *) |
---|
[961] | 36 | | Ointoffloat: intsize → unary_operation (**r signed integer to float *) |
---|
| 37 | | Ointuoffloat: intsize → unary_operation (**r unsigned integer to float *) |
---|
[639] | 38 | | Ofloatofint: unary_operation (**r float to signed integer *) |
---|
[727] | 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 *) |
---|
[961] | 42 | | Ointofptr: intsize → unary_operation. (**r pointer to int *) |
---|
[639] | 43 | |
---|
| 44 | inductive binary_operation : Type[0] ≝ |
---|
| 45 | | Oadd: binary_operation (**r integer addition *) |
---|
| 46 | | Osub: binary_operation (**r integer subtraction *) |
---|
| 47 | | Omul: binary_operation (**r integer multiplication *) |
---|
| 48 | | Odiv: binary_operation (**r integer signed division *) |
---|
| 49 | | Odivu: binary_operation (**r integer unsigned division *) |
---|
| 50 | | Omod: binary_operation (**r integer signed modulus *) |
---|
| 51 | | Omodu: binary_operation (**r integer unsigned modulus *) |
---|
| 52 | | Oand: binary_operation (**r bitwise ``and'' *) |
---|
| 53 | | Oor: binary_operation (**r bitwise ``or'' *) |
---|
| 54 | | Oxor: binary_operation (**r bitwise ``xor'' *) |
---|
| 55 | | Oshl: binary_operation (**r left shift *) |
---|
| 56 | | Oshr: binary_operation (**r right signed shift *) |
---|
| 57 | | Oshru: binary_operation (**r right unsigned shift *) |
---|
| 58 | | Oaddf: binary_operation (**r float addition *) |
---|
| 59 | | Osubf: binary_operation (**r float subtraction *) |
---|
| 60 | | Omulf: binary_operation (**r float multiplication *) |
---|
| 61 | | Odivf: binary_operation (**r float division *) |
---|
| 62 | | Ocmp: comparison -> binary_operation (**r integer signed comparison *) |
---|
| 63 | | Ocmpu: comparison -> binary_operation (**r integer unsigned comparison *) |
---|
[727] | 64 | | Ocmpf: comparison -> binary_operation (**r float comparison *) |
---|
| 65 | | Oaddp: binary_operation (**r add an integer to a pointer *) |
---|
[774] | 66 | | Osubpi: binary_operation (**r subtract int from a pointers *) |
---|
[961] | 67 | | Osubpp: intsize → binary_operation (**r subtract two pointers *) |
---|
[727] | 68 | | Ocmpp: comparison → binary_operation. (**r compare pointers *) |
---|
[639] | 69 | |
---|
| 70 | |
---|
| 71 | (* * Evaluation of constants and operator applications. |
---|
| 72 | [None] is returned when the computation is undefined, e.g. |
---|
| 73 | if arguments are of the wrong types, or in case of an integer division |
---|
| 74 | by zero. *) |
---|
| 75 | |
---|
| 76 | definition eval_constant : (ident → option block) → block → constant → option val ≝ |
---|
| 77 | λfind_symbol,sp,cst. |
---|
| 78 | match cst with |
---|
[961] | 79 | [ Ointconst sz n ⇒ Some ? (Vint sz n) |
---|
[639] | 80 | | Ofloatconst n ⇒ Some ? (Vfloat n) |
---|
| 81 | | Oaddrsymbol s ofs ⇒ |
---|
| 82 | match find_symbol s with |
---|
| 83 | [ None ⇒ None ? |
---|
[961] | 84 | | Some b ⇒ Some ? (Vptr Any b (match b with [ mk_block r id ⇒ universal_compat r id ]) (shift_offset ? zero_offset (repr I16 ofs))) |
---|
[639] | 85 | ] |
---|
| 86 | | Oaddrstack ofs ⇒ |
---|
[961] | 87 | Some ? (Vptr Any sp ? (shift_offset ? zero_offset (repr I16 ofs))) |
---|
[639] | 88 | ]. cases sp // qed. |
---|
| 89 | |
---|
| 90 | definition eval_unop : unary_operation → val → option val ≝ |
---|
| 91 | λop,arg. |
---|
| 92 | match op with |
---|
[961] | 93 | [ Ocastint sz sg ⇒ |
---|
| 94 | match sg with |
---|
| 95 | [ Unsigned ⇒ Some ? (zero_ext sz arg) |
---|
| 96 | | Signed ⇒ Some ? (sign_ext sz arg) |
---|
| 97 | ] |
---|
| 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 ?))) |
---|
[639] | 100 | | Vptr _ _ _ _ ⇒ Some ? Vfalse |
---|
| 101 | | Vnull _ ⇒ Some ? Vtrue |
---|
| 102 | | _ ⇒ None ? |
---|
| 103 | ] |
---|
[961] | 104 | | Onotint ⇒ match arg with [ Vint sz1 n1 ⇒ Some ? (Vint sz1 (exclusive_disjunction_bv ? n1 (mone ?))) | _ ⇒ None ? ] |
---|
[639] | 105 | | Onegf ⇒ match arg with [ Vfloat f1 ⇒ Some ? (Vfloat (Fneg f1)) | _ ⇒ None ? ] |
---|
| 106 | | Oabsf ⇒ match arg with [ Vfloat f1 ⇒ Some ? (Vfloat (Fabs f1)) | _ ⇒ None ? ] |
---|
| 107 | | Osingleoffloat ⇒ Some ? (singleoffloat arg) |
---|
[961] | 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 ? ] |
---|
[727] | 112 | | Oid ⇒ Some ? arg (* XXX should we restricted the values allowed? *) |
---|
| 113 | (* Only conversion of null pointers is specified. *) |
---|
[961] | 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 ? ] |
---|
[639] | 116 | ]. |
---|
| 117 | |
---|
| 118 | (* I think this is duplicated somewhere else *) |
---|
| 119 | definition eval_compare_mismatch : comparison → option val ≝ |
---|
| 120 | λc. match c with [ Ceq ⇒ Some ? Vfalse | Cne ⇒ Some ? Vtrue | _ ⇒ None ? ]. |
---|
| 121 | |
---|
[961] | 122 | (* Individual operations, adapted from Values. These differ in that they |
---|
| 123 | implement the plain Cminor/RTLabs operations (e.g., with separate addition |
---|
| 124 | for ints,floats and pointers) and use option rather than Vundef. The ones |
---|
| 125 | in Value are probably not needed. *) |
---|
[639] | 126 | |
---|
| 127 | definition ev_add ≝ λv1,v2: val. |
---|
| 128 | match v1 with |
---|
[961] | 129 | [ Vint sz1 n1 ⇒ match v2 with |
---|
| 130 | [ Vint sz2 n2 ⇒ intsize_eq_elim ? sz1 sz2 ? n1 |
---|
| 131 | (λn1. Some ? (Vint ? (addition_n ? n1 n2))) |
---|
| 132 | (None ?) |
---|
[639] | 133 | | _ ⇒ None ? ] |
---|
| 134 | | _ ⇒ None ? ]. |
---|
| 135 | |
---|
| 136 | definition ev_sub ≝ λv1,v2: val. |
---|
| 137 | match v1 with |
---|
[961] | 138 | [ Vint sz1 n1 ⇒ match v2 with |
---|
| 139 | [ Vint sz2 n2 ⇒ intsize_eq_elim ? sz1 sz2 ? n1 |
---|
| 140 | (λn1. Some ? (Vint ? (subtraction ? n1 n2))) |
---|
| 141 | (None ?) |
---|
[639] | 142 | | _ ⇒ None ? ] |
---|
[774] | 143 | | _ ⇒ None ? ]. |
---|
| 144 | |
---|
| 145 | (* NB: requires arguments to be presented pointer first. *) |
---|
| 146 | definition ev_addp ≝ λv1,v2: val. |
---|
| 147 | match v1 with |
---|
| 148 | [ Vptr r b1 p ofs1 ⇒ match v2 with |
---|
[961] | 149 | [ Vint sz2 n2 ⇒ Some ? (Vptr r b1 p (shift_offset ? ofs1 n2)) |
---|
[774] | 150 | | _ ⇒ None ? ] |
---|
| 151 | | Vnull r ⇒ match v2 with |
---|
[961] | 152 | [ Vint sz2 n2 ⇒ if eq_bv ? n2 (zero ?) then Some ? (Vnull r) else None ? |
---|
[774] | 153 | | _ ⇒ None ? |
---|
| 154 | ] |
---|
| 155 | | _ ⇒ None ? ]. |
---|
| 156 | |
---|
| 157 | definition ev_subpi ≝ λv1,v2: val. |
---|
| 158 | match v1 with |
---|
| 159 | [ Vptr r1 b1 p1 ofs1 ⇒ match v2 with |
---|
[961] | 160 | [ Vint sz2 n2 ⇒ Some ? (Vptr r1 b1 p1 (neg_shift_offset ? ofs1 n2)) |
---|
[774] | 161 | | _ ⇒ None ? ] |
---|
[961] | 162 | | Vnull r ⇒ match v2 with [ Vint sz2 n2 ⇒ if eq_bv ? n2 (zero ?) then Some ? (Vnull r) else None ? | _ ⇒ None ? ] |
---|
[774] | 163 | | _ ⇒ None ? ]. |
---|
| 164 | |
---|
[961] | 165 | definition ev_subpp ≝ λsz. λv1,v2: val. |
---|
[774] | 166 | match v1 with |
---|
| 167 | [ Vptr r1 b1 p1 ofs1 ⇒ match v2 with |
---|
| 168 | [ Vptr r2 b2 p2 ofs2 ⇒ |
---|
[961] | 169 | if eq_block b1 b2 then Some ? (Vint sz (sub_offset ? ofs1 ofs2)) else None ? |
---|
[639] | 170 | | _ ⇒ None ? ] |
---|
[961] | 171 | | Vnull r ⇒ match v2 with [ Vnull r' ⇒ Some ? (Vint sz (zero ?)) | _ ⇒ None ? ] |
---|
[639] | 172 | | _ ⇒ None ? ]. |
---|
| 173 | |
---|
| 174 | definition ev_mul ≝ λv1, v2: val. |
---|
| 175 | match v1 with |
---|
[961] | 176 | [ Vint sz1 n1 ⇒ match v2 with |
---|
| 177 | [ Vint sz2 n2 ⇒ intsize_eq_elim ? sz1 sz2 ? n1 |
---|
| 178 | (λn1. Some ? (Vint ? (\snd (split … (multiplication ? n1 n2))))) |
---|
| 179 | (None ?) |
---|
[639] | 180 | | _ ⇒ None ? ] |
---|
| 181 | | _ ⇒ None ? ]. |
---|
| 182 | |
---|
| 183 | definition ev_divs ≝ λv1, v2: val. |
---|
| 184 | match v1 with |
---|
[961] | 185 | [ Vint sz1 n1 ⇒ match v2 with |
---|
| 186 | [ Vint sz2 n2 ⇒ intsize_eq_elim ? sz1 sz2 ? n1 |
---|
| 187 | (λn1. option_map ?? (Vint ?) (division_s ? n1 n2)) |
---|
| 188 | (None ?) |
---|
[639] | 189 | | _ ⇒ None ? ] |
---|
| 190 | | _ ⇒ None ? ]. |
---|
| 191 | |
---|
| 192 | definition ev_mods ≝ λv1, v2: val. |
---|
| 193 | match v1 with |
---|
[961] | 194 | [ Vint sz1 n1 ⇒ match v2 with |
---|
| 195 | [ Vint sz2 n2 ⇒ intsize_eq_elim ? sz1 sz2 ? n1 |
---|
| 196 | (λn1. option_map ?? (Vint ?) (modulus_s ? n1 n2)) |
---|
| 197 | (None ?) |
---|
[639] | 198 | | _ ⇒ None ? |
---|
| 199 | ] |
---|
| 200 | | _ ⇒ None ? |
---|
| 201 | ]. |
---|
| 202 | |
---|
| 203 | definition ev_divu ≝ λv1, v2: val. |
---|
| 204 | match v1 with |
---|
[961] | 205 | [ Vint sz1 n1 ⇒ match v2 with |
---|
| 206 | [ Vint sz2 n2 ⇒ intsize_eq_elim ? sz1 sz2 ? n1 |
---|
| 207 | (λn1. option_map ?? (Vint ?) (division_u ? n1 n2)) |
---|
| 208 | (None ?) |
---|
[639] | 209 | | _ ⇒ None ? |
---|
| 210 | ] |
---|
| 211 | | _ ⇒ None ? |
---|
| 212 | ]. |
---|
| 213 | |
---|
| 214 | definition ev_modu ≝ λv1, v2: val. |
---|
| 215 | match v1 with |
---|
[961] | 216 | [ Vint sz1 n1 ⇒ match v2 with |
---|
| 217 | [ Vint sz2 n2 ⇒ intsize_eq_elim ? sz1 sz2 ? n1 |
---|
| 218 | (λn1. option_map ?? (Vint ?) (modulus_u ? n1 n2)) |
---|
| 219 | (None ?) |
---|
[639] | 220 | | _ ⇒ None ? |
---|
| 221 | ] |
---|
| 222 | | _ ⇒ None ? |
---|
| 223 | ]. |
---|
| 224 | |
---|
| 225 | definition ev_and ≝ λv1, v2: val. |
---|
| 226 | match v1 with |
---|
[961] | 227 | [ Vint sz1 n1 ⇒ match v2 with |
---|
| 228 | [ Vint sz2 n2 ⇒ intsize_eq_elim ? sz1 sz2 ? n1 |
---|
| 229 | (λn1. Some ? (Vint ? (conjunction_bv ? n1 n2))) |
---|
| 230 | (None ?) |
---|
[639] | 231 | | _ ⇒ None ? ] |
---|
| 232 | | _ ⇒ None ? ]. |
---|
| 233 | |
---|
| 234 | definition ev_or ≝ λv1, v2: val. |
---|
| 235 | match v1 with |
---|
[961] | 236 | [ Vint sz1 n1 ⇒ match v2 with |
---|
| 237 | [ Vint sz2 n2 ⇒ intsize_eq_elim ? sz1 sz2 ? n1 |
---|
| 238 | (λn1. Some ? (Vint ? (inclusive_disjunction_bv ? n1 n2))) |
---|
| 239 | (None ?) |
---|
[639] | 240 | | _ ⇒ None ? ] |
---|
| 241 | | _ ⇒ None ? ]. |
---|
| 242 | |
---|
| 243 | definition ev_xor ≝ λv1, v2: val. |
---|
| 244 | match v1 with |
---|
[961] | 245 | [ Vint sz1 n1 ⇒ match v2 with |
---|
| 246 | [ Vint sz2 n2 ⇒ intsize_eq_elim ? sz1 sz2 ? n1 |
---|
| 247 | (λn1. Some ? (Vint ? (exclusive_disjunction_bv ? n1 n2))) |
---|
| 248 | (None ?) |
---|
[639] | 249 | | _ ⇒ None ? ] |
---|
| 250 | | _ ⇒ None ? ]. |
---|
| 251 | |
---|
| 252 | definition ev_shl ≝ λv1, v2: val. |
---|
| 253 | match v1 with |
---|
[961] | 254 | [ Vint sz1 n1 ⇒ match v2 with |
---|
| 255 | [ Vint sz2 n2 ⇒ |
---|
| 256 | if lt_u ? n2 (bitvector_of_nat … (bitsize_of_intsize sz1)) |
---|
| 257 | then Some ? (Vint sz1 (shift_left ?? (nat_of_bitvector … n2) n1 false)) |
---|
[639] | 258 | else None ? |
---|
| 259 | | _ ⇒ None ? ] |
---|
| 260 | | _ ⇒ None ? ]. |
---|
| 261 | |
---|
| 262 | definition ev_shr ≝ λv1, v2: val. |
---|
| 263 | match v1 with |
---|
[961] | 264 | [ Vint sz1 n1 ⇒ match v2 with |
---|
| 265 | [ Vint sz2 n2 ⇒ |
---|
| 266 | if lt_u ? n2 (bitvector_of_nat … (bitsize_of_intsize sz1)) |
---|
| 267 | then Some ? (Vint sz1 (shift_right ?? (nat_of_bitvector … n2) n1 (head' … n1))) |
---|
[639] | 268 | else None ? |
---|
| 269 | | _ ⇒ None ? ] |
---|
| 270 | | _ ⇒ None ? ]. |
---|
| 271 | |
---|
| 272 | definition ev_shru ≝ λv1, v2: val. |
---|
| 273 | match v1 with |
---|
[961] | 274 | [ Vint sz1 n1 ⇒ match v2 with |
---|
| 275 | [ Vint sz2 n2 ⇒ |
---|
| 276 | if lt_u ? n2 (bitvector_of_nat … (bitsize_of_intsize sz1)) |
---|
| 277 | then Some ? (Vint sz1 (shift_right ?? (nat_of_bitvector … n2) n1 false)) |
---|
[639] | 278 | else None ? |
---|
| 279 | | _ ⇒ None ? ] |
---|
| 280 | | _ ⇒ None ? ]. |
---|
| 281 | |
---|
| 282 | definition ev_addf ≝ λv1,v2: val. |
---|
| 283 | match v1 with |
---|
| 284 | [ Vfloat f1 ⇒ match v2 with |
---|
| 285 | [ Vfloat f2 ⇒ Some ? (Vfloat (Fadd f1 f2)) |
---|
| 286 | | _ ⇒ None ? ] |
---|
| 287 | | _ ⇒ None ? ]. |
---|
| 288 | |
---|
| 289 | definition ev_subf ≝ λv1,v2: val. |
---|
| 290 | match v1 with |
---|
| 291 | [ Vfloat f1 ⇒ match v2 with |
---|
| 292 | [ Vfloat f2 ⇒ Some ? (Vfloat (Fsub f1 f2)) |
---|
| 293 | | _ ⇒ None ? ] |
---|
| 294 | | _ ⇒ None ? ]. |
---|
| 295 | |
---|
| 296 | definition ev_mulf ≝ λv1,v2: val. |
---|
| 297 | match v1 with |
---|
| 298 | [ Vfloat f1 ⇒ match v2 with |
---|
| 299 | [ Vfloat f2 ⇒ Some ? (Vfloat (Fmul f1 f2)) |
---|
| 300 | | _ ⇒ None ? ] |
---|
| 301 | | _ ⇒ None ? ]. |
---|
| 302 | |
---|
| 303 | definition ev_divf ≝ λv1,v2: val. |
---|
| 304 | match v1 with |
---|
| 305 | [ Vfloat f1 ⇒ match v2 with |
---|
| 306 | [ Vfloat f2 ⇒ Some ? (Vfloat (Fdiv f1 f2)) |
---|
| 307 | | _ ⇒ None ? ] |
---|
| 308 | | _ ⇒ None ? ]. |
---|
| 309 | |
---|
| 310 | definition ev_cmp_match : comparison → option val ≝ λc. |
---|
| 311 | match c with |
---|
| 312 | [ Ceq ⇒ Some ? Vtrue |
---|
| 313 | | Cne ⇒ Some ? Vfalse |
---|
| 314 | | _ ⇒ None ? |
---|
| 315 | ]. |
---|
| 316 | |
---|
| 317 | definition ev_cmp_mismatch : comparison → option val ≝ λc. |
---|
| 318 | match c with |
---|
| 319 | [ Ceq ⇒ Some ? Vfalse |
---|
| 320 | | Cne ⇒ Some ? Vtrue |
---|
| 321 | | _ ⇒ None ? |
---|
| 322 | ]. |
---|
| 323 | |
---|
| 324 | definition ev_cmp ≝ λc: comparison. λv1,v2: val. |
---|
| 325 | match v1 with |
---|
[961] | 326 | [ Vint sz1 n1 ⇒ match v2 with |
---|
| 327 | [ Vint sz2 n2 ⇒ intsize_eq_elim ? sz1 sz2 ? n1 |
---|
| 328 | (λn1. Some ? (of_bool (cmp_int ? c n1 n2))) |
---|
| 329 | (None ?) |
---|
[639] | 330 | | _ ⇒ None ? ] |
---|
[774] | 331 | | _ ⇒ None ? ]. |
---|
| 332 | |
---|
| 333 | definition ev_cmpp ≝ λc: comparison. λv1,v2: val. |
---|
| 334 | match v1 with |
---|
| 335 | [ Vptr r1 b1 p1 ofs1 ⇒ match v2 with |
---|
[639] | 336 | [ Vptr r2 b2 p2 ofs2 ⇒ |
---|
| 337 | if eq_block b1 b2 |
---|
| 338 | then Some ? (of_bool (cmp_offset c ofs1 ofs2)) |
---|
| 339 | else ev_cmp_mismatch c |
---|
| 340 | | Vnull r2 ⇒ ev_cmp_mismatch c |
---|
| 341 | | _ ⇒ None ? ] |
---|
| 342 | | Vnull r1 ⇒ match v2 with |
---|
| 343 | [ Vptr _ _ _ _ ⇒ ev_cmp_mismatch c |
---|
| 344 | | Vnull r2 ⇒ ev_cmp_match c |
---|
| 345 | | _ ⇒ None ? |
---|
| 346 | ] |
---|
| 347 | | _ ⇒ None ? ]. |
---|
| 348 | |
---|
| 349 | (* TODO: check this, it isn't the cmpu used elsewhere *) |
---|
| 350 | definition ev_cmpu ≝ λc: comparison. λv1,v2: val. |
---|
| 351 | match v1 with |
---|
[961] | 352 | [ Vint sz1 n1 ⇒ match v2 with |
---|
| 353 | [ Vint sz2 n2 ⇒ intsize_eq_elim ? sz1 sz2 ? n1 |
---|
| 354 | (λn1. Some ? (of_bool (cmpu_int ? c n1 n2))) |
---|
| 355 | (None ?) |
---|
[639] | 356 | | _ ⇒ None ? ] |
---|
| 357 | | _ ⇒ None ? ]. |
---|
| 358 | |
---|
| 359 | definition ev_cmpf ≝ λc: comparison. λv1,v2: val. |
---|
| 360 | match v1 with |
---|
| 361 | [ Vfloat f1 ⇒ match v2 with |
---|
| 362 | [ Vfloat f2 ⇒ Some ? (of_bool (Fcmp c f1 f2)) |
---|
| 363 | | _ ⇒ None ? ] |
---|
| 364 | | _ ⇒ None ? ]. |
---|
| 365 | |
---|
| 366 | definition eval_binop : binary_operation → val → val → option val ≝ |
---|
| 367 | λop. |
---|
| 368 | match op with |
---|
| 369 | [ Oadd ⇒ ev_add |
---|
| 370 | | Osub ⇒ ev_sub |
---|
| 371 | | Omul ⇒ ev_mul |
---|
| 372 | | Odiv ⇒ ev_divs |
---|
| 373 | | Odivu ⇒ ev_divu |
---|
| 374 | | Omod ⇒ ev_mods |
---|
| 375 | | Omodu ⇒ ev_modu |
---|
| 376 | | Oand ⇒ ev_and |
---|
| 377 | | Oor ⇒ ev_or |
---|
| 378 | | Oxor ⇒ ev_xor |
---|
| 379 | | Oshl ⇒ ev_shl |
---|
| 380 | | Oshr ⇒ ev_shr |
---|
| 381 | | Oshru ⇒ ev_shru |
---|
| 382 | | Oaddf ⇒ ev_addf |
---|
| 383 | | Osubf ⇒ ev_subf |
---|
| 384 | | Omulf ⇒ ev_mulf |
---|
| 385 | | Odivf ⇒ ev_divf |
---|
| 386 | | Ocmp c ⇒ ev_cmp c |
---|
| 387 | | Ocmpu c ⇒ ev_cmpu c |
---|
| 388 | | Ocmpf c ⇒ ev_cmpf c |
---|
[774] | 389 | | Oaddp ⇒ ev_addp |
---|
| 390 | | Osubpi ⇒ ev_subpi |
---|
[961] | 391 | | Osubpp sz ⇒ ev_subpp sz |
---|
[774] | 392 | | Ocmpp c ⇒ ev_cmpp c |
---|
[639] | 393 | ]. |
---|
| 394 | |
---|