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

Side by Side Diff: pkg/compiler/lib/src/js_backend/codegen/task.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) 2014, the Dart project authors. Please see the AUTHORS file 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 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 /// Generate code using the cps-based IR pipeline. 5 /// Generate code using the cps-based IR pipeline.
6 library code_generator_task; 6 library code_generator_task;
7 7
8 import 'glue.dart'; 8 import 'glue.dart';
9 import 'codegen.dart'; 9 import 'codegen.dart';
10 import 'unsugar.dart'; 10 import 'unsugar.dart';
11 11
12 import '../js_backend.dart'; 12 import '../js_backend.dart';
13 import '../../constants/constant_system.dart'; 13 import '../../constants/constant_system.dart';
14 import '../../dart2jslib.dart'; 14 import '../../dart2jslib.dart';
15 import '../../cps_ir/cps_ir_nodes.dart' as cps; 15 import '../../cps_ir/cps_ir_nodes.dart' as cps;
16 import '../../cps_ir/cps_ir_builder.dart'; 16 import '../../cps_ir/cps_ir_builder.dart';
17 import '../../cps_ir/cps_ir_integrity.dart'; 17 import '../../cps_ir/cps_ir_integrity.dart';
18 import '../../cps_ir/cps_ir_builder_task.dart'; 18 import '../../cps_ir/cps_ir_builder_task.dart';
19 import '../../tree_ir/tree_ir_nodes.dart' as tree_ir; 19 import '../../tree_ir/tree_ir_nodes.dart' as tree_ir;
20 import '../../types/types.dart' show TypeMask, UnionTypeMask, FlatTypeMask, 20 import '../../types/types.dart' show TypeMask, UnionTypeMask, FlatTypeMask,
21 ForwardingTypeMask; 21 ForwardingTypeMask;
22 import '../../elements/elements.dart'; 22 import '../../elements/elements.dart';
23 import '../../js/js.dart' as js; 23 import '../../js/js.dart' as js;
24 import '../../io/source_information.dart' show StartEndSourceInformation; 24 import '../../io/source_information.dart' show SourceInformationFactory;
25 import '../../tree_ir/tree_ir_builder.dart' as tree_builder; 25 import '../../tree_ir/tree_ir_builder.dart' as tree_builder;
26 import '../../dart_backend/backend_ast_emitter.dart' as backend_ast_emitter; 26 import '../../dart_backend/backend_ast_emitter.dart' as backend_ast_emitter;
27 import '../../cps_ir/optimizers.dart'; 27 import '../../cps_ir/optimizers.dart';
28 import '../../cps_ir/optimizers.dart' as cps_opt; 28 import '../../cps_ir/optimizers.dart' as cps_opt;
29 import '../../tracer.dart'; 29 import '../../tracer.dart';
30 import '../../js_backend/codegen/codegen.dart'; 30 import '../../js_backend/codegen/codegen.dart';
31 import '../../ssa/ssa.dart' as ssa; 31 import '../../ssa/ssa.dart' as ssa;
32 import '../../tree_ir/optimization/optimization.dart'; 32 import '../../tree_ir/optimization/optimization.dart';
33 import '../../tree_ir/optimization/optimization.dart' as tree_opt; 33 import '../../tree_ir/optimization/optimization.dart' as tree_opt;
34 import '../../tree_ir/tree_ir_integrity.dart'; 34 import '../../tree_ir/tree_ir_integrity.dart';
35 import '../../cps_ir/cps_ir_nodes_sexpr.dart'; 35 import '../../cps_ir/cps_ir_nodes_sexpr.dart';
36 import 'js_tree_builder.dart'; 36 import 'js_tree_builder.dart';
37 37
38 class CpsFunctionCompiler implements FunctionCompiler { 38 class CpsFunctionCompiler implements FunctionCompiler {
39 final ConstantSystem constantSystem; 39 final ConstantSystem constantSystem;
40 final Compiler compiler; 40 final Compiler compiler;
41 final Glue glue; 41 final Glue glue;
42 final SourceInformationFactory sourceInformationFactory;
42 43
43 TypeSystem types; 44 TypeSystem types;
44 45
45 // TODO(karlklose,sigurm): remove and update dart-doc of [compile]. 46 // TODO(karlklose,sigurm): remove and update dart-doc of [compile].
46 final FunctionCompiler fallbackCompiler; 47 final FunctionCompiler fallbackCompiler;
47 48
48 Tracer get tracer => compiler.tracer; 49 Tracer get tracer => compiler.tracer;
49 50
50 IrBuilderTask get irBuilderTask => compiler.irBuilder; 51 IrBuilderTask get irBuilderTask => compiler.irBuilder;
51 52
52 CpsFunctionCompiler(Compiler compiler, JavaScriptBackend backend, 53 CpsFunctionCompiler(Compiler compiler, JavaScriptBackend backend,
53 {bool generateSourceMap: true}) 54 SourceInformationFactory sourceInformationFactory)
54 : fallbackCompiler = 55 : fallbackCompiler =
55 new ssa.SsaFunctionCompiler(backend, generateSourceMap), 56 new ssa.SsaFunctionCompiler(backend, sourceInformationFactory),
57 this.sourceInformationFactory = sourceInformationFactory,
56 constantSystem = backend.constantSystem, 58 constantSystem = backend.constantSystem,
57 compiler = compiler, 59 compiler = compiler,
58 glue = new Glue(compiler); 60 glue = new Glue(compiler);
59 61
60 String get name => 'CPS Ir pipeline'; 62 String get name => 'CPS Ir pipeline';
61 63
62 /// Generates JavaScript code for `work.element`. First tries to use the 64 /// Generates JavaScript code for `work.element`. First tries to use the
63 /// Cps Ir -> tree ir -> js pipeline, and if that fails due to language 65 /// Cps Ir -> tree ir -> js pipeline, and if that fails due to language
64 /// features not implemented it will fall back to the ssa pipeline (for 66 /// features not implemented it will fall back to the ssa pipeline (for
65 /// platform code) or will cancel compilation (for user code). 67 /// platform code) or will cancel compilation (for user code).
(...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after
214 applyTreePass(new LoopRewriter()); 216 applyTreePass(new LoopRewriter());
215 applyTreePass(new LogicalRewriter()); 217 applyTreePass(new LogicalRewriter());
216 applyTreePass(new PullIntoInitializers()); 218 applyTreePass(new PullIntoInitializers());
217 219
218 return node; 220 return node;
219 } 221 }
220 222
221 js.Fun compileToJavaScript(CodegenWorkItem work, 223 js.Fun compileToJavaScript(CodegenWorkItem work,
222 tree_ir.FunctionDefinition definition) { 224 tree_ir.FunctionDefinition definition) {
223 CodeGenerator codeGen = new CodeGenerator(glue, work.registry); 225 CodeGenerator codeGen = new CodeGenerator(glue, work.registry);
224
225 return attachPosition(codeGen.buildFunction(definition), work.element); 226 return attachPosition(codeGen.buildFunction(definition), work.element);
226 } 227 }
227 228
228 Iterable<CompilerTask> get tasks { 229 Iterable<CompilerTask> get tasks {
229 // TODO(sigurdm): Make a better list of tasks. 230 // TODO(sigurdm): Make a better list of tasks.
230 return <CompilerTask>[irBuilderTask]..addAll(fallbackCompiler.tasks); 231 return <CompilerTask>[irBuilderTask]..addAll(fallbackCompiler.tasks);
231 } 232 }
232 233
233 js.Node attachPosition(js.Node node, AstElement element) { 234 js.Node attachPosition(js.Node node, AstElement element) {
234 return node.withSourceInformation( 235 return node.withSourceInformation(
235 StartEndSourceInformation.computeSourceInformation(element)); 236 sourceInformationFactory.forContext(element)
237 .buildDeclaration(element));
236 } 238 }
237 } 239 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698