[llvm-dev] A BNF grammar for LLVM IR assembly

Previous Topic Next Topic
classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view

[llvm-dev] A BNF grammar for LLVM IR assembly

Tim Northover via llvm-dev

My friends and I have written a BNF grammar for LLVM IR assembly by
cross-referencing the LLVM Language Reference Manual [1], LLVM blog
posts [2], and the source code and associated comments of the LLVM IR
assembly parser [3]. We did this as we wanted to be able to write tools
for both generating arbitrary syntactically correct LLVM IR (e.g. csmith
[4]) to validate the tool chain, to generate LLVM IR parsers based on
the BNF, and to create a source of truth for the grammar of the LLVM IR
assembly language.

The current version of the BNF covers the entire LLVM IR assembly
language as of 2018-02-19, and is based on the source code of
lib/AsmParser/LLParser.cpp at revision rL324928 [5].

Without further ado, find the BNF grammar attached to this message. It
is also made available through Gist at [6] and a BNF grammar with
annotated production actions for an LLVM IR parser in Go is at [7].

/u & i

[1]: https://llvm.org/docs/LangRef.html
[2]: http://blog.llvm.org/
[3]: https://reviews.llvm.org/diffusion/L/browse/llvm/trunk/lib/AsmParser/
[4]: https://embed.cs.utah.edu/csmith/
[6]: Plain BNF:
[7]: BNF annotated with production actions for Go:

LLVM Developers mailing list
[hidden email]

ll.bnf (126K) Download Attachment