You are doing this the wrong way around. You want as little code as possible in your tree walker, just just want a set of API calls that your tree walker can make, where it passes pointers to trees and/or tokens. The API code is then I n a separate C file, and it is that C file that makes the LLVM calls and has the includes you need for that. That file also has the antlr headers so that it knows about tree structures etc.
Golden rule is to keep code out of the .g files. Jim > -----Original Message----- > From: [email protected] [mailto:antlr-interest- > [email protected]] On Behalf Of Aaron Leiby > Sent: Wednesday, October 13, 2010 5:39 PM > To: antlr-interest > Subject: [antlr-interest] antlr-c and llvm > > This is probably pretty basic C stuff, but I could use some pointers in the right > direction. > > I've gone through Terrance's tutorial, but would like to work with the llvm > libraries directly (as opposed to using string templates to generate IR files to > be processed offline). > > So to that end, I've been using the C output generation with ANTLR, but I'm > having difficulties including the LLVM headers into my tree walker (so I can > generate code to JIT, etc.). > > First, a couple of points: > > 1) I'm not having troubles compiling LLVM itself. I'm working on Snow > Leopard, and the standard ./configure make install went just fine. I also > went through the process of using cmake to generate an Xcode project to > build from, but that's not what I'm looking for. > > 2) LLVM has a pretty complicated build process. They've got a nice llvm- > config tool that's useful for spitting out cflags to use in your makefile, etc. > The two important things there is to define both __STDC_LIMIT_MACROS > and __STDC_CONSTANT_MACROS before any headers are included. I've > added this to my Xcode project settings, and that seems to be working fine. > > 3) LLVM has a set of C bindings which I'm guessing I'm going to have to use if I > want to do any of this from within my tree walker. These headers live in > include/llvm-c fwiw. > > Now, in my main.cpp if I include <llvm-c/Core.h> at the very top, everything > compiles nicely. > > However, if I include it in the @includes section of my tree grammar, or for > that matter anywhere after I include the header for my tree walker, then I > get a ton of errors. Note: including <antlr3treeparser.h> does not appear to > cause these issues. > > Here's some things it's choking on in the llvm code (stripped down for > readability): > > namespace llvm { > > > template<typename ValueTy> class StringMapEntry; > > typedef StringMapEntry<Value*> ValueName; > > class Twine; > > class Value { > > ... > > ValueName *Name; //!Expected unqualified-id before numeric constant > > ... > > void setName(const Twine &Name); //!Expected ',' or '...' before numeric > constant > > > > So, in this case it looks like 'Name' is getting defined elsewhere that's causing > me problems. And in fact it is -- it's one of my tokens which gets #defined in > my tree walker header (picked up from my lexer tokens). > > > I suppose I can go through an rename all of my lexer rules to make them > more obscure, but that seems like something the C output templates should > maybe handle instead. I'd be surprised if I wasn't the first to run into this > kind of issue, so I imagine there might be some facilities for working around > this already that I just haven't discovered. > > > Thoughts? > > List: http://www.antlr.org/mailman/listinfo/antlr-interest > Unsubscribe: http://www.antlr.org/mailman/options/antlr-interest/your- > email-address List: http://www.antlr.org/mailman/listinfo/antlr-interest Unsubscribe: http://www.antlr.org/mailman/options/antlr-interest/your-email-address -- You received this message because you are subscribed to the Google Groups "il-antlr-interest" group. To post to this group, send email to [email protected]. To unsubscribe from this group, send email to [email protected]. For more options, visit this group at http://groups.google.com/group/il-antlr-interest?hl=en.
