| OLD | NEW |
| 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 library tracer; | 5 library tracer; |
| 6 | 6 |
| 7 import 'dart:async' show EventSink; | 7 import 'dart:async' show EventSink; |
| 8 | 8 |
| 9 import '../compiler.dart' as api; | 9 import '../compiler.dart' as api; |
| 10 import 'compiler.dart' show Compiler; | 10 import 'js_backend/namer.dart' show Namer; |
| 11 import 'ssa/nodes.dart' as ssa show HGraph; | 11 import 'ssa/nodes.dart' as ssa show HGraph; |
| 12 import 'ssa/ssa_tracer.dart' show HTracer; | 12 import 'ssa/ssa_tracer.dart' show HTracer; |
| 13 import 'util/util.dart' show Indentation; | 13 import 'util/util.dart' show Indentation; |
| 14 import 'world.dart' show ClosedWorld; |
| 14 | 15 |
| 15 /** | 16 /** |
| 16 * If non-null, we only trace methods whose name match the regexp defined by the | 17 * If non-null, we only trace methods whose name match the regexp defined by the |
| 17 * given pattern. | 18 * given pattern. |
| 18 */ | 19 */ |
| 19 const String TRACE_FILTER_PATTERN = const String.fromEnvironment("DUMP_IR"); | 20 const String TRACE_FILTER_PATTERN = const String.fromEnvironment("DUMP_IR"); |
| 20 | 21 |
| 21 final RegExp TRACE_FILTER = | 22 final RegExp TRACE_FILTER = |
| 22 TRACE_FILTER_PATTERN == null ? null : new RegExp(TRACE_FILTER_PATTERN); | 23 TRACE_FILTER_PATTERN == null ? null : new RegExp(TRACE_FILTER_PATTERN); |
| 23 | 24 |
| 24 /** | 25 /** |
| 25 * Dumps the intermediate representation after each phase in a format | 26 * Dumps the intermediate representation after each phase in a format |
| 26 * readable by IR Hydra. | 27 * readable by IR Hydra. |
| 27 */ | 28 */ |
| 28 class Tracer extends TracerUtil { | 29 class Tracer extends TracerUtil { |
| 29 final Compiler compiler; | 30 final ClosedWorld closedWorld; |
| 31 final Namer namer; |
| 30 bool traceActive = false; | 32 bool traceActive = false; |
| 31 final EventSink<String> output; | 33 final EventSink<String> output; |
| 32 final bool isEnabled = TRACE_FILTER != null; | 34 final bool isEnabled = TRACE_FILTER != null; |
| 33 | 35 |
| 34 Tracer(Compiler compiler, api.CompilerOutputProvider outputProvider) | 36 Tracer( |
| 35 : this.compiler = compiler, | 37 this.closedWorld, this.namer, api.CompilerOutputProvider outputProvider) |
| 36 output = TRACE_FILTER != null ? outputProvider('dart', 'cfg') : null; | 38 : output = TRACE_FILTER != null ? outputProvider('dart', 'cfg') : null; |
| 37 | 39 |
| 38 void traceCompilation(String methodName) { | 40 void traceCompilation(String methodName) { |
| 39 if (!isEnabled) return; | 41 if (!isEnabled) return; |
| 40 traceActive = TRACE_FILTER.hasMatch(methodName); | 42 traceActive = TRACE_FILTER.hasMatch(methodName); |
| 41 if (!traceActive) return; | 43 if (!traceActive) return; |
| 42 tag("compilation", () { | 44 tag("compilation", () { |
| 43 printProperty("name", methodName); | 45 printProperty("name", methodName); |
| 44 printProperty("method", methodName); | 46 printProperty("method", methodName); |
| 45 printProperty("date", new DateTime.now().millisecondsSinceEpoch); | 47 printProperty("date", new DateTime.now().millisecondsSinceEpoch); |
| 46 }); | 48 }); |
| 47 } | 49 } |
| 48 | 50 |
| 49 void traceGraph(String name, var irObject) { | 51 void traceGraph(String name, var irObject) { |
| 50 if (!traceActive) return; | 52 if (!traceActive) return; |
| 51 if (irObject is ssa.HGraph) { | 53 if (irObject is ssa.HGraph) { |
| 52 new HTracer(output, compiler).traceGraph(name, irObject); | 54 new HTracer(output, closedWorld, namer).traceGraph(name, irObject); |
| 53 } | 55 } |
| 54 } | 56 } |
| 55 | 57 |
| 56 void close() { | 58 void close() { |
| 57 if (output != null) { | 59 if (output != null) { |
| 58 output.close(); | 60 output.close(); |
| 59 } | 61 } |
| 60 } | 62 } |
| 61 } | 63 } |
| 62 | 64 |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 97 } | 99 } |
| 98 | 100 |
| 99 void add(String string) { | 101 void add(String string) { |
| 100 output.add(string); | 102 output.add(string); |
| 101 } | 103 } |
| 102 | 104 |
| 103 void addIndent() { | 105 void addIndent() { |
| 104 add(_ind.indentation); | 106 add(_ind.indentation); |
| 105 } | 107 } |
| 106 } | 108 } |
| OLD | NEW |