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

Side by Side Diff: sdk/lib/_internal/compiler/implementation/js_emitter/new_emitter/emitter.dart

Issue 694353007: Move dart2js from sdk/lib/_internal/compiler to pkg/compiler (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 years, 1 month 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 | Annotate | Revision Log
OLDNEW
(Empty)
1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file
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.
4
5 library dart2js.new_js_emitter.emitter;
6
7 import '../model.dart';
8 import 'model_emitter.dart';
9 import '../../common.dart';
10 import '../../js/js.dart' as js;
11
12 import '../../js_backend/js_backend.dart' show Namer, JavaScriptBackend;
13 import '../../js_emitter/js_emitter.dart' as emitterTask show
14 CodeEmitterTask,
15 Emitter;
16
17 class Emitter implements emitterTask.Emitter {
18 final Compiler _compiler;
19 final Namer namer;
20 final ModelEmitter _emitter;
21
22 Emitter(Compiler compiler, Namer namer)
23 : this._compiler = compiler,
24 this.namer = namer,
25 _emitter = new ModelEmitter(compiler, namer);
26
27 void emitProgram(Program program) {
28 _emitter.emitProgram(program);
29 }
30
31 // TODO(floitsch): copied from OldEmitter. Adjust or share.
32 bool isConstantInlinedOrAlreadyEmitted(ConstantValue constant) {
33 if (constant.isFunction) return true; // Already emitted.
34 if (constant.isPrimitive) return true; // Inlined.
35 if (constant.isDummy) return true; // Inlined.
36 // The name is null when the constant is already a JS constant.
37 // TODO(floitsch): every constant should be registered, so that we can
38 // share the ones that take up too much space (like some strings).
39 if (namer.constantName(constant) == null) return true;
40 return false;
41 }
42
43 // TODO(floitsch): copied from OldEmitter. Adjust or share.
44 int compareConstants(ConstantValue a, ConstantValue b) {
45 // Inlined constants don't affect the order and sometimes don't even have
46 // names.
47 int cmp1 = isConstantInlinedOrAlreadyEmitted(a) ? 0 : 1;
48 int cmp2 = isConstantInlinedOrAlreadyEmitted(b) ? 0 : 1;
49 if (cmp1 + cmp2 < 2) return cmp1 - cmp2;
50
51 // Emit constant interceptors first. Constant interceptors for primitives
52 // might be used by code that builds other constants. See Issue 18173.
53 if (a.isInterceptor != b.isInterceptor) {
54 return a.isInterceptor ? -1 : 1;
55 }
56
57 // Sorting by the long name clusters constants with the same constructor
58 // which compresses a tiny bit better.
59 int r = namer.constantLongName(a).compareTo(namer.constantLongName(b));
60 if (r != 0) return r;
61 // Resolve collisions in the long name by using the constant name (i.e. JS
62 // name) which is unique.
63 return namer.constantName(a).compareTo(namer.constantName(b));
64 }
65
66 js.Expression generateEmbeddedGlobalAccess(String global) {
67 // TODO(floitsch): We should not use "init" for globals.
68 return js.string("init.$global");
69 }
70
71 js.Expression constantReference(ConstantValue value) {
72 return _emitter.constantEmitter.reference(value);
73 }
74
75 void invalidateCaches() {}
76 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698