| 1 |
Require Import TestSuite.admit. |
| 2 |
Require Corelib.Setoids.Setoid. |
| 3 |
|
| 4 |
Axiom BITS : nat -> Set. |
| 5 |
Definition n7 := 7. |
| 6 |
Definition n15 := 15. |
| 7 |
Definition n31 := 31. |
| 8 |
Notation n8 := (S n7). |
| 9 |
Notation n16 := (S n15). |
| 10 |
Notation n32 := (S n31). |
| 11 |
Inductive OpSize := OpSize1 | OpSize2 | OpSize4 . |
| 12 |
Definition VWORD s := BITS (match s with OpSize1 => n8 | OpSize2 => n16 | OpSize4 => n32 end). |
| 13 |
Definition BYTE := VWORD OpSize1. |
| 14 |
Definition WORD := VWORD OpSize2. |
| 15 |
Definition DWORD := VWORD OpSize4. |
| 16 |
Ltac subst_body := |
| 17 |
repeat match goal with |
| 18 |
| [ H := _ |- _ ] => subst H |
| 19 |
end. |
| 20 |
Import Corelib.Setoids.Setoid. |
| 21 |
Class Equiv (A : Type) := equiv : relation A. |
| 22 |
Infix "===" := equiv (at level 70, no associativity). |
| 23 |
Class type (A : Type) {e : Equiv A} := eq_equiv : Equivalence equiv. |
| 24 |
Definition setoid_resp {T T'} (f : T -> T') `{e : type T} `{e' : type T'} := forall x y, x === y -> f x === f y. |
| 25 |
Record morphism T T' `{e : type T} `{e' : type T'} := |
| 26 |
mkMorph { |
| 27 |
morph :> T -> T'; |
| 28 |
morph_resp : setoid_resp morph}. |
| 29 |
Arguments mkMorph [T T' e0 e e1 e']. |
| 30 |
Infix "-s>" := morphism (at level 45, right associativity). |
| 31 |
Section Morphisms. |
| 32 |
Context {S T U V} `{eS : type S} `{eT : type T} `{eU : type U} `{eV : type V}. |
| 33 |
Global Instance morph_equiv : Equiv (S -s> T). |
| 34 |
admit. |
| 35 |
Defined. |
| 36 |
|
| 37 |
Global Instance morph_type : type (S -s> T). |
| 38 |
admit. |
| 39 |
Defined. |
| 40 |
|
| 41 |
Program Definition mcomp (f: T -s> U) (g: S -s> T) : (S -s> U) := |
| 42 |
mkMorph (fun x => f (g x)) _. |
| 43 |
Next Obligation. |
| 44 |
admit. |
| 45 |
Defined. |
| 46 |
|
| 47 |
End Morphisms. |
| 48 |
|
| 49 |
Infix "<<" := mcomp (at level 35). |
| 50 |
|
| 51 |
Section MorphConsts. |
| 52 |
Context {S T U V} `{eS : type S} `{eT : type T} `{eU : type U} `{eV : type V}. |
| 53 |
|
| 54 |
Definition lift2s (f : S -> T -> U) p q : (S -s> T -s> U) := |
| 55 |
mkMorph (fun x => mkMorph (f x) (p x)) q. |
| 56 |
|
| 57 |
End MorphConsts. |
| 58 |
#[export] Instance Equiv_PropP : Equiv Prop. |
| 59 |
admit. |
| 60 |
Defined. |
| 61 |
|
| 62 |
Section SetoidProducts. |
| 63 |
Context {A B : Type} `{eA : type A} `{eB : type B}. |
| 64 |
Global Instance Equiv_prod : Equiv (A * B). |
| 65 |
admit. |
| 66 |
Defined. |
| 67 |
|
| 68 |
Global Instance type_prod : type (A * B). |
| 69 |
admit. |
| 70 |
Defined. |
| 71 |
|
| 72 |
Program Definition mfst : (A * B) -s> A := |
| 73 |
mkMorph (fun p => fst p) _. |
| 74 |
Next Obligation. |
| 75 |
admit. |
| 76 |
Defined. |
| 77 |
|
| 78 |
Program Definition msnd : (A * B) -s> B := |
| 79 |
mkMorph (fun p => snd p) _. |
| 80 |
Next Obligation. |
| 81 |
admit. |
| 82 |
Defined. |
| 83 |
|
| 84 |
Context {C} `{eC : type C}. |
| 85 |
|
| 86 |
Program Definition mprod (f: C -s> A) (g: C -s> B) : C -s> (A * B) := |
| 87 |
mkMorph (fun c => (f c, g c)) _. |
| 88 |
Next Obligation. |
| 89 |
admit. |
| 90 |
Defined. |
| 91 |
|
| 92 |
End SetoidProducts. |
| 93 |
|
| 94 |
Section IndexedProducts. |
| 95 |
|
| 96 |
Record ttyp := {carr :> Type; eqc : Equiv carr; eqok : type carr}. |
| 97 |
Global Instance ttyp_proj_eq {A : ttyp} : Equiv A. |
| 98 |
admit. |
| 99 |
Defined. |
| 100 |
Global Instance ttyp_proj_prop {A : ttyp} : type A. |
| 101 |
admit. |
| 102 |
Defined. |
| 103 |
Context {I : Type} {P : I -> ttyp}. |
| 104 |
|
| 105 |
Global Program Instance Equiv_prodI : Equiv (forall i, P i) := |
| 106 |
fun p p' : forall i, P i => (forall i : I, @equiv _ (eqc _) (p i) (p' i)). |
| 107 |
|
| 108 |
Global Instance type_prodI : type (forall i, P i). |
| 109 |
admit. |
| 110 |
Defined. |
| 111 |
|
| 112 |
Program Definition mprojI (i : I) : (forall i, P i) -s> P i := |
| 113 |
mkMorph (fun X => X i) _. |
| 114 |
Next Obligation. |
| 115 |
admit. |
| 116 |
Defined. |
| 117 |
|
| 118 |
Context {C : Type} `{eC : type C}. |
| 119 |
|
| 120 |
Program Definition mprodI (f : forall i, C -s> P i) : C -s> (forall i, P i) := |
| 121 |
mkMorph (fun c i => f i c) _. |
| 122 |
Next Obligation. |
| 123 |
admit. |
| 124 |
Defined. |
| 125 |
|
| 126 |
End IndexedProducts. |
| 127 |
|
| 128 |
Section Exponentials. |
| 129 |
|
| 130 |
Context {A B C D} `{eA : type A} `{eB : type B} `{eC : type C} `{eD : type D}. |
| 131 |
|
| 132 |
Program Definition comps : (B -s> C) -s> (A -s> B) -s> A -s> C := |
| 133 |
lift2s (fun f g => f << g) _ _. |
| 134 |
Next Obligation. |
| 135 |
admit. |
| 136 |
Defined. |
| 137 |
Next Obligation. |
| 138 |
admit. |
| 139 |
Defined. |
| 140 |
|
| 141 |
Program Definition muncurry (f : A -s> B -s> C) : A * B -s> C := |
| 142 |
mkMorph (fun p => f (fst p) (snd p)) _. |
| 143 |
Next Obligation. |
| 144 |
admit. |
| 145 |
Defined. |
| 146 |
|
| 147 |
Program Definition mcurry (f : A * B -s> C) : A -s> B -s> C := |
| 148 |
lift2s (fun a b => f (a, b)) _ _. |
| 149 |
Next Obligation. |
| 150 |
admit. |
| 151 |
Defined. |
| 152 |
Next Obligation. |
| 153 |
admit. |
| 154 |
Defined. |
| 155 |
|
| 156 |
Program Definition meval : (B -s> A) * B -s> A := |
| 157 |
mkMorph (fun p => fst p (snd p)) _. |
| 158 |
Next Obligation. |
| 159 |
admit. |
| 160 |
Defined. |
| 161 |
|
| 162 |
Program Definition mid : A -s> A := mkMorph (fun x => x) _. |
| 163 |
Next Obligation. |
| 164 |
admit. |
| 165 |
Defined. |
| 166 |
|
| 167 |
Program Definition mconst (b : B) : A -s> B := mkMorph (fun _ => b) _. |
| 168 |
Next Obligation. |
| 169 |
admit. |
| 170 |
Defined. |
| 171 |
|
| 172 |
End Exponentials. |
| 173 |
|
| 174 |
Inductive empty : Set := . |
| 175 |
#[export] Instance empty_Equiv : Equiv empty. |
| 176 |
admit. |
| 177 |
Defined. |
| 178 |
#[export] Instance empty_type : type empty. |
| 179 |
admit. |
| 180 |
Defined. |
| 181 |
|
| 182 |
Section Initials. |
| 183 |
Context {A} `{eA : type A}. |
| 184 |
|
| 185 |
Program Definition mzero_init : empty -s> A := mkMorph (fun x => match x with end) _. |
| 186 |
Next Obligation. |
| 187 |
admit. |
| 188 |
Defined. |
| 189 |
|
| 190 |
End Initials. |
| 191 |
|
| 192 |
Section Subsetoid. |
| 193 |
|
| 194 |
Context {A} `{eA : type A} {P : A -> Prop}. |
| 195 |
Global Instance subset_Equiv : Equiv {a : A | P a}. |
| 196 |
admit. |
| 197 |
Defined. |
| 198 |
Global Instance subset_type : type {a : A | P a}. |
| 199 |
admit. |
| 200 |
Defined. |
| 201 |
|
| 202 |
Program Definition mforget : {a : A | P a} -s> A := |
| 203 |
mkMorph (fun x => x) _. |
| 204 |
Next Obligation. |
| 205 |
admit. |
| 206 |
Defined. |
| 207 |
|
| 208 |
Context {B} `{eB : type B}. |
| 209 |
Program Definition minherit (f : B -s> A) (HB : forall b, P (f b)) : B -s> {a : A | P a} := |
| 210 |
mkMorph (fun b => exist P (f b) (HB b)) _. |
| 211 |
Next Obligation. |
| 212 |
admit. |
| 213 |
Defined. |
| 214 |
|
| 215 |
End Subsetoid. |
| 216 |
|
| 217 |
Section Option. |
| 218 |
|
| 219 |
Context {A} `{eA : type A}. |
| 220 |
Global Instance option_Equiv : Equiv (option A). |
| 221 |
admit. |
| 222 |
Defined. |
| 223 |
|
| 224 |
Global Instance option_type : type (option A). |
| 225 |
admit. |
| 226 |
Defined. |
| 227 |
|
| 228 |
End Option. |
| 229 |
|
| 230 |
Section OptDefs. |
| 231 |
Context {A B} `{eA : type A} `{eB : type B}. |
| 232 |
|
| 233 |
Program Definition msome : A -s> option A := mkMorph (fun a => Some a) _. |
| 234 |
Next Obligation. |
| 235 |
admit. |
| 236 |
Defined. |
| 237 |
|
| 238 |
Program Definition moptionbind (f : A -s> option B) : option A -s> option B := |
| 239 |
mkMorph (fun oa => match oa with None => None | Some a => f a end) _. |
| 240 |
Next Obligation. |
| 241 |
admit. |
| 242 |
Defined. |
| 243 |
|
| 244 |
End OptDefs. |
| 245 |
|
| 246 |
Generalizable Variables Frm. |
| 247 |
|
| 248 |
Class ILogicOps Frm := { |
| 249 |
lentails: relation Frm; |
| 250 |
ltrue: Frm; |
| 251 |
lfalse: Frm; |
| 252 |
limpl: Frm -> Frm -> Frm; |
| 253 |
land: Frm -> Frm -> Frm; |
| 254 |
lor: Frm -> Frm -> Frm; |
| 255 |
lforall: forall {T}, (T -> Frm) -> Frm; |
| 256 |
lexists: forall {T}, (T -> Frm) -> Frm |
| 257 |
}. |
| 258 |
|
| 259 |
Infix "|--" := lentails (at level 79, no associativity). |
| 260 |
Infix "//\\" := land (at level 75, right associativity). |
| 261 |
Infix "\\//" := lor (at level 76, right associativity). |
| 262 |
Infix "-->>" := limpl (at level 77, right associativity). |
| 263 |
Notation "'Forall' x .. y , p" := |
| 264 |
(lforall (fun x => .. (lforall (fun y => p)) .. )) (at level 78, x binder, y binder, right associativity). |
| 265 |
Notation "'Exists' x .. y , p" := |
| 266 |
(lexists (fun x => .. (lexists (fun y => p)) .. )) (at level 78, x binder, y binder, right associativity). |
| 267 |
|
| 268 |
Class ILogic Frm {ILOps: ILogicOps Frm} := { |
| 269 |
lentailsPre :: PreOrder lentails; |
| 270 |
ltrueR: forall C, C |-- ltrue; |
| 271 |
lfalseL: forall C, lfalse |-- C; |
| 272 |
lforallL: forall T x (P: T -> Frm) C, P x |-- C -> lforall P |-- C; |
| 273 |
lforallR: forall T (P: T -> Frm) C, (forall x, C |-- P x) -> C |-- lforall P; |
| 274 |
lexistsL: forall T (P: T -> Frm) C, (forall x, P x |-- C) -> lexists P |-- C; |
| 275 |
lexistsR: forall T x (P: T -> Frm) C, C |-- P x -> C |-- lexists P; |
| 276 |
landL1: forall P Q C, P |-- C -> P //\\ Q |-- C; |
| 277 |
landL2: forall P Q C, Q |-- C -> P //\\ Q |-- C; |
| 278 |
lorR1: forall P Q C, C |-- P -> C |-- P \\// Q; |
| 279 |
lorR2: forall P Q C, C |-- Q -> C |-- P \\// Q; |
| 280 |
landR: forall P Q C, C |-- P -> C |-- Q -> C |-- P //\\ Q; |
| 281 |
lorL: forall P Q C, P |-- C -> Q |-- C -> P \\// Q |-- C; |
| 282 |
landAdj: forall P Q C, C |-- (P -->> Q) -> C //\\ P |-- Q; |
| 283 |
limplAdj: forall P Q C, C //\\ P |-- Q -> C |-- (P -->> Q) |
| 284 |
}. |
| 285 |
#[export] Hint Extern 0 (?x |-- ?x) => reflexivity. |
| 286 |
|
| 287 |
Section ILogicExtra. |
| 288 |
Context `{IL: ILogic Frm}. |
| 289 |
Definition lpropand (p: Prop) Q := Exists _: p, Q. |
| 290 |
Definition lpropimpl (p: Prop) Q := Forall _: p, Q. |
| 291 |
|
| 292 |
End ILogicExtra. |
| 293 |
|
| 294 |
Infix "/\\" := lpropand (at level 75, right associativity). |
| 295 |
Infix "->>" := lpropimpl (at level 77, right associativity). |
| 296 |
|
| 297 |
Section ILogic_Fun. |
| 298 |
Context (T: Type) `{TType: type T}. |
| 299 |
Context `{IL: ILogic Frm}. |
| 300 |
|
| 301 |
Record ILFunFrm := mkILFunFrm { |
| 302 |
ILFunFrm_pred :> T -> Frm; |
| 303 |
ILFunFrm_closed: forall t t': T, t === t' -> |
| 304 |
ILFunFrm_pred t |-- ILFunFrm_pred t' |
| 305 |
}. |
| 306 |
|
| 307 |
Notation "'mk'" := @mkILFunFrm. |
| 308 |
|
| 309 |
Program Definition ILFun_Ops : ILogicOps ILFunFrm := {| |
| 310 |
lentails P Q := forall t:T, P t |-- Q t; |
| 311 |
ltrue := mk (fun t => ltrue) _; |
| 312 |
lfalse := mk (fun t => lfalse) _; |
| 313 |
limpl P Q := mk (fun t => P t -->> Q t) _; |
| 314 |
land P Q := mk (fun t => P t //\\ Q t) _; |
| 315 |
lor P Q := mk (fun t => P t \\// Q t) _; |
| 316 |
lforall A P := mk (fun t => Forall a, P a t) _; |
| 317 |
lexists A P := mk (fun t => Exists a, P a t) _ |
| 318 |
|}. |
| 319 |
Next Obligation. |
| 320 |
admit. |
| 321 |
Defined. |
| 322 |
Next Obligation. |
| 323 |
admit. |
| 324 |
Defined. |
| 325 |
Next Obligation. |
| 326 |
admit. |
| 327 |
Defined. |
| 328 |
Next Obligation. |
| 329 |
admit. |
| 330 |
Defined. |
| 331 |
Next Obligation. |
| 332 |
admit. |
| 333 |
Defined. |
| 334 |
|
| 335 |
End ILogic_Fun. |
| 336 |
|
| 337 |
Arguments ILFunFrm _ {e} _ {ILOps}. |
| 338 |
Arguments mkILFunFrm [T] _ [Frm ILOps]. |
| 339 |
|
| 340 |
Program Definition ILFun_eq {T R} {ILOps: ILogicOps R} {ILogic: ILogic R} (P : T -> R) : |
| 341 |
@ILFunFrm T _ R ILOps := |
| 342 |
@mkILFunFrm T eq R ILOps P _. |
| 343 |
Next Obligation. |
| 344 |
admit. |
| 345 |
Defined. |
| 346 |
|
| 347 |
#[export] Instance ILogicOps_Prop : ILogicOps Prop | 2 := {| |
| 348 |
lentails P Q := (P : Prop) -> Q; |
| 349 |
ltrue := True; |
| 350 |
lfalse := False; |
| 351 |
limpl P Q := P -> Q; |
| 352 |
land P Q := P /\ Q; |
| 353 |
lor P Q := P \/ Q; |
| 354 |
lforall T F := forall x:T, F x; |
| 355 |
lexists T F := exists x:T, F x |
| 356 |
|}. |
| 357 |
|
| 358 |
#[export] Instance ILogic_Prop : ILogic Prop. |
| 359 |
admit. |
| 360 |
Defined. |
| 361 |
|
| 362 |
Section FunEq. |
| 363 |
Context A `{eT: type A}. |
| 364 |
|
| 365 |
Global Instance FunEquiv {T} : Equiv (T -> A) := { |
| 366 |
equiv P Q := forall a, P a === Q a |
| 367 |
}. |
| 368 |
End FunEq. |
| 369 |
|
| 370 |
Section SepAlgSect. |
| 371 |
Class SepAlgOps T `{eT : type T}:= { |
| 372 |
sa_unit : T; |
| 373 |
|
| 374 |
sa_mul : T -> T -> T -> Prop |
| 375 |
}. |
| 376 |
|
| 377 |
Class SepAlg T `{SAOps: SepAlgOps T} : Type := { |
| 378 |
sa_mul_eqL a b c d : sa_mul a b c -> c === d -> sa_mul a b d; |
| 379 |
sa_mul_eqR a b c d : sa_mul a b c -> sa_mul a b d -> c === d; |
| 380 |
sa_mon a b c : a === b -> sa_mul a c === sa_mul b c; |
| 381 |
sa_mulC a b : sa_mul a b === sa_mul b a; |
| 382 |
sa_mulA a b c : forall bc abc, sa_mul a bc abc -> sa_mul b c bc -> |
| 383 |
exists ac, sa_mul b ac abc /\ sa_mul a c ac; |
| 384 |
sa_unitI a : sa_mul a sa_unit a |
| 385 |
}. |
| 386 |
|
| 387 |
End SepAlgSect. |
| 388 |
|
| 389 |
Section BILogic. |
| 390 |
|
| 391 |
Class BILOperators (A : Type) := { |
| 392 |
empSP : A; |
| 393 |
sepSP : A -> A -> A; |
| 394 |
wandSP : A -> A -> A |
| 395 |
}. |
| 396 |
|
| 397 |
End BILogic. |
| 398 |
|
| 399 |
Notation "a '**' b" := (sepSP a b) |
| 400 |
(at level 75, right associativity). |
| 401 |
|
| 402 |
Section BISepAlg. |
| 403 |
Context {A} `{sa : SepAlg A}. |
| 404 |
Context {B} `{IL: ILogic B}. |
| 405 |
|
| 406 |
Program Instance SABIOps: BILOperators (ILFunFrm A B) := { |
| 407 |
empSP := mkILFunFrm e (fun x => sa_unit === x /\\ ltrue) _; |
| 408 |
sepSP P Q := mkILFunFrm e (fun x => Exists x1, Exists x2, sa_mul x1 x2 x /\\ |
| 409 |
P x1 //\\ Q x2) _; |
| 410 |
wandSP P Q := mkILFunFrm e (fun x => Forall x1, Forall x2, sa_mul x x1 x2 ->> |
| 411 |
P x1 -->> Q x2) _ |
| 412 |
}. |
| 413 |
Next Obligation. |
| 414 |
admit. |
| 415 |
Defined. |
| 416 |
Next Obligation. |
| 417 |
admit. |
| 418 |
Defined. |
| 419 |
Next Obligation. |
| 420 |
admit. |
| 421 |
Defined. |
| 422 |
|
| 423 |
End BISepAlg. |
| 424 |
|
| 425 |
Set Implicit Arguments. |
| 426 |
|
| 427 |
Definition Chan := WORD. |
| 428 |
Definition Data := BYTE. |
| 429 |
|
| 430 |
Inductive Action := |
| 431 |
| Out (c:Chan) (d:Data) |
| 432 |
| In (c:Chan) (d:Data). |
| 433 |
|
| 434 |
Definition Actions := list Action. |
| 435 |
|
| 436 |
#[export] Instance ActionsEquiv : Equiv Actions := { |
| 437 |
equiv a1 a2 := a1 = a2 |
| 438 |
}. |
| 439 |
|
| 440 |
Definition OPred := ILFunFrm Actions Prop. |
| 441 |
Definition mkOPred (P : Actions -> Prop) : OPred. |
| 442 |
admit. |
| 443 |
Defined. |
| 444 |
|
| 445 |
Definition eq_opred s := mkOPred (fun s' => s === s'). |
| 446 |
Definition empOP : OPred. |
| 447 |
exact (eq_opred nil). |
| 448 |
Defined. |
| 449 |
Definition catOP (P Q: OPred) : OPred. |
| 450 |
admit. |
| 451 |
Defined. |
| 452 |
|
| 453 |
Class IsPointed (T : Type) := point : T. |
| 454 |
|
| 455 |
Generalizable All Variables. |
| 456 |
|
| 457 |
Notation IsPointed_OPred P := (IsPointed (exists x : Actions, (P : OPred) x)). |
| 458 |
|
| 459 |
Record PointedOPred := mkPointedOPred { |
| 460 |
OPred_pred :> OPred; |
| 461 |
OPred_inhabited: IsPointed_OPred OPred_pred |
| 462 |
}. |
| 463 |
|
| 464 |
#[export] Existing Instance OPred_inhabited. |
| 465 |
|
| 466 |
Canonical Structure default_PointedOPred O `{IsPointed_OPred O} : PointedOPred |
| 467 |
:= {| OPred_pred := O ; OPred_inhabited := _ |}. |
| 468 |
#[export] Instance IsPointed_eq_opred x : IsPointed_OPred (eq_opred x). |
| 469 |
admit. |
| 470 |
Defined. |
| 471 |
#[export] Instance IsPointed_catOP `{IsPointed_OPred P, IsPointed_OPred Q} : IsPointed_OPred (catOP P Q). |
| 472 |
admit. |
| 473 |
Defined. |
| 474 |
|
| 475 |
Definition Flag := BITS 5. |
| 476 |
Definition OF: Flag. |
| 477 |
admit. |
| 478 |
Defined. |
| 479 |
|
| 480 |
Inductive FlagVal := mkFlag (b: bool) | FlagUnspecified. |
| 481 |
Coercion mkFlag : bool >-> FlagVal. |
| 482 |
Inductive NonSPReg := EAX | EBX | ECX | EDX | ESI | EDI | EBP. |
| 483 |
|
| 484 |
Inductive Reg := nonSPReg (r: NonSPReg) | ESP. |
| 485 |
|
| 486 |
Inductive AnyReg := regToAnyReg (r: Reg) | EIP. |
| 487 |
|
| 488 |
Inductive BYTEReg := AL|BL|CL|DL|AH|BH|CH|DH. |
| 489 |
|
| 490 |
Inductive WORDReg := mkWordReg (r:Reg). |
| 491 |
Definition PState : Type. |
| 492 |
admit. |
| 493 |
Defined. |
| 494 |
|
| 495 |
#[export] Instance PStateEquiv : Equiv PState. |
| 496 |
admit. |
| 497 |
Defined. |
| 498 |
|
| 499 |
#[export] Instance PStateType : type PState. |
| 500 |
admit. |
| 501 |
Defined. |
| 502 |
|
| 503 |
#[export] Instance PStateSepAlgOps: SepAlgOps PState. |
| 504 |
admit. |
| 505 |
Defined. |
| 506 |
Definition SPred : Type. |
| 507 |
exact (ILFunFrm PState Prop). |
| 508 |
Defined. |
| 509 |
|
| 510 |
Local Existing Instance ILFun_Ops. |
| 511 |
Local Existing Instance SABIOps. |
| 512 |
Axiom BYTEregIs : BYTEReg -> BYTE -> SPred. |
| 513 |
|
| 514 |
Inductive RegOrFlag := |
| 515 |
| RegOrFlagDWORD :> AnyReg -> RegOrFlag |
| 516 |
| RegOrFlagWORD :> WORDReg -> RegOrFlag |
| 517 |
| RegOrFlagBYTE :> BYTEReg -> RegOrFlag |
| 518 |
| RegOrFlagF :> Flag -> RegOrFlag. |
| 519 |
|
| 520 |
Definition RegOrFlag_target rf := |
| 521 |
match rf with |
| 522 |
| RegOrFlagDWORD _ => DWORD |
| 523 |
| RegOrFlagWORD _ => WORD |
| 524 |
| RegOrFlagBYTE _ => BYTE |
| 525 |
| RegOrFlagF _ => FlagVal |
| 526 |
end. |
| 527 |
|
| 528 |
Inductive Condition := |
| 529 |
| CC_O | CC_B | CC_Z | CC_BE | CC_S | CC_P | CC_L | CC_LE. |
| 530 |
|
| 531 |
Section ILSpecSect. |
| 532 |
|
| 533 |
Axiom spec : Type. |
| 534 |
Global Instance ILOps: ILogicOps spec | 2. |
| 535 |
admit. |
| 536 |
Defined. |
| 537 |
|
| 538 |
End ILSpecSect. |
| 539 |
|
| 540 |
Axiom parameterized_basic : forall {T_OPred} {proj : T_OPred -> OPred} {T} (P : SPred) (c : T) (O : OPred) (Q : SPred), spec. |
| 541 |
Global Notation loopy_basic := (@parameterized_basic PointedOPred OPred_pred _). |
| 542 |
|
| 543 |
Axiom program : Type. |
| 544 |
|
| 545 |
Axiom ConditionIs : forall (cc : Condition) (cv : RegOrFlag_target OF), SPred. |
| 546 |
|
| 547 |
Axiom foldl : forall {T R}, (R -> T -> R) -> R -> list T -> R. |
| 548 |
Axiom nth : forall {T}, T -> list T -> nat -> T. |
| 549 |
Axiom while : forall (ptest: program) |
| 550 |
(cond: Condition) (value: bool) |
| 551 |
(pbody: program), program. |
| 552 |
|
| 553 |
Lemma while_rule_ind {quantT} |
| 554 |
{ptest} {cond : Condition} {value : bool} {pbody} |
| 555 |
{S} |
| 556 |
{transition_body : quantT -> quantT} |
| 557 |
{P : quantT -> SPred} {Otest : quantT -> OPred} {Obody : quantT -> OPred} {O : quantT -> PointedOPred} |
| 558 |
{O_after_test : quantT -> PointedOPred} |
| 559 |
{I_state : quantT -> bool -> SPred} |
| 560 |
{I_logic : quantT -> bool -> bool} |
| 561 |
{Q : quantT -> SPred} |
| 562 |
(Htest : S |-- (Forall (x : quantT), |
| 563 |
(loopy_basic (P x) |
| 564 |
ptest |
| 565 |
(Otest x) |
| 566 |
(Exists b, I_logic x b = true /\\ I_state x b ** ConditionIs cond b)))) |
| 567 |
(Hbody : S |-- (Forall (x : quantT), |
| 568 |
(loopy_basic (I_logic x value = true /\\ I_state x value ** ConditionIs cond value) |
| 569 |
pbody |
| 570 |
(Obody x) |
| 571 |
(P (transition_body x))))) |
| 572 |
(H_after_test : forall x, catOP (Otest x) (O_after_test x) |-- O x) |
| 573 |
(H_body_after_test : forall x, I_logic x value = true -> catOP (Obody x) (O (transition_body x)) |-- O_after_test x) |
| 574 |
(H_empty : forall x, I_logic x (negb value) = true -> empOP |-- O_after_test x) |
| 575 |
(Q_correct : forall x, I_logic x (negb value) = true /\\ I_state x (negb value) ** ConditionIs cond (negb value) |-- Q x) |
| 576 |
(Q_safe : forall x, I_logic x value = true -> Q (transition_body x) |-- Q x) |
| 577 |
: S |-- (Forall (x : quantT), |
| 578 |
loopy_basic (P x) |
| 579 |
(while ptest cond value pbody) |
| 580 |
(O x) |
| 581 |
(Q x)). |
| 582 |
admit. |
| 583 |
Defined. |
| 584 |
Axiom behead : forall {T}, list T -> list T. |
| 585 |
Axiom all : forall {T}, (T -> bool) -> list T -> bool. |
| 586 |
Axiom all_behead : forall {T} (xs : list T) P, all P xs = true -> all P (behead xs) = true. |
| 587 |
#[export] Instance IsPointed_foldlOP A B C f g (init : A * B) `{IsPointed_OPred (g init)} |
| 588 |
`{forall a acc, IsPointed_OPred (g acc) -> IsPointed_OPred (g (f acc a))} |
| 589 |
(ls : list C) |
| 590 |
: IsPointed_OPred (g (foldl f init ls)). |
| 591 |
admit. |
| 592 |
Defined. |
| 593 |
Goal forall (ptest : program) (cond : Condition) (value : bool) |
| 594 |
(pbody : program) (T ioT : Type) (P : T -> SPred) |
| 595 |
(I : T -> bool -> SPred) (accumulate : T -> ioT -> T) |
| 596 |
(Otest Obody : T -> ioT -> PointedOPred) |
| 597 |
(coq_test__is_finished : ioT -> bool) (S : spec) |
| 598 |
(al : BYTE), |
| 599 |
(forall (initial : T) (xs : list ioT) (x : ioT), |
| 600 |
all (fun t : ioT => negb (coq_test__is_finished t)) xs = true -> |
| 601 |
coq_test__is_finished x = true -> |
| 602 |
S |
| 603 |
|-- loopy_basic (P initial ** BYTEregIs AL al) ptest |
| 604 |
(Otest initial (nth x xs 0)) |
| 605 |
(I initial |
| 606 |
(match coq_test__is_finished (nth x xs 0) with true => negb value | false => value end) ** |
| 607 |
ConditionIs cond |
| 608 |
(match coq_test__is_finished (nth x xs 0) with true => negb value | false => value end))) -> |
| 609 |
(forall (initial : T) (xs : list ioT) (x : ioT), |
| 610 |
all (fun t : ioT => negb (coq_test__is_finished t)) xs = true -> |
| 611 |
xs <> nil -> |
| 612 |
coq_test__is_finished x = true -> |
| 613 |
S |
| 614 |
|-- loopy_basic (I initial value ** ConditionIs cond value) pbody |
| 615 |
(Obody initial (nth x xs 0)) |
| 616 |
(P (accumulate initial (nth x xs 0)) ** BYTEregIs AL al)) -> |
| 617 |
forall x : ioT, |
| 618 |
coq_test__is_finished x = true -> |
| 619 |
S |
| 620 |
|-- Forall ixsp : {init_xs : T * list ioT & |
| 621 |
all (fun t : ioT => negb (coq_test__is_finished t)) |
| 622 |
(snd init_xs) = true}, |
| 623 |
loopy_basic (P (fst (projT1 ixsp)) ** BYTEregIs AL al) |
| 624 |
(while ptest cond value pbody) |
| 625 |
(catOP |
| 626 |
(snd |
| 627 |
(foldl |
| 628 |
(fun (xy : T * OPred) (v : ioT) => |
| 629 |
(accumulate (fst xy) v, |
| 630 |
catOP (catOP (Otest (fst xy) v) (Obody (fst xy) v)) |
| 631 |
(snd xy))) (fst (projT1 ixsp), empOP) |
| 632 |
(snd (projT1 ixsp)))) |
| 633 |
(Otest (foldl accumulate (fst (projT1 ixsp)) (snd (projT1 ixsp))) |
| 634 |
x)) |
| 635 |
(I (foldl accumulate (fst (projT1 ixsp)) (snd (projT1 ixsp))) |
| 636 |
(negb value) ** ConditionIs cond (negb value)). |
| 637 |
intros. |
| 638 |
eapply @while_rule_ind |
| 639 |
with (I_logic := fun ixsp b => match (match (coq_test__is_finished (nth x (snd (projT1 ixsp)) 0)) with true => negb value | false => value end), b with true, true => true | false, false => true | _, _ => false end) |
| 640 |
(Otest := fun ixsp => Otest (fst (projT1 ixsp)) (nth x (snd (projT1 ixsp)) 0)) |
| 641 |
(Obody := fun ixsp => Obody (fst (projT1 ixsp)) (nth x (snd (projT1 ixsp)) 0)) |
| 642 |
(I_state := fun ixsp => I (fst (projT1 ixsp))) |
| 643 |
(transition_body := fun ixsp => let initial := fst (projT1 ixsp) in |
| 644 |
let xs := snd (projT1 ixsp) in |
| 645 |
existT _ (accumulate initial (nth x xs 0), behead xs) _) |
| 646 |
(O_after_test := fun ixsp => let initial := fst (projT1 ixsp) in |
| 647 |
let xs := snd (projT1 ixsp) in |
| 648 |
match xs with | nil => default_PointedOPred empOP | _ => Obody initial (nth x xs 0) end); |
| 649 |
simpl projT1; simpl projT2; simpl fst; simpl snd; clear; let H := fresh in assert (H : False) by (clear; admit); destruct H. |
| 650 |
|
| 651 |
Unshelve. |
| 652 |
subst_body; simpl. |
| 653 |
Fail refine (all_behead (projT2 _)). |
| 654 |
Unset Solve Unification Constraints. refine (all_behead (projT2 _)). |
| 655 |
Abort. |