[pre propagation] done.
This commit is contained in:
36
src/main.ml
36
src/main.ml
@@ -9,16 +9,20 @@ 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 run ast verbose debug passes =
|
||||
let exec_passes ast verbose debug passes f =
|
||||
let rec aux ast = function
|
||||
| [] -> Format.printf "%a" Ast_to_c.ast_to_c ast
|
||||
| [] -> f ast
|
||||
| (n, p) :: passes ->
|
||||
verbose (Format.asprintf "Executing pass %s:\n" n);
|
||||
match p ast with
|
||||
| None -> (exit_error ("Error while in the pass "^n^".\n"); exit 0)
|
||||
| Some ast -> aux ast passes
|
||||
| Some ast -> (
|
||||
debug (Format.asprintf "Current AST (after %s):\n%a\n" n Pp.pp_ast ast);
|
||||
aux ast passes)
|
||||
in
|
||||
aux ast passes
|
||||
|
||||
|
||||
let _ =
|
||||
(** Usage and argument parsing. *)
|
||||
let default_passes = ["pre2vars"] in
|
||||
@@ -45,7 +49,7 @@ let _ =
|
||||
if !source_file = "" then exit_error "No source file specified" else
|
||||
if !passes = [] then passes := default_passes;
|
||||
let print_verbose = print_verbose !verbose in
|
||||
let print_debug = print_debug !verbose in
|
||||
let print_debug = print_debug !debug in
|
||||
|
||||
(** Definition of the passes table *)
|
||||
let passes_table : (string, t_nodelist -> t_nodelist option) Hashtbl.t = Hashtbl.create 100 in
|
||||
@@ -84,13 +88,19 @@ let _ =
|
||||
end
|
||||
in
|
||||
|
||||
if !ppast then Format.printf "%a" Pp.pp_ast ast
|
||||
else
|
||||
let passes = List.map (fun (pass: string) -> (pass,
|
||||
match Hashtbl.find_opt passes_table pass with
|
||||
| None ->
|
||||
(exit_error (Format.sprintf "The pass %s does not exist." pass); exit 0)
|
||||
| Some f ->
|
||||
(print_debug ("The pass "^pass^" has been selected."); f))) !passes in
|
||||
run ast print_verbose print_debug passes
|
||||
let passes = List.map (fun (pass: string) -> (pass,
|
||||
match Hashtbl.find_opt passes_table pass with
|
||||
| None ->
|
||||
(exit_error (Format.sprintf "The pass %s does not exist." pass); exit 0)
|
||||
| Some f ->
|
||||
(print_debug ("The pass "^pass^" has been selected."); f))) !passes in
|
||||
|
||||
print_debug (Format.asprintf "Initial AST (before executing any passes):\n%a"
|
||||
Pp.pp_ast ast) ;
|
||||
exec_passes ast print_verbose print_debug passes
|
||||
begin
|
||||
if !ppast
|
||||
then (Format.printf "%a" Pp.pp_ast)
|
||||
else (Format.printf "%a" Ast_to_c.ast_to_c)
|
||||
end
|
||||
|
||||
|
Reference in New Issue
Block a user