[passes] linearisation des équations
This commit is contained in:
34
src/main.ml
34
src/main.ml
@@ -9,12 +9,12 @@ let print_debug d s =
|
||||
let print_verbose v s =
|
||||
if v then Format.printf "\x1b[33;01;04mStatus:\x1b[0m %s\n" s else ()
|
||||
|
||||
let exec_passes ast verbose debug passes f =
|
||||
let exec_passes ast main_fn verbose debug passes f =
|
||||
let rec aux ast = function
|
||||
| [] -> f ast
|
||||
| (n, p) :: passes ->
|
||||
verbose (Format.asprintf "Executing pass %s:\n" n);
|
||||
match p verbose debug ast with
|
||||
match p verbose debug main_fn ast with
|
||||
| None -> (exit_error ("Error while in the pass "^n^".\n"); exit 0)
|
||||
| Some ast -> (
|
||||
debug (Format.asprintf "Current AST (after %s):\n%a\n" n Pp.pp_ast ast);
|
||||
@@ -25,15 +25,17 @@ let exec_passes ast verbose debug passes f =
|
||||
|
||||
let _ =
|
||||
(** Usage and argument parsing. *)
|
||||
let default_passes = ["chkvar_init_unicity"; "pre2vars"] in
|
||||
let default_passes = ["chkvar_init_unicity"; "pre2vars"; "linearization"] in
|
||||
let usage_msg =
|
||||
"Usage: main [-passes p1,...,pn] [-ast] [-verbose] [-debug] \
|
||||
[-o output_file] source_file\n" in
|
||||
[-o output_file] [-m main_function] source_file\n" in
|
||||
let verbose = ref false in
|
||||
let debug = ref false in
|
||||
let ppast = ref false in
|
||||
let nopopt = ref false in
|
||||
let simopt = ref false in
|
||||
let passes = ref [] in
|
||||
let main_fn = ref "main" in
|
||||
let source_file = ref "" in
|
||||
let output_file = ref "out.c" in
|
||||
let anon_fun filename = source_file := filename in
|
||||
@@ -45,6 +47,9 @@ let _ =
|
||||
("-debug", Arg.Set debug, "Output a lot of debug information");
|
||||
("-p", Arg.String (fun s -> passes := s :: !passes),
|
||||
"Add a pass to the compilation process");
|
||||
("-sim", Arg.Set simopt, "Simulate the main node");
|
||||
("-m", Arg.String (fun s -> main_fn := s),
|
||||
"Defines what the main function is (defaults to main).");
|
||||
("-o", Arg.Set_string output_file, "Output file (defaults to [out.c])");
|
||||
] in
|
||||
Arg.parse speclist anon_fun usage_msg ;
|
||||
@@ -52,6 +57,7 @@ let _ =
|
||||
if !passes = [] then passes := default_passes;
|
||||
let print_verbose = print_verbose !verbose in
|
||||
let print_debug = print_debug !debug in
|
||||
let main_fn = !main_fn in
|
||||
|
||||
(** Definition of the passes table *)
|
||||
let passes_table = Hashtbl.create 100 in
|
||||
@@ -59,6 +65,7 @@ let _ =
|
||||
[
|
||||
("pre2vars", Passes.pre2vars);
|
||||
("chkvar_init_unicity", Passes.chkvar_init_unicity);
|
||||
("linearization", Passes.pass_linearization);
|
||||
];
|
||||
|
||||
(** Main functionality below *)
|
||||
@@ -101,13 +108,18 @@ let _ =
|
||||
|
||||
print_debug (Format.asprintf "Initial AST (before executing any passes):\n%a"
|
||||
Pp.pp_ast ast) ;
|
||||
exec_passes ast print_verbose print_debug passes
|
||||
exec_passes ast main_fn print_verbose print_debug passes
|
||||
begin
|
||||
if !ppast
|
||||
then (Format.printf "%a" Pp.pp_ast)
|
||||
else (
|
||||
if !nopopt
|
||||
then (fun _ -> ())
|
||||
else Format.printf "%a" Ast_to_c.ast_to_c)
|
||||
if !simopt
|
||||
then Simulation.simulate main_fn
|
||||
else
|
||||
begin
|
||||
if !ppast
|
||||
then (Format.printf "%a" Pp.pp_ast)
|
||||
else (
|
||||
if !nopopt
|
||||
then (fun _ -> ())
|
||||
else Format.printf "%a" Ast_to_c.ast_to_c)
|
||||
end
|
||||
end
|
||||
|
||||
|
Reference in New Issue
Block a user