2019-03-18 20:47:11 +04:00
|
|
|
(* Driver for the lexer of LIGO *)
|
2019-02-26 01:29:29 +04:00
|
|
|
|
|
|
|
open! EvalOpt (* Reads the command-line options: Effectful! *)
|
|
|
|
|
|
|
|
(* Error printing and exception tracing *)
|
|
|
|
|
|
|
|
let () = Printexc.record_backtrace true
|
|
|
|
|
|
|
|
let external_ text =
|
|
|
|
Utils.highlight (Printf.sprintf "External error: %s" text); exit 1;;
|
|
|
|
|
2019-03-14 17:27:00 +04:00
|
|
|
(* Path for CPP inclusions (#include) *)
|
|
|
|
|
|
|
|
let lib_path =
|
|
|
|
match EvalOpt.libs with
|
|
|
|
[] -> ""
|
|
|
|
| libs -> let mk_I dir path = Printf.sprintf " -I %s%s" dir path
|
|
|
|
in List.fold_right mk_I libs ""
|
|
|
|
|
2019-03-12 21:33:29 +04:00
|
|
|
(* Preprocessing the input source and opening the input channels *)
|
|
|
|
|
|
|
|
let prefix =
|
|
|
|
match EvalOpt.input with
|
|
|
|
None | Some "-" -> "temp"
|
|
|
|
| Some file -> Filename.(file |> basename |> remove_extension)
|
|
|
|
|
|
|
|
let suffix = ".pp.li"
|
|
|
|
|
|
|
|
let pp_input =
|
|
|
|
if Utils.String.Set.mem "cpp" EvalOpt.verbose
|
|
|
|
then prefix ^ suffix
|
|
|
|
else let pp_input, pp_out = Filename.open_temp_file prefix suffix
|
|
|
|
in close_out pp_out; pp_input
|
|
|
|
|
|
|
|
let cpp_cmd =
|
|
|
|
match EvalOpt.input with
|
|
|
|
None | Some "-" ->
|
2019-03-14 17:27:00 +04:00
|
|
|
Printf.sprintf "cpp -traditional-cpp%s - -o %s"
|
|
|
|
lib_path pp_input
|
2019-03-12 21:33:29 +04:00
|
|
|
| Some file ->
|
2019-03-14 17:27:00 +04:00
|
|
|
Printf.sprintf "cpp -traditional-cpp%s %s -o %s"
|
|
|
|
lib_path file pp_input
|
2019-03-12 21:33:29 +04:00
|
|
|
|
|
|
|
let () =
|
|
|
|
if Utils.String.Set.mem "cpp" EvalOpt.verbose
|
|
|
|
then Printf.eprintf "%s\n%!" cpp_cmd;
|
|
|
|
if Sys.command cpp_cmd <> 0 then
|
|
|
|
external_ (Printf.sprintf "the command \"%s\" failed." cpp_cmd)
|
|
|
|
|
2019-02-26 01:29:29 +04:00
|
|
|
(* Running the lexer on the input file *)
|
|
|
|
|
|
|
|
module Lexer = Lexer.Make (LexToken)
|
|
|
|
|
|
|
|
let () = Lexer.trace ~offsets:EvalOpt.offsets
|
2019-03-12 21:33:29 +04:00
|
|
|
EvalOpt.mode (Some pp_input) EvalOpt.cmd
|