hi guys. I'm mid thought on this, but I'm thinking of trying out  
something akin to an LLVM IR approach. i think of it as doing for  
source code gen what TWIG/BURG did for assembly generation.

Instead of sharing common code chunks between matchToken,  
matchTokenRoot, matchTokenLeaf, etc... with another template and  
instead of lots of template variants, let's try to identify all the  
common chunks among all templates and identify some common operations.  
Then, we make those operations instructions in an IR.  For example,  
token ref T would become

match T

then t=T would become

t = LT(1)
match T

T^ would be

label42 = LT(1)
match T
root label42

rule ref r would be

r()

r[3,"hi"]

becomes

t1=3
t2="hi"
call r, t1..t2

x=r[34]

becomes

t1=34
rv = call r
x.a = rv.a      ; assume r returns values a and b not single value
x.b = rv.b

etc...

The target developer can combine the operations into x=r(34) or push  
args onto software stack (to avoid pred hoisting issues), etc...

I'm thinking of a typed IR like llvm where we have token, tree,  
string, int etc...

Once we have that, it divorces the grammar to code part, though not  
the surrounding class and set up stuff.

One could even imagine some symbol table manipulation instructions.

We could interpret this or translate to source code with 1-to-1  
templates for these canonical operations. We could even go straight to  
LLVM IR from this ANTLR IR for some serious cranking. heh,that's an  
interesting idea.

The good thing about this is that it'd be a well defined interface  
(finally!) for target developers.  We could ALMOST just ask developers  
to identify what assignment, call, hashtable lookup, WHILE, IF looks  
like in their language to get a basic target built pronto.  Beyond  
that we'd need them to identify patterns in the IR to make it higher  
level.  It'll be a balance between high level enough to make it easy  
to map to high level code but low level enough to make it easy to  
share common elements.

[added to wiki]

Ter
_______________________________________________
antlr-dev mailing list
[email protected]
http://www.antlr.org/mailman/listinfo/antlr-dev

Reply via email to