Changeset 3338 for proto


Ignore:
Timestamp:
Jun 20, 2013, 2:33:57 PM (6 years ago)
Author:
ksherdy
Message:

Encode visitor dependencies explicitly within 'apply' methods.

Location:
proto/pabloj/trunk/src/toolchain/pabloS/transformer
Files:
2 added
2 deleted
3 edited

Legend:

Unmodified
Added
Removed
  • proto/pabloj/trunk/src/toolchain/pabloS/transformer/Transformer.java

    r3335 r3338  
    5555                decoratedTree = CombineAdvances.apply(decoratedTree);
    5656               
    57                 decoratedTree = TempifyCarryBuiltinCalls.apply(decoratedTree);
    5857                decoratedTree = CarryIntroXFormer.apply(decoratedTree, getBuiltinEncoder(), getCarrySet2Lang(), finalBlockMode);
    59 
     58               
    6059                decoratedTree = SurroundConditionsWithBitBlockAny.apply(decoratedTree);
    6160                decoratedTree = ConvertBitwiseBooleanToIDISACalls.apply(decoratedTree);
    6261                //decoratedTree = InitializeStreamDefaults.apply(decoratedTree);
    63                
    64                 decoratedTree = SplitVarDeclsInits.apply(decoratedTree);
    65                 //decoratedTree = FlattenBlockScopes.apply(decoratedTree);
    6662                               
    6763                return decoratedTree;
  • proto/pabloj/trunk/src/toolchain/pabloS/transformer/visitors/carry/CarryIntroXFormer.java

    r3337 r3338  
    6464
    6565public class CarryIntroXFormer {           
    66     public static ASTNode apply(ASTNode root, Context context) {
    67         Transformer transformer = new Transformer(context);
    68         root.accept(transformer);
    69         return root;
     66   
     67    private static boolean isTempified = false;
     68   
     69    private static ASTNode TempifyOnce(ASTNode ASTree) {
     70        if(!isTempified) {
     71            isTempified = true;
     72            return TempifyCarryBuiltinCalls.apply(ASTree);
     73        }
     74        return ASTree;
    7075    }
    71     public static ASTNode apply(ASTNode root, Context context, int carry1Base, int carryNBase) {
    72         Transformer transformer = new Transformer(context, carry1Base, carryNBase);
    73         root.accept(transformer);
    74         return root;
    75     }   
    76     public static ASTNode apply(ASTNode root, BuiltinEncoder builtinEncoder, CarrySetEncoder carrySetEncoder,
     76   
     77    public static ASTNode apply(ASTNode root, BuiltinEncoder builtinEncoder, CarrySetEncoder carrySetEncoder, boolean finalBlockMode) {
     78       
     79        ASTNode xTree = apply(root, builtinEncoder, carrySetEncoder, finalBlockMode, true, 0);
     80        isTempified = false;
     81        return xTree;
     82    }
     83
     84    private static ASTNode apply(ASTNode root, BuiltinEncoder builtinEncoder, CarrySetEncoder carrySetEncoder,
    7785                                boolean finalBlockMode, boolean ciMode, int carrySetDepth) {
    7886        Context context = new Context(builtinEncoder, carrySetEncoder, ciMode, finalBlockMode, carrySetDepth);
    79         return apply(root, context);
     87        return apply(root, context); 
    8088    }
    81     public static ASTNode apply(ASTNode root, BuiltinEncoder builtinEncoder, CarrySetEncoder carrySetEncoder, boolean finalBlockMode) {
    82         return apply(root, builtinEncoder, carrySetEncoder, finalBlockMode, true, 0);
     89       
     90    private static ASTNode apply(ASTNode root, Context context) {
     91        ASTNode xTree = TempifyOnce(root);
     92        Transformer transformer = new Transformer(context);
     93        xTree.accept(transformer);
     94        return xTree;
    8395    }
    84    
     96    private static ASTNode apply(ASTNode root, Context context, int carry1Base, int carryNBase) {
     97       
     98        ASTNode xTree = TempifyOnce(root);
     99        Transformer transformer = new Transformer(context, carry1Base, carryNBase);
     100        xTree.accept(transformer);
     101        return xTree;
     102    }   
    85103   
    86104    static private class Transformer extends VoidVisitor.Default {
     
    166184                }
    167185               
     186                ///////////////////////////////////////////////////////////////////
     187                // LocalVarDeclNode
     188                public void visitLeave(VarDeclNode node) {
     189                    if(Accessors.hasInitializationExpr(node)) {
     190
     191                        ASTNode rhs = Accessors.rhs(node);
     192                        if(BuiltinCallUtil.isCarry(rhs)) {
     193                            IdentifierNode lhs = (IdentifierNode) Accessors.identifier(node);
     194
     195                            FuncCallNode funcCall = (FuncCallNode) rhs;
     196
     197                            PabloSBuiltin builtin = BuiltinCallUtil.builtin(funcCall);
     198                            Counter counter = selectCounter(builtin, carryCounter, advanceNCounter);
     199                            CarryBuiltinTranslator translator = (CarryBuiltinTranslator) builtin.getTranslator();
     200                            IdentifierNode returnValue = lhs;
     201                            translator.translate(builtin, funcCall, counter, context, returnValue);
     202
     203                            node.replaceChild(lhs, counter.makeGetCarryCall(node,context));
     204                            counter.increment();
     205                        }
     206                    }
     207                }
     208           
    168209                ///////////////////////////////////////////////////////////////////
    169210                // FuncCallNode
  • proto/pabloj/trunk/src/toolchain/pabloS/transformer/visitors/carry/TempifyCarryBuiltinCalls.java

    r3336 r3338  
    5353import toolchain.pabloS.ast.Generators;
    5454import toolchain.pabloS.lang.BuiltinCallUtil;
     55import toolchain.pabloS.transformer.visitors.SplitVarDeclInits;
    5556import toolchain.util.Labeller;
    5657import toolchain.util.Pair;
    5758import static toolchain.util.MapUtil.*;
    5859
    59 
     60import toolchain.pabloS.transformer.visitors.*;
    6061public class TempifyCarryBuiltinCalls {
    6162       
    6263        static public ASTNode apply(ASTNode ASTree) {
     64           
     65            ASTNode xTree = SplitVarDeclInits.apply(ASTree);
     66           
    6367            Tempifier tempifier = new Tempifier();
    64                 ASTree.accept(tempifier);
     68            xTree.accept(tempifier);
    6569                return ASTree;                 
    6670        }   
     
    109113            insertTempAssigns(node);
    110114            }
    111            
    112         public void visitLeave(VarDeclNode node) {
    113             bindTempDeclsToBlockStmt(node);
    114             bindTempAssignToBlockStmt(node);           
    115         }           
    116            
     115   
    117116            public void visitLeave(AssignNode node) {
    118117            bindTempDeclsToBlockStmt(node);
Note: See TracChangeset for help on using the changeset viewer.