diff options
| author | Alasdair Armstrong | 2017-09-07 16:54:20 +0100 |
|---|---|---|
| committer | Alasdair Armstrong | 2017-09-07 16:54:20 +0100 |
| commit | 842165c1171fde332bd42e7520338c59a797f76b (patch) | |
| tree | 75b61297b6d9b6e4810542390eb1371afc2f183f /lib/ocaml_rts/linksem/byte_sequence_wrapper.ml | |
| parent | 8124c487b576661dfa7a0833415d07d0978bc43e (diff) | |
Add ocaml run-time and updates to sail for ocaml backend
Diffstat (limited to 'lib/ocaml_rts/linksem/byte_sequence_wrapper.ml')
| -rw-r--r-- | lib/ocaml_rts/linksem/byte_sequence_wrapper.ml | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/lib/ocaml_rts/linksem/byte_sequence_wrapper.ml b/lib/ocaml_rts/linksem/byte_sequence_wrapper.ml new file mode 100644 index 00000000..69efcc8d --- /dev/null +++ b/lib/ocaml_rts/linksem/byte_sequence_wrapper.ml @@ -0,0 +1,33 @@ +open Big_int + +open Error + +let acquire_char_list (fname : string) = + let char_list = ref [] in + try + let ic = open_in_bin fname in + while true do + let c = input_char ic in + let _ = char_list := c :: !char_list in + () + done; + let _ = close_in ic in + Fail "acquire_char_list: the impossible happened" + with End_of_file -> + Success (List.rev !char_list) +;; + +let serialise_char_list (fname : string) bytes = + let rec go oc bytes = + match bytes with + | [] -> () + | x::xs -> output_char oc x; go oc xs + in + try + let oc = open_out_bin fname in + let _ = go oc bytes in + let _ = close_out oc in + Success () + with _ -> + Fail "serialise_char_list: unable to open file for writing" +;;
\ No newline at end of file |
