I am trying to write a compiler for a simple C inspired language. My dune file looks like this
(ocamllex scanner)
(ocamlyacc mylanguageparse)
(executable
(name mylanguage)
(libraries
llvm
llvm.analysis
)
(link_flags (-linkall))
)
I want to be able to pass in a “-a” as an argument to give the option of just printing my ast, so in top level compiler mylanguage.ml file I do
type action = Ast
let () =
let action = ref Compile in
let set_action a () = action := a in
let speclist = [
("-a", Arg.Unit (set_action Ast), "Print the AST"); ]
in
let usage_msg = "usage: ./mylanguage.native [-a|-s|-l|-c] [file.mylanguage]" in
let channel = ref stdin in
Arg.parse speclist (fun filename -> channel := open_in filename) usage_msg;
let lexbuf = Lexing.from_channel !channel in
let ast = mylanguage.program Scanner.token lexbuf in
match !action with
Ast -> print_string (Ast.string_of_program ast)
| _ -> let sast = Semant.check ast in
Llvm_analysis.assert_valid_module m;
print_string (Llvm.string_of_llmodule m)
Following the format in dune documentation I’ve tried variations of this
dune exec -a ./mylanguage.exe ../tests/test-hello.mylanguage
dune: unknown option `-a'.
How do I pass in my “-a” as an option? I’ve tried just a, --a, no difference
7 posts - 3 participants