-o option

This commit is contained in:
Dmitry Boulytchev 2020-02-23 22:15:27 +03:00
parent fe5a93218b
commit 3e2c87d42f
5 changed files with 18 additions and 2 deletions

Binary file not shown.

View file

@ -34,6 +34,7 @@ procedure for each unit will be called only once (regardless of the imports' sha
Additionally, the following options can be given to the driver: Additionally, the following options can be given to the driver:
\begin{itemize} \begin{itemize}
\item "\texttt{-o $filename$}"~--- specifies an alternative file name for the executable.
\item "\texttt{-I $path$}"~--- specifies a path to look for external units. Multiples instances of this option can be given in driver's \item "\texttt{-I $path$}"~--- specifies a path to look for external units. Multiples instances of this option can be given in driver's
invocation, and the paths are looked up in that order. invocation, and the paths are looked up in that order.
\item "\texttt{-dp}"~--- forces the driver to dump the AST of compiled unit in \textsc{html} representation. The dump is written in the file with the same \item "\texttt{-dp}"~--- forces the driver to dump the AST of compiled unit in \textsc{html} representation. The dump is written in the file with the same

View file

@ -47,6 +47,7 @@ class options args =
"When no options specified, builds the source file into executable.\n" ^ "When no options specified, builds the source file into executable.\n" ^
"Options:\n" ^ "Options:\n" ^
" -c --- compile into object file\n" ^ " -c --- compile into object file\n" ^
" -o <file> --- write executable into file <file>\n" ^
" -I <path> --- add <path> into unit search path list\n" ^ " -I <path> --- add <path> into unit search path list\n" ^
" -i --- interpret on a source-level interpreter\n" ^ " -i --- interpret on a source-level interpreter\n" ^
" -s --- compile into stack machine code and interpret on the stack machine initerpreter\n" ^ " -s --- compile into stack machine code and interpret on the stack machine initerpreter\n" ^
@ -61,6 +62,7 @@ class options args =
val help = ref false val help = ref false
val i = ref 1 val i = ref 1
val infile = ref (None : string option) val infile = ref (None : string option)
val outfile = ref (None : string option)
val paths = ref [X86.get_std_path ()] val paths = ref [X86.get_std_path ()]
val mode = ref (`Default : [`Default | `Eval | `SM | `Compile ]) val mode = ref (`Default : [`Default | `Eval | `SM | `Compile ])
(* Workaround until Ostap starts to memoize properly *) (* Workaround until Ostap starts to memoize properly *)
@ -76,6 +78,7 @@ class options args =
| "-w" -> self#set_workaround | "-w" -> self#set_workaround
(* end of the workaround *) (* end of the workaround *)
| "-c" -> self#set_mode `Compile | "-c" -> self#set_mode `Compile
| "-o" -> (match self#peek with None -> raise (Commandline_error "File name expected after '-o' specifier") | Some fname -> self#set_outfile fname)
| "-I" -> (match self#peek with None -> raise (Commandline_error "Path expected after '-I' specifier") | Some path -> self#add_include_path path) | "-I" -> (match self#peek with None -> raise (Commandline_error "Path expected after '-I' specifier") | Some path -> self#add_include_path path)
| "-s" -> self#set_mode `SM | "-s" -> self#set_mode `SM
| "-i" -> self#set_mode `Eval | "-i" -> self#set_mode `Eval
@ -104,6 +107,10 @@ class options args =
match !infile with match !infile with
| None -> infile := Some name | None -> infile := Some name
| Some name' -> raise (Commandline_error (Printf.sprintf "Input file ('%s') already specified" name')) | Some name' -> raise (Commandline_error (Printf.sprintf "Input file ('%s') already specified" name'))
method private set_outfile name =
match !outfile with
| None -> outfile := Some name
| Some name' -> raise (Commandline_error (Printf.sprintf "Output file ('%s') already specified" name'))
method private add_include_path path = method private add_include_path path =
paths := path :: !paths paths := path :: !paths
method private set_mode s = method private set_mode s =
@ -116,6 +123,10 @@ class options args =
then (incr i; Some (args.(j))) then (incr i; Some (args.(j)))
else None else None
method get_mode = !mode method get_mode = !mode
method get_output_option =
match !outfile with
| None -> Printf.sprintf "-o %s" self#basename
| Some name -> Printf.sprintf "-o %s" name
method get_infile = method get_infile =
match !infile with match !infile with
| None -> raise (Commandline_error "Input file not specified") | None -> raise (Commandline_error "Input file not specified")
@ -150,6 +161,10 @@ class options args =
then self#dump_file "sm" (SM.show_prg sm) then self#dump_file "sm" (SM.show_prg sm)
else () else ()
method greet = method greet =
(match !outfile with
| None -> ()
| Some _ -> (match !mode with `Default -> () | _ -> Printf.printf "Output file option ignored in this mode.\n")
);
if !version then Printf.printf "%s\n" Version.version; if !version then Printf.printf "%s\n" Version.version;
if !help then Printf.printf "%s" help_string if !help then Printf.printf "%s" help_string
end end

View file

@ -722,7 +722,7 @@ let build cmd prog =
let objs = find_objects (fst @@ fst prog) cmd#get_include_paths in let objs = find_objects (fst @@ fst prog) cmd#get_include_paths in
let buf = Buffer.create 255 in let buf = Buffer.create 255 in
List.iter (fun o -> Buffer.add_string buf o; Buffer.add_string buf " ") objs; List.iter (fun o -> Buffer.add_string buf o; Buffer.add_string buf " ") objs;
let gcc_cmdline = Printf.sprintf "gcc -g -m32 -o %s %s.s %s %s/runtime.a" cmd#basename cmd#basename (Buffer.contents buf) inc in let gcc_cmdline = Printf.sprintf "gcc -g -m32 %s %s.s %s %s/runtime.a" cmd#get_output_option cmd#basename (Buffer.contents buf) inc in
Sys.command gcc_cmdline Sys.command gcc_cmdline
| `Compile -> | `Compile ->
Sys.command (Printf.sprintf "gcc -g -m32 -c %s.s" cmd#basename) Sys.command (Printf.sprintf "gcc -g -m32 -c %s.s" cmd#basename)

View file

@ -1 +1 @@
let version = "Version 1.00, e0ad5aa8, Thu Feb 20 20:29:57 2020 +0300" let version = "Version 1.00, fe5a9321, Sun Feb 23 01:48:49 2020 +0300"