aboutsummaryrefslogtreecommitdiff
path: root/src/Compilers/TypeUtil.v
diff options
context:
space:
mode:
authorGravatar Andres Erbsen <andreser@mit.edu>2017-04-06 22:53:07 -0400
committerGravatar Andres Erbsen <andreser@mit.edu>2017-04-06 22:53:07 -0400
commitc9fc5a3cdf1f5ea2d104c150c30d1b1a6ac64239 (patch)
treedb7187f6984acff324ca468e7b33d9285806a1eb /src/Compilers/TypeUtil.v
parent21198245dab432d3c0ba2bb8a02254e7d0594382 (diff)
rename-everything
Diffstat (limited to 'src/Compilers/TypeUtil.v')
-rw-r--r--src/Compilers/TypeUtil.v35
1 files changed, 35 insertions, 0 deletions
diff --git a/src/Compilers/TypeUtil.v b/src/Compilers/TypeUtil.v
new file mode 100644
index 000000000..050374562
--- /dev/null
+++ b/src/Compilers/TypeUtil.v
@@ -0,0 +1,35 @@
+Require Import Crypto.Compilers.Syntax.
+Require Import Crypto.Util.Notations.
+
+Local Open Scope expr_scope.
+
+Section language.
+ Context {base_type_code : Type}
+ (base_type_beq : base_type_code -> base_type_code -> bool)
+ (base_type_leb : base_type_code -> base_type_code -> bool).
+ Local Infix "<=?" := base_type_leb : expr_scope.
+ Local Infix "=?" := base_type_beq : expr_scope.
+
+ Definition base_type_min (a b : base_type_code) : base_type_code
+ := if a <=? b then a else b.
+ Definition base_type_max (a b : base_type_code) : base_type_code
+ := if a <=? b then b else a.
+ Section gen.
+ Context (join : base_type_code -> base_type_code -> base_type_code).
+ Fixpoint flat_type_join {t : flat_type base_type_code}
+ : interp_flat_type (fun _ => base_type_code) t -> option base_type_code
+ := match t with
+ | Tbase _ => fun v => Some v
+ | Unit => fun _ => None
+ | Prod A B
+ => fun v => match @flat_type_join A (fst v), @flat_type_join B (snd v) with
+ | Some a, Some b => Some (join a b)
+ | Some a, None => Some a
+ | None, Some b => Some b
+ | None, None => None
+ end
+ end.
+ End gen.
+ Definition flat_type_min {t} := @flat_type_join base_type_min t.
+ Definition flat_type_max {t} := @flat_type_join base_type_max t.
+End language.