|
@@ -2,13 +2,12 @@ open Printf
|
|
|
open Lexing
|
|
open Lexing
|
|
|
open Types
|
|
open Types
|
|
|
open Util
|
|
open Util
|
|
|
-open Globals
|
|
|
|
|
|
|
|
|
|
(* For some reason OCaml wants me to redefine this type's implementation -.- *)
|
|
(* For some reason OCaml wants me to redefine this type's implementation -.- *)
|
|
|
type phase_func = Types.intermediate -> Types.intermediate
|
|
type phase_func = Types.intermediate -> Types.intermediate
|
|
|
|
|
|
|
|
let always _ = true
|
|
let always _ = true
|
|
|
-let when_optimize _ = args.optimize
|
|
|
|
|
|
|
+let when_optimize _ = Globals.args.optimize
|
|
|
|
|
|
|
|
(* List of all phases, which will be executed in the order defined here. *)
|
|
(* List of all phases, which will be executed in the order defined here. *)
|
|
|
let phases = [
|
|
let phases = [
|
|
@@ -40,30 +39,8 @@ let phases = [
|
|
|
"Output assembly");
|
|
"Output assembly");
|
|
|
]
|
|
]
|
|
|
|
|
|
|
|
-(* Compile CVC file to assembly code *)
|
|
|
|
|
-let compile () =
|
|
|
|
|
- let rec run_phases input = function
|
|
|
|
|
- | [] -> ()
|
|
|
|
|
- | (id, phase, cond, msg) :: tl ->
|
|
|
|
|
- let output =
|
|
|
|
|
- if cond () then begin
|
|
|
|
|
- log_plain_line 2 (expand 13 ("- " ^ id ^ ":") ^ msg);
|
|
|
|
|
- let output = phase input in
|
|
|
|
|
- if id = args.endphase || args.verbose >= 2 then begin
|
|
|
|
|
- ignore (Print.phase output)
|
|
|
|
|
- end;
|
|
|
|
|
- output
|
|
|
|
|
- end else
|
|
|
|
|
- input
|
|
|
|
|
- in
|
|
|
|
|
- if id = args.endphase then () else run_phases output tl
|
|
|
|
|
- in
|
|
|
|
|
- run_phases Empty phases
|
|
|
|
|
-
|
|
|
|
|
-(* Main function, returns exit status
|
|
|
|
|
- * Command-line arguments are stored in Util.args
|
|
|
|
|
- * () -> int *)
|
|
|
|
|
-let main () =
|
|
|
|
|
|
|
+(* Parse command-line arguments *)
|
|
|
|
|
+let parse_args () =
|
|
|
let rec upto_usage = function
|
|
let rec upto_usage = function
|
|
|
| [] -> ""
|
|
| [] -> ""
|
|
|
| (id, _, _, msg) :: tl ->
|
|
| (id, _, _, msg) :: tl ->
|
|
@@ -73,23 +50,23 @@ let main () =
|
|
|
("<file>", Arg.Rest (fun s -> ()),
|
|
("<file>", Arg.Rest (fun s -> ()),
|
|
|
" Optional input file (default is to read from stdin)");
|
|
" Optional input file (default is to read from stdin)");
|
|
|
|
|
|
|
|
- ("-o", Arg.String (fun s -> args.outfile <- Some s),
|
|
|
|
|
|
|
+ ("-o", Arg.String (fun s -> Globals.args.outfile <- Some s),
|
|
|
"<file> Output file (defaults to foo.s for foo.cvc)");
|
|
"<file> Output file (defaults to foo.s for foo.cvc)");
|
|
|
|
|
|
|
|
- ("-v", Arg.Int (fun i -> args.verbose <- i),
|
|
|
|
|
|
|
+ ("-v", Arg.Int (fun i -> Globals.args.verbose <- i),
|
|
|
"<num> Set verbosity (0: nothing, 1: errors, 2: intermediate, 3: debug)");
|
|
"<num> Set verbosity (0: nothing, 1: errors, 2: intermediate, 3: debug)");
|
|
|
|
|
|
|
|
- ("-nocpp", Arg.Unit (fun _ -> args.cpp <- false),
|
|
|
|
|
|
|
+ ("-nocpp", Arg.Unit (fun _ -> Globals.args.cpp <- false),
|
|
|
" Disable C preprocessor");
|
|
" Disable C preprocessor");
|
|
|
- ("-cpp", Arg.Unit (fun _ -> args.cpp <- true),
|
|
|
|
|
|
|
+ ("-cpp", Arg.Unit (fun _ -> Globals.args.cpp <- true),
|
|
|
" Enable C preprocessor (overwrite earlier -nocpp)");
|
|
" Enable C preprocessor (overwrite earlier -nocpp)");
|
|
|
|
|
|
|
|
- ("-noopt", Arg.Unit (fun _ -> args.optimize <- false),
|
|
|
|
|
|
|
+ ("-noopt", Arg.Unit (fun _ -> Globals.args.optimize <- false),
|
|
|
" Disable optimization");
|
|
" Disable optimization");
|
|
|
- ("-opt", Arg.Unit (fun _ -> args.optimize <- true),
|
|
|
|
|
|
|
+ ("-opt", Arg.Unit (fun _ -> Globals.args.optimize <- true),
|
|
|
" Enable optimization (overwrite earlier -nocpp)");
|
|
" Enable optimization (overwrite earlier -nocpp)");
|
|
|
|
|
|
|
|
- ("-upto", Arg.String (fun s -> args.endphase <- s),
|
|
|
|
|
|
|
+ ("-upto", Arg.String (fun s -> Globals.args.endphase <- s),
|
|
|
"<phase> Stop after the specified phase, and print the intermediate \
|
|
"<phase> Stop after the specified phase, and print the intermediate \
|
|
|
representation to stderr.\n \
|
|
representation to stderr.\n \
|
|
|
Possible options are (in order of execution):" ^ upto_usage phases);
|
|
Possible options are (in order of execution):" ^ upto_usage phases);
|
|
@@ -100,9 +77,34 @@ let main () =
|
|
|
[-v <verbosity>] [-upto <phase>] [<file>]"
|
|
[-v <verbosity>] [-upto <phase>] [<file>]"
|
|
|
in
|
|
in
|
|
|
|
|
|
|
|
|
|
+ Arg.parse args_spec (fun s -> Globals.args.infile <- Some s) usage
|
|
|
|
|
+
|
|
|
|
|
+(* Compile CVC file to assembly code *)
|
|
|
|
|
+let compile () =
|
|
|
|
|
+ let rec run_phases input = function
|
|
|
|
|
+ | [] -> ()
|
|
|
|
|
+ | (id, phase, cond, msg) :: tl ->
|
|
|
|
|
+ let output =
|
|
|
|
|
+ if cond () then begin
|
|
|
|
|
+ log_plain_line 2 (expand 13 ("- " ^ id ^ ":") ^ msg);
|
|
|
|
|
+ let output = phase input in
|
|
|
|
|
+ if id = Globals.args.endphase || Globals.args.verbose >= 2 then begin
|
|
|
|
|
+ ignore (Print.phase output)
|
|
|
|
|
+ end;
|
|
|
|
|
+ output
|
|
|
|
|
+ end else
|
|
|
|
|
+ input
|
|
|
|
|
+ in
|
|
|
|
|
+ if id = Globals.args.endphase then () else run_phases output tl
|
|
|
|
|
+ in
|
|
|
|
|
+ run_phases Empty phases
|
|
|
|
|
+
|
|
|
|
|
+(* Main function, returns exit status
|
|
|
|
|
+ * Command-line arguments are stored in lobals.args *)
|
|
|
|
|
+let main () =
|
|
|
try
|
|
try
|
|
|
try
|
|
try
|
|
|
- Arg.parse args_spec (fun s -> args.infile <- Some s) usage;
|
|
|
|
|
|
|
+ parse_args ();
|
|
|
compile ();
|
|
compile ();
|
|
|
0
|
|
0
|
|
|
with
|
|
with
|