OLD | NEW |
1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2013, 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:io'; | 7 import 'dart:async' show EventSink; |
| 8 |
8 import 'ssa.dart'; | 9 import 'ssa.dart'; |
9 import '../js_backend/js_backend.dart'; | 10 import '../js_backend/js_backend.dart'; |
10 import '../dart2jslib.dart'; | 11 import '../dart2jslib.dart'; |
11 | 12 |
12 const bool GENERATE_SSA_TRACE = false; | 13 const bool GENERATE_SSA_TRACE = false; |
13 const String SSA_TRACE_FILTER = null; | 14 const String SSA_TRACE_FILTER = null; |
14 | 15 |
15 class HTracer extends HGraphVisitor implements Tracer { | 16 class HTracer extends HGraphVisitor implements Tracer { |
16 JavaScriptItemCompilationContext context; | 17 JavaScriptItemCompilationContext context; |
17 int indent = 0; | 18 int indent = 0; |
18 final RandomAccessFile output; | 19 final EventSink<String> output; |
19 final bool enabled = GENERATE_SSA_TRACE; | 20 final bool enabled = GENERATE_SSA_TRACE; |
20 bool traceActive = false; | 21 bool traceActive = false; |
21 | 22 |
22 HTracer([String path = "dart.cfg"]) | 23 HTracer(this.output); |
23 : output = GENERATE_SSA_TRACE | |
24 ? new File(path).openSync(mode: FileMode.WRITE) | |
25 : null; | |
26 | 24 |
27 void close() { | 25 void close() { |
28 if (enabled) output.closeSync(); | 26 if (enabled) output.close(); |
29 } | 27 } |
30 | 28 |
31 void traceCompilation(String methodName, | 29 void traceCompilation(String methodName, |
32 JavaScriptItemCompilationContext compilationContext) { | 30 JavaScriptItemCompilationContext compilationContext) { |
33 if (!enabled) return; | 31 if (!enabled) return; |
34 this.context = compilationContext; | 32 this.context = compilationContext; |
35 traceActive = | 33 traceActive = |
36 SSA_TRACE_FILTER == null || methodName.contains(SSA_TRACE_FILTER); | 34 SSA_TRACE_FILTER == null || methodName.contains(SSA_TRACE_FILTER); |
37 if (!traceActive) return; | 35 if (!traceActive) return; |
38 tag("compilation", () { | 36 tag("compilation", () { |
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
149 | 147 |
150 void printProperty(String propertyName, var value) { | 148 void printProperty(String propertyName, var value) { |
151 if (value is num) { | 149 if (value is num) { |
152 println("$propertyName $value"); | 150 println("$propertyName $value"); |
153 } else { | 151 } else { |
154 println('$propertyName "$value"'); | 152 println('$propertyName "$value"'); |
155 } | 153 } |
156 } | 154 } |
157 | 155 |
158 void add(String string) { | 156 void add(String string) { |
159 output.writeStringSync(string); | 157 output.add(string); |
160 } | 158 } |
161 | 159 |
162 void addIndent() { | 160 void addIndent() { |
163 for (int i = 0; i < indent; i++) { | 161 for (int i = 0; i < indent; i++) { |
164 add(" "); | 162 add(" "); |
165 } | 163 } |
166 } | 164 } |
167 } | 165 } |
168 | 166 |
169 class HInstructionStringifier implements HVisitor<String> { | 167 class HInstructionStringifier implements HVisitor<String> { |
(...skipping 382 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
552 | 550 |
553 String visitTypeConversion(HTypeConversion node) { | 551 String visitTypeConversion(HTypeConversion node) { |
554 return "TypeConversion: ${temporaryId(node.checkedInput)} to " | 552 return "TypeConversion: ${temporaryId(node.checkedInput)} to " |
555 "${node.instructionType}"; | 553 "${node.instructionType}"; |
556 } | 554 } |
557 | 555 |
558 String visitRangeConversion(HRangeConversion node) { | 556 String visitRangeConversion(HRangeConversion node) { |
559 return "RangeConversion: ${node.checkedInput}"; | 557 return "RangeConversion: ${node.checkedInput}"; |
560 } | 558 } |
561 } | 559 } |
OLD | NEW |