main.ml 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. open Printf
  2. open Lexing
  3. open Ast
  4. open Util
  5. (* Compile CVC file to assembly code
  6. * in_channel -> int -> repr *)
  7. let compile () =
  8. let rec run_phases input = function
  9. | [] -> ()
  10. | h::t -> run_phases (h input) t
  11. in
  12. run_phases Empty [
  13. Load.phase;
  14. (*Print.phase;*)
  15. Parse.phase;
  16. (*Print.phase*)
  17. Desug.phase;
  18. (*Print.phase*)
  19. Context_analysis.phase;
  20. (*Print.phase*)
  21. Typecheck.phase;
  22. (*Print.phase*)
  23. Expand_dims.phase;
  24. (*Print.phase*)
  25. Bool_op.phase;
  26. Print.phase;
  27. (*
  28. Dim_reduce.phase;
  29. Print.phase;
  30. Extern_vars.phase;
  31. Print.phase;
  32. Assemble.phase;
  33. Print.phase;
  34. Peephole.phase;
  35. Print.phase;
  36. *)
  37. ]
  38. (* Main function, returns exit status
  39. * Command-line arguments are stored in Util.args
  40. * () -> int *)
  41. let main () =
  42. let args_spec = [
  43. ("-o", Arg.String (fun s -> args.outfile <- Some s),
  44. "Output file (defaults to foo.s for foo.cvc)");
  45. ("-v", Arg.Int (fun i -> args.verbose <- i),
  46. "Set verbosity (0|1|2)");
  47. ("-nocpp", Arg.Unit (fun i -> args.cpp <- false),
  48. "Disable C preprocessor");
  49. ] in
  50. let usage = "Usage: " ^ Sys.argv.(0) ^ " [-o <file>] [-nocpp] [-v <verbosity>] [<file>]" in
  51. try
  52. try
  53. Arg.parse args_spec (fun s -> args.infile <- Some s) usage;
  54. compile ();
  55. 0
  56. with
  57. (*| InvalidNode ->
  58. raise (CompileError "invalid node")*)
  59. | InvalidInput name ->
  60. raise (CompileError ("invalid input for phase \"" ^ name ^ "\""))
  61. | NodeError (node, msg) ->
  62. raise (LocError (locof node, msg))
  63. with
  64. | CompileError msg ->
  65. eprintf "Error: %s\n" msg;
  66. 1
  67. | LocError (loc, msg) ->
  68. prerr_loc_msg loc ("Error: " ^ msg) args.verbose;
  69. 1
  70. | EmptyError ->
  71. 1
  72. let _ = exit (main ())