MCPcopy Create free account
hub / github.com/DeepRec-AI/DeepRec / Rewrite

Method Rewrite

tensorflow/lite/delegates/gpu/gl/compiler/preprocessor.cc:49–91  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

47} // namespace
48
49Status TextPreprocessor::Rewrite(const std::string& input,
50 std::string* output) {
51 absl::string_view s = input;
52 std::string result;
53 while (true) {
54 absl::string_view inline_block = FindInlineBlock(s, inline_delimiter_);
55 result.append(s.data(), inline_block.data() - s.data());
56 if (inline_block.empty()) {
57 break;
58 }
59 if (inline_block.size() == 1) {
60 return NotFoundError("Unable to find end of inline block");
61 }
62 s = PastSubstr(s, inline_block);
63 bool processed = false;
64 for (auto& rewrite : inline_rewrites_) {
65 if (processed) {
66 break;
67 }
68 switch (rewrite->Rewrite(inline_block.substr(1, inline_block.size() - 2),
69 &result)) {
70 case RewriteStatus::NOT_RECOGNIZED:
71 // try another rewrite.
72 break;
73 case RewriteStatus::SUCCESS:
74 processed = true;
75 break;
76 case RewriteStatus::ERROR:
77 return InternalError(absl::StrCat("Error while rewriting '",
78 inline_block, "': ", result));
79 }
80 }
81 if (!processed) {
82 if (!keep_unknown_rewrites_) {
83 return NotFoundError(absl::StrCat("Didn't find inline rewrite for '",
84 inline_block, "'"));
85 }
86 absl::StrAppend(&result, inline_block);
87 }
88 }
89 *output = std::move(result);
90 return OkStatus();
91}
92
93} // namespace gl
94} // namespace gpu

Callers 3

TESTFunction · 0.45
BuildMethod · 0.45
TESTFunction · 0.45

Calls 11

FindInlineBlockFunction · 0.85
PastSubstrFunction · 0.85
OkStatusFunction · 0.85
NotFoundErrorFunction · 0.50
InternalErrorFunction · 0.50
StrCatFunction · 0.50
StrAppendFunction · 0.50
appendMethod · 0.45
dataMethod · 0.45
emptyMethod · 0.45
sizeMethod · 0.45

Tested by 2

TESTFunction · 0.36
TESTFunction · 0.36