Skip to content

Allow building FLambda parser in Dune #495

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 24, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,9 @@ _build
/manual/manual/cmds/warnings-help.etex
/manual/manual/warnings-help.etex

middle_end/flambda/parser/flambda_parser.ml.in
middle_end/flambda/parser/flambda_parser.mli.in
middle_end/flambda/parser/flambda_parser_in.ml
middle_end/flambda/parser/flambda_parser_in.mli
middle_end/flambda/parser/flambda_parser.new-messages
middle_end/flambda/simplify/simplify.ml
middle_end/flambda/terms/flambda.ml
middle_end/flambda/types/flambda_type.ml
Expand Down
1 change: 1 addition & 0 deletions middle_end/flambda/dune
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
(wrapped false)
(flags (:standard -principal -nostdlib))
(ocamlopt_flags (:standard -O3))
(modules (:standard \ flambda_parser_in)) ; ignore inputs to sed
(modules_without_implementation flambda_backend_intf)
(libraries stdlib ocamlcommon ocamlbytecomp flambdadeps)
)
14 changes: 5 additions & 9 deletions middle_end/flambda/parser/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,13 @@ OCAMLLEX=ocamllex
flambda_lex.ml: flambda_lex.mll
${OCAMLLEX} flambda_lex.mll

# Avoid creating intermediate files with .ml or .mli extensions so Dune
# doesn't complain
flambda_parser.ml.in flambda_parser.mli.in: flambda_parser.mly
${MENHIR} --table flambda_parser.mly --base flambda_parser-in
mv -f flambda_parser-in.ml flambda_parser.ml.in
mv -f flambda_parser-in.mli flambda_parser.mli.in

flambda_parser.ml: flambda_parser.ml.in
flambda_parser_in.ml flambda_parser_in.mli: flambda_parser.mly
${MENHIR} --table flambda_parser.mly --base flambda_parser_in

flambda_parser.ml: flambda_parser_in.ml
sed "s/MenhirLib/CamlinternalMenhirLib/g" $< > $@

flambda_parser.mli: flambda_parser.mli.in
flambda_parser.mli: flambda_parser_in.mli
sed "s/MenhirLib/CamlinternalMenhirLib/g" $< > $@

flambda_parser_messages.ml: flambda_parser.mly flambda_parser.messages
Expand Down
70 changes: 70 additions & 0 deletions middle_end/flambda/parser/dune
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
; Using user actions rather than (ocamllex) and (menhir) because the Makefile
; runs ocamllex and menhir from this directory rather than the workspace root,
; meaning the generated source is annotated with the bare filename.

; These rules are disabled by default because you need precisely the correct
; version of Menhir installed. Comment out (mode fallback) and uncomment (mode
; promote) in each stanza if you make changes to the Flambda
; parser.

(rule
(mode fallback)
;(mode promote)
(target flambda_lex.ml)
(deps flambda_lex.mll)
(action (run ocamllex -q %{deps})))

(rule
(mode fallback)
;(mode promote)
(target flambda_parser.ml)
(deps flambda_parser_in.ml)
(action (with-stdin-from %{deps}
(with-stdout-to %{target}
(run sed "s/MenhirLib/CamlinternalMenhirLib/g")))))

(rule
(mode fallback)
;(mode promote)
(target flambda_parser.mli)
(deps flambda_parser_in.mli)
(action (with-stdin-from %{deps}
(with-stdout-to %{target}
(run sed "s/MenhirLib/CamlinternalMenhirLib/g")))))

(rule
(targets flambda_parser_in.ml
flambda_parser_in.mli)
(deps flambda_parser.mly)
(action (run menhir --table %{deps} --base flambda_parser_in)))

; NOTE: flambda_parser.messages is massively out of date. No need to activate
; this rule unless you've fixed it (thanks!).
(rule
(mode fallback)
;(mode promote)
(target flambda_parser_messages.ml)
(deps flambda_parser.messages flambda_parser.mly)
(action (with-stdout-to %{target}
(run menhir --compile-errors %{deps}))))

(alias (name list-errors))

(rule
(alias list-errors)
(target flambda_parser.new-messages)
(deps flambda_parser.mly)
(mode promote)
(action (with-stdout-to %{target}
(run menhir --list-errors %{deps}))))

(alias (name check-errors))

(rule
(alias check-errors)
(deps flambda_parser.mly
flambda_parser.messages
flambda_parser.new-messages)
(action (run menhir flambda_parser.mly
--compare-errors flambda_parser.messages
--compare-errors flambda_parser.new-messages)))