[antlr-interest] antlr-c and llvm

Aaron Leiby aleiby.antlr at gmail.com
Wed Oct 13 17:39:01 PDT 2010


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?


More information about the antlr-interest mailing list