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 dart2js.js_emitter; | 5 part of dart2js.js_emitter; |
6 | 6 |
7 const USE_NEW_EMITTER = const bool.fromEnvironment("dart2js.use.new.emitter"); | 7 const USE_NEW_EMITTER = const bool.fromEnvironment("dart2js.use.new.emitter"); |
8 | 8 |
9 /** | 9 /** |
10 * Generates the code for all used classes in the program. Static fields (even | 10 * Generates the code for all used classes in the program. Static fields (even |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
52 oldEmitter = new OldEmitter(compiler, namer, generateSourceMap, this); | 52 oldEmitter = new OldEmitter(compiler, namer, generateSourceMap, this); |
53 emitter = USE_NEW_EMITTER | 53 emitter = USE_NEW_EMITTER |
54 ? new new_js_emitter.Emitter(compiler, namer) | 54 ? new new_js_emitter.Emitter(compiler, namer) |
55 : oldEmitter; | 55 : oldEmitter; |
56 nativeEmitter = new NativeEmitter(this); | 56 nativeEmitter = new NativeEmitter(this); |
57 } | 57 } |
58 | 58 |
59 jsAst.Expression isolateStaticClosureAccess(Element element) { | 59 jsAst.Expression isolateStaticClosureAccess(Element element) { |
60 return emitter.isolateStaticClosureAccess(element); | 60 return emitter.isolateStaticClosureAccess(element); |
61 } | 61 } |
62 | 62 |
63 jsAst.Expression isolateLazyInitializerAccess(Element element) { | 63 jsAst.Expression isolateLazyInitializerAccess(Element element) { |
64 return emitter.isolateLazyInitializerAccess(element); | 64 return emitter.isolateLazyInitializerAccess(element); |
65 } | 65 } |
66 | 66 |
67 jsAst.Expression generateEmbeddedGlobalAccess(String global) { | 67 jsAst.Expression generateEmbeddedGlobalAccess(String global) { |
68 return emitter.generateEmbeddedGlobalAccess(global); | 68 return emitter.generateEmbeddedGlobalAccess(global); |
69 } | 69 } |
70 | 70 |
71 jsAst.Expression constantReference(ConstantValue value) { | 71 jsAst.Expression constantReference(ConstantValue value) { |
72 return emitter.constantReference(value); | 72 return emitter.constantReference(value); |
73 } | 73 } |
74 | 74 |
75 jsAst.Expression staticFieldAccess(Element e) { | 75 jsAst.Expression staticFieldAccess(Element e) { |
76 return emitter.staticFunctionAccess(e); | 76 return emitter.staticFunctionAccess(e); |
77 } | 77 } |
78 | 78 |
79 jsAst.Expression staticFunctionAccess(Element e) { | 79 jsAst.Expression staticFunctionAccess(Element e) { |
80 return emitter.staticFunctionAccess(e); | 80 return emitter.staticFunctionAccess(e); |
81 } | 81 } |
82 | 82 |
83 jsAst.Expression classAccess(Element e) { | 83 jsAst.Expression classAccess(Element e) { |
84 return emitter.classAccess(e); | 84 return emitter.classAccess(e); |
85 } | 85 } |
86 | 86 |
87 jsAst.Expression typedefAccess(Element e) { | 87 jsAst.Expression typedefAccess(Element e) { |
88 return emitter.typedefAccess(e); | 88 return emitter.typedefAccess(e); |
89 } | 89 } |
90 | 90 |
91 void registerReadTypeVariable(TypeVariableElement element) { | 91 void registerReadTypeVariable(TypeVariableElement element) { |
92 readTypeVariables.add(element); | 92 readTypeVariables.add(element); |
93 } | 93 } |
94 | 94 |
95 Set<ClassElement> interceptorsReferencedFromConstants() { | 95 Set<ClassElement> interceptorsReferencedFromConstants() { |
96 Set<ClassElement> classes = new Set<ClassElement>(); | 96 Set<ClassElement> classes = new Set<ClassElement>(); |
(...skipping 256 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
353 // Compute the required type checks to know which classes need a | 353 // Compute the required type checks to know which classes need a |
354 // 'is$' method. | 354 // 'is$' method. |
355 typeTestRegistry.computeRequiredTypeChecks(); | 355 typeTestRegistry.computeRequiredTypeChecks(); |
356 | 356 |
357 computeNeededDeclarations(); | 357 computeNeededDeclarations(); |
358 computeNeededConstants(); | 358 computeNeededConstants(); |
359 computeNeededStatics(); | 359 computeNeededStatics(); |
360 computeNeededLibraries(); | 360 computeNeededLibraries(); |
361 } | 361 } |
362 | 362 |
363 void assembleProgram() { | 363 int assembleProgram() { |
364 measure(() { | 364 return measure(() { |
365 emitter.invalidateCaches(); | 365 emitter.invalidateCaches(); |
366 | 366 |
367 computeAllNeededEntities(); | 367 computeAllNeededEntities(); |
368 | 368 |
369 Program program; | 369 Program program; |
370 if (USE_NEW_EMITTER) { | 370 if (USE_NEW_EMITTER) { |
371 program = new ProgramBuilder(compiler, namer, this).buildProgram(); | 371 program = new ProgramBuilder(compiler, namer, this).buildProgram(); |
372 } | 372 } |
373 emitter.emitProgram(program); | 373 return emitter.emitProgram(program); |
374 }); | 374 }); |
375 } | 375 } |
376 } | 376 } |
377 | 377 |
378 abstract class Emitter { | 378 abstract class Emitter { |
379 void emitProgram(Program program); | 379 /// Emits [program] and returns the size of the generated output. |
| 380 int emitProgram(Program program); |
380 | 381 |
381 jsAst.Expression isolateLazyInitializerAccess(Element element); | 382 jsAst.Expression isolateLazyInitializerAccess(Element element); |
382 jsAst.Expression isolateStaticClosureAccess(Element element); | 383 jsAst.Expression isolateStaticClosureAccess(Element element); |
383 jsAst.Expression generateEmbeddedGlobalAccess(String global); | 384 jsAst.Expression generateEmbeddedGlobalAccess(String global); |
384 jsAst.Expression constantReference(ConstantValue value); | 385 jsAst.Expression constantReference(ConstantValue value); |
385 jsAst.PropertyAccess staticFunctionAccess(Element element); | 386 jsAst.PropertyAccess staticFunctionAccess(Element element); |
386 | 387 |
387 // TODO(zarah): Split into more fine-grained accesses. | 388 // TODO(zarah): Split into more fine-grained accesses. |
388 /// Generates access to the js constructor of the class represented by | 389 /// Generates access to the js constructor of the class represented by |
389 /// [element] | 390 /// [element] |
390 jsAst.PropertyAccess classAccess(Element element); | 391 jsAst.PropertyAccess classAccess(Element element); |
391 jsAst.PropertyAccess typedefAccess(Element element); | 392 jsAst.PropertyAccess typedefAccess(Element element); |
392 jsAst.PropertyAccess staticFieldAccess(Element element); | 393 jsAst.PropertyAccess staticFieldAccess(Element element); |
393 | 394 |
394 | 395 |
395 int compareConstants(ConstantValue a, ConstantValue b); | 396 int compareConstants(ConstantValue a, ConstantValue b); |
396 bool isConstantInlinedOrAlreadyEmitted(ConstantValue constant); | 397 bool isConstantInlinedOrAlreadyEmitted(ConstantValue constant); |
397 | 398 |
398 void invalidateCaches(); | 399 void invalidateCaches(); |
399 } | 400 } |
OLD | NEW |