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

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

Issue 893963005: Refactor handling of source map information. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 5 years, 10 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 10
11 SsaCodeGeneratorTask(JavaScriptBackend backend) 11 SsaCodeGeneratorTask(JavaScriptBackend backend)
12 : this.backend = backend, 12 : this.backend = backend,
13 super(backend.compiler); 13 super(backend.compiler);
14 String get name => 'SSA code generator'; 14 String get name => 'SSA code generator';
15 NativeEmitter get nativeEmitter => backend.emitter.nativeEmitter; 15 NativeEmitter get nativeEmitter => backend.emitter.nativeEmitter;
16 16
17 17
18 js.Node attachPosition(js.Node node, AstElement element) { 18 js.Node attachPosition(js.Node node, AstElement element) {
19 // TODO(sra): Attaching positions might be cleaner if the source position 19 return node.withSourceInformation(
20 // was on a wrapping node. 20 StartEndSourceInformation.computeSourceInformation(element));
21 SourceFile sourceFile = sourceFileOfElement(element);
22 String name = element.name;
23 AstElement implementation = element.implementation;
24 ast.Node expression = implementation.node;
25 Token beginToken;
26 Token endToken;
27 if (expression == null) {
28 // Synthesized node. Use the enclosing element for the location.
29 beginToken = endToken = element.position;
30 } else {
31 beginToken = expression.getBeginToken();
32 endToken = expression.getEndToken();
33 }
34 // TODO(podivilov): find the right sourceFile here and remove offset
35 // checks below.
36 var sourcePosition, endSourcePosition;
37 if (beginToken.charOffset < sourceFile.length) {
38 sourcePosition =
39 new TokenSourceFileLocation(sourceFile, beginToken, name);
40 }
41 if (endToken.charOffset < sourceFile.length) {
42 endSourcePosition =
43 new TokenSourceFileLocation(sourceFile, endToken, name);
44 }
45 return node.withPosition(sourcePosition, endSourcePosition);
46 }
47
48 SourceFile sourceFileOfElement(Element element) {
49 return element.implementation.compilationUnit.script.file;
50 } 21 }
51 22
52 js.Fun buildJavaScriptFunction(FunctionElement element, 23 js.Fun buildJavaScriptFunction(FunctionElement element,
53 List<js.Parameter> parameters, 24 List<js.Parameter> parameters,
54 js.Block body) { 25 js.Block body) {
55 return attachPosition(new js.Fun(parameters, body), element); 26 return attachPosition(new js.Fun(parameters, body), element);
56 } 27 }
57 28
58 js.Expression generateCode(CodegenWorkItem work, HGraph graph) { 29 js.Expression generateCode(CodegenWorkItem work, HGraph graph) {
59 if (work.element.isField) { 30 if (work.element.isField) {
(...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after
234 return expressionStack.removeLast(); 205 return expressionStack.removeLast();
235 } 206 }
236 207
237 attachLocationToLast(HInstruction instruction) { 208 attachLocationToLast(HInstruction instruction) {
238 int index = expressionStack.length - 1; 209 int index = expressionStack.length - 1;
239 expressionStack[index] = 210 expressionStack[index] =
240 attachLocation(expressionStack[index], instruction); 211 attachLocation(expressionStack[index], instruction);
241 } 212 }
242 213
243 js.Node attachLocation(js.Node jsNode, HInstruction instruction) { 214 js.Node attachLocation(js.Node jsNode, HInstruction instruction) {
244 return jsNode.withLocation(instruction.sourcePosition); 215 return attachSourceInformation(jsNode, instruction.sourceInformation);
245 } 216 }
246 217
247 js.Node attachLocationRange(js.Node jsNode, 218 js.Node attachSourceInformation(js.Node jsNode,
248 SourceFileLocation sourcePosition, 219 SourceInformation sourceInformation) {
249 SourceFileLocation endSourcePosition) { 220 return jsNode.withSourceInformation(sourceInformation);
250 return jsNode.withPosition(sourcePosition, endSourcePosition);
251 } 221 }
252 222
253 void preGenerateMethod(HGraph graph) { 223 void preGenerateMethod(HGraph graph) {
254 new SsaInstructionSelection(compiler).visitGraph(graph); 224 new SsaInstructionSelection(compiler).visitGraph(graph);
255 new SsaTypeKnownRemover().visitGraph(graph); 225 new SsaTypeKnownRemover().visitGraph(graph);
256 new SsaTrustedCheckRemover(compiler).visitGraph(graph); 226 new SsaTrustedCheckRemover(compiler).visitGraph(graph);
257 new SsaInstructionMerger(generateAtUseSite, compiler).visitGraph(graph); 227 new SsaInstructionMerger(generateAtUseSite, compiler).visitGraph(graph);
258 new SsaConditionMerger( 228 new SsaConditionMerger(
259 generateAtUseSite, controlFlowOperators).visitGraph(graph); 229 generateAtUseSite, controlFlowOperators).visitGraph(graph);
260 SsaLiveIntervalBuilder intervalBuilder = new SsaLiveIntervalBuilder( 230 SsaLiveIntervalBuilder intervalBuilder = new SsaLiveIntervalBuilder(
(...skipping 688 matching lines...) Expand 10 before | Expand all | Expand 10 after
949 jsCondition = newLiteralBool(true); 919 jsCondition = newLiteralBool(true);
950 } 920 }
951 loop = new js.Do(unwrapStatement(body), jsCondition); 921 loop = new js.Do(unwrapStatement(body), jsCondition);
952 } 922 }
953 currentContainer = oldContainer; 923 currentContainer = oldContainer;
954 break; 924 break;
955 default: 925 default:
956 compiler.internalError(condition.conditionExpression, 926 compiler.internalError(condition.conditionExpression,
957 'Unexpected loop kind: ${info.kind}.'); 927 'Unexpected loop kind: ${info.kind}.');
958 } 928 }
959 js.Statement result = 929 js.Statement result = attachSourceInformation(loop, info.sourceInformation);
960 attachLocationRange(loop, info.sourcePosition, info.endSourcePosition);
961 if (info.kind == HLoopBlockInformation.SWITCH_CONTINUE_LOOP) { 930 if (info.kind == HLoopBlockInformation.SWITCH_CONTINUE_LOOP) {
962 String continueLabelString = 931 String continueLabelString =
963 backend.namer.implicitContinueLabelName(info.target); 932 backend.namer.implicitContinueLabelName(info.target);
964 result = new js.LabeledStatement(continueLabelString, result); 933 result = new js.LabeledStatement(continueLabelString, result);
965 } 934 }
966 pushStatement(wrapIntoLabels(result, info.labels)); 935 pushStatement(wrapIntoLabels(result, info.labels));
967 return true; 936 return true;
968 } 937 }
969 938
970 bool visitLabeledBlockInfo(HLabeledBlockInformation labeledBlockInfo) { 939 bool visitLabeledBlockInfo(HLabeledBlockInformation labeledBlockInfo) {
(...skipping 1698 matching lines...) Expand 10 before | Expand all | Expand 10 after
2669 js.PropertyAccess accessHelper(String name) { 2638 js.PropertyAccess accessHelper(String name) {
2670 Element helper = backend.findHelper(name); 2639 Element helper = backend.findHelper(name);
2671 if (helper == null) { 2640 if (helper == null) {
2672 // For mocked-up tests. 2641 // For mocked-up tests.
2673 return js.js('(void 0).$name'); 2642 return js.js('(void 0).$name');
2674 } 2643 }
2675 registry.registerStaticUse(helper); 2644 registry.registerStaticUse(helper);
2676 return backend.emitter.staticFunctionAccess(helper); 2645 return backend.emitter.staticFunctionAccess(helper);
2677 } 2646 }
2678 } 2647 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698