2019-07-24 17:41:52 +04:00
|
|
|
(* Driver for the lexer of PascaLIGO *)
|
2019-05-13 00:56:22 +04:00
|
|
|
|
|
|
|
(* Error printing and exception tracing *)
|
|
|
|
|
|
|
|
let () = Printexc.record_backtrace true
|
|
|
|
|
2019-07-24 17:41:52 +04:00
|
|
|
(* Running the lexer on the source *)
|
|
|
|
|
|
|
|
let options = EvalOpt.read ()
|
|
|
|
|
|
|
|
open EvalOpt
|
|
|
|
|
2019-05-13 00:56:22 +04:00
|
|
|
let external_ text =
|
|
|
|
Utils.highlight (Printf.sprintf "External error: %s" text); exit 1;;
|
|
|
|
|
|
|
|
(* Path for CPP inclusions (#include) *)
|
|
|
|
|
|
|
|
let lib_path =
|
2019-07-24 17:41:52 +04:00
|
|
|
match options.libs with
|
2019-05-13 00:56:22 +04:00
|
|
|
[] -> ""
|
|
|
|
| libs -> let mk_I dir path = Printf.sprintf " -I %s%s" dir path
|
|
|
|
in List.fold_right mk_I libs ""
|
|
|
|
|
|
|
|
(* Preprocessing the input source and opening the input channels *)
|
|
|
|
|
|
|
|
let prefix =
|
2019-07-24 17:41:52 +04:00
|
|
|
match options.input with
|
2019-05-13 00:56:22 +04:00
|
|
|
None | Some "-" -> "temp"
|
|
|
|
| Some file -> Filename.(file |> basename |> remove_extension)
|
|
|
|
|
|
|
|
let suffix = ".pp.ligo"
|
|
|
|
|
|
|
|
let pp_input =
|
2019-07-24 17:41:52 +04:00
|
|
|
if Utils.String.Set.mem "cpp" options.verbose
|
2019-05-13 00:56:22 +04:00
|
|
|
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 =
|
2019-07-24 17:41:52 +04:00
|
|
|
match options.input with
|
2019-05-13 00:56:22 +04:00
|
|
|
None | Some "-" ->
|
|
|
|
Printf.sprintf "cpp -traditional-cpp%s - > %s"
|
|
|
|
lib_path pp_input
|
|
|
|
| Some file ->
|
|
|
|
Printf.sprintf "cpp -traditional-cpp%s %s > %s"
|
|
|
|
lib_path file pp_input
|
|
|
|
|
|
|
|
let () =
|
2019-07-24 17:41:52 +04:00
|
|
|
if Utils.String.Set.mem "cpp" options.verbose
|
2019-05-13 00:56:22 +04:00
|
|
|
then Printf.eprintf "%s\n%!" cpp_cmd;
|
|
|
|
if Sys.command cpp_cmd <> 0 then
|
|
|
|
external_ (Printf.sprintf "the command \"%s\" failed." cpp_cmd)
|
|
|
|
|
|
|
|
(* Running the lexer on the input file *)
|
|
|
|
|
|
|
|
module Lexer = Lexer.Make (LexToken)
|
|
|
|
|
|
|
|
module Log = LexerLog.Make (Lexer)
|
|
|
|
|
2019-07-24 17:41:52 +04:00
|
|
|
let () = Log.trace ~offsets:options.offsets
|
|
|
|
options.mode (Some pp_input) options.cmd
|