LLVM tutorial with Dune (Part 2)

build
c
llvm
menhir
dune

#1

Hi everyone, I just made an updated version of the OCaml LLVM since the posted one is pretty out of date. Check it out here: https://github.com/adamrk/llvm-ocaml-tutorial. The main changes are:

  • switch build system to dune from ocamlbuild
  • switch lexing and parsing to use ocamllex/menhir instead of camlp4
  • update to newer LLVM API (version 6.0.0)

There are also a couple outstanding issues that I can’t figure out, so if you have any ideas how to fix these it’d be really helpful:

  • Menhir is generated files which cause warnings during compilation:
ocamlc lib/parser__mock.mli.inferred
  File "parser__mock.ml.mock", line 388, characters 9-18:
  Warning 3: deprecated: Not_found
ocamlopt lib/.kaleidoscope_lib.objs/kaleidoscope_lib__Parser.{cmx,o}
  File "parser.ml", line 161, characters 45-612:
  Warning 9: the following labels are not bound in this record pattern: state

Are there any ways to prevent Menhir from causing these warnings? I’m currently handling it by suppressing the warnings with

(env
 (dev
  (flags (:standard -warn-error -3-9))))

in the dune file. Alternatively, is there a way to suppress the warnings only for these specific files?

  • The cstubs are currently printing to stderr because when I set them to print to stdout, those calls don’t occur until the program exists. Any ideas on why that happens and if there is a better fix?
  • I’m currently linking the cstubs dynamically which is annoying. Does anyone know if there’s a way to statically link them in?

Edit: actually it appears that the Warning 9 problem was fixed in the latest version of Menhir (20181113). Not_found is actually only deprecated in Base/Core so I got rid of that error by not opening Core at the toplevel. I’m still curious about if there’s an easy way to suppress warnings only for specific files though.


#2

You can locally disable the warnings with [@ocaml.warning “-9”] or [@@ocaml.warning “-9”]. If you use a version of ocaml prior to 4.06, you may be better off by wrapping the module with

[@@@ocaml.warning “-9”]
...
[@@@ocaml.warning “+9”]