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

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

Issue 1100723002: Add SourceInformationFactory. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Cleanup. Created 5 years, 8 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 | Annotate | Revision Log
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 part of ssa; 5 part of ssa;
6 6
7 class SsaCodeGeneratorTask extends CompilerTask { 7 class SsaCodeGeneratorTask extends CompilerTask {
8 8
9 final JavaScriptBackend backend; 9 final JavaScriptBackend backend;
10 final SourceInformationFactory sourceInformationFactory;
10 11
11 SsaCodeGeneratorTask(JavaScriptBackend backend) 12 SsaCodeGeneratorTask(JavaScriptBackend backend,
13 this.sourceInformationFactory)
12 : this.backend = backend, 14 : this.backend = backend,
13 super(backend.compiler); 15 super(backend.compiler);
16
14 String get name => 'SSA code generator'; 17 String get name => 'SSA code generator';
15 NativeEmitter get nativeEmitter => backend.emitter.nativeEmitter; 18 NativeEmitter get nativeEmitter => backend.emitter.nativeEmitter;
16 19
17 20
18 js.Node attachPosition(js.Node node, AstElement element) { 21 js.Node attachPosition(js.Node node, AstElement element) {
19 return node.withSourceInformation( 22 return node.withSourceInformation(
20 StartEndSourceInformation.computeSourceInformation(element)); 23 StartEndSourceInformation.computeSourceInformation(element));
21 } 24 }
22 25
23 js.Fun buildJavaScriptFunction(FunctionElement element, 26 js.Fun buildJavaScriptFunction(FunctionElement element,
24 List<js.Parameter> parameters, 27 List<js.Parameter> parameters,
25 js.Block body) { 28 js.Block body) {
26 js.AsyncModifier asyncModifier = element.asyncMarker.isAsync 29 js.AsyncModifier asyncModifier = element.asyncMarker.isAsync
27 ? (element.asyncMarker.isYielding 30 ? (element.asyncMarker.isYielding
28 ? const js.AsyncModifier.asyncStar() 31 ? const js.AsyncModifier.asyncStar()
29 : const js.AsyncModifier.async()) 32 : const js.AsyncModifier.async())
30 : (element.asyncMarker.isYielding 33 : (element.asyncMarker.isYielding
31 ? const js.AsyncModifier.syncStar() 34 ? const js.AsyncModifier.syncStar()
32 : const js.AsyncModifier.sync()); 35 : const js.AsyncModifier.sync());
33 36
34 return attachPosition( 37 return new js.Fun(parameters, body, asyncModifier: asyncModifier)
35 new js.Fun(parameters, body, asyncModifier: asyncModifier), element); 38 .withSourceInformation(sourceInformationFactory.forContext(element)
39 .buildDeclaration(element));
36 } 40 }
37 41
38 js.Expression generateCode(CodegenWorkItem work, HGraph graph) { 42 js.Expression generateCode(CodegenWorkItem work, HGraph graph) {
39 if (work.element.isField) { 43 if (work.element.isField) {
40 return generateLazyInitializer(work, graph); 44 return generateLazyInitializer(work, graph);
41 } else { 45 } else {
42 return generateMethod(work, graph); 46 return generateMethod(work, graph);
43 } 47 }
44 } 48 }
45 49
46 js.Expression generateLazyInitializer(work, graph) { 50 js.Expression generateLazyInitializer(work, graph) {
47 return measure(() { 51 return measure(() {
48 compiler.tracer.traceGraph("codegen", graph); 52 compiler.tracer.traceGraph("codegen", graph);
53 SourceInformation sourceInformation =
54 sourceInformationFactory.forContext(work.element)
55 .buildDeclaration(work.element);
49 SsaCodeGenerator codegen = new SsaCodeGenerator(backend, work); 56 SsaCodeGenerator codegen = new SsaCodeGenerator(backend, work);
50 codegen.visitGraph(graph); 57 codegen.visitGraph(graph);
51 return new js.Fun(codegen.parameters, 58 return new js.Fun(codegen.parameters, codegen.body)
52 attachPosition(codegen.body, work.element)); 59 .withSourceInformation(sourceInformation);
53 }); 60 });
54 } 61 }
55 62
56 js.Expression generateMethod(CodegenWorkItem work, HGraph graph) { 63 js.Expression generateMethod(CodegenWorkItem work, HGraph graph) {
57 return measure(() { 64 return measure(() {
58 FunctionElement element = work.element; 65 FunctionElement element = work.element;
59 if (element.asyncMarker != AsyncMarker.SYNC) { 66 if (element.asyncMarker != AsyncMarker.SYNC) {
60 work.registry.registerAsyncMarker(element); 67 work.registry.registerAsyncMarker(element);
61 } 68 }
62 SsaCodeGenerator codegen = new SsaCodeGenerator(backend, work); 69 SsaCodeGenerator codegen = new SsaCodeGenerator(backend, work);
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
128 135
129 HGraph currentGraph; 136 HGraph currentGraph;
130 137
131 // Records a block-information that is being handled specially. 138 // Records a block-information that is being handled specially.
132 // Used to break bad recursion. 139 // Used to break bad recursion.
133 HBlockInformation currentBlockInformation; 140 HBlockInformation currentBlockInformation;
134 // The subgraph is used to delimit traversal for some constructions, e.g., 141 // The subgraph is used to delimit traversal for some constructions, e.g.,
135 // if branches. 142 // if branches.
136 SubGraph subGraph; 143 SubGraph subGraph;
137 144
138 SsaCodeGenerator(this.backend, CodegenWorkItem work) 145 SsaCodeGenerator(this.backend, CodegenWorkItem work,
146 {SourceInformation sourceInformation})
139 : this.work = work, 147 : this.work = work,
140 declaredLocals = new Set<String>(), 148 declaredLocals = new Set<String>(),
141 collectedVariableDeclarations = new Set<String>(), 149 collectedVariableDeclarations = new Set<String>(),
142 currentContainer = new js.Block.empty(), 150 currentContainer = new js.Block.empty(),
143 parameters = <js.Parameter>[], 151 parameters = <js.Parameter>[],
144 expressionStack = <js.Expression>[], 152 expressionStack = <js.Expression>[],
145 oldContainerStack = <js.Block>[], 153 oldContainerStack = <js.Block>[],
146 generateAtUseSite = new Set<HInstruction>(), 154 generateAtUseSite = new Set<HInstruction>(),
147 controlFlowOperators = new Set<HInstruction>(), 155 controlFlowOperators = new Set<HInstruction>(),
148 breakAction = new Map<Entity, EntityAction>(), 156 breakAction = new Map<Entity, EntityAction>(),
(...skipping 2555 matching lines...) Expand 10 before | Expand all | Expand 10 after
2704 js.PropertyAccess accessHelper(String name) { 2712 js.PropertyAccess accessHelper(String name) {
2705 Element helper = backend.findHelper(name); 2713 Element helper = backend.findHelper(name);
2706 if (helper == null) { 2714 if (helper == null) {
2707 // For mocked-up tests. 2715 // For mocked-up tests.
2708 return js.js('(void 0).$name'); 2716 return js.js('(void 0).$name');
2709 } 2717 }
2710 registry.registerStaticUse(helper); 2718 registry.registerStaticUse(helper);
2711 return backend.emitter.staticFunctionAccess(helper); 2719 return backend.emitter.staticFunctionAccess(helper);
2712 } 2720 }
2713 } 2721 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698