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_RECORD_NAME = "_ESConcurrentModuleRequestsAnnotation"; 37 constexpr std::string_view SLOT_NUMBER_RECORD_NAME = "_ESSlotNumberAnnotation"; 38 constexpr std::string_view DOT = "."; 39 constexpr char NORMALIZED_OHMURL_SEPARATOR = '&'; 40 41 // attribute constant 42 constexpr std::string_view ABC_ATTR_EXTERNAL = "external"; 43 constexpr std::string_view ABC_ATTR_STATIC = "static"; 44 45 // literal array name 46 constexpr std::string_view UNDERLINE = "_"; 47 48 // width constant 49 constexpr uint32_t LINE_WIDTH = 40; 50 constexpr uint32_t COLUMN_WIDTH = 10; 51 constexpr uint32_t START_WIDTH = 5; 52 constexpr uint32_t END_WIDTH = 6; 53 constexpr uint32_t REG_WIDTH = 8; 54 constexpr uint32_t NAME_WIDTH = 13; 55 56 // ins constant 57 constexpr std::string_view LABEL_PREFIX = "label@"; 58 59 // module literal 60 constexpr uint8_t LITERAL_NUM_OF_REGULAR_IMPORT = 3; 61 constexpr uint8_t LITERAL_NUM_OF_NAMESPACE_IMPORT = 2; 62 constexpr uint8_t LITERAL_NUM_OF_LOCAL_EXPORT = 2; 63 constexpr uint8_t LITERAL_NUM_OF_INDIRECT_EXPORT = 3; 64 constexpr uint8_t LITERAL_NUM_OF_STAR_EXPORT = 1; 65 constexpr uint8_t LITERAL_NUMS[] = { 66 LITERAL_NUM_OF_REGULAR_IMPORT, 67 LITERAL_NUM_OF_NAMESPACE_IMPORT, 68 LITERAL_NUM_OF_LOCAL_EXPORT, 69 LITERAL_NUM_OF_INDIRECT_EXPORT, 70 LITERAL_NUM_OF_STAR_EXPORT 71 }; 72 73 class AbcFileUtils { 74 public: 75 static bool IsGlobalTypeName(const std::string &type_name); 76 static bool IsArrayTypeName(const std::string &type_name); 77 static bool IsSystemTypeName(const std::string &type_name); 78 static bool IsESTypeAnnotationName(const std::string &type_name); 79 static std::string GetLabelNameByInstIdx(size_t inst_idx); 80 }; // class AbcFileUtils 81 82 } // namespace panda::abc2program 83 84 #endif // ABC2PROGRAM_ABC_FILE_UTILS_H 85