Skip to content

Conversation

katrinafyi
Copy link
Member

(the AST format is the one that looks like this: Stmt_ConstDecl(Type_Bits(64),"Cse0__5",Expr_TApply("add_bits.0",... and is used in gtirb-semantics and BASIL)

This adds a BNFC grammar to gain all the benefits of BNFC, most importantly, multi-language parser generator generating. This is the same language which is described in Semantics.g4, but BNFC brings some improvements and I've also just written a better grammar this time.

Some notes:

  • I've tried to be reasonably precise in the grammar. For instance, there is a fixed list of intrinsic operations and variable names, and narrower rules are used where possible. Much of this is taken from the IBI for the offline lifter.
  • The bnfc-generated files are checked in to the repo using Dune's "promote" feature. This means that bnfc is not a build dependency, as most people can just use the checked-in files. Only if you want to update the BNFC grammar and re-generate the files will BNFC be needed. Then, it will search for bnfc in PATH. (I didn't really want to write Dune code to download the bnfc binary).

Tested by running through all the AST outputs in test_cntlm.t and also by adding a BNFC parse to the coverage checking. This passes with no problems, so we can be sure that the BNFC grammar describes a superset of the AST which we see in coverage.

(targets AbsSemantics.ml LexSemantics.mll ParSemantics.mly SkelSemantics.ml PrintSemantics.ml ShowSemantics.ml TestSemantics.ml BNFC_Util.ml Makefile)
(mode promote)
(enabled_if %{env:ASLP_BNFC_PROMOTE=false}))
; NOTE: bnfc is not run unless ASLP_BNFC_PROMOTE is manually set to `true`.
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

--makefile could probably be replaced with a trivial dune executable depending on libASL_bnfc.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agree.

libASL/dune Outdated
(flags (:standard -w -27))
(modules asl_ast asl_parser asl_parser_pp asl_utils asl_visitor visitor utils value primops symbolic)
(libraries pprint (re_export zarith)))
(libraries pprint (re_export zarith) libASL_bnfc))
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably want libSAL_bnfc to be a separate library so that it can be installed independently without Z3?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is, it's just used as a dependency here.

libASL/dune Outdated
(preprocessor_deps (alias ../asl_files) (alias cpp_backend_files) ../offlineASL/template_offline_utils.ml)
(preprocess (pps ppx_blob))
(libraries libASL_stage0 libASL_support str mlbdd))
(libraries libASL_stage0 libASL_support str mlbdd unix))
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will unix break JS?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oops, yes. That shouldn't be there.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants