2010-06-18 15:40:48 +02:00
|
|
|
(**************************************************************************)
|
|
|
|
(* *)
|
|
|
|
(* Heptagon *)
|
|
|
|
(* *)
|
|
|
|
(* Author : Marc Pouzet *)
|
|
|
|
(* Organization : Demons, LRI, University of Paris-Sud, Orsay *)
|
|
|
|
(* *)
|
|
|
|
(**************************************************************************)
|
2010-06-29 19:09:05 +02:00
|
|
|
|
2010-06-18 15:40:48 +02:00
|
|
|
|
|
|
|
open Misc
|
2010-09-09 00:35:06 +02:00
|
|
|
open Modules
|
2010-06-21 18:19:58 +02:00
|
|
|
open Location
|
2010-06-18 15:40:48 +02:00
|
|
|
open Compiler_utils
|
2010-09-15 09:38:52 +02:00
|
|
|
open Compiler_options
|
2010-09-09 00:35:06 +02:00
|
|
|
open Hept_compiler
|
2010-06-18 15:40:48 +02:00
|
|
|
|
2010-06-21 18:19:58 +02:00
|
|
|
|
2010-06-18 15:40:48 +02:00
|
|
|
|
2010-06-29 19:09:05 +02:00
|
|
|
let compile_impl modname filename =
|
2010-06-18 15:40:48 +02:00
|
|
|
(* input and output files *)
|
2010-07-27 14:00:15 +02:00
|
|
|
let source_name = filename ^ ".ept" in
|
|
|
|
let filename = String.uncapitalize filename
|
2010-06-18 15:40:48 +02:00
|
|
|
and obj_interf_name = filename ^ ".epci"
|
2010-07-13 14:03:39 +02:00
|
|
|
and mls_name = filename ^ ".mls" in
|
2010-06-18 15:40:48 +02:00
|
|
|
|
2010-07-16 17:33:14 +02:00
|
|
|
let ic, lexbuf = lexbuf_from_file source_name
|
2010-06-18 15:40:48 +02:00
|
|
|
and itc = open_out_bin obj_interf_name
|
2010-07-13 14:03:39 +02:00
|
|
|
and mlsc = open_out mls_name in
|
2010-06-18 15:40:48 +02:00
|
|
|
|
|
|
|
let close_all_files () =
|
|
|
|
close_in ic;
|
|
|
|
close_out itc;
|
2010-07-13 14:03:39 +02:00
|
|
|
close_out mlsc in
|
2010-06-18 15:40:48 +02:00
|
|
|
|
|
|
|
try
|
2010-09-15 09:38:52 +02:00
|
|
|
Initial.initialize modname;
|
2010-07-27 14:00:15 +02:00
|
|
|
add_include (Filename.dirname filename);
|
2010-06-18 15:40:48 +02:00
|
|
|
|
|
|
|
(* Parsing of the file *)
|
2010-09-09 00:35:06 +02:00
|
|
|
let p = do_silent_pass "Parsing" (parse_implementation modname) lexbuf in
|
2010-06-18 15:40:48 +02:00
|
|
|
|
|
|
|
(* Convert the parse tree to Heptagon AST *)
|
2010-09-09 00:35:06 +02:00
|
|
|
let p = do_pass "Scoping" Hept_scoping.translate_program p pp in
|
2010-06-18 15:40:48 +02:00
|
|
|
|
2010-06-26 16:53:25 +02:00
|
|
|
(* Process the Heptagon AST *)
|
2010-09-09 00:35:06 +02:00
|
|
|
let p = compile_impl pp p in
|
2010-09-10 14:29:13 +02:00
|
|
|
output_value itc (Modules.current_module ());
|
2010-06-26 16:53:25 +02:00
|
|
|
|
2010-07-27 13:31:13 +02:00
|
|
|
(* Set pretty printer to the Minils one *)
|
|
|
|
let pp = Mls_compiler.pp in
|
|
|
|
|
2010-06-26 16:53:25 +02:00
|
|
|
(* Compile Heptagon to MiniLS *)
|
2010-09-09 00:35:06 +02:00
|
|
|
let p = do_pass "Translation into MiniLs" Hept2mls.program p pp in
|
2010-06-26 16:53:25 +02:00
|
|
|
Mls_printer.print mlsc p;
|
|
|
|
|
|
|
|
(* Process the MiniLS AST *)
|
2010-07-14 03:45:38 +02:00
|
|
|
let p = Mls_compiler.compile pp p in
|
2010-06-26 16:53:25 +02:00
|
|
|
|
2010-07-21 17:24:18 +02:00
|
|
|
(* Generate the sequential code *)
|
|
|
|
Mls2seq.program p;
|
2010-06-26 16:53:25 +02:00
|
|
|
|
|
|
|
close_all_files ()
|
|
|
|
|
2010-09-09 00:35:06 +02:00
|
|
|
with x -> close_all_files (); raise x
|
2010-06-29 19:09:05 +02:00
|
|
|
|
2010-09-30 21:40:04 +02:00
|
|
|
let read_qualname f = Arg.String (fun s -> f (Names.qualname_of_string s))
|
2010-06-18 15:40:48 +02:00
|
|
|
|
|
|
|
let main () =
|
|
|
|
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;
|
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-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;
|
2010-09-15 09:53:20 +02:00
|
|
|
"-itfusion", Arg.Set do_iterator_fusion, doc_itfusion;
|
2010-06-18 15:40:48 +02:00
|
|
|
]
|
2010-09-09 00:35:06 +02:00
|
|
|
(compile compile_impl)
|
2010-06-18 15:40:48 +02:00
|
|
|
errmsg;
|
|
|
|
with
|
2010-09-15 09:38:52 +02:00
|
|
|
| Errors.Error -> exit 2;;
|
2010-06-18 15:40:48 +02:00
|
|
|
|
|
|
|
main ()
|