1 /* 2 * Copyright (c) 2022 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 ES2PANDA_UTIL_SYMBOL_TABLE_H 17 #define ES2PANDA_UTIL_SYMBOL_TABLE_H 18 19 #include <libpandabase/utils/arena_containers.h> 20 21 #include <mutex> 22 23 namespace panda::es2panda::util { 24 class SymbolTable { 25 public: 26 static const std::string FIRST_LEVEL_SEPERATOR; 27 static const std::string SECOND_LEVEL_SEPERATOR; 28 29 struct OriginFunctionInfo { 30 std::string funcName; 31 std::string funcInternalName; 32 std::string funcHash; 33 ArenaMap<uint32_t, std::pair<std::string, int>> lexenv; // lexenv: <slot, <name, type>> 34 ArenaMap<std::string, std::string> classHash; 35 OriginFunctionInfoOriginFunctionInfo36 explicit OriginFunctionInfo(ArenaAllocator *allocator) : lexenv(allocator->Adapter()), 37 classHash(allocator->Adapter()) {} 38 }; 39 SymbolTable(const std::string & inputSymbolTable,const std::string & dumpSymbolTable)40 SymbolTable(const std::string &inputSymbolTable, const std::string &dumpSymbolTable) 41 : symbolTable_(inputSymbolTable), dumpSymbolTable_(dumpSymbolTable), 42 allocator_(SpaceType::SPACE_TYPE_COMPILER, nullptr, true), 43 originFunctionInfo_(allocator_.Adapter()), 44 originModuleInfo_(allocator_.Adapter()) {} 45 46 bool Initialize(); 47 void WriteSymbolTable(const std::string &content); GetOriginFunctionInfo()48 ArenaUnorderedMap<std::string, OriginFunctionInfo> *GetOriginFunctionInfo() 49 { 50 return &originFunctionInfo_; 51 } 52 GetOriginModuleInfo()53 ArenaUnorderedMap<std::string, std::string> *GetOriginModuleInfo() 54 { 55 return &originModuleInfo_; 56 } 57 58 private: 59 bool ReadSymbolTable(const std::string &symbolTable); 60 std::vector<std::string_view> GetStringItems(std::string_view input, const std::string &separator); 61 62 std::mutex m_; 63 std::string symbolTable_; 64 std::string dumpSymbolTable_; 65 ArenaAllocator allocator_; 66 ArenaUnorderedMap<std::string, OriginFunctionInfo> originFunctionInfo_; 67 ArenaUnorderedMap<std::string, std::string> originModuleInfo_; 68 }; 69 } // namespace panda::es2panda::util 70 71 #endif // ES2PANDA_UTIL_SYMBOL_TABLE_H