Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(424)

Side by Side Diff: lib/compiler/implementation/ssa/codegen.dart

Issue 10343002: Make bit-operations return a positive result. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: rebase Created 8 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « lib/compiler/implementation/lib/js_helper.dart ('k') | tests/standalone/standalone.status » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 class SsaCodeGeneratorTask extends CompilerTask { 5 class SsaCodeGeneratorTask extends CompilerTask {
6 SsaCodeGeneratorTask(Compiler compiler) : super(compiler); 6 SsaCodeGeneratorTask(Compiler compiler) : super(compiler);
7 String get name() => 'SSA code generator'; 7 String get name() => 'SSA code generator';
8 8
9 9
10 String buildJavaScriptFunction(FunctionElement element, 10 String buildJavaScriptFunction(FunctionElement element,
(...skipping 1082 matching lines...) Expand 10 before | Expand all | Expand 10 after
1093 beginExpression(operatorPrecedences.precedence); 1093 beginExpression(operatorPrecedences.precedence);
1094 use(node.left, operatorPrecedences.left); 1094 use(node.left, operatorPrecedences.left);
1095 buffer.add(' $op '); 1095 buffer.add(' $op ');
1096 use(node.right, operatorPrecedences.right); 1096 use(node.right, operatorPrecedences.right);
1097 endExpression(operatorPrecedences.precedence); 1097 endExpression(operatorPrecedences.precedence);
1098 } else { 1098 } else {
1099 visitInvokeStatic(node); 1099 visitInvokeStatic(node);
1100 } 1100 }
1101 } 1101 }
1102 1102
1103 // We want the outcome of bit-operations to be positive. We use the unsigned
1104 // shift operator to achieve this.
1105 visitBitInvokeBinary(HBinaryBitOp node, String op) {
1106 if (node.builtin){
1107 JSBinaryOperatorPrecedence unsignedShiftPrecedences =
kasperl 2012/05/03 07:05:50 Could this be cached somewhere? It feels a bit ove
floitsch 2012/05/03 11:10:36 cached as instance field now.
1108 JSPrecedence.binary['>>>'];
1109 beginExpression(unsignedShiftPrecedences.precedence);
1110 visitInvokeBinary(node, op);
1111 buffer.add(' >>> 0');
1112 endExpression(unsignedShiftPrecedences.precedence);
1113 } else {
1114 visitInvokeBinary(node, op);
1115 }
1116 }
1117
1103 visitInvokeUnary(HInvokeUnary node, String op) { 1118 visitInvokeUnary(HInvokeUnary node, String op) {
1104 if (node.builtin) { 1119 if (node.builtin) {
1105 beginExpression(JSPrecedence.PREFIX_PRECEDENCE); 1120 beginExpression(JSPrecedence.PREFIX_PRECEDENCE);
1106 buffer.add('$op'); 1121 buffer.add('$op');
1107 use(node.operand, JSPrecedence.PREFIX_PRECEDENCE); 1122 use(node.operand, JSPrecedence.PREFIX_PRECEDENCE);
1108 endExpression(JSPrecedence.PREFIX_PRECEDENCE); 1123 endExpression(JSPrecedence.PREFIX_PRECEDENCE);
1109 } else { 1124 } else {
1110 visitInvokeStatic(node); 1125 visitInvokeStatic(node);
1111 } 1126 }
1112 } 1127 }
1113 1128
1129 // We want the outcome of bit-operations to be positive. We use the unsigned
1130 // shift operator to achieve this.
1131 visitBitInvokeUnary(HInvokeUnary node, String op) {
1132 if (node.builtin){
1133 JSBinaryOperatorPrecedence unsignedShiftPrecedences =
1134 JSPrecedence.binary['>>>'];
1135 beginExpression(unsignedShiftPrecedences.precedence);
1136 visitInvokeUnary(node, op);
1137 buffer.add(' >>> 0');
1138 endExpression(unsignedShiftPrecedences.precedence);
1139 } else {
1140 visitInvokeUnary(node, op);
1141 }
1142 }
1143
1114 visitEquals(HEquals node) { 1144 visitEquals(HEquals node) {
1115 if (node.builtin) { 1145 if (node.builtin) {
1116 beginExpression(JSPrecedence.EQUALITY_PRECEDENCE); 1146 beginExpression(JSPrecedence.EQUALITY_PRECEDENCE);
1117 use(node.left, JSPrecedence.EQUALITY_PRECEDENCE); 1147 use(node.left, JSPrecedence.EQUALITY_PRECEDENCE);
1118 buffer.add(' === '); 1148 buffer.add(' === ');
1119 use(node.right, JSPrecedence.RELATIONAL_PRECEDENCE); 1149 use(node.right, JSPrecedence.RELATIONAL_PRECEDENCE);
1120 endExpression(JSPrecedence.EQUALITY_PRECEDENCE); 1150 endExpression(JSPrecedence.EQUALITY_PRECEDENCE);
1121 } else if (node.element === equalsNullElement || 1151 } else if (node.element === equalsNullElement ||
1122 node.element === boolifiedEqualsNullElement) { 1152 node.element === boolifiedEqualsNullElement) {
1123 beginExpression(JSPrecedence.CALL_PRECEDENCE); 1153 beginExpression(JSPrecedence.CALL_PRECEDENCE);
1124 use(node.target, JSPrecedence.CALL_PRECEDENCE); 1154 use(node.target, JSPrecedence.CALL_PRECEDENCE);
1125 buffer.add('('); 1155 buffer.add('(');
1126 use(node.left, JSPrecedence.ASSIGNMENT_PRECEDENCE); 1156 use(node.left, JSPrecedence.ASSIGNMENT_PRECEDENCE);
1127 buffer.add(')'); 1157 buffer.add(')');
1128 endExpression(JSPrecedence.CALL_PRECEDENCE); 1158 endExpression(JSPrecedence.CALL_PRECEDENCE);
1129 } else { 1159 } else {
1130 visitInvokeStatic(node); 1160 visitInvokeStatic(node);
1131 } 1161 }
1132 } 1162 }
1133 1163
1134 visitAdd(HAdd node) => visitInvokeBinary(node, '+'); 1164 visitAdd(HAdd node) => visitInvokeBinary(node, '+');
1135 visitDivide(HDivide node) => visitInvokeBinary(node, '/'); 1165 visitDivide(HDivide node) => visitInvokeBinary(node, '/');
1136 visitMultiply(HMultiply node) => visitInvokeBinary(node, '*'); 1166 visitMultiply(HMultiply node) => visitInvokeBinary(node, '*');
1137 visitSubtract(HSubtract node) => visitInvokeBinary(node, '-'); 1167 visitSubtract(HSubtract node) => visitInvokeBinary(node, '-');
1138 // Truncating divide does not have a JS equivalent. 1168 // Truncating divide does not have a JS equivalent.
1139 visitTruncatingDivide(HTruncatingDivide node) => visitInvokeStatic(node); 1169 visitTruncatingDivide(HTruncatingDivide node) => visitInvokeStatic(node);
1140 // Modulo cannot be mapped to the native operator (different semantics). 1170 // Modulo cannot be mapped to the native operator (different semantics).
1141 visitModulo(HModulo node) => visitInvokeStatic(node); 1171 visitModulo(HModulo node) => visitInvokeStatic(node);
1142 1172
1143 visitBitAnd(HBitAnd node) => visitInvokeBinary(node, '&'); 1173 visitBitAnd(HBitAnd node) => visitBitInvokeBinary(node, '&');
1144 visitBitNot(HBitNot node) => visitInvokeUnary(node, '~'); 1174 visitBitNot(HBitNot node) => visitBitInvokeUnary(node, '~');
1145 visitBitOr(HBitOr node) => visitInvokeBinary(node, '|'); 1175 visitBitOr(HBitOr node) => visitBitInvokeBinary(node, '|');
1146 visitBitXor(HBitXor node) => visitInvokeBinary(node, '^'); 1176 visitBitXor(HBitXor node) => visitBitInvokeBinary(node, '^');
1147 1177
1148 // We need to check if the left operand is negative in order to use 1178 // We need to check if the left operand is negative in order to use
1149 // the native operator. 1179 // the native operator.
1150 visitShiftRight(HShiftRight node) => visitInvokeStatic(node); 1180 visitShiftRight(HShiftRight node) => visitInvokeStatic(node);
1151 1181
1152 // Shift left cannot be mapped to the native operator (different semantics). 1182 // Shift left cannot be mapped to the native operator (different semantics).
1153 visitShiftLeft(HShiftLeft node) => visitInvokeStatic(node); 1183 visitShiftLeft(HShiftLeft node) => visitInvokeStatic(node);
1154 1184
1155 visitNegate(HNegate node) => visitInvokeUnary(node, '-'); 1185 visitNegate(HNegate node) => visitInvokeUnary(node, '-');
1156 1186
(...skipping 1232 matching lines...) Expand 10 before | Expand all | Expand 10 after
2389 startBailoutSwitch(); 2419 startBailoutSwitch();
2390 } 2420 }
2391 } 2421 }
2392 2422
2393 void endLabeledBlock(HLabeledBlockInformation labeledBlockInfo) { 2423 void endLabeledBlock(HLabeledBlockInformation labeledBlockInfo) {
2394 if (labeledBlockInfo.body.start.hasGuards()) { 2424 if (labeledBlockInfo.body.start.hasGuards()) {
2395 endBailoutSwitch(); 2425 endBailoutSwitch();
2396 } 2426 }
2397 } 2427 }
2398 } 2428 }
OLDNEW
« no previous file with comments | « lib/compiler/implementation/lib/js_helper.dart ('k') | tests/standalone/standalone.status » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698