diff options
| author | Jon French | 2018-05-10 11:19:41 +0100 |
|---|---|---|
| committer | Jon French | 2018-05-10 11:19:41 +0100 |
| commit | a67ad9ca27c5e2909c852a61f34b18a3414efc46 (patch) | |
| tree | 00b7a6c99566023ba7582ecb2cba0143dc197dea /src | |
| parent | d72cd585d7fe71c98a83f7c863167d79f2520159 (diff) | |
add space handling mappings to riscv prelude and sail_lib.ml
Diffstat (limited to 'src')
| -rw-r--r-- | src/sail_lib.ml | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/src/sail_lib.ml b/src/sail_lib.ml index 1f3d0bba..b4c5a8aa 100644 --- a/src/sail_lib.ml +++ b/src/sail_lib.ml @@ -622,3 +622,25 @@ let speculate_conditional_success () = true (* Return nanoseconds since epoch. Truncates to ocaml int but will be OK for next 100 years or so... *) let get_time_ns () = Big_int.of_int (int_of_float (1e9 *. Unix.gettimeofday ())) +let rec n_leading_spaces s = + match String.length s with + | 0 -> 0 + | 1 -> begin match s with + | " " -> 1 + | _ -> 0 + end + | len -> begin match String.get s 0 with + | ' ' -> 1 + (n_leading_spaces (String.sub s 1 (len - 1))) + | _ -> 0 + end + + +let opt_spaces_matches_prefix s = + ZSome ((), n_leading_spaces s |> Big_int.of_int) + +let spaces_matches_prefix s = + let n = n_leading_spaces s in + match n with + | 0 -> ZNone () + | n -> ZSome ((), Big_int.of_int n) + |
