| 1 |
From Coq Require Import ZArith. |
| 2 |
Require Import Rewriter.Language.Language. |
| 3 |
Require Import Crypto.Language.API. |
| 4 |
Require Import Rewriter.Language.Wf. |
| 5 |
Require Import Crypto.Language.WfExtra. |
| 6 |
Require Import Crypto.Rewriter.AllTacticsExtra. |
| 7 |
Require Import Crypto.Rewriter.RulesProofs. |
| 8 |
|
| 9 |
Module Compilers. |
| 10 |
Import Language.Compilers. |
| 11 |
Import Language.API.Compilers. |
| 12 |
Import Language.Wf.Compilers. |
| 13 |
Import Language.WfExtra.Compilers. |
| 14 |
Import Rewriter.AllTacticsExtra.Compilers.RewriteRules.GoalType. |
| 15 |
Import Rewriter.AllTactics.Compilers.RewriteRules.Tactic. |
| 16 |
Import Compilers.Classes. |
| 17 |
|
| 18 |
Module Import RewriteRules. |
| 19 |
Section __. |
| 20 |
Context (invert_low invert_high : Z (*log2wordmax*) -> Z -> @option Z) |
| 21 |
(Hlow : forall s v v', invert_low s v = Some v' -> v = Z.land v' (2^(s/2)-1)) |
| 22 |
(Hhigh : forall s v v', invert_high s v = Some v' -> v = Z.shiftr v' (s/2)). |
| 23 |
|
| 24 |
Definition VerifiedRewriterToFancy : VerifiedRewriter_with_args false false true fancy_rewrite_rules_proofs. |
| 25 |
Proof using All. make_rewriter. Defined. |
| 26 |
|
| 27 |
Definition default_opts := Eval hnf in @default_opts VerifiedRewriterToFancy. |
| 28 |
Let optsT := Eval hnf in optsT VerifiedRewriterToFancy. |
| 29 |
|
| 30 |
Definition RewriteToFancy (opts : optsT) {t : API.type} : API.Expr t -> API.Expr t. |
| 31 |
Proof using invert_low invert_high. |
| 32 |
let v := (eval hnf in (@Rewrite VerifiedRewriterToFancy opts t)) in exact v. |
| 33 |
Defined. |
| 34 |
|
| 35 |
Lemma Wf_RewriteToFancy opts {t} e (Hwf : Wf e) : Wf (@RewriteToFancy opts t e). |
| 36 |
Proof using All. now apply VerifiedRewriterToFancy. Qed. |
| 37 |
|
| 38 |
Lemma Interp_RewriteToFancy opts {t} e (Hwf : Wf e) : API.Interp (@RewriteToFancy opts t e) == API.Interp e. |
| 39 |
Proof using All. now apply VerifiedRewriterToFancy. Qed. |
| 40 |
End __. |
| 41 |
End RewriteRules. |
| 42 |
|
| 43 |
Module Export Hints. |
| 44 |
#[global] |
| 45 |
Hint Resolve Wf_RewriteToFancy : wf wf_extra. |
| 46 |
#[global] |
| 47 |
Hint Opaque RewriteToFancy : wf wf_extra interp interp_extra rewrite. |
| 48 |
#[global] |
| 49 |
Hint Rewrite @Interp_RewriteToFancy : interp interp_extra. |
| 50 |
End Hints. |
| 51 |
End Compilers. |