summaryrefslogtreecommitdiff
path: root/src/gen_lib/vector.lem
diff options
context:
space:
mode:
authorChristopher Pulte2015-10-28 12:09:28 +0000
committerChristopher Pulte2015-10-28 12:09:28 +0000
commit91a38a0dbcac11574768ff2fa2cb180d8d897487 (patch)
tree96345da4636839e26a80678a22b1b4003310e632 /src/gen_lib/vector.lem
parentea3171159c61ce03c76aef37b472ba9da2d932c7 (diff)
progress on lem backend: auto-generate read_register and write_register functions, and state definition
Diffstat (limited to 'src/gen_lib/vector.lem')
-rw-r--r--src/gen_lib/vector.lem16
1 files changed, 16 insertions, 0 deletions
diff --git a/src/gen_lib/vector.lem b/src/gen_lib/vector.lem
new file mode 100644
index 00000000..e7b20aeb
--- /dev/null
+++ b/src/gen_lib/vector.lem
@@ -0,0 +1,16 @@
+open import Pervasives
+
+type bit = Zero | One | Undef
+type vector = Vector of list bit * nat
+
+let read_vector_subrange is_inc (Vector bs start) n m =
+ let (length,offset) = if is_inc then (m-n+1,n-start) else (n-m+1,start-n) in
+ let (_,suffix) = List.splitAt offset bs in
+ let (subvector,_) = List.splitAt length suffix in
+ Vector subvector n
+
+let write_vector_subrange is_inc (Vector bs start) n m (Vector bs' _) =
+ let (length,offset) = if is_inc then (m-n+1,n-start) else (n-m+1,start-n) in
+ let (prefix,_) = List.splitAt offset bs in
+ let (_,suffix) = List.splitAt (offset + length) bs in
+ Vector (prefix ++ (List.take length bs') ++ suffix) start