• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1/*
2 * Copyright (c) 2024 Huawei Device Co., Ltd.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15
16#include "assembly-function.h"
17#include "assembly-ins.h"
18
19namespace panda::pandasm {
20
21std::set<std::string> panda::pandasm::Function::CollectStringsFromFunctionInsns() const {
22    std::set<std::string> function_strings {};
23    for (const auto &panda_insn : this->ins) {
24        switch (panda_insn->opcode) {
25% Panda::instructions.group_by(&:mnemonic).each do |mnemonic, group|
26% insn = group[index_of_max(group.map(&:format).map(&:size))]
27%       if (insn.properties.include?('string_id') || insn.properties.include?('method_id'))
28            case Opcode::<%= insn.asm_token %>: {
29%               num_id = 0
30%               property_idx_start = 0
31%               insn.operands.each do |op|
32%                   if op.id?
33%                       id_properties = insn.properties.slice(property_idx_start, insn.properties.length - property_idx_start)
34%                       id_properties.each_with_index do |prop, prop_idx|
35%                           if prop == 'string_id'
36                function_strings.insert(panda_insn->Ids()[<%= num_id %>]);
37%                               property_idx_start += prop_idx + 1
38%                               num_id += 1
39%                               break
40%                           elsif prop == 'method_id'
41                function_strings.insert(panda_insn->Ids()[<%= num_id %>]);
42%                               property_idx_start += prop_idx + 1
43%                               num_id += 1
44%                               break
45%                           elsif prop == 'literalarray_id'
46%                               property_idx_start += prop_idx + 1
47%                               num_id += 1
48%                               break
49%                           else
50%                               next
51%                           end
52%                       end
53%                   else
54%                       next
55%                   end
56%               end
57                break;
58            }
59%       else
60%           next
61%       end
62% end
63            default:
64                break;
65        }
66    }
67    return function_strings;
68}
69
70} // namespace panda::pandasm
71