Changeset 2394
- Timestamp:
- Sep 25, 2012, 2:56:58 PM (6 years ago)
- Location:
- proto/pablo/src/compiler
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
proto/pablo/src/compiler/PabloCompiler.java
r2392 r2394 56 56 57 57 for (Map.Entry<String, ASTNode> entry : streamFunctionMap.entrySet()) { 58 System.out.println("BEFORE");59 60 System.out.println(entry.getKey());61 System.out.println(entry.getValue());62 58 63 59 AdvanceCombiner.transform(entry.getValue()); 64 60 65 66 System.out.println("AFTER");67 68 System.out.println(entry.getKey());69 61 System.out.println(entry.getValue()); 70 71 62 72 63 } -
proto/pablo/src/compiler/visitors/AdvanceCombiner.java
r2392 r2394 45 45 int amount2 = advanceAmount(child); 46 46 47 // System.out.println("amount1=" + amount1);48 // System.out.println("amount2=" + amount2);49 // System.out.println("sum=" + (amount1+amount2) );50 51 //ASTNode sum = astForSum(amount1, amount2);52 47 53 54 node.replaceChild(child, streamBeingAdvanced); 55 IntegerConstantNode integerConstantNode = Helpers.makeIntegerConstantNode(amount1+amount2, node.getToken()); 56 if(node.nChildren()==2) { 57 node.appendChild(integerConstantNode); 58 } 59 assert node.nChildren()==3; 60 node.replaceChild(node.child(2), integerConstantNode); 48 translateAdvanceNode(node, child, streamBeingAdvanced, amount1, 49 amount2); 61 50 62 51 } 63 52 64 65 // private ASTNode astForSum(ASTNode amount1, ASTNode amount2) {66 // Token token = amount1.getToken(); // used for its location only.67 //68 // // optimize when both amounts are constant.69 // // this if can be removed if tree is later subject to an70 // // optimizer that does this anyway.71 // if(isIntConstant(amount1) && isIntConstant(amount2)) {72 // int sum = valueOf(amount1) + valueOf(amount2);73 // return makeIntegerConstantNode(sum, token);74 // }75 //76 // BinaryOperatorNode sumNode = new BinaryOperatorNode(newPlusToken(token));77 // sumNode.appendChild(amount1);78 // sumNode.appendChild(amount2);79 // return sumNode;80 // }81 // private LextantToken newPlusToken(Token token) {82 // return makeLextantToken(Lextant.PLUS, token);83 // }84 53 } 85 54 … … 97 66 return node instanceof IntegerConstantNode; 98 67 } 99 100 68 101 69 /////////////////////////////////////////////////////////////////// 102 70 // intelligence about calls to advance() … … 107 75 assert isAdvance(node); 108 76 return node.child(1); 109 }110 // given that node is an advance, advance by how much? (expressed as an AST node)111 // private static ASTNode advanceAmount(FunctionInvocationNode node) {112 // assert isAdvance(node);113 // if(node.nChildren()==2) {114 // return Helpers.makeIntegerConstantNode(1, node.getToken());115 // }116 // assert node.nChildren()==3;117 // return node.child(2);118 // }119 private static void updateAdvanceNode(FunctionInvocationNode node, ASTNode streamBeingAdvanced, int amount1, int amount2) {120 assert isAdvance(node);121 node.replaceChild(node.child(1), streamBeingAdvanced);122 IntegerConstantNode integerConstantNode = Helpers.makeIntegerConstantNode(amount1 + amount2, node.getToken());123 node.appendChild(integerConstantNode);124 125 77 } 126 78 … … 144 96 return Helpers.isBuiltInCall(node, "Advance"); 145 97 } 98 99 private static void translateAdvanceNode(FunctionInvocationNode node, 100 FunctionInvocationNode child, ASTNode streamBeingAdvanced, 101 int amount1, int amount2) { 102 node.replaceChild(child, streamBeingAdvanced); 103 IntegerConstantNode integerConstantNode = Helpers.makeIntegerConstantNode(amount1+amount2, node.getToken()); 104 if(node.nChildren()==2) { 105 node.appendChild(integerConstantNode); 106 } 107 assert node.nChildren()==3; 108 node.replaceChild(node.child(2), integerConstantNode); 109 } 110 146 111 }
Note: See TracChangeset
for help on using the changeset viewer.