aboutsummaryrefslogtreecommitdiffstats
path: root/src/verilog/AssocMap.v
diff options
context:
space:
mode:
authorYann Herklotz <git@yannherklotz.com>2020-05-08 23:34:15 +0100
committerYann Herklotz <git@yannherklotz.com>2020-05-08 23:34:15 +0100
commit32990af23915c15e5cfd4cfe32c47cafa508f11d (patch)
treed63e4df8e989c5fa51a3a240beca8e670d7a600a /src/verilog/AssocMap.v
parent32f0f542c18b73303613b53573e6c61bc7ae6890 (diff)
downloadvericert-32990af23915c15e5cfd4cfe32c47cafa508f11d.tar.gz
vericert-32990af23915c15e5cfd4cfe32c47cafa508f11d.zip
Add AssocMap
Diffstat (limited to 'src/verilog/AssocMap.v')
-rw-r--r--src/verilog/AssocMap.v60
1 files changed, 60 insertions, 0 deletions
diff --git a/src/verilog/AssocMap.v b/src/verilog/AssocMap.v
new file mode 100644
index 0000000..e550072
--- /dev/null
+++ b/src/verilog/AssocMap.v
@@ -0,0 +1,60 @@
+(*
+ * CoqUp: Verified high-level synthesis.
+ * Copyright (C) 2020 Yann Herklotz <yann@yannherklotz.com>
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <https://www.gnu.org/licenses/>.
+ *)
+
+From coqup Require Import Coquplib Value.
+From Coq Require Import FSets.FMapPositive.
+
+Definition reg := positive.
+
+Module AssocMap := PositiveMap.
+
+Module AssocMapExt.
+ Import AssocMap.
+
+ Section Operations.
+
+ Variable elt : Type.
+
+ Definition merge : t elt -> t elt -> t elt := fold (@add elt).
+
+ Definition find_default (a : elt) (k : reg) (m : t elt) : elt :=
+ match find k m with
+ | None => a
+ | Some v => v
+ end.
+
+ End Operations.
+
+End AssocMapExt.
+Import AssocMapExt.
+
+Definition assocmap := AssocMap.t value.
+
+Definition find_assocmap (n : nat) : reg -> assocmap -> value :=
+ find_default value (ZToValue n 0).
+
+Definition empty_assocmap : assocmap := AssocMap.empty value.
+
+Definition merge_assocmap : assocmap -> assocmap -> assocmap := merge value.
+
+Module AssocMapNotation.
+ Notation "a ! b" := (AssocMap.find b a) (at level 1).
+ Notation "a # ( b , c )" := (find_assocmap c b a) (at level 1).
+ Notation "a # b" := (find_assocmap 32 b a) (at level 1).
+ Notation "a ## b" := (List.map (fun c => find_assocmap 32 c a) b) (at level 1).
+End AssocMapNotation.