I am wondering that whether there is a BNF-grammar to describe LLVM IR? like C BNF grammar describing C language, etc.
问题:
回答1:
There isn't a published BNF grammar, but there is a polygen grammer file which is partially maintained, and used for exactly the purpose of randomly generating inputs to use to test the LLVM IR parser and lexer.
You can see the current version of the grammar here:
http://llvm.org/viewvc/llvm-project/llvm/trunk/utils/llvm.grm?revision=112427&view=markup
回答2:
My parser for LLVM assembly language, written for a YACC-like parser generator, can serve as a BNF definition for the language.
回答3:
Yes. Go to the file "LLParser.cpp" in "LLVM/lib/AsmParser"; the EBNF is spread throughput the file, for instance, the function LLParser::ParseNamedType()
around line 350 has the following function-comment:
/// toplevelentity
/// ::= LocalVar '=' 'type' type
bool LLParser::ParseNamedType() {
/* impl. */
}
I'm sure a regular-expression would happily extract the EBNF. I'm doing so by hand as I go through the parser.
回答4:
There is no published BNF grammar for LLVM IR. There are docs to describe the format and, of course, source code, mailing lists, and an IRC channel. Those places are far better sources of information than StackOverflow.
回答5:
In reply to @tschwinge
I just found LLIR ("Unofficial libraries for interacting with LLVM IR"), which includes a (WIP?) grammar repository ("BNF grammar for LLVM IR assembly").
One of the original authors here. The grammar repository is indeed a work in process, and the aim is to define a BNF grammar for the assembly language representation of LLVM IR. It's current progress may be tracked at https://github.com/llir/llvm/blob/master/current.md
In the future, my friends and I would wish to contribute this grammar back to the official LLVM project, and would love it if the lexer and parser were one day generated from a BNF grammar, as that would ensure an up-to-date specification of the language.
A problem we've encountered when writing the BNF grammar is that there is no single source of truth (well except the source code of course). We've compared the BNF comments of the source code against the LangRef documentation, and sometimes these were not in sync with the actual C++ code, which has lead to some confusion.
The current status of the BNF grammar is that it supports all instructions and constants expressions of LLVM IR. There are still some minor additions to be added to support all LLVM IR concepts, and currently we are working on supporting DWARF metadata. General metadata nodes are already supported.
Cheerful regards, /u & i
回答6:
This Eclipse plugin contains an Xtext grammar for LLVM IR.
回答7:
I just found LLIR ("Unofficial libraries for interacting with LLVM IR"), which includes a (WIP?) grammar repository ("BNF grammar for LLVM IR assembly").