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

Side by Side Diff: pkg/compiler/lib/src/ssa/builder.dart

Issue 2942863002: Compile and run Hello World! (Closed)
Patch Set: Cleanup Created 3 years, 6 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
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 import 'dart:collection'; 5 import 'dart:collection';
6 6
7 import 'package:js_runtime/shared/embedded_names.dart'; 7 import 'package:js_runtime/shared/embedded_names.dart';
8 8
9 import '../closure.dart'; 9 import '../closure.dart';
10 import '../common.dart'; 10 import '../common.dart';
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
48 import 'locals_handler.dart'; 48 import 'locals_handler.dart';
49 import 'loop_handler.dart'; 49 import 'loop_handler.dart';
50 import 'nodes.dart'; 50 import 'nodes.dart';
51 import 'optimize.dart'; 51 import 'optimize.dart';
52 import 'ssa.dart'; 52 import 'ssa.dart';
53 import 'ssa_branch_builder.dart'; 53 import 'ssa_branch_builder.dart';
54 import 'type_builder.dart'; 54 import 'type_builder.dart';
55 import 'types.dart'; 55 import 'types.dart';
56 56
57 abstract class SsaAstBuilderBase extends CompilerTask 57 abstract class SsaAstBuilderBase extends CompilerTask
58 with SsaBuilderFieldMixin
58 implements SsaBuilderTask { 59 implements SsaBuilderTask {
59 final JavaScriptBackend backend; 60 final JavaScriptBackend backend;
60 61
61 SsaAstBuilderBase(this.backend) : super(backend.compiler.measurer); 62 SsaAstBuilderBase(this.backend) : super(backend.compiler.measurer);
62 63
63 /// Handle field initializer of `work.element`. Returns `true` if no code 64 ConstantValue getFieldInitialConstantValue(FieldElement field) {
64 /// is needed for the field. 65 ConstantExpression constant = field.constant;
65 /// 66 if (constant != null) {
66 /// If `work.element` is a field with a constant initializer, the value is 67 ConstantValue initialValue = backend.constants.getConstantValue(constant);
67 /// registered with the world impact. Otherwise the cyclic-throw helper is 68 if (initialValue == null) {
68 /// registered for the lazy value computation. 69 assert(
69 /// 70 field.isInstanceMember ||
70 /// If the field is constant, no code is needed for the field and the method 71 constant.isImplicit ||
71 /// return `true`. 72 constant.isPotential,
72 bool handleConstantField( 73 failedAt(
73 ElementCodegenWorkItem work, ClosedWorld closedWorld) { 74 field,
74 MemberElement element = work.element; 75 "Constant expression without value: "
75 if (element.isField) { 76 "${constant.toStructuredText()}."));
76 FieldElement field = element;
77 ConstantExpression constant = field.constant;
78 if (constant != null) {
79 ConstantValue initialValue =
80 backend.constants.getConstantValue(constant);
81 if (initialValue != null) {
82 work.registry.worldImpact
83 .registerConstantUse(new ConstantUse.init(initialValue));
84 // We don't need to generate code for static or top-level
85 // variables. For instance variables, we may need to generate
86 // the checked setter.
87 if (field.isStatic || field.isTopLevel) {
88 /// No code is created for this field.
89 return true;
90 }
91 } else {
92 assert(
93 field.isInstanceMember ||
94 constant.isImplicit ||
95 constant.isPotential,
96 failedAt(
97 field,
98 "Constant expression without value: "
99 "${constant.toStructuredText()}."));
100 }
101 } else {
102 // If the constant-handler was not able to produce a result we have to
103 // go through the builder (below) to generate the lazy initializer for
104 // the static variable.
105 // We also need to register the use of the cyclic-error helper.
106 work.registry.worldImpact.registerStaticUse(new StaticUse.staticInvoke(
107 closedWorld.commonElements.cyclicThrowHelper,
108 CallStructure.ONE_ARG));
109 } 77 }
78 return initialValue;
110 } 79 }
111 return false; 80 return null;
112 } 81 }
113 } 82 }
114 83
115 class SsaAstBuilderTask extends SsaAstBuilderBase { 84 class SsaAstBuilderTask extends SsaAstBuilderBase {
116 final CodeEmitterTask emitter; 85 final CodeEmitterTask emitter;
117 final SourceInformationStrategy sourceInformationFactory; 86 final SourceInformationStrategy sourceInformationFactory;
118 87
119 String get name => 'SSA builder'; 88 String get name => 'SSA builder';
120 89
121 SsaAstBuilderTask(JavaScriptBackend backend, this.sourceInformationFactory) 90 SsaAstBuilderTask(JavaScriptBackend backend, this.sourceInformationFactory)
122 : emitter = backend.emitter, 91 : emitter = backend.emitter,
123 super(backend); 92 super(backend);
124 93
125 DiagnosticReporter get reporter => backend.reporter; 94 DiagnosticReporter get reporter => backend.reporter;
126 95
127 HGraph build(ElementCodegenWorkItem work, ClosedWorld closedWorld) { 96 HGraph build(ElementCodegenWorkItem work, ClosedWorld closedWorld) {
128 return measure(() { 97 return measure(() {
129 if (handleConstantField(work, closedWorld)) { 98 if (handleConstantField(work.element, work.registry, closedWorld)) {
130 // No code is generated for `work.element`. 99 // No code is generated for `work.element`.
131 return null; 100 return null;
132 } 101 }
133 MemberElement element = work.element.implementation; 102 MemberElement element = work.element.implementation;
134 return reporter.withCurrentElement(element, () { 103 return reporter.withCurrentElement(element, () {
135 SsaBuilder builder = new SsaBuilder( 104 SsaBuilder builder = new SsaBuilder(
136 work.element.implementation, 105 work.element.implementation,
137 work.resolvedAst, 106 work.resolvedAst,
138 work.registry, 107 work.registry,
139 backend, 108 backend,
(...skipping 6727 matching lines...) Expand 10 before | Expand all | Expand 10 after
6867 this.oldReturnLocal, 6836 this.oldReturnLocal,
6868 this.oldReturnType, 6837 this.oldReturnType,
6869 this.oldResolvedAst, 6838 this.oldResolvedAst,
6870 this.oldStack, 6839 this.oldStack,
6871 this.oldLocalsHandler, 6840 this.oldLocalsHandler,
6872 this.inTryStatement, 6841 this.inTryStatement,
6873 this.allFunctionsCalledOnce, 6842 this.allFunctionsCalledOnce,
6874 this.oldElementInferenceResults) 6843 this.oldElementInferenceResults)
6875 : super(function); 6844 : super(function);
6876 } 6845 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698