|
@@ -3,60 +3,93 @@ open Lexing
|
|
|
open Types
|
|
open Types
|
|
|
open Util
|
|
open Util
|
|
|
|
|
|
|
|
|
|
+let always _ = true
|
|
|
|
|
+let when_optimize _ = args.optimize
|
|
|
|
|
+
|
|
|
|
|
+let phases = [
|
|
|
|
|
+ ("load", Load.phase, always,
|
|
|
|
|
+ "Load input file");
|
|
|
|
|
+ ("parse", Parse.phase, always,
|
|
|
|
|
+ "Parse input");
|
|
|
|
|
+ ("desug", Desug.phase, always,
|
|
|
|
|
+ "Desugaring");
|
|
|
|
|
+ ("context", Context_analysis.phase, always,
|
|
|
|
|
+ "Context analysis");
|
|
|
|
|
+ ("typecheck", Typecheck.phase, always,
|
|
|
|
|
+ "Type checking");
|
|
|
|
|
+ ("expand", Expand_dims.phase, always,
|
|
|
|
|
+ "Expand array dimensions");
|
|
|
|
|
+ ("boolop", Bool_op.phase, always,
|
|
|
|
|
+ "Convert bool operations");
|
|
|
|
|
+ ("dimreduce", Dim_reduce.phase, always,
|
|
|
|
|
+ "Array dimension reduction");
|
|
|
|
|
+ ("extern", Extern_vars.phase, always,
|
|
|
|
|
+ "Create getters and setters for extern variables");
|
|
|
|
|
+ ("constant", Constant_propagation.phase, when_optimize,
|
|
|
|
|
+ "Constant propagation");
|
|
|
|
|
+ ("index", Index_analysis.phase, always,
|
|
|
|
|
+ "Index analysis");
|
|
|
|
|
+ ("assemble", Assemble.phase, always,
|
|
|
|
|
+ "Assembly");
|
|
|
|
|
+ ("peephole", Peephole.phase, when_optimize,
|
|
|
|
|
+ "Peephole optimization");
|
|
|
|
|
+ ("output", Output.phase, always,
|
|
|
|
|
+ "Output assembly");
|
|
|
|
|
+]
|
|
|
|
|
+
|
|
|
(* Compile CVC file to assembly code
|
|
(* Compile CVC file to assembly code
|
|
|
* in_channel -> int -> repr *)
|
|
* in_channel -> int -> repr *)
|
|
|
let compile () =
|
|
let compile () =
|
|
|
let rec run_phases input = function
|
|
let rec run_phases input = function
|
|
|
| [] -> ()
|
|
| [] -> ()
|
|
|
- | h::t -> run_phases (h input) t
|
|
|
|
|
|
|
+ | (id, phase, cond, msg) :: tl ->
|
|
|
|
|
+ let output = if cond () then (
|
|
|
|
|
+ log_plain_line 1 (expand 13 ("- " ^ id ^ ":") ^ msg);
|
|
|
|
|
+ let output = phase input in
|
|
|
|
|
+ if id = args.endphase || args.verbose = 2 then (
|
|
|
|
|
+ let _ = Print.phase output in ()
|
|
|
|
|
+ );
|
|
|
|
|
+ output
|
|
|
|
|
+ ) else input in
|
|
|
|
|
+ if id = args.endphase then () else run_phases output tl
|
|
|
in
|
|
in
|
|
|
- run_phases Empty [
|
|
|
|
|
- Load.phase;
|
|
|
|
|
- Print.phase;
|
|
|
|
|
- Parse.phase;
|
|
|
|
|
- (*Print.phase;*)
|
|
|
|
|
- Desug.phase;
|
|
|
|
|
- Print.phase;
|
|
|
|
|
- Context_analysis.phase;
|
|
|
|
|
- (*Print.phase;*)
|
|
|
|
|
- Typecheck.phase;
|
|
|
|
|
- (*Print.phase;*)
|
|
|
|
|
- Expand_dims.phase;
|
|
|
|
|
- (*Print.phase;*)
|
|
|
|
|
- Bool_op.phase;
|
|
|
|
|
- (*Print.phase;*)
|
|
|
|
|
- Dim_reduce.phase;
|
|
|
|
|
- (*Print.phase;*)
|
|
|
|
|
- Extern_vars.phase;
|
|
|
|
|
- (*Print.phase;*)
|
|
|
|
|
- Constant_propagation.phase;
|
|
|
|
|
- Print.phase;
|
|
|
|
|
- Index_analysis.phase;
|
|
|
|
|
- Print.phase;
|
|
|
|
|
- Assemble.phase;
|
|
|
|
|
- Print.phase;
|
|
|
|
|
- Peephole.phase;
|
|
|
|
|
- Print.phase;
|
|
|
|
|
- Output.phase;
|
|
|
|
|
- ]
|
|
|
|
|
|
|
+ run_phases Empty phases
|
|
|
|
|
|
|
|
(* Main function, returns exit status
|
|
(* Main function, returns exit status
|
|
|
* Command-line arguments are stored in Util.args
|
|
* Command-line arguments are stored in Util.args
|
|
|
* () -> int *)
|
|
* () -> int *)
|
|
|
let main () =
|
|
let main () =
|
|
|
|
|
+ let rec upto_usage = function
|
|
|
|
|
+ | [] -> ""
|
|
|
|
|
+ | (id, _, _, msg) :: tl ->
|
|
|
|
|
+ "\n" ^ repeat " " 8 ^ expand 10 id ^ ": " ^ msg ^ (upto_usage tl)
|
|
|
|
|
+ in
|
|
|
let args_spec = [
|
|
let args_spec = [
|
|
|
("-o", Arg.String (fun s -> args.outfile <- Some s),
|
|
("-o", Arg.String (fun s -> args.outfile <- Some s),
|
|
|
"Output file (defaults to foo.s for foo.cvc)");
|
|
"Output file (defaults to foo.s for foo.cvc)");
|
|
|
|
|
+
|
|
|
("-v", Arg.Int (fun i -> args.verbose <- i),
|
|
("-v", Arg.Int (fun i -> args.verbose <- i),
|
|
|
"Set verbosity (0: nothing, 1: phase titles, 2: intermediate, 3: debug)");
|
|
"Set verbosity (0: nothing, 1: phase titles, 2: intermediate, 3: debug)");
|
|
|
|
|
+
|
|
|
("-nocpp", Arg.Unit (fun _ -> args.cpp <- false),
|
|
("-nocpp", Arg.Unit (fun _ -> args.cpp <- false),
|
|
|
"Disable C preprocessor");
|
|
"Disable C preprocessor");
|
|
|
|
|
+ ("-cpp", Arg.Unit (fun _ -> args.cpp <- true),
|
|
|
|
|
+ "Enable C preprocessor (overwrite earlier -nocpp)");
|
|
|
|
|
+
|
|
|
("-noopt", Arg.Unit (fun _ -> args.optimize <- false),
|
|
("-noopt", Arg.Unit (fun _ -> args.optimize <- false),
|
|
|
"Disable optimization");
|
|
"Disable optimization");
|
|
|
|
|
+ ("-opt", Arg.Unit (fun _ -> args.optimize <- true),
|
|
|
|
|
+ "Enable optimization (overwrite earlier -nocpp)");
|
|
|
|
|
+
|
|
|
|
|
+ ("-upto", Arg.String (fun s -> args.endphase <- s),
|
|
|
|
|
+ "Stop after the specified phase, and print the intermediate " ^
|
|
|
|
|
+ "representation to stderr.\n " ^
|
|
|
|
|
+ "Possible options are:" ^ upto_usage phases);
|
|
|
] in
|
|
] in
|
|
|
|
|
+
|
|
|
let usage =
|
|
let usage =
|
|
|
"Usage: " ^ Sys.argv.(0) ^ " [-o <file>] [-nocpp] [-noopt] " ^
|
|
"Usage: " ^ Sys.argv.(0) ^ " [-o <file>] [-nocpp] [-noopt] " ^
|
|
|
- " [-v <verbosity>] [<file>]"
|
|
|
|
|
|
|
+ " [-v <verbosity>] [-upto <phase>] [<file>]"
|
|
|
in
|
|
in
|
|
|
|
|
|
|
|
try
|
|
try
|