2010-06-18 14:00:58 +02:00
|
|
|
(**************************************************************************)
|
|
|
|
(* *)
|
|
|
|
(* Heptagon *)
|
|
|
|
(* *)
|
|
|
|
(* Author : Marc Pouzet *)
|
|
|
|
(* Organization : Demons, LRI, University of Paris-Sud, Orsay *)
|
|
|
|
(* *)
|
|
|
|
(**************************************************************************)
|
|
|
|
|
2010-06-18 15:40:48 +02:00
|
|
|
open Compiler_utils
|
2010-09-15 09:38:52 +02:00
|
|
|
open Compiler_options
|
2010-07-13 14:03:39 +02:00
|
|
|
open Obc
|
|
|
|
open Minils
|
|
|
|
open Misc
|
2010-06-18 15:40:48 +02:00
|
|
|
|
2010-07-15 11:37:30 +02:00
|
|
|
(** Definition of a target. A target starts either from
|
|
|
|
dataflow code (ie Minils) or sequential code (ie Obc),
|
2011-01-11 14:27:29 +01:00
|
|
|
with or without static parameters *)
|
2010-07-15 11:37:30 +02:00
|
|
|
type target =
|
|
|
|
| Obc of (Obc.program -> unit)
|
|
|
|
| Obc_no_params of (Obc.program -> unit)
|
|
|
|
| Minils of (Minils.program -> unit)
|
|
|
|
| Minils_no_params of (Minils.program -> unit)
|
2010-07-13 14:03:39 +02:00
|
|
|
|
2010-07-15 11:37:30 +02:00
|
|
|
(** Writes a .epo file for program [p]. *)
|
2010-07-13 14:03:39 +02:00
|
|
|
let write_object_file p =
|
2011-02-07 14:24:17 +01:00
|
|
|
let filename = (Names.modul_to_string p.Minils.p_modname)^".epo" in
|
2010-07-13 14:03:39 +02:00
|
|
|
let epoc = open_out_bin filename in
|
|
|
|
output_value epoc p;
|
2010-07-27 13:31:13 +02:00
|
|
|
close_out epoc;
|
|
|
|
comment "Generating of object file"
|
2010-07-13 14:03:39 +02:00
|
|
|
|
2010-12-14 18:29:55 +01:00
|
|
|
(** Writes a .obc file for program [p]. *)
|
2010-07-13 14:03:39 +02:00
|
|
|
let write_obc_file p =
|
2011-02-07 14:24:17 +01:00
|
|
|
let obc_name = (Names.modul_to_string p.Obc.p_modname)^".obc" in
|
2010-07-13 14:03:39 +02:00
|
|
|
let obc = open_out obc_name in
|
|
|
|
Obc_printer.print obc p;
|
2010-07-27 13:31:13 +02:00
|
|
|
close_out obc;
|
|
|
|
comment "Generation of Obc code"
|
2010-07-13 14:03:39 +02:00
|
|
|
|
2011-04-14 13:53:30 +02:00
|
|
|
let no_conf () = ()
|
2011-03-21 14:30:19 +01:00
|
|
|
|
2011-04-14 13:53:30 +02:00
|
|
|
let targets = [ "c",(Obc_no_params Cmain.program, no_conf);
|
2011-04-19 09:49:00 +02:00
|
|
|
(*"java", (Obc Java_main.program, Java_main.java_conf);*)
|
2011-04-14 18:06:54 +02:00
|
|
|
"obc", (Obc write_obc_file, no_conf);
|
2011-04-14 13:53:30 +02:00
|
|
|
"obc_np", (Obc_no_params write_obc_file, no_conf);
|
|
|
|
"epo", (Minils write_object_file, no_conf) ]
|
2010-07-13 14:03:39 +02:00
|
|
|
|
|
|
|
let generate_target p s =
|
2010-08-17 17:51:11 +02:00
|
|
|
let print_unfolded p_list =
|
2010-09-02 17:52:42 +02:00
|
|
|
comment "Unfolding";
|
2010-12-16 16:52:23 +01:00
|
|
|
if !Compiler_options.verbose
|
|
|
|
then List.iter (Mls_printer.print stderr) p_list in
|
2010-07-15 11:37:30 +02:00
|
|
|
let target =
|
2011-04-14 13:53:30 +02:00
|
|
|
(try fst (List.assoc s targets)
|
2010-12-16 16:52:23 +01:00
|
|
|
with Not_found -> language_error s; raise Errors.Error) in
|
|
|
|
match target with
|
|
|
|
| Minils convert_fun ->
|
|
|
|
convert_fun p
|
|
|
|
| Obc convert_fun ->
|
|
|
|
let o = Mls2obc.program p in
|
2011-04-14 11:53:39 +02:00
|
|
|
let o = Obc_compiler.compile_program o in
|
2010-12-16 16:52:23 +01:00
|
|
|
convert_fun o
|
|
|
|
| Minils_no_params convert_fun ->
|
|
|
|
let p_list = Callgraph.program p in
|
|
|
|
List.iter convert_fun p_list
|
|
|
|
| Obc_no_params convert_fun ->
|
|
|
|
let p_list = Callgraph.program p in
|
|
|
|
let o_list = List.map Mls2obc.program p_list in
|
2011-04-18 15:38:42 +02:00
|
|
|
let o_list = List.map Obc_compiler.compile_program o_list in
|
2011-04-14 11:53:39 +02:00
|
|
|
List.iter convert_fun o_list
|
2011-03-08 13:41:28 +01:00
|
|
|
|
2011-04-14 13:53:30 +02:00
|
|
|
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
|
2010-07-13 14:03:39 +02:00
|
|
|
|
2010-12-16 16:52:23 +01:00
|
|
|
(** Translation into dataflow and sequential languages, defaults to obc. *)
|
2010-07-13 14:03:39 +02:00
|
|
|
let program p =
|
2010-12-16 16:52:23 +01:00
|
|
|
let targets = match !target_languages with
|
|
|
|
| [] -> ["obc"] (* by default, generate obc file *)
|
|
|
|
| l -> l in
|
|
|
|
let targets = if !create_object_file then "epo"::targets else targets in
|
|
|
|
List.iter (generate_target p) targets
|