| Index: runtime/vm/il_printer.cc
|
| diff --git a/runtime/vm/il_printer.cc b/runtime/vm/il_printer.cc
|
| index c81ac93ec1280d8a67eaba9f26d150cd7e2065d3..6889e3cb496dc88da977fde8bdba5d7d9d73c2c6 100644
|
| --- a/runtime/vm/il_printer.cc
|
| +++ b/runtime/vm/il_printer.cc
|
| @@ -12,7 +12,8 @@
|
| namespace dart {
|
|
|
| DEFINE_FLAG(bool, print_environments, false, "Print SSA environments.");
|
| -
|
| +DEFINE_FLAG(charp, print_flow_graph_filter, NULL,
|
| + "Print only IR of functions with matching names");
|
|
|
| void BufferFormatter::Print(const char* format, ...) {
|
| va_list args;
|
| @@ -33,6 +34,52 @@ void BufferFormatter::VPrint(const char* format, va_list args) {
|
| }
|
|
|
|
|
| +// Checks whether function's name matches the given filter, which is
|
| +// a comma-separated list of strings.
|
| +bool FlowGraphPrinter::PassesFilter(const char* filter,
|
| + const Function& function) {
|
| + if (filter == NULL) {
|
| + return true;
|
| + }
|
| +
|
| + char* save_ptr; // Needed for strtok_r.
|
| + const char* function_name = function.ToFullyQualifiedCString();
|
| + intptr_t function_name_len = strlen(function_name);
|
| +
|
| + intptr_t len = strlen(filter) + 1; // Length with \0.
|
| + char* filter_buffer = new char[len];
|
| + strncpy(filter_buffer, filter, len); // strtok modifies arg 1.
|
| + char* token = strtok_r(filter_buffer, ",", &save_ptr);
|
| + bool found = false;
|
| + while (token != NULL) {
|
| + if (strstr(function_name, token) != NULL) {
|
| + found = true;
|
| + break;
|
| + }
|
| + const intptr_t token_len = strlen(token);
|
| + if (token[token_len - 1] == '%') {
|
| + if (function_name_len > token_len) {
|
| + const char* suffix = function_name +
|
| + (function_name_len - token_len + 1);
|
| + if (strncmp(suffix, token, token_len - 1) == 0) {
|
| + found = true;
|
| + break;
|
| + }
|
| + }
|
| + }
|
| + token = strtok_r(NULL, ",", &save_ptr);
|
| + }
|
| + delete[] filter_buffer;
|
| +
|
| + return found;
|
| +}
|
| +
|
| +
|
| +bool FlowGraphPrinter::ShouldPrint(const Function& function) {
|
| + return PassesFilter(FLAG_print_flow_graph_filter, function);
|
| +}
|
| +
|
| +
|
| void FlowGraphPrinter::PrintGraph(const char* phase, FlowGraph* flow_graph) {
|
| OS::Print("*** BEGIN CFG\n%s\n", phase);
|
| FlowGraphPrinter printer(*flow_graph);
|
|
|