summaryrefslogtreecommitdiff
path: root/caml/Main2.ml
diff options
context:
space:
mode:
Diffstat (limited to 'caml/Main2.ml')
-rw-r--r--caml/Main2.ml34
1 files changed, 34 insertions, 0 deletions
diff --git a/caml/Main2.ml b/caml/Main2.ml
new file mode 100644
index 0000000..b701419
--- /dev/null
+++ b/caml/Main2.ml
@@ -0,0 +1,34 @@
+open Printf
+open Datatypes
+
+let process_cminor_file sourcename =
+ let targetname = Filename.chop_suffix sourcename ".cm" ^ ".s" in
+ let ic = open_in sourcename in
+ let lb = Lexing.from_channel ic in
+ try
+ match Main.transf_cminor_program (CMparser.prog CMlexer.token lb) with
+ | None ->
+ eprintf "Compiler failure\n";
+ exit 2
+ | Some p ->
+ let oc = open_out targetname in
+ PrintPPC.print_program oc p;
+ close_out oc
+ with Parsing.Parse_error ->
+ eprintf "File %s, character %d: Syntax error\n"
+ sourcename (Lexing.lexeme_start lb);
+ exit 2
+ | CMlexer.Error msg ->
+ eprintf "File %s, character %d: %s\n"
+ sourcename (Lexing.lexeme_start lb) msg;
+ exit 2
+
+let process_file filename =
+ if Filename.check_suffix filename ".cm" then
+ process_cminor_file filename
+ else
+ raise (Arg.Bad ("unknown file type " ^ filename))
+
+let _ =
+ Arg.parse [] process_file
+ "Usage: ccomp <options> <files>\nOptions are:"