Revision 217837e2
Added by Pierre-Loïc Garoche over 6 years ago
src/compiler_common.ml | ||
---|---|---|
35 | 35 |
end |
36 | 36 |
end |
37 | 37 |
|
38 |
(* Loading Lusi file and filling type tables with parsed |
|
38 |
(* Loading Lus/Lusi file and filling type tables with parsed
|
|
39 | 39 |
functions/nodes *) |
40 |
let parse_header own filename =
|
|
40 |
let parse filename extension =
|
|
41 | 41 |
Location.set_input filename; |
42 |
let h_in = open_in filename in
|
|
43 |
let lexbuf = Lexing.from_channel h_in in
|
|
42 |
let f_in = open_in filename in
|
|
43 |
let lexbuf = Lexing.from_channel f_in in
|
|
44 | 44 |
Location.init lexbuf filename; |
45 | 45 |
(* Parsing *) |
46 |
Log.report ~level:1 (fun fmt -> fprintf fmt ".. parsing header file %s@ " filename);
|
|
46 |
let prog =
|
|
47 | 47 |
try |
48 |
let header = Parse.header Parser_lustre.header Lexer_lustre.token lexbuf in |
|
49 |
(*ignore (Modules.load_header ISet.empty header);*) |
|
50 |
close_in h_in; |
|
51 |
header |
|
48 |
match extension with |
|
49 |
".lusi" -> |
|
50 |
Log.report ~level:1 |
|
51 |
(fun fmt -> fprintf fmt ".. parsing header file %s@ " filename); |
|
52 |
Parse.header Parser_lustre.header Lexer_lustre.token lexbuf |
|
53 |
| ".lus" -> |
|
54 |
Log.report ~level:1 |
|
55 |
(fun fmt -> fprintf fmt ".. parsing source file %s@ " filename); |
|
56 |
Parse.prog Parser_lustre.prog Lexer_lustre.token lexbuf |
|
57 |
| _ -> assert false |
|
52 | 58 |
with |
53 | 59 |
| (Parse.Error err) as exc -> |
54 |
Parse.report_error err; |
|
55 |
raise exc |
|
60 |
Parse.report_error err;
|
|
61 |
raise exc
|
|
56 | 62 |
| Corelang.Error (loc, err) as exc -> ( |
57 | 63 |
eprintf "Parsing error: %a%a@." |
58 |
Error.pp_error_msg err
|
|
59 |
Location.pp_loc loc;
|
|
64 |
Error.pp_error_msg err
|
|
65 |
Location.pp_loc loc;
|
|
60 | 66 |
raise exc |
61 | 67 |
) |
62 |
|
|
63 |
let parse_source source_name = |
|
64 |
(* Loading the input file *) |
|
65 |
Location.set_input source_name; |
|
66 |
let s_in = open_in source_name in |
|
67 |
let lexbuf = Lexing.from_channel s_in in |
|
68 |
Location.init lexbuf source_name; |
|
69 |
|
|
70 |
(* Parsing *) |
|
71 |
Log.report ~level:1 |
|
72 |
(fun fmt -> fprintf fmt ".. parsing source file %s@ " source_name); |
|
73 |
try |
|
74 |
let prog = Parse.prog Parser_lustre.prog Lexer_lustre.token lexbuf in |
|
75 |
(*ignore (Modules.load_program ISet.empty prog);*) |
|
76 |
close_in s_in; |
|
77 |
prog |
|
78 |
with |
|
79 |
| (Parse.Error err) as exc -> |
|
80 |
Parse.report_error err; |
|
81 |
raise exc |
|
82 |
| Corelang.Error (loc, err) as exc -> |
|
83 |
eprintf "Parsing error: %a%a@." |
|
84 |
Error.pp_error_msg err |
|
85 |
Location.pp_loc loc; |
|
86 |
raise exc |
|
68 |
in |
|
69 |
close_in f_in; |
|
70 |
prog |
|
71 |
|
|
87 | 72 |
|
88 | 73 |
let expand_automata decls = |
89 | 74 |
Log.report ~level:1 (fun fmt -> fprintf fmt ".. expanding automata@ "); |
... | ... | |
169 | 154 |
(Env.initial, Env.initial) |
170 | 155 |
*) |
171 | 156 |
|
172 |
let generate_lusic_header destname lusic_ext = |
|
173 |
match !Options.output with |
|
174 |
| "C" -> C_backend_lusic.print_lusic_to_h destname lusic_ext |
|
175 |
| _ -> () |
|
176 | 157 |
|
177 | 158 |
|
178 | 159 |
|
Also available in: Unified diff
Unified compilation of lusi and lus files
Different parsers yet but shared process.
In case of lusi input the C backend is bypassed since the .h is generated from the lusic and no C code should be generated since it may overwrite existing manually written code
But