summaryrefslogtreecommitdiff
path: root/compiler/TranslateCore.ml
diff options
context:
space:
mode:
authorSon Ho2022-10-27 09:16:46 +0200
committerSon HO2022-10-27 12:58:47 +0200
commit7e7d0d67de8285e1d6c589750191bce4f49aacb3 (patch)
tree5ef3178d2c3f7eadc82a0ea9497788e48ce67c2b /compiler/TranslateCore.ml
parent16560ce5d6409e0f0326a0c6046960253e444ba4 (diff)
Reorganize a bit the project
Diffstat (limited to 'compiler/TranslateCore.ml')
-rw-r--r--compiler/TranslateCore.ml65
1 files changed, 65 insertions, 0 deletions
diff --git a/compiler/TranslateCore.ml b/compiler/TranslateCore.ml
new file mode 100644
index 00000000..a658147d
--- /dev/null
+++ b/compiler/TranslateCore.ml
@@ -0,0 +1,65 @@
+(** Some utilities for the translation *)
+
+open InterpreterStatements
+module L = Logging
+module T = Types
+module A = LlbcAst
+module SA = SymbolicAst
+module FA = FunsAnalysis
+
+(** The local logger *)
+let log = L.translate_log
+
+type type_context = C.type_context [@@deriving show]
+
+type fun_context = {
+ fun_decls : A.fun_decl A.FunDeclId.Map.t;
+ fun_infos : FA.fun_info A.FunDeclId.Map.t;
+}
+[@@deriving show]
+
+type global_context = C.global_context [@@deriving show]
+
+type trans_ctx = {
+ type_context : type_context;
+ fun_context : fun_context;
+ global_context : global_context;
+}
+
+type pure_fun_translation = Pure.fun_decl * Pure.fun_decl list
+
+let type_decl_to_string (ctx : trans_ctx) (def : Pure.type_decl) : string =
+ let type_params = def.type_params in
+ let type_decls = ctx.type_context.type_decls in
+ let fmt = PrintPure.mk_type_formatter type_decls type_params in
+ PrintPure.type_decl_to_string fmt def
+
+let type_id_to_string (ctx : trans_ctx) (def : Pure.type_decl) : string =
+ let type_params = def.type_params in
+ let type_decls = ctx.type_context.type_decls in
+ let fmt = PrintPure.mk_type_formatter type_decls type_params in
+ PrintPure.type_decl_to_string fmt def
+
+let fun_sig_to_string (ctx : trans_ctx) (sg : Pure.fun_sig) : string =
+ let type_params = sg.type_params in
+ let type_decls = ctx.type_context.type_decls in
+ let fun_decls = ctx.fun_context.fun_decls in
+ let global_decls = ctx.global_context.global_decls in
+ let fmt =
+ PrintPure.mk_ast_formatter type_decls fun_decls global_decls type_params
+ in
+ PrintPure.fun_sig_to_string fmt sg
+
+let fun_decl_to_string (ctx : trans_ctx) (def : Pure.fun_decl) : string =
+ let type_params = def.signature.type_params in
+ let type_decls = ctx.type_context.type_decls in
+ let fun_decls = ctx.fun_context.fun_decls in
+ let global_decls = ctx.global_context.global_decls in
+ let fmt =
+ PrintPure.mk_ast_formatter type_decls fun_decls global_decls type_params
+ in
+ PrintPure.fun_decl_to_string fmt def
+
+let fun_decl_id_to_string (ctx : trans_ctx) (id : A.FunDeclId.id) : string =
+ Print.fun_name_to_string
+ (A.FunDeclId.Map.find id ctx.fun_context.fun_decls).name