2012-06-27 18:09:30 +02:00
|
|
|
(***********************************************************************)
|
|
|
|
(* *)
|
|
|
|
(* Heptagon *)
|
|
|
|
(* *)
|
|
|
|
(* Gwenael Delaval, LIG/INRIA, UJF *)
|
|
|
|
(* Leonard Gerard, Parkas, ENS *)
|
|
|
|
(* Adrien Guatto, Parkas, ENS *)
|
|
|
|
(* Cedric Pasteur, Parkas, ENS *)
|
2012-06-29 01:43:15 +02:00
|
|
|
(* Marc Pouzet, Parkas, ENS *)
|
2012-06-27 18:09:30 +02:00
|
|
|
(* *)
|
|
|
|
(* Copyright 2012 ENS, INRIA, UJF *)
|
|
|
|
(* *)
|
|
|
|
(* This file is part of the Heptagon compiler. *)
|
|
|
|
(* *)
|
|
|
|
(* Heptagon is free software: you can redistribute it and/or modify it *)
|
|
|
|
(* under the terms of the GNU General Public License as published by *)
|
|
|
|
(* the Free Software Foundation, either version 3 of the License, or *)
|
|
|
|
(* (at your option) any later version. *)
|
|
|
|
(* *)
|
|
|
|
(* Heptagon is distributed in the hope that it will be useful, *)
|
|
|
|
(* but WITHOUT ANY WARRANTY; without even the implied warranty of *)
|
|
|
|
(* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *)
|
|
|
|
(* GNU General Public License for more details. *)
|
|
|
|
(* *)
|
|
|
|
(* You should have received a copy of the GNU General Public License *)
|
|
|
|
(* along with Heptagon. If not, see <http://www.gnu.org/licenses/> *)
|
|
|
|
(* *)
|
|
|
|
(***********************************************************************)
|
2010-06-29 19:09:05 +02:00
|
|
|
|
2010-06-18 15:40:48 +02:00
|
|
|
|
|
|
|
open Compiler_utils
|
2010-09-15 09:38:52 +02:00
|
|
|
open Compiler_options
|
2010-06-18 15:40:48 +02:00
|
|
|
|
2010-06-21 18:19:58 +02:00
|
|
|
|
2011-01-07 17:16:50 +01:00
|
|
|
let compile_interface modname source_f =
|
2010-06-18 15:40:48 +02:00
|
|
|
|
2011-01-07 17:16:50 +01:00
|
|
|
(* output file names *)
|
2017-03-14 12:24:29 +01:00
|
|
|
let output = String.uncapitalize_ascii modname in
|
2011-01-07 17:16:50 +01:00
|
|
|
let epci_f = output ^ ".epci" in
|
2010-06-18 15:40:48 +02:00
|
|
|
|
2011-01-07 17:16:50 +01:00
|
|
|
(* input/output channels *)
|
|
|
|
let source_c, lexbuf = lexbuf_from_file source_f in
|
|
|
|
let epci_c = open_out_bin epci_f in
|
|
|
|
let close_all_files () = close_in source_c; close_out epci_c in
|
2010-06-18 15:40:48 +02:00
|
|
|
|
|
|
|
try
|
2011-01-07 17:16:50 +01:00
|
|
|
(* Process the [lexbuf] to an Heptagon AST *)
|
2011-09-05 14:50:49 +02:00
|
|
|
let p = Hept_parser_scoper.parse_interface modname lexbuf in
|
2011-01-07 17:16:50 +01:00
|
|
|
if !print_types then Global_printer.print_interface Format.std_formatter;
|
2011-09-05 14:50:49 +02:00
|
|
|
|
|
|
|
(* Process the interface *)
|
2011-09-06 11:54:03 +02:00
|
|
|
let p = Hept_compiler.compile_interface p in
|
|
|
|
(* Output the .epci *)
|
2011-01-07 17:16:50 +01:00
|
|
|
output_value epci_c (Modules.current_module ());
|
2011-09-06 11:54:03 +02:00
|
|
|
(* Translate to Obc *)
|
|
|
|
let p = Hept2mls.interface p in
|
|
|
|
(* Generate the sequential code *)
|
|
|
|
Mls2seq.interface p;
|
2011-01-07 17:16:50 +01:00
|
|
|
close_all_files ()
|
|
|
|
with
|
|
|
|
| x -> close_all_files (); raise x
|
2010-06-18 15:40:48 +02:00
|
|
|
|
2011-01-07 17:16:50 +01:00
|
|
|
(* [modname] is the module name, [source_f] is the source file *)
|
|
|
|
let compile_program modname source_f =
|
2010-06-18 15:40:48 +02:00
|
|
|
|
2011-01-07 17:16:50 +01:00
|
|
|
(* output file names *)
|
2017-03-14 12:24:29 +01:00
|
|
|
let output = String.uncapitalize_ascii modname in
|
2011-01-07 17:16:50 +01:00
|
|
|
let epci_f = output ^ ".epci" in
|
|
|
|
let mls_f = output ^ ".mls" in
|
2017-05-23 11:37:30 +02:00
|
|
|
let log_f = output ^ ".log" in
|
2010-06-18 15:40:48 +02:00
|
|
|
|
2011-01-07 17:16:50 +01:00
|
|
|
(* input/output channels *)
|
|
|
|
let source_c, lexbuf = lexbuf_from_file source_f in
|
|
|
|
let epci_c = open_out_bin epci_f in
|
|
|
|
let mls_c = open_out mls_f in
|
2017-05-23 11:37:30 +02:00
|
|
|
let log_c = open_out log_f in
|
|
|
|
let close_all_files () =
|
|
|
|
close_in source_c;
|
|
|
|
close_out epci_c;
|
|
|
|
close_out mls_c;
|
|
|
|
close_out log_c
|
|
|
|
in
|
2011-01-07 17:16:50 +01:00
|
|
|
|
|
|
|
try
|
2011-04-14 13:53:30 +02:00
|
|
|
(* Activates passes according to the backend used *)
|
|
|
|
Mls2seq.load_conf ();
|
2012-03-07 17:44:57 +01:00
|
|
|
(* Record timing information *)
|
|
|
|
Compiler_timings.start_compiling modname;
|
2011-01-07 17:16:50 +01:00
|
|
|
(* Process the [lexbuf] to an Heptagon AST *)
|
2017-05-23 11:37:30 +02:00
|
|
|
let p = Hept_parser_scoper.parse_program modname lexbuf log_c in
|
2011-01-07 17:16:50 +01:00
|
|
|
(* Process the Heptagon AST *)
|
2017-05-23 11:37:30 +02:00
|
|
|
let p = Hept_compiler.compile_program p log_c in
|
2011-01-07 17:16:50 +01:00
|
|
|
(* Compile Heptagon to MiniLS *)
|
2017-05-23 11:37:30 +02:00
|
|
|
let p = do_pass "Translation into MiniLS"
|
|
|
|
Hept2mls.program p (Mls_compiler.pp log_c) in
|
2011-01-07 17:16:50 +01:00
|
|
|
(* Output the .mls *)
|
2012-03-07 17:44:57 +01:00
|
|
|
do_silent_pass "MiniLS serialization" (fun () -> Mls_printer.print mls_c p) ();
|
2011-01-07 17:16:50 +01:00
|
|
|
(* Process the MiniLS AST *)
|
2017-05-23 11:37:30 +02:00
|
|
|
let p = Mls_compiler.compile_program p log_c in
|
2011-11-24 11:41:11 +01:00
|
|
|
(* Output the .epci *)
|
|
|
|
output_value epci_c (Modules.current_module ());
|
2011-01-07 17:16:50 +01:00
|
|
|
(* Generate the sequential code *)
|
2017-05-23 11:37:30 +02:00
|
|
|
Mls2seq.program p log_c;
|
2012-03-07 17:44:57 +01:00
|
|
|
close_all_files ();
|
|
|
|
Compiler_timings.report_statistics ()
|
2011-01-07 17:16:50 +01:00
|
|
|
with x -> close_all_files (); raise x
|
2010-06-26 16:53:25 +02:00
|
|
|
|
2010-07-27 13:31:13 +02:00
|
|
|
|
2010-06-26 16:53:25 +02:00
|
|
|
|
2011-01-07 17:16:50 +01:00
|
|
|
let compile source_f =
|
2017-03-14 12:24:29 +01:00
|
|
|
let modname = source_f
|
|
|
|
|> Filename.basename
|
|
|
|
|> Filename.chop_extension
|
|
|
|
|> String.capitalize_ascii in
|
2011-02-07 14:24:17 +01:00
|
|
|
let modul = Names.modul_of_string modname in
|
|
|
|
Initial.initialize modul;
|
2011-01-07 17:16:50 +01:00
|
|
|
source_f |> Filename.dirname |> add_include;
|
2011-11-21 01:37:15 +01:00
|
|
|
check_options ();
|
2011-01-07 17:16:50 +01:00
|
|
|
match Misc.file_extension source_f with
|
|
|
|
| "ept" -> compile_program modname source_f
|
|
|
|
| "epi" -> compile_interface modname source_f
|
|
|
|
| ext -> raise (Arg.Bad ("Unknow file type: " ^ ext ^ " for file: " ^ source_f))
|
2010-06-26 16:53:25 +02:00
|
|
|
|
2010-06-29 19:09:05 +02:00
|
|
|
|
2010-06-18 15:40:48 +02:00
|
|
|
|
2011-01-07 17:16:50 +01:00
|
|
|
(** [main] function to be launched *)
|
2010-06-18 15:40:48 +02:00
|
|
|
let main () =
|
2014-10-28 16:34:58 +01:00
|
|
|
let read_qualname f =
|
|
|
|
Arg.String (fun s -> f (try Names.qualname_of_string s with
|
|
|
|
| Exit -> raise (Arg.Bad ("Invalid name: "^ s)))) in
|
2010-06-18 15:40:48 +02:00
|
|
|
try
|
|
|
|
Arg.parse
|
|
|
|
[
|
|
|
|
"-v",Arg.Set verbose, doc_verbose;
|
|
|
|
"-version", Arg.Unit show_version, doc_version;
|
|
|
|
"-i", Arg.Set print_types, doc_print_types;
|
|
|
|
"-I", Arg.String add_include, doc_include;
|
|
|
|
"-where", Arg.Unit locate_stdlib, doc_locate_stdlib;
|
|
|
|
"-stdlib", Arg.String set_stdlib, doc_stdlib;
|
2010-07-13 14:03:39 +02:00
|
|
|
"-c", Arg.Set create_object_file, doc_object_file;
|
2010-10-04 00:33:05 +02:00
|
|
|
"-s", Arg.String set_simulation_node, doc_sim;
|
2011-05-12 10:08:13 +02:00
|
|
|
"-hepts", Arg.Set hepts_simulation, doc_hepts;
|
2011-03-10 23:00:18 +01:00
|
|
|
"-bool", Arg.Set boolean, doc_boolean;
|
|
|
|
"-deadcode", Arg.Set deadcode, doc_deadcode;
|
2010-09-30 21:44:18 +02:00
|
|
|
"-tomato", Arg.Set tomato, doc_tomato;
|
|
|
|
"-tomanode", read_qualname add_tomato_node, doc_tomato;
|
|
|
|
"-tomacheck", read_qualname add_tomato_check, "";
|
2010-09-30 21:40:04 +02:00
|
|
|
"-inline", read_qualname add_inlined_node, doc_inline;
|
2010-07-19 13:20:11 +02:00
|
|
|
"-flatten", Arg.Set flatten, doc_flatten;
|
2010-10-04 00:33:05 +02:00
|
|
|
"-assert", Arg.String add_assert, doc_assert;
|
2010-06-18 15:40:48 +02:00
|
|
|
"-nopervasives", Arg.Unit set_no_pervasives, doc_no_pervasives;
|
|
|
|
"-target", Arg.String add_target_language, doc_target;
|
|
|
|
"-targetpath", Arg.String set_target_path, doc_target_path;
|
2010-12-14 18:29:55 +01:00
|
|
|
"-nocaus", Arg.Clear causality, doc_nocaus;
|
2010-06-26 16:53:25 +02:00
|
|
|
"-noinit", Arg.Clear init, doc_noinit;
|
2010-06-18 15:40:48 +02:00
|
|
|
"-fti", Arg.Set full_type_info, doc_full_type_info;
|
2011-11-02 13:14:07 +01:00
|
|
|
"-statefuli", Arg.Set stateful_info, doc_stateful_info;
|
2010-12-14 19:34:09 +01:00
|
|
|
"-fname", Arg.Set full_name, doc_full_name;
|
2012-11-26 09:44:23 +01:00
|
|
|
"-nbvars", Arg.Set nbvars, doc_nbvars;
|
2010-09-15 09:53:20 +02:00
|
|
|
"-itfusion", Arg.Set do_iterator_fusion, doc_itfusion;
|
2012-06-20 09:17:13 +02:00
|
|
|
"-strict_ssa", Arg.Unit set_strict_ssa, doc_strict_ssa;
|
2017-03-03 11:41:57 +01:00
|
|
|
"-nosink", Arg.Set nosink, doc_nosink;
|
2011-09-09 16:05:44 +02:00
|
|
|
"-memalloc", Arg.Unit do_mem_alloc_and_typing, doc_memalloc;
|
|
|
|
"-only-memalloc", Arg.Set do_mem_alloc, doc_memalloc_only;
|
|
|
|
"-only-linear", Arg.Set do_linear_typing, doc_linear_only;
|
2011-11-02 17:23:23 +01:00
|
|
|
"-old-scheduler", Arg.Set use_old_scheduler, doc_interf_scheduler;
|
2012-02-08 16:16:41 +01:00
|
|
|
"-unroll", Arg.Set unroll_loops, doc_unroll;
|
2012-01-23 13:36:24 +01:00
|
|
|
"-O", Arg.Unit do_optim, doc_optim;
|
|
|
|
"-mall", Arg.Set interf_all, doc_interf_all;
|
2012-03-07 17:44:57 +01:00
|
|
|
"-time", Arg.Set time_passes, doc_time_passes;
|
2015-09-18 13:48:58 +02:00
|
|
|
"-abstract-infinite", Arg.Set abstract_infinite, doc_abstract_infinite;
|
2015-09-18 13:26:48 +02:00
|
|
|
("-Wno-untranslatable", Arg.Clear warn_untranslatable,
|
|
|
|
doc_no_warn_untranslat);
|
2015-09-18 13:48:58 +02:00
|
|
|
("-Wno-abstract", Arg.Clear warn_abstractions,
|
|
|
|
doc_no_warn_abstractions);
|
2010-06-18 15:40:48 +02:00
|
|
|
]
|
2011-01-07 17:16:50 +01:00
|
|
|
compile errmsg;
|
2010-06-18 15:40:48 +02:00
|
|
|
with
|
2010-09-15 09:38:52 +02:00
|
|
|
| Errors.Error -> exit 2;;
|
2010-06-18 15:40:48 +02:00
|
|
|
|
2011-01-07 17:16:50 +01:00
|
|
|
|
2017-03-03 11:41:57 +01:00
|
|
|
(* Launch the [main] *)
|
2010-06-18 15:40:48 +02:00
|
|
|
main ()
|