summaryrefslogtreecommitdiff
path: root/compiler/TranslateCore.ml
diff options
context:
space:
mode:
Diffstat (limited to 'compiler/TranslateCore.ml')
-rw-r--r--compiler/TranslateCore.ml121
1 files changed, 65 insertions, 56 deletions
diff --git a/compiler/TranslateCore.ml b/compiler/TranslateCore.ml
index ba5e237b..abf4fcf7 100644
--- a/compiler/TranslateCore.ml
+++ b/compiler/TranslateCore.ml
@@ -1,73 +1,82 @@
(** Some utilities for the translation *)
-open InterpreterStatements
-module L = Logging
-module T = Types
-module A = LlbcAst
-module SA = SymbolicAst
-module FA = FunsAnalysis
+open Contexts
+open ExtractName
(** The local logger *)
-let log = L.translate_log
+let log = Logging.translate_log
-type type_context = C.type_context [@@deriving show]
+type trans_ctx = decls_ctx [@@deriving show]
+type fun_and_loops = { f : Pure.fun_decl; loops : Pure.fun_decl list }
+type pure_fun_translation_no_loops = Pure.fun_decl * Pure.fun_decl list
+
+type pure_fun_translation = {
+ keep_fwd : bool;
+ (** Should we extract the forward function?
-type fun_context = {
- fun_decls : A.fun_decl A.FunDeclId.Map.t;
- fun_infos : FA.fun_info A.FunDeclId.Map.t;
+ If the forward function returns `()` and there is exactly one
+ backward function, we may merge the forward into the backward
+ function and thus don't extract the forward function)?
+ *)
+ fwd : fun_and_loops;
+ backs : fun_and_loops list;
}
-[@@deriving show]
-type global_context = C.global_context [@@deriving show]
+let trans_ctx_to_fmt_env (ctx : trans_ctx) : Print.fmt_env =
+ Print.Contexts.decls_ctx_to_fmt_env ctx
-type trans_ctx = {
- type_context : type_context;
- fun_context : fun_context;
- global_context : global_context;
-}
+let trans_ctx_to_pure_fmt_env (ctx : trans_ctx) : PrintPure.fmt_env =
+ PrintPure.decls_ctx_to_fmt_env ctx
-type fun_and_loops = Pure.fun_decl * Pure.fun_decl list
-type pure_fun_translation_no_loops = Pure.fun_decl * Pure.fun_decl list
-type pure_fun_translation = fun_and_loops * fun_and_loops list
+let name_to_string (ctx : trans_ctx) =
+ Print.Types.name_to_string (trans_ctx_to_fmt_env ctx)
-let type_decl_to_string (ctx : trans_ctx) (def : Pure.type_decl) : string =
- let type_params = def.type_params in
- let cg_params = def.const_generic_params in
- let type_decls = ctx.type_context.type_decls in
- let global_decls = ctx.global_context.global_decls in
- let fmt =
- PrintPure.mk_type_formatter type_decls global_decls type_params cg_params
+let match_name_find_opt (ctx : trans_ctx) (name : Types.name)
+ (m : 'a NameMatcherMap.t) : 'a option =
+ let open Charon.NameMatcher in
+ let open ExtractBuiltin in
+ let mctx : ctx =
+ {
+ type_decls = ctx.type_ctx.type_decls;
+ global_decls = ctx.global_ctx.global_decls;
+ trait_decls = ctx.trait_decls_ctx.trait_decls;
+ }
in
- PrintPure.type_decl_to_string fmt def
-
-let type_id_to_string (ctx : trans_ctx) (id : Pure.TypeDeclId.id) : string =
- Print.fun_name_to_string
- (Pure.TypeDeclId.Map.find id ctx.type_context.type_decls).name
+ NameMatcherMap.find_opt mctx name m
-let fun_sig_to_string (ctx : trans_ctx) (sg : Pure.fun_sig) : string =
- let type_params = sg.type_params in
- let cg_params = sg.const_generic_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
- cg_params
+let match_name_with_generics_find_opt (ctx : trans_ctx) (name : Types.name)
+ (generics : Types.generic_args) (m : 'a NameMatcherMap.t) : 'a option =
+ let open Charon.NameMatcher in
+ let open ExtractBuiltin in
+ let mctx : ctx =
+ {
+ type_decls = ctx.type_ctx.type_decls;
+ global_decls = ctx.global_ctx.global_decls;
+ trait_decls = ctx.trait_decls_ctx.trait_decls;
+ }
in
- PrintPure.fun_sig_to_string fmt sg
+ NameMatcherMap.find_with_generics_opt mctx name generics m
-let fun_decl_to_string (ctx : trans_ctx) (def : Pure.fun_decl) : string =
- let type_params = def.signature.type_params in
- let cg_params = def.signature.const_generic_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
- cg_params
+let name_to_simple_name (ctx : trans_ctx) (n : Types.name) : string list =
+ let mctx : Charon.NameMatcher.ctx =
+ {
+ type_decls = ctx.type_ctx.type_decls;
+ global_decls = ctx.global_ctx.global_decls;
+ trait_decls = ctx.trait_decls_ctx.trait_decls;
+ }
in
- PrintPure.fun_decl_to_string fmt def
+ let is_trait_impl = false in
+ name_to_simple_name mctx is_trait_impl n
-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
+let trait_name_with_generics_to_simple_name (ctx : trans_ctx)
+ ?(prefix : Types.name option = None) (n : Types.name)
+ (p : Types.generic_params) (g : Types.generic_args) : string list =
+ let mctx : Charon.NameMatcher.ctx =
+ {
+ type_decls = ctx.type_ctx.type_decls;
+ global_decls = ctx.global_ctx.global_decls;
+ trait_decls = ctx.trait_decls_ctx.trait_decls;
+ }
+ in
+ let is_trait_impl = true in
+ name_with_generics_to_simple_name mctx is_trait_impl ~prefix n p g