[antlr-interest] Threading a compiler (C++)

Peggy Fieland madcapmaggie at yahoo.com
Fri Mar 24 14:31:12 PST 2006


Bryan,

We're doing something similar -- separate threads for
various phases -- one thread does the lexing and
parsing, another does the semantic analysis.

We haven't run into any major problems beyond needing
to be very careful with locks so the reference counts
on the ANTLR nodes don't get screwed up.  

I was occasionally paranoid in that some routines made
copies of their input before making any modifications.

I'll be in the office next week if you'd like to
discuss any details.

We're using C++ and Zthreads on Linux.  

Peggy

--- Bryan Ewbank <ewbank at gmail.com> wrote:

> Has anyone done any work with threading an
> ANTLR-based compiler so
> that each pass is in a separate thread?  Any things
> to be aware of
> when taking this approach (e.g., unexpected state
> information, etc)?
> 
> I'm looking at a function inlining pass (whole
> program optimization)
> that makes the AST simply huge, followed by an
> optimization pass that
> shrinks the AST substantially, and rather than
> having them each
> operate on the whole program, instead have them work
> on each
> statement, preserving state as needed.
> 
> So, instead of each TreeParser starting here:
>    program : #( PROGRAM ( statement )* );
> 
> I instead have a wrapper that does this:
>    program : #( PROGRAM ( s1: statement {
> inline.statement(s1);
> optim.statement(s1); } )* );
> 
> then each of the other passes (inlining,
> optimization) would be a
> separate thread...
> 
> Any advice would be great
> - Bryan Ewbank
> 



More information about the antlr-interest mailing list