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 "abc_code_converter.h"
17
18 namespace panda::abc2program {
19
IDToString(BytecodeInstruction bc_ins,panda_file::File::EntityId method_id,size_t idx) const20 std::string AbcCodeConverter::IDToString(BytecodeInstruction bc_ins, panda_file::File::EntityId method_id,
21 size_t idx) const
22 {
23 panda_file::File::EntityId entity_id = file_.ResolveOffsetByIndex(method_id, bc_ins.GetId(idx).AsIndex());
24 if (bc_ins.IsIdMatchFlag(idx, BytecodeInstruction::Flags::METHOD_ID)) {
25 std::string full_method_name = entity_container_.GetFullMethodNameById(entity_id);
26 entity_container_.AddProgramString(full_method_name);
27 return full_method_name;
28 } else if (bc_ins.IsIdMatchFlag(idx, BytecodeInstruction::Flags::STRING_ID)) {
29 std::string str_constant = entity_container_.GetStringById(entity_id);
30 entity_container_.AddProgramString(str_constant);
31 return str_constant;
32 } else {
33 ASSERT(bc_ins.IsIdMatchFlag(idx, BytecodeInstruction::Flags::LITERALARRAY_ID));
34 entity_container_.AddUnnestedLiteralArrayId(entity_id.GetOffset());
35 return entity_container_.GetLiteralArrayIdName(entity_id.GetOffset());
36 }
37 }
38
39 } // namespace panda::abc2program