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),
|
|
|
|
with or without static parameters*)
|
|
|
|
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 =
|
|
|
|
let filename = (filename_of_name p.Minils.p_modname)^".epo" in
|
|
|
|
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-07-15 11:37:30 +02:00
|
|
|
(** Writes a .epo file for program [p]. *)
|
2010-07-13 14:03:39 +02:00
|
|
|
let write_obc_file p =
|
|
|
|
let obc_name = (filename_of_name p.Obc.p_modname)^".obc" in
|
|
|
|
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
|
|
|
|
2010-07-15 11:37:30 +02:00
|
|
|
let targets = [ "c", Obc_no_params Cmain.program;
|
|
|
|
"obc", Obc write_obc_file;
|
|
|
|
"obc_np", Obc_no_params write_obc_file;
|
|
|
|
"epo", Minils write_object_file ]
|
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-09-15 09:38:52 +02:00
|
|
|
if !Compiler_options.verbose then
|
|
|
|
List.iter (Mls_printer.print stderr) p_list in
|
2010-08-17 17:51:11 +02:00
|
|
|
|
2010-07-15 11:37:30 +02:00
|
|
|
let target =
|
2010-07-13 15:37:29 +02:00
|
|
|
(try List.assoc s targets
|
2010-09-15 09:38:52 +02:00
|
|
|
with Not_found -> language_error s; raise Errors.Error) in
|
2010-07-15 11:37:30 +02:00
|
|
|
match target with
|
|
|
|
| Minils convert_fun ->
|
2010-07-13 15:37:29 +02:00
|
|
|
convert_fun p
|
2010-07-15 11:37:30 +02:00
|
|
|
| Obc convert_fun ->
|
2010-07-13 15:37:29 +02:00
|
|
|
let o = Mls2obc.program p in
|
|
|
|
convert_fun o
|
2010-07-15 11:37:30 +02:00
|
|
|
| Minils_no_params convert_fun ->
|
2010-08-26 13:55:29 +02:00
|
|
|
let p_list = Callgraph.program p in
|
2010-07-13 15:37:29 +02:00
|
|
|
List.iter convert_fun p_list
|
2010-07-15 11:37:30 +02:00
|
|
|
| Obc_no_params convert_fun ->
|
2010-08-26 13:55:29 +02:00
|
|
|
let p_list = Callgraph.program p in
|
2010-07-13 15:37:29 +02:00
|
|
|
let o_list = List.map Mls2obc.program p_list in
|
2010-08-17 17:51:11 +02:00
|
|
|
print_unfolded p_list;
|
2010-09-02 17:52:42 +02:00
|
|
|
comment "Translation to Obc";
|
2010-09-15 09:38:52 +02:00
|
|
|
if !verbose then
|
2010-09-13 10:10:40 +02:00
|
|
|
List.iter (Obc_printer.print stdout) o_list;
|
2010-09-02 17:52:42 +02:00
|
|
|
List.iter convert_fun o_list
|
2010-07-13 14:03:39 +02:00
|
|
|
|
|
|
|
let program p =
|
|
|
|
(* Translation into dataflow and sequential languages *)
|
|
|
|
let targets =
|
|
|
|
if !create_object_file then
|
|
|
|
["epo"]
|
|
|
|
else
|
|
|
|
match !target_languages with
|
2010-07-15 11:37:30 +02:00
|
|
|
| [] -> ["obc"]; (* by default, generate obc file *)
|
2010-07-13 14:03:39 +02:00
|
|
|
| l -> l
|
|
|
|
in
|
2010-07-15 11:37:30 +02:00
|
|
|
List.iter (generate_target p) targets
|