| OLD | NEW |
| 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2013, 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 part of dart2js.ir_builder; | 5 part of dart2js.ir_builder; |
| 6 | 6 |
| 7 /** | 7 /** |
| 8 * This task iterates through all resolved elements and builds [ir.Node]s. The | 8 * This task iterates through all resolved elements and builds [ir.Node]s. The |
| 9 * nodes are stored in the [nodes] map and accessible through [hasIr] and | 9 * nodes are stored in the [nodes] map and accessible through [hasIr] and |
| 10 * [getIr]. | 10 * [getIr]. |
| (...skipping 15 matching lines...) Expand all Loading... |
| 26 <Element, ir.FunctionDefinition>{}; | 26 <Element, ir.FunctionDefinition>{}; |
| 27 | 27 |
| 28 IrBuilderTask(Compiler compiler) : super(compiler); | 28 IrBuilderTask(Compiler compiler) : super(compiler); |
| 29 | 29 |
| 30 String get name => 'IR builder'; | 30 String get name => 'IR builder'; |
| 31 | 31 |
| 32 bool hasIr(Element element) => nodes.containsKey(element.implementation); | 32 bool hasIr(Element element) => nodes.containsKey(element.implementation); |
| 33 | 33 |
| 34 ir.FunctionDefinition getIr(Element element) => nodes[element.implementation]; | 34 ir.FunctionDefinition getIr(Element element) => nodes[element.implementation]; |
| 35 | 35 |
| 36 void buildNodes({bool useNewBackend: false}) { | 36 ir.FunctionDefinition buildNode(AstElement element) { |
| 37 if (!irEnabled(useNewBackend: useNewBackend)) return; | 37 if (!canBuild(element)) return null; |
| 38 TreeElements elementsMapping = element.resolvedAst.elements; |
| 39 element = element.implementation; |
| 40 return compiler.withCurrentElement(element, () { |
| 41 SourceFile sourceFile = elementSourceFile(element); |
| 42 IrBuilderVisitor builder = |
| 43 new IrBuilderVisitor(elementsMapping, compiler, sourceFile); |
| 44 ir.FunctionDefinition function; |
| 45 function = builder.buildFunction(element); |
| 46 |
| 47 return function; |
| 48 }); |
| 49 } |
| 50 |
| 51 void buildNodes() { |
| 38 measure(() { | 52 measure(() { |
| 39 Set<Element> resolved = compiler.enqueuer.resolution.resolvedElements; | 53 Set<Element> resolved = compiler.enqueuer.resolution.resolvedElements; |
| 40 resolved.forEach((AstElement element) { | 54 resolved.forEach((AstElement element) { |
| 41 if (canBuild(element)) { | 55 ir.FunctionDefinition functionDefinition = buildNode(element); |
| 42 TreeElements elementsMapping = element.resolvedAst.elements; | 56 if (functionDefinition != null) { |
| 43 element = element.implementation; | 57 nodes[element] = functionDefinition; |
| 44 compiler.withCurrentElement(element, () { | |
| 45 SourceFile sourceFile = elementSourceFile(element); | |
| 46 IrBuilderVisitor builder = | |
| 47 new IrBuilderVisitor(elementsMapping, compiler, sourceFile); | |
| 48 ir.FunctionDefinition function; | |
| 49 function = builder.buildFunction(element); | |
| 50 | |
| 51 if (function != null) { | |
| 52 nodes[element] = function; | |
| 53 compiler.tracer.traceCompilation(element.name, null); | |
| 54 compiler.tracer.traceGraph("IR Builder", function); | |
| 55 } | |
| 56 }); | |
| 57 } | 58 } |
| 58 }); | 59 }); |
| 59 }); | 60 }); |
| 60 } | 61 } |
| 61 | 62 |
| 62 bool irEnabled({bool useNewBackend: false}) { | |
| 63 // TODO(sigurdm,kmillikin): Support checked-mode checks. | |
| 64 return (useNewBackend || const bool.fromEnvironment('USE_NEW_BACKEND')) && | |
| 65 compiler.backend is DartBackend && | |
| 66 !compiler.enableTypeAssertions && | |
| 67 !compiler.enableConcreteTypeInference; | |
| 68 } | |
| 69 | |
| 70 bool canBuild(Element element) { | 63 bool canBuild(Element element) { |
| 71 FunctionElement function = element.asFunctionElement(); | 64 FunctionElement function = element.asFunctionElement(); |
| 72 // TODO(kmillikin,sigurdm): support lazy field initializers. | 65 // TODO(kmillikin,sigurdm): support lazy field initializers. |
| 73 if (function == null) return false; | 66 if (function == null) return false; |
| 74 | 67 |
| 75 if (!compiler.backend.shouldOutput(function)) return false; | 68 if (!compiler.backend.shouldOutput(function)) return false; |
| 76 | 69 |
| 77 assert(invariant(element, !function.isNative)); | 70 assert(invariant(element, !function.isNative)); |
| 78 | 71 |
| 79 // TODO(kmillikin,sigurdm): Support constructors. | 72 // TODO(kmillikin,sigurdm): Support constructors. |
| (...skipping 805 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 885 node.visitChildren(this); | 878 node.visitChildren(this); |
| 886 } | 879 } |
| 887 | 880 |
| 888 visitFunctionExpression(ast.FunctionExpression node) { | 881 visitFunctionExpression(ast.FunctionExpression node) { |
| 889 FunctionElement oldFunction = currentFunction; | 882 FunctionElement oldFunction = currentFunction; |
| 890 currentFunction = elements[node]; | 883 currentFunction = elements[node]; |
| 891 visit(node.body); | 884 visit(node.body); |
| 892 currentFunction = oldFunction; | 885 currentFunction = oldFunction; |
| 893 } | 886 } |
| 894 } | 887 } |
| OLD | NEW |