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

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
« no previous file with comments | « lib/compiler/implementation/lib/mock.dart ('k') | lib/compiler/implementation/ssa/codegen.dart » ('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 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.enableTypeAssertions) return original;
1038
1039 Type type = sourceElement.computeType(compiler);
1040 if (type === null) return original;
1041 if (type.element === compiler.dynamicClass) return original;
1042 if (type.element === compiler.objectClass) return original;
1043
1044 HType convertedType = new HType.fromBoundedType(type, compiler, true);
1045
1046 // TODO(ngeoffray): the factory method should never return null.
1047 if (convertedType === null) {
1048 return original;
1049 }
1050
1051 // No need to convert if we know the instruction has
1052 // [convertedType] as a bound.
1053 if (original.guaranteedType == convertedType) {
1054 return original;
1055 }
1056
1057 HInstruction instruction =
1058 new HTypeConversion(convertedType, original, true);
1059 add(instruction);
1060 return instruction;
1061 }
1062
1034 HGraph closeFunction() { 1063 HGraph closeFunction() {
1035 // TODO(kasperl): Make this goto an implicit return. 1064 // TODO(kasperl): Make this goto an implicit return.
1036 if (!isAborted()) close(new HGoto()).addSuccessor(graph.exit); 1065 if (!isAborted()) close(new HGoto()).addSuccessor(graph.exit);
1037 graph.finalize(); 1066 graph.finalize();
1038 return graph; 1067 return graph;
1039 } 1068 }
1040 1069
1041 HBasicBlock addNewBlock() { 1070 HBasicBlock addNewBlock() {
1042 HBasicBlock block = graph.addNewBlock(); 1071 HBasicBlock block = graph.addNewBlock();
1043 // If adding a new block during building of an expression, it is due to 1072 // 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); 1817 add(target);
1789 add(new HInvokeStatic(selector, <HInstruction>[target, value])); 1818 add(new HInvokeStatic(selector, <HInstruction>[target, value]));
1790 } else { 1819 } else {
1791 add(new HStaticStore(element, value)); 1820 add(new HStaticStore(element, value));
1792 } 1821 }
1793 stack.add(value); 1822 stack.add(value);
1794 } else if (element === null || Elements.isInstanceField(element)) { 1823 } else if (element === null || Elements.isInstanceField(element)) {
1795 HInstruction receiver = generateInstanceSendReceiver(send); 1824 HInstruction receiver = generateInstanceSendReceiver(send);
1796 generateInstanceSetterWithCompiledReceiver(send, receiver, value); 1825 generateInstanceSetterWithCompiledReceiver(send, receiver, value);
1797 } else { 1826 } else {
1798 localsHandler.updateLocal(element, value);
1799 stack.add(value); 1827 stack.add(value);
1800 // If the value does not already have a name, give it here. 1828 // If the value does not already have a name, give it here.
1801 if (value.sourceElement === null) { 1829 if (value.sourceElement === null) {
1802 value.sourceElement = element; 1830 value.sourceElement = element;
1803 } 1831 }
1832 HInstruction checked = potentiallyCheckType(value, element);
1833 if (checked !== value) {
1834 pop();
1835 stack.add(checked);
1836 }
1837 localsHandler.updateLocal(element, checked);
1804 } 1838 }
1805 } 1839 }
1806 1840
1807 visitOperatorSend(node) { 1841 visitOperatorSend(node) {
1808 assert(node.selector is Operator); 1842 assert(node.selector is Operator);
1809 Operator op = node.selector; 1843 Operator op = node.selector;
1810 if (const SourceString("[]") == op.source) { 1844 if (const SourceString("[]") == op.source) {
1811 HStatic target = new HStatic(interceptors.getIndexInterceptor()); 1845 HStatic target = new HStatic(interceptors.getIndexInterceptor());
1812 add(target); 1846 add(target);
1813 visit(node.receiver); 1847 visit(node.receiver);
(...skipping 1430 matching lines...) Expand 10 before | Expand all | Expand 10 after
3244 <HInstruction>[target, input], 3278 <HInstruction>[target, input],
3245 HType.STRING)); 3279 HType.STRING));
3246 return builder.pop(); 3280 return builder.pop();
3247 } 3281 }
3248 3282
3249 HInstruction result() { 3283 HInstruction result() {
3250 flushLiterals(); 3284 flushLiterals();
3251 return prefix; 3285 return prefix;
3252 } 3286 }
3253 } 3287 }
OLDNEW
« no previous file with comments | « lib/compiler/implementation/lib/mock.dart ('k') | lib/compiler/implementation/ssa/codegen.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698