Chromium Code Reviews| 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 part of js_backend; | 5 part of js_backend; |
| 6 | 6 |
| 7 const VERBOSE_OPTIMIZER_HINTS = false; | 7 const VERBOSE_OPTIMIZER_HINTS = false; |
| 8 | 8 |
| 9 class JavaScriptItemCompilationContext extends ItemCompilationContext { | 9 class JavaScriptItemCompilationContext extends ItemCompilationContext { |
| 10 final Set<HInstruction> boundsChecked = new Set<HInstruction>(); | 10 final Set<HInstruction> boundsChecked = new Set<HInstruction>(); |
| (...skipping 270 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 281 | 281 |
| 282 TypeVariableHandler typeVariableHandler; | 282 TypeVariableHandler typeVariableHandler; |
| 283 | 283 |
| 284 /// Number of methods compiled before considering reflection. | 284 /// Number of methods compiled before considering reflection. |
| 285 int preMirrorsMethodCount = 0; | 285 int preMirrorsMethodCount = 0; |
| 286 | 286 |
| 287 /// Resolution and codegen support for generating table of interceptors and | 287 /// Resolution and codegen support for generating table of interceptors and |
| 288 /// constructors for custom elements. | 288 /// constructors for custom elements. |
| 289 CustomElementsAnalysis customElementsAnalysis; | 289 CustomElementsAnalysis customElementsAnalysis; |
| 290 | 290 |
| 291 JavaScriptConstantHandler constantCompiler; | |
| 292 | |
| 291 JavaScriptBackend(Compiler compiler, bool generateSourceMap) | 293 JavaScriptBackend(Compiler compiler, bool generateSourceMap) |
| 292 : namer = determineNamer(compiler), | 294 : namer = determineNamer(compiler), |
| 293 oneShotInterceptors = new Map<String, Selector>(), | 295 oneShotInterceptors = new Map<String, Selector>(), |
| 294 interceptedElements = new Map<String, Set<Element>>(), | 296 interceptedElements = new Map<String, Set<Element>>(), |
| 295 rti = new RuntimeTypes(compiler), | 297 rti = new RuntimeTypes(compiler), |
| 296 specializedGetInterceptors = new Map<String, Set<ClassElement>>(), | 298 specializedGetInterceptors = new Map<String, Set<ClassElement>>(), |
| 297 super(compiler, JAVA_SCRIPT_CONSTANT_SYSTEM) { | 299 super(compiler) { |
| 298 emitter = new CodeEmitterTask(compiler, namer, generateSourceMap); | 300 emitter = new CodeEmitterTask(compiler, namer, generateSourceMap); |
| 299 builder = new SsaBuilderTask(this); | 301 builder = new SsaBuilderTask(this); |
| 300 optimizer = new SsaOptimizerTask(this); | 302 optimizer = new SsaOptimizerTask(this); |
| 301 generator = new SsaCodeGeneratorTask(this); | 303 generator = new SsaCodeGeneratorTask(this); |
| 302 typeVariableHandler = new TypeVariableHandler(this); | 304 typeVariableHandler = new TypeVariableHandler(this); |
| 303 customElementsAnalysis = new CustomElementsAnalysis(this); | 305 customElementsAnalysis = new CustomElementsAnalysis(this); |
| 306 constantCompiler = new JavaScriptConstantHandler(compiler); | |
| 307 } | |
| 308 | |
| 309 ConstantSystem get constantSystem => constantHandler.constantSystem; | |
| 310 | |
| 311 JavaScriptBackendConstantHandler get constantHandler { | |
| 312 return constantCompiler.jsConstantCompiler; | |
| 304 } | 313 } |
| 305 | 314 |
| 306 static Namer determineNamer(Compiler compiler) { | 315 static Namer determineNamer(Compiler compiler) { |
| 307 return compiler.enableMinification ? | 316 return compiler.enableMinification ? |
| 308 new MinifyNamer(compiler) : | 317 new MinifyNamer(compiler) : |
| 309 new Namer(compiler); | 318 new Namer(compiler); |
| 310 } | 319 } |
| 311 | 320 |
| 312 bool usedByBackend(Element element) { | 321 bool usedByBackend(Element element) { |
| 313 if (element.isParameter() | 322 if (element.isParameter() |
| (...skipping 821 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1135 | 1144 |
| 1136 void codegen(CodegenWorkItem work) { | 1145 void codegen(CodegenWorkItem work) { |
| 1137 Element element = work.element; | 1146 Element element = work.element; |
| 1138 var kind = element.kind; | 1147 var kind = element.kind; |
| 1139 if (kind == ElementKind.TYPEDEF) return; | 1148 if (kind == ElementKind.TYPEDEF) return; |
| 1140 if (element.isConstructor() && element.getEnclosingClass() == jsNullClass) { | 1149 if (element.isConstructor() && element.getEnclosingClass() == jsNullClass) { |
| 1141 // Work around a problem compiling JSNull's constructor. | 1150 // Work around a problem compiling JSNull's constructor. |
| 1142 return; | 1151 return; |
| 1143 } | 1152 } |
| 1144 if (kind.category == ElementCategory.VARIABLE) { | 1153 if (kind.category == ElementCategory.VARIABLE) { |
| 1154 JavaScriptBackend backend = compiler.backend; | |
|
karlklose
2014/04/02 13:04:44
Isn't this the JavaScriptBackend?
Johnni Winther
2014/04/07 11:42:27
Yes! Removed.
| |
| 1145 Constant initialValue = | 1155 Constant initialValue = |
| 1146 compiler.constantHandler.getConstantForVariable(element); | 1156 backend.constantHandler.getConstantForVariable(element); |
| 1147 if (initialValue != null) { | 1157 if (initialValue != null) { |
| 1148 registerCompileTimeConstant(initialValue, work.resolutionTree); | 1158 registerCompileTimeConstant(initialValue, work.resolutionTree); |
| 1149 compiler.constantHandler.addCompileTimeConstantForEmission( | 1159 backend.constantHandler.addCompileTimeConstantForEmission( |
| 1150 initialValue); | 1160 initialValue); |
| 1151 // We don't need to generate code for static or top-level | 1161 // We don't need to generate code for static or top-level |
| 1152 // variables. For instance variables, we may need to generate | 1162 // variables. For instance variables, we may need to generate |
| 1153 // the checked setter. | 1163 // the checked setter. |
| 1154 if (Elements.isStaticOrTopLevel(element)) return; | 1164 if (Elements.isStaticOrTopLevel(element)) return; |
| 1155 } else { | 1165 } else { |
| 1156 // If the constant-handler was not able to produce a result we have to | 1166 // If the constant-handler was not able to produce a result we have to |
| 1157 // go through the builder (below) to generate the lazy initializer for | 1167 // go through the builder (below) to generate the lazy initializer for |
| 1158 // the static variable. | 1168 // the static variable. |
| 1159 // We also need to register the use of the cyclic-error helper. | 1169 // We also need to register the use of the cyclic-error helper. |
| (...skipping 440 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1600 return symbolsUsed.contains(name); | 1610 return symbolsUsed.contains(name); |
| 1601 } | 1611 } |
| 1602 | 1612 |
| 1603 bool get rememberLazies => isTreeShakingDisabled; | 1613 bool get rememberLazies => isTreeShakingDisabled; |
| 1604 | 1614 |
| 1605 bool retainMetadataOf(Element element) { | 1615 bool retainMetadataOf(Element element) { |
| 1606 if (mustRetainMetadata) hasRetainedMetadata = true; | 1616 if (mustRetainMetadata) hasRetainedMetadata = true; |
| 1607 if (mustRetainMetadata && isNeededForReflection(element)) { | 1617 if (mustRetainMetadata && isNeededForReflection(element)) { |
| 1608 for (MetadataAnnotation metadata in element.metadata) { | 1618 for (MetadataAnnotation metadata in element.metadata) { |
| 1609 metadata.ensureResolved(compiler); | 1619 metadata.ensureResolved(compiler); |
| 1610 compiler.constantHandler.addCompileTimeConstantForEmission( | 1620 Constant constant = constantHandler.getConstantForMetadata(metadata); |
| 1611 metadata.value); | 1621 constantHandler.addCompileTimeConstantForEmission(constant); |
| 1612 } | 1622 } |
| 1613 return true; | 1623 return true; |
| 1614 } | 1624 } |
| 1615 return false; | 1625 return false; |
| 1616 } | 1626 } |
| 1617 | 1627 |
| 1618 Future onLibraryLoaded(LibraryElement library, Uri uri) { | 1628 Future onLibraryLoaded(LibraryElement library, Uri uri) { |
| 1619 if (uri == Uri.parse('dart:_js_mirrors')) { | 1629 if (uri == Uri.parse('dart:_js_mirrors')) { |
| 1620 disableTreeShakingMarker = | 1630 disableTreeShakingMarker = |
| 1621 library.find('disableTreeShaking'); | 1631 library.find('disableTreeShaking'); |
| (...skipping 257 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1879 } | 1889 } |
| 1880 } | 1890 } |
| 1881 | 1891 |
| 1882 /// Records that [constant] is used by [user.element]. | 1892 /// Records that [constant] is used by [user.element]. |
| 1883 class Dependency { | 1893 class Dependency { |
| 1884 final Constant constant; | 1894 final Constant constant; |
| 1885 final TreeElements user; | 1895 final TreeElements user; |
| 1886 | 1896 |
| 1887 const Dependency(this.constant, this.user); | 1897 const Dependency(this.constant, this.user); |
| 1888 } | 1898 } |
| 1889 | |
| OLD | NEW |