Эх сурвалжийг харах

Added output file comand-line option

Taddeus Kroes 12 жил өмнө
parent
commit
73f3b81c3f
3 өөрчлөгдсөн 17 нэмэгдсэн , 11 устгасан
  1. 2 1
      ast.ml
  2. 12 7
      main.ml
  3. 3 3
      phases/load.ml

+ 2 - 1
ast.ml

@@ -47,7 +47,8 @@ and node =
 
 (* container for command-line arguments *)
 type args = {
-    mutable filename : string option;
+    mutable infile : string option;
+    mutable outfile : string option;
     mutable verbose : int;
     mutable cpp : bool;
 }

+ 12 - 7
main.ml

@@ -11,9 +11,9 @@ let compile args =
     in
     run_phases (Args args) [
         Load.phase;
-        Print.phase;
+        (*Print.phase;*)
         Parse.phase;
-        Print.phase;
+        (*Print.phase;*)
         Desug.phase;
         Print.phase;
         Context_analysis.phase;
@@ -67,19 +67,24 @@ let print_fancy_error msg loc verbose =
  * () -> int *)
 let main () =
     let args = {
-        filename = None;
+        infile = None;
+        outfile = None;
         verbose = 2;
         cpp = true;
     } in
     let args_spec = [
-        ("-v",     Arg.Int (fun i -> args.verbose <- i),  "Set verbosity");
-        ("-nocpp", Arg.Unit (fun i -> args.cpp <- false), "Disable C preprocessor");
+        ("-o", Arg.String (fun s -> args.outfile <- Some s),
+            "Output file (defaults to foo.s for foo.cvc)");
+        ("-v", Arg.Int (fun i -> args.verbose <- i),
+            "Set verbosity (0|1|2)");
+        ("-nocpp", Arg.Unit (fun i -> args.cpp <- false),
+            "Disable C preprocessor");
     ] in
-    let usage = "Usage: " ^ Sys.argv.(0) ^ " [-nocpp] [-v <verbosity>] <file>" in
+    let usage = "Usage: " ^ Sys.argv.(0) ^ " [-o <file>] [-nocpp] [-v <verbosity>] [<file>]" in
 
     try
         try
-            Arg.parse args_spec (fun s -> args.filename <- Some s) usage;
+            Arg.parse args_spec (fun s -> args.infile <- Some s) usage;
             compile args;
             0
         with

+ 3 - 3
phases/load.ml

@@ -24,14 +24,14 @@ let phase ir =
     prerr_endline "- Load input file";
     match ir with
     | Args args ->
-        let display_name = match args.filename with
+        let display_name = match args.infile with
             | Some filename -> filename
             | None -> "<stdin>"
         in
         let bufsize = 512 in
 
         if args.cpp then
-            let cpp_out = match args.filename with
+            let cpp_out = match args.infile with
                 | Some filename ->
                     Unix.open_process_in ("cpp " ^ filename)
                 | None ->
@@ -48,7 +48,7 @@ let phase ir =
             let preprocessed = input_buffered cpp_out bufsize in
             FileContent (display_name, preprocessed, args)
         else
-            let content = match args.filename with
+            let content = match args.infile with
                 | Some filename -> input_all (open_in filename)
                 | None -> input_buffered stdin bufsize
             in