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