From 989c7f8ab0bf908d0cd26b58c542d264c63b72fe Mon Sep 17 00:00:00 2001 From: Alasdair Armstrong Date: Wed, 27 Mar 2019 19:21:24 +0000 Subject: C: Generate C from sliced specifications --- src/specialize.ml | 18 ++++++------------ 1 file changed, 6 insertions(+), 12 deletions(-) (limited to 'src/specialize.ml') diff --git a/src/specialize.ml b/src/specialize.ml index afce4b0f..5a7624bc 100644 --- a/src/specialize.ml +++ b/src/specialize.ml @@ -483,7 +483,7 @@ let specialize_id_overloads instantiations id (Defs defs) = valspecs are then re-specialized. This process is iterated until the whole spec is specialized. *) -let initial_calls = IdSet.of_list +let initial_calls = ref (IdSet.of_list [ mk_id "main"; mk_id "__SetConfig"; mk_id "__ListConfig"; @@ -491,10 +491,12 @@ let initial_calls = IdSet.of_list mk_id "decode"; mk_id "initialize_registers"; mk_id "append_64" (* used to construct bitvector literals in C backend *) - ] + ]) -let remove_unused_valspecs ?(initial_calls=initial_calls) env ast = - let calls = ref initial_calls in +let add_initial_calls ids = initial_calls := IdSet.union ids !initial_calls + +let remove_unused_valspecs env ast = + let calls = ref !initial_calls in let vs_ids = val_spec_ids ast in let inspect_exp = function @@ -527,14 +529,6 @@ let remove_unused_valspecs ?(initial_calls=initial_calls) env ast = List.fold_left (fun ast id -> Defs (remove_unused ast id)) ast (IdSet.elements unused) -let slice_defs env (Defs defs) keep_ids = - let keep = function - | DEF_fundef fd -> IdSet.mem (id_of_fundef fd) keep_ids - | _ -> true - in - let defs = List.filter keep defs in - remove_unused_valspecs env (Defs defs) ~initial_calls:keep_ids - let specialize_id spec id ast = let instantiations = instantiations_of spec id ast in let ast = specialize_id_valspec spec instantiations id ast in -- cgit v1.2.3 From 21a26461caf237783d93dacfad933fc6ef0fe0c0 Mon Sep 17 00:00:00 2001 From: Alasdair Armstrong Date: Fri, 5 Apr 2019 17:03:33 +0100 Subject: Fix: Don't remove uncalled polymorphic constructors if they are matched upon Previously the specialization would remove any polymorphic union constructor that was never created anywhere in the specification. While this wasn't usually problematic, it does leave an edge case where such a constructor could be matched upon in a pattern, and then the resulting match would fail to compile as it would be matching on a constructor kind that doesn't exists. This should fix that issue by chaging the V_ctor_kind value into an F_ctor_kind fragment. Previously a polymorphic constructor-kind would have been represented by its mangled name, e.g. V_ctor_kind "zSome_unit" would now be represented as V_ctor_kind ("Some", unifiers, ty) where ty is a monomorphic version of the original constructor's type such that ctyp_unify original_ty ty = unifiers and the mangled name we generate is zencode_string ("Some_" ^ string_of_list "_" string_of_ctyp unifiers) --- src/specialize.ml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/specialize.ml') diff --git a/src/specialize.ml b/src/specialize.ml index 5a7624bc..ca33ee85 100644 --- a/src/specialize.ml +++ b/src/specialize.ml @@ -53,7 +53,7 @@ open Ast_util open Rewriter let opt_ddump_spec_ast = ref None - + let is_typ_ord_arg = function | A_aux (A_typ _, _) -> true | A_aux (A_order _, _) -> true -- cgit v1.2.3