Chromium Code Reviews| 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() { | |
| 52 if (!irEnabled()) return; | |
|
floitsch
2014/11/13 14:30:55
We should not call `buildNodes` if we aren't inter
sigurdm
2014/11/13 14:43:41
Done.
| |
| 38 measure(() { | 53 measure(() { |
| 39 Set<Element> resolved = compiler.enqueuer.resolution.resolvedElements; | 54 Set<Element> resolved = compiler.enqueuer.resolution.resolvedElements; |
| 40 resolved.forEach((AstElement element) { | 55 resolved.forEach((AstElement element) { |
| 41 if (canBuild(element)) { | 56 ir.FunctionDefinition functionDefinition = buildNode(element); |
| 42 TreeElements elementsMapping = element.resolvedAst.elements; | 57 if (functionDefinition != null) { |
| 43 element = element.implementation; | 58 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 } | 59 } |
| 58 }); | 60 }); |
| 59 }); | 61 }); |
| 60 } | 62 } |
| 61 | 63 |
| 62 bool irEnabled({bool useNewBackend: false}) { | 64 bool irEnabled() { |
| 63 // TODO(sigurdm,kmillikin): Support checked-mode checks. | 65 // TODO(sigurdm,kmillikin): Support checked-mode checks. |
| 64 return (useNewBackend || const bool.fromEnvironment('USE_NEW_BACKEND')) && | 66 return compiler.backend is DartBackend && |
| 65 compiler.backend is DartBackend && | 67 !compiler.enableTypeAssertions && |
|
floitsch
2014/11/13 14:30:55
These checks should probably go to the compiler to
sigurdm
2014/11/13 14:43:41
TODO added
| |
| 66 !compiler.enableTypeAssertions && | 68 !compiler.enableConcreteTypeInference; |
| 67 !compiler.enableConcreteTypeInference; | |
| 68 } | 69 } |
| 69 | 70 |
| 70 bool canBuild(Element element) { | 71 bool canBuild(Element element) { |
| 71 FunctionElement function = element.asFunctionElement(); | 72 FunctionElement function = element.asFunctionElement(); |
| 72 // TODO(kmillikin,sigurdm): support lazy field initializers. | 73 // TODO(kmillikin,sigurdm): support lazy field initializers. |
| 73 if (function == null) return false; | 74 if (function == null) return false; |
| 74 | 75 |
| 75 if (!compiler.backend.shouldOutput(function)) return false; | 76 if (!compiler.backend.shouldOutput(function)) return false; |
| 76 | 77 |
| 77 assert(invariant(element, !function.isNative)); | 78 assert(invariant(element, !function.isNative)); |
| (...skipping 807 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 885 node.visitChildren(this); | 886 node.visitChildren(this); |
| 886 } | 887 } |
| 887 | 888 |
| 888 visitFunctionExpression(ast.FunctionExpression node) { | 889 visitFunctionExpression(ast.FunctionExpression node) { |
| 889 FunctionElement oldFunction = currentFunction; | 890 FunctionElement oldFunction = currentFunction; |
| 890 currentFunction = elements[node]; | 891 currentFunction = elements[node]; |
| 891 visit(node.body); | 892 visit(node.body); |
| 892 currentFunction = oldFunction; | 893 currentFunction = oldFunction; |
| 893 } | 894 } |
| 894 } | 895 } |
| OLD | NEW |