summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSon Ho2022-02-10 00:13:28 +0100
committerSon Ho2022-02-10 00:13:28 +0100
commit469b6b3c91b0e05df9c5ab64f7590015d3ef4cba (patch)
treee6c2b53baf5ea245ed01b67728937fd42e7ac320
parent337caa185fa51ab81fa896db0dc9671c7599f4fa (diff)
Make minor updates to deserialization
Diffstat (limited to '')
-rw-r--r--src/CfimOfJson.ml31
-rw-r--r--src/Logging.ml3
-rw-r--r--src/main.ml1
3 files changed, 22 insertions, 13 deletions
diff --git a/src/CfimOfJson.ml b/src/CfimOfJson.ml
index 6cf7cf64..9ac0a974 100644
--- a/src/CfimOfJson.ml
+++ b/src/CfimOfJson.ml
@@ -18,6 +18,9 @@ module M = Modules
module E = Expressions
module A = CfimAst
+(* The default logger *)
+let log = Logging.cfim_of_json_logger
+
let name_of_json (js : json) : (name, string) result =
combine_error_msgs js "name_of_json" (list_of_json string_of_json js)
@@ -234,40 +237,40 @@ let scalar_value_of_json (js : json) : (V.scalar_value, string) result =
let res =
combine_error_msgs js "scalar_value_of_json"
(match js with
- | `Assoc [ ("Isize", bi) ] ->
+ | `Assoc [ ("Isize", `List [ bi ]) ] ->
let* bi = big_int_of_json bi in
Ok { V.value = bi; int_ty = Isize }
- | `Assoc [ ("I8", bi) ] ->
+ | `Assoc [ ("I8", `List [ bi ]) ] ->
let* bi = big_int_of_json bi in
Ok { V.value = bi; int_ty = I8 }
- | `Assoc [ ("I16", bi) ] ->
+ | `Assoc [ ("I16", `List [ bi ]) ] ->
let* bi = big_int_of_json bi in
Ok { V.value = bi; int_ty = I16 }
- | `Assoc [ ("I32", bi) ] ->
+ | `Assoc [ ("I32", `List [ bi ]) ] ->
let* bi = big_int_of_json bi in
Ok { V.value = bi; int_ty = I32 }
- | `Assoc [ ("I64", bi) ] ->
+ | `Assoc [ ("I64", `List [ bi ]) ] ->
let* bi = big_int_of_json bi in
Ok { V.value = bi; int_ty = I64 }
- | `Assoc [ ("I128", bi) ] ->
+ | `Assoc [ ("I128", `List [ bi ]) ] ->
let* bi = big_int_of_json bi in
Ok { V.value = bi; int_ty = I128 }
- | `Assoc [ ("Usize", bi) ] ->
+ | `Assoc [ ("Usize", `List [ bi ]) ] ->
let* bi = big_int_of_json bi in
Ok { V.value = bi; int_ty = Usize }
- | `Assoc [ ("U8", bi) ] ->
+ | `Assoc [ ("U8", `List [ bi ]) ] ->
let* bi = big_int_of_json bi in
Ok { V.value = bi; int_ty = U8 }
- | `Assoc [ ("U16", bi) ] ->
+ | `Assoc [ ("U16", `List [ bi ]) ] ->
let* bi = big_int_of_json bi in
Ok { V.value = bi; int_ty = U16 }
- | `Assoc [ ("U32", bi) ] ->
+ | `Assoc [ ("U32", `List [ bi ]) ] ->
let* bi = big_int_of_json bi in
Ok { V.value = bi; int_ty = U32 }
- | `Assoc [ ("U64", bi) ] ->
+ | `Assoc [ ("U64", `List [ bi ]) ] ->
let* bi = big_int_of_json bi in
Ok { V.value = bi; int_ty = U64 }
- | `Assoc [ ("U128", bi) ] ->
+ | `Assoc [ ("U128", `List [ bi ]) ] ->
let* bi = big_int_of_json bi in
Ok { V.value = bi; int_ty = U128 }
| _ -> Error "")
@@ -275,7 +278,9 @@ let scalar_value_of_json (js : json) : (V.scalar_value, string) result =
match res with
| Error _ -> res
| Ok sv ->
- assert (S.check_scalar_value_in_range sv);
+ if not (S.check_scalar_value_in_range sv) then (
+ log#serror ("Scalar value not in range: " ^ V.show_scalar_value sv);
+ raise (Failure ("Scalar value not in range: " ^ V.show_scalar_value sv)));
res
let constant_value_of_json (js : json) : (V.constant_value, string) result =
diff --git a/src/Logging.ml b/src/Logging.ml
index a7313de5..7067920b 100644
--- a/src/Logging.ml
+++ b/src/Logging.ml
@@ -9,6 +9,9 @@ let main_log = L.get_logger "MainLogger"
(** Below, we create subgloggers for various submodules, so that we can precisely
toggle logging on/off, depending on which information we need *)
+(** Logger for CfimOfJson *)
+let cfim_of_json_logger = L.get_logger "MainLogger.CfimOfJson"
+
(** Logger for PrePasses *)
let pre_passes_log = L.get_logger "MainLogger.PrePasses"
diff --git a/src/main.ml b/src/main.ml
index 7bec093d..cf854577 100644
--- a/src/main.ml
+++ b/src/main.ml
@@ -115,6 +115,7 @@ let () =
* command-line arguments *)
Easy_logging.Handlers.set_level main_logger_handler EL.Info;
main_log#set_level EL.Info;
+ cfim_of_json_logger#set_level EL.Info;
pre_passes_log#set_level EL.Info;
interpreter_log#set_level EL.Info;
statements_log#set_level EL.Info;