summaryrefslogtreecommitdiff
path: root/src/util.ml
diff options
context:
space:
mode:
authorAlasdair Armstrong2018-01-23 21:16:02 +0000
committerAlasdair Armstrong2018-01-23 21:16:02 +0000
commitd94404854c10960c881b5146f81d4483e73a8ca6 (patch)
tree9f61403a8c88814ae91b7dc867b597fe57ea0e69 /src/util.ml
parentc5db705ca228421b4035b4361aba9823750fd67c (diff)
Started working on C backend for sail
Also updated some of the documentation in the sail source code
Diffstat (limited to 'src/util.ml')
-rw-r--r--src/util.ml18
1 files changed, 18 insertions, 0 deletions
diff --git a/src/util.ml b/src/util.ml
index e902b2dd..94bbc6dc 100644
--- a/src/util.ml
+++ b/src/util.ml
@@ -395,3 +395,21 @@ let cyan str = termcode 96 ^ str
let blue str = termcode 94 ^ str
let clear str = str ^ termcode 0
+let zchar c =
+ let zc c = "z" ^ String.make 1 c in
+ if Char.code c <= 41 then zc (Char.chr (Char.code c + 16))
+ else if Char.code c <= 47 then zc (Char.chr (Char.code c + 23))
+ else if Char.code c <= 57 then String.make 1 c
+ else if Char.code c <= 64 then zc (Char.chr (Char.code c + 13))
+ else if Char.code c <= 90 then String.make 1 c
+ else if Char.code c <= 94 then zc (Char.chr (Char.code c - 13))
+ else if Char.code c <= 95 then "_"
+ else if Char.code c <= 96 then zc (Char.chr (Char.code c - 13))
+ else if Char.code c <= 121 then String.make 1 c
+ else if Char.code c <= 122 then "zz"
+ else if Char.code c <= 126 then zc (Char.chr (Char.code c - 39))
+ else raise (Invalid_argument "zchar")
+
+let zencode_string str = "z" ^ List.fold_left (fun s1 s2 -> s1 ^ s2) "" (List.map zchar (string_to_list str))
+
+let zencode_upper_string str = "Z" ^ List.fold_left (fun s1 s2 -> s1 ^ s2) "" (List.map zchar (string_to_list str))