| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152 |
- open Printf
- open Ast
- (* Compile infile to assembly code
- * in_channel -> int -> repr *)
- let compile infile verbose =
- let rec run_phases ir = function
- | [] -> ir
- | h::t -> run_phases (h ir) t
- in
- run_phases (Inputfile (infile, verbose)) [
- Parse.phase;
- Print.phase;
- Desug.phase;
- Print.phase;
- Context_analysis.phase;
- Print.phase;
- (*Typecheck.phase;*)
- (*Extern_vars.phase;*)
- (*Dim_reduce.phase;*)
- (*Bool_op.phase;*)
- (*Assemble.phase;*)
- (*Peephole.phase;*)
- (*Print.phase;*)
- ]
- (* Main function, returns exit status
- * () -> int *)
- let main () =
- let filename = ref None in
- let verbose = ref 1 in
- let args = [
- ("-v", Arg.Int (fun i -> verbose := i), "Set verbosity")
- ] in
- let usage = "Usage: " ^ Sys.argv.(0) ^ " [ -v VERBOSITY ] FILE" in
- try
- Arg.parse args (fun s -> filename := Some s) usage;
- let _ = compile !filename !verbose in
- 0
- with
- | CompileError msg ->
- prerr_endline ("Error: " ^ msg);
- -1
- | LocError (msg, loc) ->
- let (file, ystart, yend, xstart, xend) = loc in
- let yend = if yend = ystart then "" else "-" ^ string_of_int yend in
- let xend = if xend = xstart then "" else "-" ^ string_of_int xend in
- eprintf "Error: %s at %s:%d%s:%d%s" msg file ystart yend xstart xend;
- -1
- let _ = exit (main ())
|