diff options
author | Xavier Leroy <xavierleroy@users.noreply.github.com> | 2016-02-02 09:34:36 +0100 |
---|---|---|
committer | Xavier Leroy <xavierleroy@users.noreply.github.com> | 2016-02-02 09:34:36 +0100 |
commit | 0d6a1557ae45b8c731c6715bb7109a30c32c5a26 (patch) | |
tree | 1efd61ed8213afeab7992032aef7ed4fccb9461d /lib/Json.ml | |
parent | 15fc340f69e9c4d718c15fd9ec12a81695cf8d67 (diff) | |
parent | 659a1b55f454fc262826e4edf7d938f01ae04263 (diff) | |
download | compcert-0d6a1557ae45b8c731c6715bb7109a30c32c5a26.tar.gz compcert-0d6a1557ae45b8c731c6715bb7109a30c32c5a26.zip |
Merge pull request #85 from AbsInt/option_json
Flag -doptions to save machine configuration and command-line flags to a JSON file.
Diffstat (limited to 'lib/Json.ml')
-rw-r--r-- | lib/Json.ml | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/lib/Json.ml b/lib/Json.ml new file mode 100644 index 00000000..4aa91e95 --- /dev/null +++ b/lib/Json.ml @@ -0,0 +1,42 @@ +(* *********************************************************************) +(* *) +(* The Compcert verified compiler *) +(* *) +(* Bernhard Schommer, AbsInt Angewandte Informatik GmbH *) +(* *) +(* AbsInt Angewandte Informatik GmbH. All rights reserved. This file *) +(* is distributed under the terms of the INRIA Non-Commercial *) +(* License Agreement. *) +(* *) +(* *********************************************************************) + +open Printf + +(* Simple functions for JSON printing *) + +(* Print a string as json string *) +let p_jstring oc s = fprintf oc "\"%s\"" s + +(* Print a list as json array *) +let p_jarray elem oc l = + match l with + | [] -> fprintf oc "[]" + | hd::tail -> + output_string oc "["; elem oc hd; + List.iter (fprintf oc ",%a" elem) tail; + output_string oc "]" + +(* Print a bool as json bool *) +let p_jbool oc = fprintf oc "%B" + +(* Print a int as json int *) +let p_jint oc = fprintf oc "%d" + +(* Print a member *) +let p_jmember oc name p_mem mem = + fprintf oc "\n%a:%a" p_jstring name p_mem mem + +(* Print optional value *) +let p_jopt p_elem oc = function + | None -> output_string oc "null" + | Some i -> p_elem oc i |