Has anyone written a grammar for LLVM for ANTLR. I mean an ANTLR grammar that parses LLVM instructions. Is an LLVM grammar available for any other parsing tool? Surinder
Hello Surinder, The existing hand-written parser is callable from almost anywhere so the only reason you'd need to have a parser for it would be to extend it. Originally it was written using Flex and Bison but Chris Lattner rewrote it from scratch to catch more errors at the parsing stage. The only feature I've found to be missing from the existing LLVM-AS utility was an include function with automatic unique detection. This would allow the use of headers instead of having to manually copy and paste them into the source. What were you planning on doing with your LLVM parser, if I may ask? --Sam ----- Original Message ----> From: Surinder <surifilms at gmail.com> > To: llvmdev at cs.uiuc.edu > Sent: Sun, January 23, 2011 10:35:38 PM > Subject: [LLVMdev] LLVM grammar for ANTLR > > Has anyone written a grammar for LLVM for ANTLR. I mean an ANTLR > grammar that parses LLVM instructions. Is an LLVM grammar available > for any other parsing tool? > > Surinder
On Mon, 2011-01-24 at 15:35 +1100, Surinder wrote:> Has anyone written a grammar for LLVM for ANTLR. I mean an ANTLR > grammar that parses LLVM instructions. Is an LLVM grammar available > for any other parsing tool?http://www.opendylan.org/cgi-bin/viewvc.cgi/trunk/fundev/sources/lib/llvm/llvm-asm-parser.dylgram is a grammar for LLVM assembly language written for a YACC-like LALR(1) parser generator. (The actual grammar rules start at the "define parser llvm-parser" line and continue to the end of the file.) This was constructed by starting from the original YACC-based parser for llvm-as (using a script that extracted raw grammar rules from the output of bison -v), and then augmenting it to disambiguate several shift/reduce conflicts and to handle changes to LLVM assembly language after the lib/AsmParser parser was re-implemented as a recursive-descent parser. Note that as usual with LR grammars, it contains a fair amount of left-recursion and would not be directly suitable for ANTLR, which implements LL(k). -Peter-
Hi Sam, Thanks for your reply. I am implementing my research (http://www.it.usyd.edu.au/~suri/Detecting%20Buffer%20Over.pdf), a translation of LLVM to a simple non-deterministic language to detect buffer overflows. It involves (1) printing a control flow graph of basic blocks of a function (easily done) (2) translating each llvm statement to a corresponding data flow language (needs ASTs to traverse) (3) translating control flow graph to a regular expression (4) translating data flow language statements to non-deterministic language (5) translating non-deterministic language to CLP (Prolog like solver) (6) finding a Prolog solution as proof of or absence of buffer overflows I have implemented Step (1) & (2) above by writing a transform pass. Remaining steps (3) to (6) have been written in Haskell. Step (2), translation from llvm to dfl language has been done by implementing an AnnotationWriter and it emits dfl format of each llvm statement. This is rather crude and causes crashes between llvm/haskell interface. I am considering to dump llvm as it is into Haskell program and then use a parser tool to do llvm statement translation to dfl. The translation is a set of simple rewrite tools. You can get further details from my website http://it.usyd.edu.au/~suri or you can ask me. Thank you for your interest. Surinder On Tue, Jan 25, 2011 at 3:22 AM, Samuel Crow <samuraileumas at yahoo.com> wrote:> Hello Surinder, > > The existing hand-written parser is callable from almost anywhere so the only > reason you'd need to have a parser for it would be to extend it. Originally it > was written using Flex and Bison but Chris Lattner rewrote it from scratch to > catch more errors at the parsing stage. > > The only feature I've found to be missing from the existing LLVM-AS utility was > an include function with automatic unique detection. This would allow the use > of headers instead of having to manually copy and paste them into the source. > What were you planning on doing with your LLVM parser, if I may ask? > > --Sam > > > ----- Original Message ---- >> From: Surinder <surifilms at gmail.com> >> To: llvmdev at cs.uiuc.edu >> Sent: Sun, January 23, 2011 10:35:38 PM >> Subject: [LLVMdev] LLVM grammar for ANTLR >> >> Has anyone written a grammar for LLVM for ANTLR. I mean an ANTLR >> grammar that parses LLVM instructions. Is an LLVM grammar available >> for any other parsing tool? >> >> Surinder > > > >
Possibly Parallel Threads
- [LLVMdev] LLVM grammar for ANTLR
- [LLVMdev] LLVM grammar for ANTLR
- [LLVMdev] Segmentation fault on using get parent of a PHINode
- [LLVMdev] llvm::Pass::Pass(llvm::PassKind, intptr_t): Assertion `pid && "pid cannot be 0"' failed.
- [LLVMdev] Error : llvm/include/llvm/Pass.h:188: error: incomplete type 'llvm::DominatorTree' used in nested name specifier