Changeset 1281 for proto/pebble


Ignore:
Timestamp:
Aug 4, 2011, 11:21:07 PM (8 years ago)
Author:
shermer
Message:

Continuing work on cleaning 'incode' package:
Moved instruction factories to their own class.

Location:
proto/pebble/trunk/src
Files:
1 added
5 edited

Legend:

Unmodified
Added
Removed
  • proto/pebble/trunk/src/ast/transforms/ASTtoIncode.java

    r1260 r1281  
    11package ast.transforms;
    22
    3 import static incode.Instruction.*;
    43import incode.BasicBlock;
    54import incode.Fragment;
    65import incode.Instruction;
     6import static incode.InstructionFactories.*;
    77
    88import java.util.ArrayList;
     
    4747                        if(BasicBlock.lookup(name) == null) {
    4848                                String var = newTemporary();
    49                                 addToBlock(Instruction.makeCopy(var, name));
     49                                addToBlock(makeCopy(var, name));
    5050                                return blocks.peek();
    5151                        }
  • proto/pebble/trunk/src/incode/BasicBlock.java

    r1279 r1281  
    11package incode;
    22
    3 import static incode.Instruction.makeJump;
    4 import static incode.Instruction.makeJoin;
    5 import static incode.Instruction.makeIter;
     3import static incode.InstructionFactories.*;
    64
    75import java.util.ArrayList;
     
    295293        public Instruction lastInstruction() {
    296294                if(store.isEmpty())
    297                         return Instruction.makeNull();
     295                        return InstructionFactories.makeNull();
    298296               
    299297                int size = store.size();
  • proto/pebble/trunk/src/incode/Instruction.java

    r1280 r1281  
    3737                notEqualsComparison = false;
    3838        }
    39 
    4039        private String translateArrayIndices(String operand) {
    4140                if(operand == null)
     
    212211
    213212        ///////////////////////////////////////////////////////////////////////////
    214         // static factories for each op-type
    215         ///////////////////////////////////////////////////////////////////////////
    216         public static Instruction makeAnd(String var, String operand1, String operand2) {
    217                 return new Instruction(Op.AND, var, operand1, operand2);
    218         }
    219         public static Instruction makeOr(String var, String operand1, String operand2) {
    220                 return new Instruction(Op.OR, var, operand1, operand2);
    221         }
    222         public static Instruction makeXor(String var, String operand1, String operand2) {
    223                 return new Instruction(Op.XOR, var, operand1, operand2);
    224         }
    225         public static Instruction makeNot(String var, String operand1) {
    226                 return new Instruction(Op.NOT, var, operand1);
    227         }
    228         public static Instruction makeCopy(String var, String operand1) {
    229                 return new Instruction(Op.COPY, var, operand1);
    230         }
    231         public static Instruction makeSel(String var, String operand1, String operand2, String operand3) {
    232                 return new Instruction(Op.SEL, var, operand1, operand2, operand3);
    233         }
    234         public static Instruction makeAndNot(String var, String operand1, String operand2) {
    235                 return new Instruction(Op.ANDNOT, var, operand1, operand2);
    236         }
    237         public static Instruction makeShift(String var, String operand1, String operand2) {
    238                 return new Instruction(Op.SHIFT, var, operand1, operand2);
    239         }       
    240         public static Instruction makeScan(String var, String operand1, String operand2) {
    241                 return new Instruction(Op.SCAN, var, operand1, operand2);
    242         }
    243         public static Instruction makeSpan(String var, String operand1, String operand2) {
    244                 return new Instruction(Op.SPAN, var, operand1, operand2);
    245         }
    246 
    247         public static Instruction makeNop() {
    248                 return new Instruction(Op.NOP);
    249         }
    250         public static Instruction makeComment(String comment) {
    251                 return new Instruction(Op.COMMENT, "", comment);
    252         }
    253         public static Instruction makeNull() {
    254                 return new NullInstruction();
    255         }
    256         public static Instruction makeInstantiate(String var, String typeName) {
    257                 return new Instruction(Op.INSTANTIATE, var, typeName);
    258         }
    259        
    260         public static Instruction makeTest(String var, String trueName, String falseName, String joinName, boolean notEqualsComparison) {
    261                 return makeTestType(Op.TEST, var, trueName, falseName, joinName, notEqualsComparison);
    262         }
    263         public static Instruction makeWhile(String var, String loopName, String exitName, boolean notEqualsComparison) {
    264                 return makeTestType(Op.WHILE, var, loopName, exitName, null, notEqualsComparison);
    265         }
    266         private static Instruction makeTestType(Op op, String var,
    267                         String trueName, String falseName, String joinName, boolean notEqualComparison) {
    268                 Instruction instruction = new Instruction(op, var, trueName, falseName, joinName);
    269                 if(notEqualComparison) instruction.setNotEqualsComparison();
    270                 return instruction;
    271         }
    272         public static Instruction makeJump(String label) {
    273                 return new Instruction(Op.JUMP, "", label);
    274         }
    275         public static Instruction makeIter(String label) {
    276                 return new Instruction(Op.ITER, "", label);
    277         }
    278         public static Instruction makeJoin(String label) {
    279                 return new Instruction(Op.JOIN, "", label);
    280         }
    281         public static Instruction makeError(String var, String falseName, String trueMessage, boolean notEqualsComparison) {
    282                 return makeTestType(Op.ERROR, var, falseName, trueMessage, null, notEqualsComparison);
    283         }
    284        
    285 
    286         ///////////////////////////////////////////////////////////////////////////
    287         // Null Object.  Use the makeNull factory, above, to create.
    288         ///////////////////////////////////////////////////////////////////////////
    289         static private class NullInstruction extends Instruction {
     213        // Null Object.  Use the makeNull factory in InstructionFactories to create.
     214        ///////////////////////////////////////////////////////////////////////////
     215        static class NullInstruction extends Instruction {
    290216                public NullInstruction() {
    291217                        super(Op.INVALID);
  • proto/pebble/trunk/src/incode/localOptimization/ReuseAvailableExpressions.java

    r1254 r1281  
    33import incode.BasicBlock;
    44import incode.Instruction;
     5import static incode.InstructionFactories.makeCopy;
    56import incode.Op;
    67
     
    1011import java.util.Map;
    1112import java.util.Map.Entry;
    12 
    13 
    1413
    1514public class ReuseAvailableExpressions {
     
    140139                        String currentName = currentI.getVariable();
    141140                       
    142                         Instruction copy = Instruction.makeCopy(currentName, priorName);
     141                        Instruction copy = makeCopy(currentName, priorName);
    143142                        block.replaceInstruction(index, copy);
    144143                        replaceUses(currentName, priorName);
  • proto/pebble/trunk/src/lexicalStream/LexicalCollector.java

    r1262 r1281  
    22
    33import incode.BasicBlock;
    4 import incode.Instruction;
     4import static incode.InstructionFactories.*;
    55
    66import java.util.ArrayList;
     
    196196        private void addSectionHeaderComment(BasicBlock block, String streamTypes) {
    197197                addSeparatorComment(block);     
    198         block.add(Instruction.makeComment("compute " + streamTypes + " streams"));     
     198        block.add(makeComment("compute " + streamTypes + " streams")); 
    199199        }
    200200        private void addSeparatorComment(BasicBlock block) {
    201         block.add(Instruction.makeComment(" "));
     201        block.add(makeComment(" "));
    202202        }
    203203
Note: See TracChangeset for help on using the changeset viewer.