Flutter Engine
The Flutter Engine
print_filter.cc
Go to the documentation of this file.
1// Copyright (c) 2020, the Dart project authors. Please see the AUTHORS file
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.
4#include "platform/globals.h" // For INCLUDE_IL_PRINTER
5#if defined(INCLUDE_IL_PRINTER)
6
8
9#include "vm/flags.h"
10#if !defined(DART_PRECOMPILED_RUNTIME)
12#include "vm/object.h"
13#endif
14#include "vm/symbols.h"
15
16namespace dart {
17
19 print_flow_graph_filter,
20 nullptr,
21 "Print only IR of functions with matching names");
22
23namespace compiler {
24
25// Checks whether function's name matches the given filter, which is
26// a comma-separated list of strings.
27static bool PassesFilter(const char* filter,
28 const Function& function,
29 uint8_t** compiler_pass_filter) {
30 if (filter == nullptr) {
31 return true;
32 }
33
34#if !defined(DART_PRECOMPILED_RUNTIME)
35 if (strcmp(filter, "@pragma") == 0) {
36 Object& pass_filter = Object::Handle();
37 const auto has_pragma =
38 Library::FindPragma(dart::Thread::Current(), /*only_core=*/false,
39 function, Symbols::vm_testing_print_flow_graph(),
40 /*multiple=*/false, &pass_filter);
41 if (has_pragma && !pass_filter.IsNull() &&
42 compiler_pass_filter != nullptr) {
43 *compiler_pass_filter = dart::CompilerPass::ParseFiltersFromPragma(
44 String::Cast(pass_filter).ToCString());
45 }
46 return has_pragma;
47 }
48#endif
49
50 char* save_ptr; // Needed for strtok_r.
51 const char* scrubbed_name = function.QualifiedScrubbedNameCString();
52 const char* function_name = function.ToFullyQualifiedCString();
53 intptr_t function_name_len = strlen(function_name);
54
55 intptr_t len = strlen(filter) + 1; // Length with \0.
56 char* filter_buffer = new char[len];
57 strncpy(filter_buffer, filter, len); // strtok modifies arg 1.
58 char* token = strtok_r(filter_buffer, ",", &save_ptr);
59 bool found = false;
60 while (token != nullptr) {
61 if ((strstr(function_name, token) != nullptr) ||
62 (strstr(scrubbed_name, token) != nullptr)) {
63 found = true;
64 break;
65 }
66 const intptr_t token_len = strlen(token);
67 if (token[token_len - 1] == '%') {
68 if (function_name_len > token_len) {
69 const char* suffix =
70 function_name + (function_name_len - token_len + 1);
71 if (strncmp(suffix, token, token_len - 1) == 0) {
72 found = true;
73 break;
74 }
75 }
76 }
77 token = strtok_r(nullptr, ",", &save_ptr);
78 }
79 delete[] filter_buffer;
80
81 return found;
82}
83
84bool PrintFilter::ShouldPrint(const Function& function,
85 uint8_t** compiler_pass_filter /* = nullptr */) {
86 return PassesFilter(FLAG_print_flow_graph_filter, function,
87 compiler_pass_filter);
88}
89
90} // namespace compiler
91
92} // namespace dart
93
94#endif // defined(INCLUDE_IL_PRINTER)
static uint8_t * ParseFiltersFromPragma(const char *filter)
static bool FindPragma(Thread *T, bool only_core, const Object &object, const String &pragma_name, bool multiple=false, Object *options=nullptr)
Definition: object.cc:4151
static Object & Handle()
Definition: object.h:407
static Thread * Current()
Definition: thread.h:362
const char * charp
Definition: flags.h:12
Dart_NativeFunction function
Definition: fuchsia.cc:51
Definition: dart_vm.cc:33
DEFINE_FLAG(bool, print_cluster_information, false, "Print information about clusters written to snapshot")
const char *const function_name