| OLD | NEW |
| 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 import '../common.dart'; | 5 import '../common.dart'; |
| 6 import '../common/codegen.dart' show CodegenRegistry, CodegenWorkItem; | 6 import '../common/codegen.dart' show CodegenRegistry, CodegenWorkItem; |
| 7 import '../common/tasks.dart' show CompilerTask; | 7 import '../common/tasks.dart' show CompilerTask; |
| 8 import '../compiler.dart' show Compiler; | 8 import '../compiler.dart' show Compiler; |
| 9 import '../constants/constant_system.dart'; | 9 import '../constants/constant_system.dart'; |
| 10 import '../constants/values.dart'; | 10 import '../constants/values.dart'; |
| 11 import '../core_types.dart' show CoreClasses; | 11 import '../core_types.dart' show CoreClasses; |
| 12 import '../dart_types.dart'; | 12 import '../dart_types.dart'; |
| 13 import '../elements/elements.dart'; | 13 import '../elements/elements.dart'; |
| 14 import '../io/source_information.dart'; | 14 import '../io/source_information.dart'; |
| 15 import '../js/js.dart' as js; | 15 import '../js/js.dart' as js; |
| 16 import '../js_backend/backend_helpers.dart' show BackendHelpers; | 16 import '../js_backend/backend_helpers.dart' show BackendHelpers; |
| 17 import '../js_backend/js_backend.dart'; | 17 import '../js_backend/js_backend.dart'; |
| 18 import '../js_emitter/js_emitter.dart' show CodeEmitterTask, NativeEmitter; | 18 import '../js_emitter/js_emitter.dart' show NativeEmitter; |
| 19 import '../native/native.dart' as native; | 19 import '../native/native.dart' as native; |
| 20 import '../types/types.dart'; | 20 import '../types/types.dart'; |
| 21 import '../universe/call_structure.dart' show CallStructure; | 21 import '../universe/call_structure.dart' show CallStructure; |
| 22 import '../universe/selector.dart' show Selector; | 22 import '../universe/selector.dart' show Selector; |
| 23 import '../universe/use.dart' show DynamicUse, StaticUse, TypeUse; | 23 import '../universe/use.dart' show DynamicUse, StaticUse, TypeUse; |
| 24 import '../util/util.dart'; | 24 import '../util/util.dart'; |
| 25 import '../world.dart' show ClassWorld, World; | 25 import '../world.dart' show ClassWorld; |
| 26 | 26 import 'codegen_helpers.dart'; |
| 27 import 'nodes.dart'; | 27 import 'nodes.dart'; |
| 28 import 'codegen_helpers.dart'; | |
| 29 import 'variable_allocator.dart'; | 28 import 'variable_allocator.dart'; |
| 30 | 29 |
| 31 class SsaCodeGeneratorTask extends CompilerTask { | 30 class SsaCodeGeneratorTask extends CompilerTask { |
| 32 final JavaScriptBackend backend; | 31 final JavaScriptBackend backend; |
| 33 final SourceInformationStrategy sourceInformationFactory; | 32 final SourceInformationStrategy sourceInformationFactory; |
| 34 | 33 |
| 35 SsaCodeGeneratorTask(JavaScriptBackend backend, this.sourceInformationFactory) | 34 SsaCodeGeneratorTask(JavaScriptBackend backend, this.sourceInformationFactory) |
| 36 : this.backend = backend, | 35 : this.backend = backend, |
| 37 super(backend.compiler); | 36 super(backend.compiler); |
| 38 | 37 |
| (...skipping 1567 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1606 .withSourceInformation(node.sourceInformation)); | 1605 .withSourceInformation(node.sourceInformation)); |
| 1607 registry.registerStaticUse(new StaticUse.constructorBodyInvoke( | 1606 registry.registerStaticUse(new StaticUse.constructorBodyInvoke( |
| 1608 node.element, new CallStructure.unnamed(arguments.length))); | 1607 node.element, new CallStructure.unnamed(arguments.length))); |
| 1609 } | 1608 } |
| 1610 | 1609 |
| 1611 void visitOneShotInterceptor(HOneShotInterceptor node) { | 1610 void visitOneShotInterceptor(HOneShotInterceptor node) { |
| 1612 List<js.Expression> arguments = visitArguments(node.inputs); | 1611 List<js.Expression> arguments = visitArguments(node.inputs); |
| 1613 var isolate = new js.VariableUse( | 1612 var isolate = new js.VariableUse( |
| 1614 backend.namer.globalObjectFor(helpers.interceptorsLibrary)); | 1613 backend.namer.globalObjectFor(helpers.interceptorsLibrary)); |
| 1615 Selector selector = node.selector; | 1614 Selector selector = node.selector; |
| 1616 TypeMask mask = getOptimizedSelectorFor(node, selector, node.mask); | |
| 1617 js.Name methodName = backend.registerOneShotInterceptor(selector); | 1615 js.Name methodName = backend.registerOneShotInterceptor(selector); |
| 1618 push(js | 1616 push(js |
| 1619 .propertyCall(isolate, methodName, arguments) | 1617 .propertyCall(isolate, methodName, arguments) |
| 1620 .withSourceInformation(node.sourceInformation)); | 1618 .withSourceInformation(node.sourceInformation)); |
| 1621 if (selector.isGetter) { | 1619 if (selector.isGetter) { |
| 1622 registerGetter(node); | 1620 registerGetter(node); |
| 1623 } else if (selector.isSetter) { | 1621 } else if (selector.isSetter) { |
| 1624 registerSetter(node); | 1622 registerSetter(node); |
| 1625 } else { | 1623 } else { |
| 1626 registerMethodInvoke(node); | 1624 registerMethodInvoke(node); |
| (...skipping 548 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2175 } else { | 2173 } else { |
| 2176 generateThrowWithHelper( | 2174 generateThrowWithHelper( |
| 2177 helpers.throwIndexOutOfRangeException, [node.array, node.index]); | 2175 helpers.throwIndexOutOfRangeException, [node.array, node.index]); |
| 2178 } | 2176 } |
| 2179 } | 2177 } |
| 2180 | 2178 |
| 2181 void generateThrowWithHelper(Element helper, argument, | 2179 void generateThrowWithHelper(Element helper, argument, |
| 2182 {SourceInformation sourceInformation}) { | 2180 {SourceInformation sourceInformation}) { |
| 2183 js.Expression jsHelper = backend.emitter.staticFunctionAccess(helper); | 2181 js.Expression jsHelper = backend.emitter.staticFunctionAccess(helper); |
| 2184 List arguments = []; | 2182 List arguments = []; |
| 2185 var location; | |
| 2186 if (argument is List) { | 2183 if (argument is List) { |
| 2187 location = argument[0]; | |
| 2188 argument.forEach((instruction) { | 2184 argument.forEach((instruction) { |
| 2189 use(instruction); | 2185 use(instruction); |
| 2190 arguments.add(pop()); | 2186 arguments.add(pop()); |
| 2191 }); | 2187 }); |
| 2192 } else { | 2188 } else { |
| 2193 location = argument; | |
| 2194 use(argument); | 2189 use(argument); |
| 2195 arguments.add(pop()); | 2190 arguments.add(pop()); |
| 2196 } | 2191 } |
| 2197 registry.registerStaticUse(new StaticUse.staticInvoke( | 2192 registry.registerStaticUse(new StaticUse.staticInvoke( |
| 2198 helper, new CallStructure.unnamed(arguments.length))); | 2193 helper, new CallStructure.unnamed(arguments.length))); |
| 2199 js.Call value = new js.Call(jsHelper, arguments.toList(growable: false), | 2194 js.Call value = new js.Call(jsHelper, arguments.toList(growable: false), |
| 2200 sourceInformation: sourceInformation); | 2195 sourceInformation: sourceInformation); |
| 2201 // BUG(4906): Using throw/return here adds to the size of the generated code | 2196 // BUG(4906): Using throw/return here adds to the size of the generated code |
| 2202 // but it has the advantage of explicitly telling the JS engine that | 2197 // but it has the advantage of explicitly telling the JS engine that |
| 2203 // this code path will terminate abruptly. Needs more work. | 2198 // this code path will terminate abruptly. Needs more work. |
| (...skipping 693 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2897 registry.registerStaticUse(new StaticUse.staticInvoke( | 2892 registry.registerStaticUse(new StaticUse.staticInvoke( |
| 2898 helper, new CallStructure.unnamed(argumentCount))); | 2893 helper, new CallStructure.unnamed(argumentCount))); |
| 2899 return backend.emitter.staticFunctionAccess(helper); | 2894 return backend.emitter.staticFunctionAccess(helper); |
| 2900 } | 2895 } |
| 2901 | 2896 |
| 2902 @override | 2897 @override |
| 2903 void visitRef(HRef node) { | 2898 void visitRef(HRef node) { |
| 2904 visit(node.value); | 2899 visit(node.value); |
| 2905 } | 2900 } |
| 2906 } | 2901 } |
| OLD | NEW |