Skip to content
Snippets Groups Projects
Commit 2544e1b3 authored by Erwan Jahier's avatar Erwan Jahier
Browse files

Do not try to guess a default node (i.e., the name of the file) when

no node is provided at  the command-line.  Instead, compile all items
even if the --compile-all-items option is not provided.
parent 529ebee5
No related branches found
No related tags found
No related merge requests found
......@@ -105,8 +105,6 @@ n'est pas le cas pour l'instant...
*** facile
* --compile-all-items devrait etre effectué par default quand -n
n'est pas fournit, plutot que de tenter un nom de noeud.
* "1..2" ne marche pas car le lexer renvoie
"1." ".2"
......
(** Time-stamp: <modified the 28/05/2008 (at 14:08) by Erwan Jahier> *)
(** Time-stamp: <modified the 30/05/2008 (at 16:08) by Erwan Jahier> *)
open Lxm
......@@ -15,38 +15,39 @@ let rec first_pack_in =
open Global
let (doit : SyntaxTree.pack_or_model list -> Ident.idref -> unit) =
fun srclist main_node ->
let (doit : SyntaxTree.pack_or_model list -> Ident.idref option -> unit) =
fun srclist main_node ->
let syntax_tab = SyntaxTab.create srclist in
(* Pour chaque package, on a un solveur de rfrences
globales, pour les types, const et node :
- les rfrences pointes (p::n) sont recherches
directement dans la syntax_tab puisqu'il n'y a pas
d'ambiguit
- les rfrences simples sont recherches :
. dans le pack lui-mme
. dans un des packs dclars "uses", avec
priorit dans l'ordre
*)
let lzcomp = LazyCompiler.create syntax_tab in
if Verbose.get_level () > 2 then SyntaxTab.dump syntax_tab;
Ident.set_dft_pack_name (first_pack_in srclist);
(* la cle "absolue" du main node (pas d'args statiques) *)
let main_node_key =
CompiledData.make_simple_node_key (Ident.long_of_idref main_node)
in
Verbose.printf
"-- MAIN NODE: \"%s\"\n"
(CompiledDataDump.string_of_node_key main_node_key);
(* Pour chaque package, on a un solveur de rfrences
globales, pour les types, const et node :
- les rfrences pointes (p::n) sont recherches
directement dans la syntax_tab puisqu'il n'y a pas
d'ambiguit
- les rfrences simples sont recherches :
. dans le pack lui-mme
. dans un des packs dclars "uses", avec
priorit dans l'ordre
*)
let lzcomp = LazyCompiler.create syntax_tab in
if Global.vars.compile_all_items then
LazyCompiler.compile_all lzcomp
else
ignore(LazyCompiler.node_check lzcomp main_node_key
(match Ident.pack_of_idref main_node with
| None -> Lxm.dummy ""
| Some pn -> Lxm.dummy (Ident.pack_name_to_string pn)))
match main_node with
| None -> LazyCompiler.compile_all lzcomp
| Some main_node ->
(* la cle "absolue" du main node (pas d'args statiques) *)
let main_node_key =
CompiledData.make_simple_node_key (Ident.long_of_idref main_node)
in
Verbose.printf
"-- MAIN NODE: \"%s\"\n"
(CompiledDataDump.string_of_node_key main_node_key);
if Global.vars.compile_all_items then
LazyCompiler.compile_all lzcomp
else
ignore(LazyCompiler.node_check lzcomp main_node_key
(match Ident.pack_of_idref main_node with
| None -> Lxm.dummy ""
| Some pn -> Lxm.dummy (Ident.pack_name_to_string pn)))
(** Time-stamp: <modified the 30/05/2008 (at 15:37) by Erwan Jahier> *)
(** Time-stamp: <modified the 30/05/2008 (at 16:41) by Erwan Jahier> *)
(** Here follows a description of the different modules used by this lus2lic compiler.
......@@ -50,8 +50,6 @@ open Parsing
open Format
open Global
let usage_msg =
"usage: "^(Version.tool)^" [options] <lustre files> | "^(Version.tool)^" -help"
(*---------------------------------------------------------
Les args sont des variables GLOBALES
......@@ -61,55 +59,63 @@ let print_version = function (x: unit) -> (
print_string (Version.str ^ "\n")
)
let rec set_infile = function (x:string) -> (
if ( Global.vars.main_node = "" ) then (
(* default node name = file name *)
try
Global.vars.main_node <- Filename.chop_extension (Filename.basename x)
with _ ->
print_string ("*** '" ^ x ^ "': Bad file name\n");
exit 1
);
Global.vars.infiles <- Global.vars.infiles@[x]
)
and arg_list = [
( "-version", Arg.Unit(fun x -> print_version () ; exit 0),
"\tprints the current version then exit"
);
( "-o", Arg.String(fun x -> Global.vars.outfile <- x),
"\t<file name> set the output file name"
);
( "-n", Arg.String(fun x -> Global.vars.main_node <- x),
"\t<node> set the main node"
);
( "--compile-all-items", Arg.Unit
(function x -> Global.vars.compile_all_items <- true),
"\tcompile all items of the program"
);
( "-unit", Arg.Unit (fun x -> Global.vars.run_unit_test <- true),
"\truns some (internal) unit tests"
);
( "-v", Arg.Unit (fun vl -> Verbose.set_level 1 ),
"\tset verbose mode on (i.e., verbose level = 1)"
);
( "-vl", Arg.Int(fun vl -> Verbose.set_level vl ),
"\t<int> set verbose level"
);
("-h", Arg.Unit (fun _ -> (Arg.usage arg_list usage_msg; exit 0)),
"\tdisplays this list of options."
);
("-help", Arg.Unit (fun _ -> (Arg.usage arg_list usage_msg; exit 0)),"");
("-help", Arg.Unit (fun _ -> (Arg.usage arg_list usage_msg; exit 0)),"" )
]
and
parse_args () = (
Arg.parse arg_list (* liste des options *)
set_infile (* arg par defaut = fichier d'entree *)
usage_msg (* message d'erreur *)
;
()
)
let usage_msg =
"usage: "^(Version.tool)^" [options] <lustre files> | "^(Version.tool)^" -help"
let rec set_infile = function (x:string) -> (
Global.vars.infiles <- Global.vars.infiles@[x]
)
and arg_list = [
( "--version", Arg.Unit(fun x -> print_version () ; exit 0),
"\tPrint the current version then exit"
);
( "--output-file", Arg.String(fun x -> Global.vars.outfile <- x), "<file>"
);
( "-o", Arg.String(fun x -> Global.vars.outfile <- x),
"<file>\tSet the output file name"
);
( "--node", Arg.String(fun x -> Global.vars.main_node <- x),
"<node>"
);
( "-n", Arg.String(fun x -> Global.vars.main_node <- x),
"<node>\tSet the main node (all items are compiled if unset)"
);
( "--compile-all-items", Arg.Unit
(function x -> Global.vars.compile_all_items <- true),
"\t"
);
( "-all", Arg.Unit
(function x -> Global.vars.compile_all_items <- true),
"\t\tCompile all items of the program"
);
( "-unit", Arg.Unit (fun x -> Global.vars.run_unit_test <- true),
"\tRun some (internal) unit tests"
);
( "--verbose", Arg.Unit (fun vl -> Verbose.set_level 1 ),
""
);
( "-v", Arg.Unit (fun vl -> Verbose.set_level 1 ),
"\t\tSet verbose mode on (i.e., verbose level = 1)"
);
( "--verbose-level", Arg.Int(fun vl -> Verbose.set_level vl ), "<int>"
);
( "-vl", Arg.Int(fun vl -> Verbose.set_level vl ),
"<int>\tSet verbose level"
);
("-h", Arg.Unit (fun _ -> (Arg.usage arg_list usage_msg; exit 0)), "" );
("-help", Arg.Unit (fun _ -> (Arg.usage arg_list usage_msg; exit 0)),"" );
("--help", Arg.Unit (fun _ -> (Arg.usage arg_list usage_msg; exit 0)),
"\tDisplay this list of options" )
]
and
parse_args () = (
Arg.parse arg_list (* liste des options *)
set_infile (* arg par defaut = fichier d'entree *)
usage_msg (* message d'erreur *)
;
()
)
let test_lex ( lexbuf ) = (
let tk = ref (Lexer.lexer lexbuf) in (
......@@ -162,7 +168,7 @@ let (get_source_list : string list -> SyntaxTree.pack_or_model list) =
let (get_one_source : string -> string list * maybe_packed) =
fun infile ->
let inchannel =
Verbose.print_string ~level:3
Verbose.print_string ~level:1
("Opening file " ^ (Sys.getcwd ()) ^ infile ^ "\n");
open_in infile in
let lexbuf = Lexing.from_channel inchannel in
......@@ -171,7 +177,7 @@ let (get_source_list : string list -> SyntaxTree.pack_or_model list) =
| PRPackBody(incl_files, pbdy) ->
let nme =
try Filename.chop_extension (Filename.basename infile)
with _ -> print_string ("*** '"^infile^"': Bad file name\n"); exit 1
with _ -> print_string ("*** '"^infile^"': bad file name.\n"); exit 1
in
let pi =
SyntaxTree.give_pack_this_name (Ident.pack_name_of_string nme) pbdy
......@@ -232,9 +238,11 @@ let main = (
);
try (
let nsl = get_source_list Global.vars.infiles in
let main_node = Ident.idref_of_string Global.vars.main_node in
if Global.vars.outfile <> "" then
Global.oc := open_out Global.vars.outfile;
let main_node =
if Global.vars.main_node = "" then None else
Some (Ident.idref_of_string Global.vars.main_node)
in
if Global.vars.outfile <> "" then Global.oc := open_out Global.vars.outfile;
Compile.doit nsl main_node;
close_out !Global.oc
) with
......
This diff is collapsed.
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment