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

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

Issue 10353014: Start implementing checked mode and tools support for using it. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: 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
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 Interceptors { 5 class Interceptors {
6 Compiler compiler; 6 Compiler compiler;
7 Interceptors(Compiler this.compiler); 7 Interceptors(Compiler this.compiler);
8 8
9 SourceString mapOperatorToMethodName(Operator op) { 9 SourceString mapOperatorToMethodName(Operator op) {
10 String name = op.source.stringValue; 10 String name = op.source.stringValue;
(...skipping 287 matching lines...) Expand 10 before | Expand all | Expand 10 after
298 298
299 void startFunction(FunctionElement function, 299 void startFunction(FunctionElement function,
300 FunctionExpression node) { 300 FunctionExpression node) {
301 301
302 ClosureTranslator translator = 302 ClosureTranslator translator =
303 new ClosureTranslator(builder.compiler, builder.elements); 303 new ClosureTranslator(builder.compiler, builder.elements);
304 closureData = translator.translate(node); 304 closureData = translator.translate(node);
305 305
306 FunctionParameters params = function.computeParameters(builder.compiler); 306 FunctionParameters params = function.computeParameters(builder.compiler);
307 params.forEachParameter((Element element) { 307 params.forEachParameter((Element element) {
308 HParameterValue parameter = new HParameterValue(element); 308 HInstruction parameter = new HParameterValue(element);
309 builder.add(parameter); 309 builder.add(parameter);
310 parameter = builder.potentiallyCheckType(parameter, element);
310 directLocals[element] = parameter; 311 directLocals[element] = parameter;
311 }); 312 });
312 313
313 enterScope(node); 314 enterScope(node);
314 315
315 // If the freeVariableMapping is not empty, then this function was a 316 // If the freeVariableMapping is not empty, then this function was a
316 // nested closure that captures variables. Redirect the captured 317 // nested closure that captures variables. Redirect the captured
317 // variables to fields in the closure. 318 // variables to fields in the closure.
318 closureData.freeVariableMapping.forEach((Element from, Element to) { 319 closureData.freeVariableMapping.forEach((Element from, Element to) {
319 redirectElement(from, to); 320 redirectElement(from, to);
(...skipping 704 matching lines...) Expand 10 before | Expand all | Expand 10 after
1024 FunctionExpression node) { 1025 FunctionExpression node) {
1025 HBasicBlock block = graph.addNewBlock(); 1026 HBasicBlock block = graph.addNewBlock();
1026 open(graph.entry); 1027 open(graph.entry);
1027 1028
1028 localsHandler.startFunction(functionElement, node); 1029 localsHandler.startFunction(functionElement, node);
1029 close(new HGoto()).addSuccessor(block); 1030 close(new HGoto()).addSuccessor(block);
1030 1031
1031 open(block); 1032 open(block);
1032 } 1033 }
1033 1034
1035 HInstruction potentiallyCheckType(HInstruction original,
1036 Element sourceElement) {
1037 if (!compiler.isCheckedModeEnabled) return original;
1038
1039 Type type = sourceElement.computeType(compiler);
1040 if (type !== null) {
kasperl 2012/05/07 10:42:39 Bailout style? if (type === null) return orig
ngeoffray 2012/05/07 13:15:42 Done.
1041 HType convertedType = new HType.fromBoundedType(type, compiler, true);
1042 if (convertedType !== null) {
1043 // No need to convert if we know the instruction has
1044 // [convertedType] as a bound.
1045 if (original.guaranteedType.union(convertedType) === convertedType) {
floitsch 2012/05/07 09:50:07 ==
ngeoffray 2012/05/07 13:15:42 Done.
1046 return original;
1047 }
1048 HInstruction instruction = new HTypeConversion(
1049 convertedType, original, true);
1050 add(instruction);
1051 return instruction;
1052 }
1053 }
1054 return original;
1055 }
1056
1034 HGraph closeFunction() { 1057 HGraph closeFunction() {
1035 // TODO(kasperl): Make this goto an implicit return. 1058 // TODO(kasperl): Make this goto an implicit return.
1036 if (!isAborted()) close(new HGoto()).addSuccessor(graph.exit); 1059 if (!isAborted()) close(new HGoto()).addSuccessor(graph.exit);
1037 graph.finalize(); 1060 graph.finalize();
1038 return graph; 1061 return graph;
1039 } 1062 }
1040 1063
1041 HBasicBlock addNewBlock() { 1064 HBasicBlock addNewBlock() {
1042 HBasicBlock block = graph.addNewBlock(); 1065 HBasicBlock block = graph.addNewBlock();
1043 // If adding a new block during building of an expression, it is due to 1066 // If adding a new block during building of an expression, it is due to
(...skipping 744 matching lines...) Expand 10 before | Expand all | Expand 10 after
1788 add(target); 1811 add(target);
1789 add(new HInvokeStatic(selector, <HInstruction>[target, value])); 1812 add(new HInvokeStatic(selector, <HInstruction>[target, value]));
1790 } else { 1813 } else {
1791 add(new HStaticStore(element, value)); 1814 add(new HStaticStore(element, value));
1792 } 1815 }
1793 stack.add(value); 1816 stack.add(value);
1794 } else if (element === null || Elements.isInstanceField(element)) { 1817 } else if (element === null || Elements.isInstanceField(element)) {
1795 HInstruction receiver = generateInstanceSendReceiver(send); 1818 HInstruction receiver = generateInstanceSendReceiver(send);
1796 generateInstanceSetterWithCompiledReceiver(send, receiver, value); 1819 generateInstanceSetterWithCompiledReceiver(send, receiver, value);
1797 } else { 1820 } else {
1798 localsHandler.updateLocal(element, value);
1799 stack.add(value); 1821 stack.add(value);
1800 // If the value does not already have a name, give it here. 1822 // If the value does not already have a name, give it here.
1801 if (value.sourceElement === null) { 1823 if (value.sourceElement === null) {
1802 value.sourceElement = element; 1824 value.sourceElement = element;
1803 } 1825 }
1826 HInstruction checked = potentiallyCheckType(value, element);
1827 if (checked !== value) {
1828 pop();
1829 stack.add(checked);
1830 }
1831 localsHandler.updateLocal(element, checked);
1804 } 1832 }
1805 } 1833 }
1806 1834
1807 visitOperatorSend(node) { 1835 visitOperatorSend(node) {
1808 assert(node.selector is Operator); 1836 assert(node.selector is Operator);
1809 Operator op = node.selector; 1837 Operator op = node.selector;
1810 if (const SourceString("[]") == op.source) { 1838 if (const SourceString("[]") == op.source) {
1811 HStatic target = new HStatic(interceptors.getIndexInterceptor()); 1839 HStatic target = new HStatic(interceptors.getIndexInterceptor());
1812 add(target); 1840 add(target);
1813 visit(node.receiver); 1841 visit(node.receiver);
(...skipping 1430 matching lines...) Expand 10 before | Expand all | Expand 10 after
3244 <HInstruction>[target, input], 3272 <HInstruction>[target, input],
3245 HType.STRING)); 3273 HType.STRING));
3246 return builder.pop(); 3274 return builder.pop();
3247 } 3275 }
3248 3276
3249 HInstruction result() { 3277 HInstruction result() {
3250 flushLiterals(); 3278 flushLiterals();
3251 return prefix; 3279 return prefix;
3252 } 3280 }
3253 } 3281 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698