| OLD | NEW |
| 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 #include "vm/il_printer.h" | 5 #include "vm/il_printer.h" |
| 6 | 6 |
| 7 #include "vm/flow_graph_range_analysis.h" | 7 #include "vm/flow_graph_range_analysis.h" |
| 8 #include "vm/intermediate_language.h" | 8 #include "vm/intermediate_language.h" |
| 9 #include "vm/os.h" | 9 #include "vm/os.h" |
| 10 #include "vm/parser.h" | 10 #include "vm/parser.h" |
| 11 | 11 |
| 12 namespace dart { | 12 namespace dart { |
| 13 | 13 |
| 14 DEFINE_FLAG(bool, print_environments, false, "Print SSA environments."); | 14 DEFINE_FLAG(bool, print_environments, false, "Print SSA environments."); |
| 15 | 15 DEFINE_FLAG(charp, print_flow_graph_filter, NULL, |
| 16 "Print only IR of functions with matching names"); |
| 16 | 17 |
| 17 void BufferFormatter::Print(const char* format, ...) { | 18 void BufferFormatter::Print(const char* format, ...) { |
| 18 va_list args; | 19 va_list args; |
| 19 va_start(args, format); | 20 va_start(args, format); |
| 20 VPrint(format, args); | 21 VPrint(format, args); |
| 21 va_end(args); | 22 va_end(args); |
| 22 } | 23 } |
| 23 | 24 |
| 24 | 25 |
| 25 void BufferFormatter::VPrint(const char* format, va_list args) { | 26 void BufferFormatter::VPrint(const char* format, va_list args) { |
| 26 intptr_t available = size_ - position_; | 27 intptr_t available = size_ - position_; |
| 27 if (available <= 0) return; | 28 if (available <= 0) return; |
| 28 intptr_t written = | 29 intptr_t written = |
| 29 OS::VSNPrint(buffer_ + position_, available, format, args); | 30 OS::VSNPrint(buffer_ + position_, available, format, args); |
| 30 if (written >= 0) { | 31 if (written >= 0) { |
| 31 position_ += (available <= written) ? available : written; | 32 position_ += (available <= written) ? available : written; |
| 32 } | 33 } |
| 33 } | 34 } |
| 34 | 35 |
| 35 | 36 |
| 37 // Checks whether function's name matches the given filter, which is |
| 38 // a comma-separated list of strings. |
| 39 bool FlowGraphPrinter::PassesFilter(const char* filter, |
| 40 const Function& function) { |
| 41 if (filter == NULL) { |
| 42 return true; |
| 43 } |
| 44 |
| 45 char* save_ptr; // Needed for strtok_r. |
| 46 const char* function_name = function.ToFullyQualifiedCString(); |
| 47 intptr_t function_name_len = strlen(function_name); |
| 48 |
| 49 intptr_t len = strlen(filter) + 1; // Length with \0. |
| 50 char* filter_buffer = new char[len]; |
| 51 strncpy(filter_buffer, filter, len); // strtok modifies arg 1. |
| 52 char* token = strtok_r(filter_buffer, ",", &save_ptr); |
| 53 bool found = false; |
| 54 while (token != NULL) { |
| 55 if (strstr(function_name, token) != NULL) { |
| 56 found = true; |
| 57 break; |
| 58 } |
| 59 const intptr_t token_len = strlen(token); |
| 60 if (token[token_len - 1] == '%') { |
| 61 if (function_name_len > token_len) { |
| 62 const char* suffix = function_name + |
| 63 (function_name_len - token_len + 1); |
| 64 if (strncmp(suffix, token, token_len - 1) == 0) { |
| 65 found = true; |
| 66 break; |
| 67 } |
| 68 } |
| 69 } |
| 70 token = strtok_r(NULL, ",", &save_ptr); |
| 71 } |
| 72 delete[] filter_buffer; |
| 73 |
| 74 return found; |
| 75 } |
| 76 |
| 77 |
| 78 bool FlowGraphPrinter::ShouldPrint(const Function& function) { |
| 79 return PassesFilter(FLAG_print_flow_graph_filter, function); |
| 80 } |
| 81 |
| 82 |
| 36 void FlowGraphPrinter::PrintGraph(const char* phase, FlowGraph* flow_graph) { | 83 void FlowGraphPrinter::PrintGraph(const char* phase, FlowGraph* flow_graph) { |
| 37 OS::Print("*** BEGIN CFG\n%s\n", phase); | 84 OS::Print("*** BEGIN CFG\n%s\n", phase); |
| 38 FlowGraphPrinter printer(*flow_graph); | 85 FlowGraphPrinter printer(*flow_graph); |
| 39 printer.PrintBlocks(); | 86 printer.PrintBlocks(); |
| 40 OS::Print("*** END CFG\n"); | 87 OS::Print("*** END CFG\n"); |
| 41 fflush(stdout); | 88 fflush(stdout); |
| 42 } | 89 } |
| 43 | 90 |
| 44 | 91 |
| 45 void FlowGraphPrinter::PrintBlock(BlockEntryInstr* block, | 92 void FlowGraphPrinter::PrintBlock(BlockEntryInstr* block, |
| (...skipping 1113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1159 } | 1206 } |
| 1160 | 1207 |
| 1161 const char* Environment::ToCString() const { | 1208 const char* Environment::ToCString() const { |
| 1162 char buffer[1024]; | 1209 char buffer[1024]; |
| 1163 BufferFormatter bf(buffer, 1024); | 1210 BufferFormatter bf(buffer, 1024); |
| 1164 PrintTo(&bf); | 1211 PrintTo(&bf); |
| 1165 return Isolate::Current()->current_zone()->MakeCopyOfString(buffer); | 1212 return Isolate::Current()->current_zone()->MakeCopyOfString(buffer); |
| 1166 } | 1213 } |
| 1167 | 1214 |
| 1168 } // namespace dart | 1215 } // namespace dart |
| OLD | NEW |