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 #ifndef ABC2PROGRAM_PROGRANM_DUMPER_PROGRAM_DUMP_H 17 #define ABC2PROGRAM_PROGRANM_DUMPER_PROGRAM_DUMP_H 18 19 #include <iostream> 20 #include <assembly-program.h> 21 #include "abc_string_table.h" 22 23 namespace ark::abc2program { 24 25 class PandasmProgramDumper { 26 public: PandasmProgramDumper(const panda_file::File &file, const AbcStringTable &stringTable)27 PandasmProgramDumper(const panda_file::File &file, const AbcStringTable &stringTable) 28 : file_(&file), stringTable_(&stringTable) 29 { 30 } 31 PandasmProgramDumper() = default; 32 void Dump(std::ostream &os, const pandasm::Program &program) const; 33 34 private: 35 bool HasNoAbcInput() const; 36 void DumpAbcFilePath(std::ostream &os) const; 37 void DumpProgramLanguage(std::ostream &os, const pandasm::Program &program) const; 38 void DumpLiteralArrayTable(std::ostream &os, const pandasm::Program &program) const; 39 void DumpLiteralArrayTableWithKey(std::ostream &os, const pandasm::Program &program) const; 40 void DumpLiteralArrayTableWithoutKey(std::ostream &os, const pandasm::Program &program) const; 41 void DumpLiteralArrayWithKey(std::ostream &os, const std::string &key, const pandasm::LiteralArray &litArray, 42 const pandasm::Program &program) const; 43 void DumpRecordTable(std::ostream &os, const pandasm::Program &program) const; 44 void DumpRecord(std::ostream &os, const pandasm::Record &record) const; 45 void DumpFieldList(std::ostream &os, const pandasm::Record &record) const; 46 void DumpField(std::ostream &os, const pandasm::Field &field) const; 47 bool DumpMetaData(std::ostream &os, const pandasm::ItemMetadata &meta) const; 48 void DumpRecordSourceFile(std::ostream &os, const pandasm::Record &record) const; 49 void DumpFunctionTable(std::ostream &os, const pandasm::Program &program) const; 50 void DumpFunction(std::ostream &os, const pandasm::Function &function) const; 51 void DumpInstructions(std::ostream &os, const pandasm::Function &function) const; 52 void DumpStrings(std::ostream &os, const pandasm::Program &program) const; 53 void DumpStringsByStringTable(std::ostream &os, const AbcStringTable &stringTable) const; 54 void DumpStringsByProgram(std::ostream &os, const pandasm::Program &program) const; 55 void DumpLiteralArray(std::ostream &os, const pandasm::LiteralArray &litArray, 56 const pandasm::Program &program) const; 57 std::string LiteralTagToString(const panda_file::LiteralTag &tag, const pandasm::Program &program) const; 58 std::string LiteralValueToString(const pandasm::LiteralArray::Literal &lit) const; 59 void DumpValues(const pandasm::LiteralArray &litArray, const bool isConst, std::ostream &os, 60 const pandasm::Program &program) const; 61 const panda_file::File *file_ = nullptr; 62 const AbcStringTable *stringTable_ = nullptr; 63 }; 64 65 } // namespace ark::abc2program 66 67 #endif // ABC2PROGRAM_PROGRANM_DUMPER_PROGRAM_DUMP_H 68