compilers refactoring. and bug fix of heptc vs heptcheck.

master
Léonard Gérard 14 years ago
parent 2127a1c2d4
commit 0c5a8d8ffe

@ -6,8 +6,32 @@
(* Organization : Demons, LRI, University of Paris-Sud, Orsay *)
(* *)
(**************************************************************************)
open Misc
open Compiler_utils
open Location
let pp p = if !verbose then Hept_printer.print stdout p
let parse parsing_fun lexing_fun lexbuf =
try
parsing_fun lexing_fun lexbuf
with
| Hept_lexer.Lexical_error(err, pos1, pos2) ->
lexical_error err (Loc(pos1, pos2))
| Parsing.Parse_error ->
let pos1 = Lexing.lexeme_start lexbuf
and pos2 = Lexing.lexeme_end lexbuf in
let l = Loc(pos1,pos2) in
syntax_error l
let parse_implementation lexbuf =
parse Hept_parser.program Hept_lexer.token lexbuf
let parse_interface lexbuf =
parse Hept_parser.interface Hept_lexer.token lexbuf
let compile_impl pp p =
(* Typing *)
@ -43,8 +67,49 @@ let compile_impl pp p =
(* Return the transformed AST *)
p
let compile_interface modname filename =
(* input and output files *)
let source_name = filename ^ ".epi" in
let obj_interf_name = filename ^ ".epci" in
let compile_interface l =
Interface.Type.main l;
if !print_types then Interface.Printer.print stdout;
l
let ic = open_in source_name in
let itc = open_out_bin obj_interf_name in
let close_all_files () =
close_in ic;
close_out itc in
try
init_compiler modname source_name ic;
(* Parsing of the file *)
let lexbuf = Lexing.from_channel ic in
let l = parse_interface lexbuf in
(* Convert the parse tree to Heptagon AST *)
let l = Scoping.translate_interface l in
(* Compile*)
Interface.Type.main l;
if !print_types then Interface.Printer.print stdout;
Modules.write itc;
close_all_files ()
with
| x -> close_all_files (); raise x
let compile compile_implementation file =
if Filename.check_suffix file ".ept"
then
let filename = Filename.chop_suffix file ".ept" in
let modname = String.capitalize(Filename.basename filename) in
compile_implementation modname filename
else if Filename.check_suffix file ".epi"
then
let filename = Filename.chop_suffix file ".epi" in
let modname = String.capitalize(Filename.basename filename) in
compile_interface modname filename
else
raise (Arg.Bad ("Unknow file type: " ^ file))

@ -11,29 +11,11 @@
open Misc
open Compiler_utils
open Hept_compiler
open Location
let pp = Hept_printer.print stdout
let parse parsing_fun lexing_fun lexbuf =
try
parsing_fun lexing_fun lexbuf
with
| Hept_lexer.Lexical_error(err, pos1, pos2) ->
lexical_error err (Loc(pos1, pos2))
| Parsing.Parse_error ->
let pos1 = Lexing.lexeme_start lexbuf
and pos2 = Lexing.lexeme_end lexbuf in
let l = Loc(pos1,pos2) in
syntax_error l
let parse_implementation lexbuf =
parse Hept_parser.program Hept_lexer.token lexbuf
let parse_interface lexbuf =
parse Hept_parser.interface Hept_lexer.token lexbuf
let compile_impl modname filename =
let check_implementation modname filename =
(* input and output files *)
let source_name = filename ^ ".ept" in
@ -51,66 +33,17 @@ let compile_impl modname filename =
(* Convert the parse tree to Heptagon AST *)
let p = Scoping.translate_program p in
if !verbose
then begin
comment "Parsing";
pp p
end;
comment "Parsing";
pp p;
(* Call the compiler*)
let p = Hept_compiler.compile_impl pp p in
comment "Checking";
if !verbose
then begin
comment "Checking"
end;
close_all_files ()
with x -> close_all_files (); raise x
let compile_interface modname filename =
(* input and output files *)
let source_name = filename ^ ".epi" in
let obj_interf_name = filename ^ ".epci" in
let ic = open_in source_name in
let itc = open_out_bin obj_interf_name in
let close_all_files () =
close_in ic;
close_out itc in
try
init_compiler modname source_name ic;
(* Parsing of the file *)
let lexbuf = Lexing.from_channel ic in
let l = parse_interface lexbuf in
(* Convert the parse tree to Heptagon AST *)
let l = Scoping.translate_interface l in
(* Call the compiler*)
let l = Hept_compiler.compile_interface l in
Modules.write itc;
close_all_files ()
with
| x -> close_all_files (); raise x
let compile file =
if Filename.check_suffix file ".ept"
then
let filename = Filename.chop_suffix file ".ept" in
let modname = String.capitalize(Filename.basename filename) in
compile_impl modname filename
else if Filename.check_suffix file ".epi"
then
let filename = Filename.chop_suffix file ".epi" in
let modname = String.capitalize(Filename.basename filename) in
compile_interface modname filename
else
raise (Arg.Bad ("Unknow file type: " ^ file))
let main () =
try
@ -126,7 +59,7 @@ let main () =
"-noinit", Arg.Clear init, doc_noinit;
"-fti", Arg.Set full_type_info, doc_full_type_info;
]
compile
(compile check_implementation)
errmsg;
with
| Misc.Error -> exit 2;;

@ -6,46 +6,16 @@
(* Organization : Demons, LRI, University of Paris-Sud, Orsay *)
(* *)
(**************************************************************************)
(* the main *)
open Misc
open Location
open Compiler_utils
open Heptcheck
open Hept_compiler
let interface modname filename =
(* input and output files *)
let source_name = filename ^ ".epi"
and obj_interf_name = filename ^ ".epci" in
let ic = open_in source_name
and itc = open_out_bin obj_interf_name in
let close_all_files () =
close_in ic;
close_out itc in
try
init_compiler modname source_name ic;
(* Parsing of the file *)
let lexbuf = Lexing.from_channel ic in
let l = parse_interface lexbuf in
(* Convert the parse tree to Heptagon AST *)
let l = Scoping.translate_interface l in
(* Call the compiler*)
let l = Hept_compiler.compile_interface l in
Modules.write itc;
close_all_files ()
with
| x -> close_all_files (); raise x
let compile modname filename =
let compile_impl modname filename =
(* input and output files *)
let source_name = filename ^ ".ept"
and obj_interf_name = filename ^ ".epci"
@ -69,19 +39,15 @@ let compile modname filename =
try
init_compiler modname source_name ic;
let pp = Hept_printer.print stdout in
(* Parsing of the file *)
let lexbuf = Lexing.from_channel ic in
let p = parse_implementation lexbuf in
(* Convert the parse tree to Heptagon AST *)
let p = Scoping.translate_program p in
if !verbose
then begin
comment "Parsing";
pp p
end;
comment "Parsing";
pp p;
(* Process the Heptagon AST *)
let p = Hept_compiler.compile_impl pp p in
@ -91,7 +57,7 @@ let compile modname filename =
let p = Hept2mls.program p in
let pp = Mls_printer.print stdout in
if !verbose then comment "Translation into MiniLs";
comment "Translation into MiniLs";
Mls_printer.print mlsc p;
(* Process the MiniLS AST *)
@ -99,7 +65,7 @@ let compile modname filename =
(* Compile MiniLS to Obc *)
let o = Mls2obc.program p in
(*if !verbose then*) comment "Translation into Obc";
comment "Translation into Obc";
Obc.Printer.print obc o;
let pp = Obc.Printer.print stdout in
@ -113,19 +79,7 @@ let compile modname filename =
with
| x -> close_all_files (); raise x
let compile file =
if Filename.check_suffix file ".ept"
then
let filename = Filename.chop_suffix file ".ept" in
let modname = String.capitalize(Filename.basename filename) in
compile modname filename
else if Filename.check_suffix file ".epi"
then
let filename = Filename.chop_suffix file ".epi" in
let modname = String.capitalize(Filename.basename filename) in
interface modname filename
else
raise (Arg.Bad ("don't know what to do with " ^ file))
let main () =
try
@ -145,7 +99,7 @@ let main () =
"-noinit", Arg.Clear init, doc_noinit;
"-fti", Arg.Set full_type_info, doc_full_type_info;
]
compile
(compile compile_impl)
errmsg;
with
| Misc.Error -> exit 2;;

11
heptc

@ -2,13 +2,16 @@
#Small wrapper to deal with compilation of the compiler and the stdlib.
SCRIPT_DIR=`dirname $0`
COMPILER_DIR=compiler #relative to the script_dir
COMPILER=heptc.byte
COMPILER_DIR=compiler
HEPTC=$COMPILER_DIR/$COMPILER
cd $SCRIPT_DIR
if [ ! -x $HEPTC ] #compile the compiler
then
cd compiler
cd $COMPILER_DIR
ocamlbuild $COMPILER
cd -
fi
@ -18,4 +21,6 @@ then
$HEPTC -nopervasives lib/pervasives.epi
fi
$HEPTC -stdlib lib "$@" #call the compiler with the passed arguments.
cd -
$SCRIPT_DIR/$HEPTC -stdlib $SCRIPT_DIR/lib "$@" #call the compiler with the passed arguments.

Loading…
Cancel
Save