From 3c8fc39745c3333d0bbb217a1d14bd4c367b35b2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Pasteur?= Date: Tue, 19 Apr 2011 09:23:52 +0200 Subject: [PATCH] Fix C backend with new obc ast --- compiler/heptagon/transformations/normalize.ml | 2 +- compiler/obc/c/cgen.ml | 6 ++++-- compiler/obc/obc_utils.ml | 14 ++++++++++++++ 3 files changed, 19 insertions(+), 3 deletions(-) diff --git a/compiler/heptagon/transformations/normalize.ml b/compiler/heptagon/transformations/normalize.ml index 8ce7c44..d24cef0 100644 --- a/compiler/heptagon/transformations/normalize.ml +++ b/compiler/heptagon/transformations/normalize.ml @@ -106,7 +106,7 @@ let add context expected_kind e = | (Evar _ | Eapp ({ a_op = Efield }, _, _) | Ewhen _ | Eapp ({ a_op = Etuple }, _, _) | Econst _) , ExtValue -> false | _ , ExtValue -> true - | _ -> Format.printf "Not normalizing \n"; false in + | _ -> false in if up then let context, n = equation context e in context, { e with e_desc = n } diff --git a/compiler/obc/c/cgen.ml b/compiler/obc/c/cgen.ml index b9de77a..6c1a231 100644 --- a/compiler/obc/c/cgen.ml +++ b/compiler/obc/c/cgen.ml @@ -737,7 +737,8 @@ let cdefs_and_cdecls_of_type_decl otd = (** [cfile_list_of_oprog oprog] translates the Obc program [oprog] to a list of C source and header files. *) let cfile_list_of_oprog_ty_decls name oprog = - let cdefs_and_cdecls = List.map cdefs_and_cdecls_of_type_decl oprog.p_types in + let types = Obc_utils.program_types oprog in + let cdefs_and_cdecls = List.map cdefs_and_cdecls_of_type_decl types in let (cty_defs, cty_decls) = List.split cdefs_and_cdecls in let filename_types = name ^ "_types" in @@ -751,8 +752,9 @@ let global_file_header name prog = let dependencies = ModulSet.elements (Obc_utils.Deps.deps_program prog) in let dependencies = List.map modul_to_string dependencies in + let classes = program_classes prog in let (decls, defs) = - List.split (List.map cdefs_and_cdecls_of_class_def prog.p_classes) in + List.split (List.map cdefs_and_cdecls_of_class_def classes) in let decls = List.concat decls and defs = List.concat defs in diff --git a/compiler/obc/obc_utils.ml b/compiler/obc/obc_utils.ml index 211ab29..fa1b3c0 100644 --- a/compiler/obc/obc_utils.ml +++ b/compiler/obc/obc_utils.ml @@ -195,3 +195,17 @@ let rec copy_array pass dest src = match dest.l_ty with | _ -> Aassgn(dest, Epattern src) *) + +let program_types p = + let add_type acc pd = match pd with + | Ptype ty -> ty :: acc + | _ -> acc + in + List.fold_left add_type [] p.p_desc + +let program_classes p = + let add_class acc pd = match pd with + | Pclass cd -> cd :: acc + | _ -> acc + in + List.fold_left add_class [] p.p_desc