From 57bc9f210b2e91f39414ca0ccce438a5fb0cb572 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Pasteur?= Date: Thu, 14 Apr 2011 13:53:30 +0200 Subject: [PATCH] Added a generic onfiguration for backends Each backend gives a function used to enable/disable passes, executed before the beginning of the compilation --- compiler/main/heptc.ml | 2 ++ compiler/main/mls2seq.ml | 26 ++++++++++++------- compiler/obc/java/java_main.ml | 2 ++ compiler/utilities/global/compiler_options.ml | 2 ++ 4 files changed, 22 insertions(+), 10 deletions(-) diff --git a/compiler/main/heptc.ml b/compiler/main/heptc.ml index 33aa914..1cf583c 100644 --- a/compiler/main/heptc.ml +++ b/compiler/main/heptc.ml @@ -51,6 +51,8 @@ let compile_program modname source_f = let close_all_files () = close_in source_c; close_out epci_c; close_out mls_c in try + (* Activates passes according to the backend used *) + Mls2seq.load_conf (); (* Process the [lexbuf] to an Heptagon AST *) let p = Hept_parser_scoper.parse_program modname lexbuf in (* Process the Heptagon AST *) diff --git a/compiler/main/mls2seq.ml b/compiler/main/mls2seq.ml index 52e6a00..e4ad7d4 100644 --- a/compiler/main/mls2seq.ml +++ b/compiler/main/mls2seq.ml @@ -19,7 +19,6 @@ open Misc type target = | Obc of (Obc.program -> unit) | Obc_no_params of (Obc.program -> unit) - | Obc_scalar of (Obc.program ->unit) | Minils of (Minils.program -> unit) | Minils_no_params of (Minils.program -> unit) @@ -39,12 +38,13 @@ let write_obc_file p = close_out obc; comment "Generation of Obc code" +let no_conf () = () -let targets = [ "c", Obc_no_params Cmain.program; - "java", Obc_scalar Java_main.program; - "obc", Obc write_obc_file; - "obc_np", Obc_no_params write_obc_file; - "epo", Minils write_object_file ] +let targets = [ "c",(Obc_no_params Cmain.program, no_conf); + "java", (Obc_scalar Java_main.program, java_conf); + "obc", (Obc write_obc_file, no_conf; + "obc_np", (Obc_no_params write_obc_file, no_conf); + "epo", (Minils write_object_file, no_conf) ] let generate_target p s = let print_unfolded p_list = @@ -52,7 +52,7 @@ let generate_target p s = if !Compiler_options.verbose then List.iter (Mls_printer.print stderr) p_list in let target = - (try List.assoc s targets + (try fst (List.assoc s targets) with Not_found -> language_error s; raise Errors.Error) in match target with | Minils convert_fun -> @@ -69,10 +69,16 @@ let generate_target p s = let o_list = List.map Mls2obc.program p_list in let o_list = List.map Obc_compiler.program o_list in List.iter convert_fun o_list - | Obc_scalar convert_fun -> - let p = p |> Mls2obc.program |> Scalarize.program in - convert_fun p +let load_conf () = + let target_conf s = + try + let conf = snd (List.assoc s targets) in + conf () + with + Not_found -> language_error s; raise Errors.Error + in + List.iter target_conf !target_languages (** Translation into dataflow and sequential languages, defaults to obc. *) let program p = diff --git a/compiler/obc/java/java_main.ml b/compiler/obc/java/java_main.ml index 7f1ac7e..8a0776a 100644 --- a/compiler/obc/java/java_main.ml +++ b/compiler/obc/java/java_main.ml @@ -3,6 +3,8 @@ open Signature open Java open Java_printer +let java_conf () = + Compiler_options.do_scalarize := true (** returns the vd and the pat of a fresh ident from [name] *) let mk_var ty name = diff --git a/compiler/utilities/global/compiler_options.ml b/compiler/utilities/global/compiler_options.ml index adcd62b..516d448 100644 --- a/compiler/utilities/global/compiler_options.ml +++ b/compiler/utilities/global/compiler_options.ml @@ -97,6 +97,8 @@ let add_tomato_check s = tomato_check := s :: !tomato_check let do_iterator_fusion = ref false +let do_scalarize = ref false + let doc_verbose = "\t\t\tSet verbose mode" and doc_version = "\t\tThe version of the compiler" and doc_print_types = "\t\t\tPrint types"