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_ABC_FILE_UTILS_H 17 #define ABC2PROGRAM_ABC_FILE_UTILS_H 18 19 #include <string> 20 #include "assembly-program.h" 21 #include "file.h" 22 23 namespace panda::abc2program { 24 25 // type name 26 constexpr std::string_view GLOBAL_TYPE_NAME = "_GLOBAL"; 27 constexpr std::string_view ARRAY_TYPE_PREFIX = "["; 28 constexpr std::string_view ANY_TYPE_NAME = "any"; 29 constexpr std::string_view ES_TYPE_ANNOTATION_NAME = "_ESTypeAnnotation"; 30 constexpr std::string_view ES_MODULE_RECORD = "_ESModuleRecord"; 31 constexpr std::string_view ES_SCOPE_NAMES_RECORD = "_ESScopeNamesRecord"; 32 constexpr std::string_view JSON_FILE_CONTENT = "jsonFileContent"; 33 constexpr std::string_view MODULE_RECORD_IDX = "moduleRecordIdx"; 34 constexpr std::string_view SCOPE_NAMES = "scopeNames"; 35 constexpr std::string_view MODULE_REQUEST_PAHSE_IDX = "moduleRequestPhaseIdx"; 36 constexpr std::string_view CONCURRENT_MODULE_REQUEST_ANN_RECORD_TYPE_DESCRIPTOR = 37 "L_ESConcurrentModuleRequestsAnnotation;"; 38 constexpr std::string_view CONCURRENT_MODULE_REQUEST_RECORD_NAME = "_ESConcurrentModuleRequestsAnnotation"; 39 constexpr std::string_view SLOT_NUMBER_ANN_RECORD_TYPE_DESCRIPTOR = "L_ESSlotNumberAnnotation;"; 40 constexpr std::string_view SLOT_NUMBER_RECORD_NAME = "_ESSlotNumberAnnotation"; 41 constexpr std::string_view DOT = "."; 42 43 // attribute constant 44 constexpr std::string_view ABC_ATTR_EXTERNAL = "external"; 45 constexpr std::string_view ABC_ATTR_STATIC = "static"; 46 47 // literal array name 48 constexpr std::string_view UNDERLINE = "_"; 49 50 // width constant 51 constexpr uint32_t LINE_WIDTH = 40; 52 constexpr uint32_t COLUMN_WIDTH = 10; 53 constexpr uint32_t START_WIDTH = 5; 54 constexpr uint32_t END_WIDTH = 6; 55 constexpr uint32_t REG_WIDTH = 8; 56 constexpr uint32_t NAME_WIDTH = 13; 57 58 // ins constant 59 constexpr std::string_view LABEL_PREFIX = "label@"; 60 61 // module literal 62 constexpr uint8_t LITERAL_NUM_OF_REGULAR_IMPORT = 3; 63 constexpr uint8_t LITERAL_NUM_OF_NAMESPACE_IMPORT = 2; 64 constexpr uint8_t LITERAL_NUM_OF_LOCAL_EXPORT = 2; 65 constexpr uint8_t LITERAL_NUM_OF_INDIRECT_EXPORT = 3; 66 constexpr uint8_t LITERAL_NUM_OF_STAR_EXPORT = 1; 67 constexpr uint8_t LITERAL_NUMS[] = { 68 LITERAL_NUM_OF_REGULAR_IMPORT, 69 LITERAL_NUM_OF_NAMESPACE_IMPORT, 70 LITERAL_NUM_OF_LOCAL_EXPORT, 71 LITERAL_NUM_OF_INDIRECT_EXPORT, 72 LITERAL_NUM_OF_STAR_EXPORT 73 }; 74 75 class AbcFileUtils { 76 public: 77 static bool IsGlobalTypeName(const std::string &type_name); 78 static bool IsArrayTypeName(const std::string &type_name); 79 static bool IsSystemTypeName(const std::string &type_name); 80 static bool IsESTypeAnnotationName(const std::string &type_name); 81 static std::string GetLabelNameByInstIdx(size_t inst_idx); 82 }; // class AbcFileUtils 83 84 } // namespace panda::abc2program 85 86 #endif // ABC2PROGRAM_ABC_FILE_UTILS_H 87