summaryrefslogtreecommitdiff
path: root/src/util.ml
diff options
context:
space:
mode:
authorAlasdair Armstrong2018-03-02 19:17:51 +0000
committerAlasdair Armstrong2018-03-02 19:34:54 +0000
commitea2ff78cf675298df64e8ebacca7156b68f3c5c8 (patch)
tree61500ccdd47247a4eab6bd19ece039d598267d28 /src/util.ml
parent936150eda67ddbd216653fe4030bb6b790c6bb17 (diff)
Use sail_lib.lem values in C backend
Rather than just using strings to represent literals, now use value types from sail_lib.lem to represent them. This allows for expressions to be evaluated at compile time, which will be useful for future optimisations involving constant folding and propagation, and allows the intermediate bytecode to be interpreted using the same lem builtins that the shallow embedding uses. To get this to work I had to tweak the build process slightly to allow ml files to import lem files from gen_lib/. Hopefully this doesn't break anything!
Diffstat (limited to 'src/util.ml')
-rw-r--r--src/util.ml7
1 files changed, 7 insertions, 0 deletions
diff --git a/src/util.ml b/src/util.ml
index b44c5dfb..b997005e 100644
--- a/src/util.ml
+++ b/src/util.ml
@@ -394,6 +394,13 @@ let rec drop n xs = match n, xs with
| n, [] -> []
| n, (x :: xs) -> drop (n - 1) xs
+let list_init len f =
+ let rec list_init' len f acc =
+ if acc >= len then []
+ else f acc :: list_init' len f (acc + 1)
+ in
+ list_init' len f 0
+
let termcode n =
if !opt_colors then
"\x1B[" ^ string_of_int n ^ "m"