diff options
author | Son Ho | 2022-01-24 07:38:30 +0100 |
---|---|---|
committer | Son Ho | 2022-01-24 07:38:30 +0100 |
commit | 536abedcbcd96922700a97de85ce2a91d807c955 (patch) | |
tree | b83073c61fc09331f8447e86328138f3af8e4366 /src/PrintSymbolicAst.ml | |
parent | 4db63550ab84572222ec55e694e3096189353063 (diff) |
Start working on printing for symbolic AST
Diffstat (limited to '')
-rw-r--r-- | src/PrintSymbolicAst.ml | 60 |
1 files changed, 60 insertions, 0 deletions
diff --git a/src/PrintSymbolicAst.ml b/src/PrintSymbolicAst.ml new file mode 100644 index 00000000..ec07a270 --- /dev/null +++ b/src/PrintSymbolicAst.ml @@ -0,0 +1,60 @@ +(** Printing utilities for symbolic AST. + + We don't put this in [Print] because: + - [Print] is getting quite big + - if we do so we have a dependency cycle... + *) + +open Errors +open Identifiers +module T = Types +module TU = TypesUtils +module V = Values +module E = Expressions +module A = CfimAst +module C = Contexts +module M = Modules +open SymbolicAst +open SymbolicAstUtils +module P = Print +module PT = Print.Types + +type formatting_ctx = { + type_context : C.type_context; + fun_context : A.fun_def A.FunDefId.Map.t; + type_vars : T.type_var list; +} + +type formatter = P.Values.value_formatter + +let formatting_ctx_to_formatter (ctx : formatting_ctx) : formatter = + (* We shouldn't use [rvar_to_string] *) + let rvar_to_string _ = failwith "Unexpected use of rvar_to_string" in + let r_to_string r = PT.region_id_to_string r in + + let type_var_id_to_string vid = + let v = T.TypeVarId.nth ctx.type_vars vid in + v.name + in + let type_def_id_to_string def_id = + let def = T.TypeDefId.Map.find def_id ctx.type_context.type_defs in + P.name_to_string def.name + in + let adt_variant_to_string = + P.Contexts.type_ctx_to_adt_variant_to_string_fun ctx.type_context.type_defs + in + (* We shouldn't use [var_id_to_string] *) + let var_id_to_string _ = failwith "Unexpected use of var_id_to_string" in + + let adt_field_names = + P.Contexts.type_ctx_to_adt_field_names_fun ctx.type_context.type_defs + in + { + rvar_to_string; + r_to_string; + type_var_id_to_string; + type_def_id_to_string; + adt_variant_to_string; + var_id_to_string; + adt_field_names; + } |