A BNF grammar for LLVM IR assembly

Hi,

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].

Cheers,
/u & i

[1]: LLVM Language Reference Manual — LLVM 15.0.0git documentation
[2]: http://blog.llvm.org/
[3]: AsmParser · rL
[4]: Csmith
[5]:
https://reviews.llvm.org/diffusion/L/browse/llvm/trunk/lib/AsmParser/LLParser.cpp;324928
[6]: Plain BNF:
A BNF grammar for LLVM IR assembly · GitHub
[7]: BNF annotated with production actions for Go:
https://raw.githubusercontent.com/llir/grammar/master/ll.bnf

ll.bnf (92.5 KB)