• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2023 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 MAPLEIR_INCLUDE_MIRSYMBOLBUILDER_H
17 #define MAPLEIR_INCLUDE_MIRSYMBOLBUILDER_H
18 #include <string>
19 #include <utility>
20 #include <vector>
21 #include <map>
22 #include "opcodes.h"
23 #include "prim_types.h"
24 #include "mir_type.h"
25 #include "mir_const.h"
26 #include "mir_symbol.h"
27 #include "mir_nodes.h"
28 #include "mir_module.h"
29 #include "mir_preg.h"
30 #include "mir_function.h"
31 #include "printing.h"
32 #include "intrinsic_op.h"
33 #include "opcode_info.h"
34 #include "global_tables.h"
35 
36 namespace maple {
37 class MIRSymbolBuilder {
38 public:
Instance()39     static MIRSymbolBuilder &Instance()
40     {
41         static MIRSymbolBuilder builder;
42         return builder;
43     }
44 
45     MIRSymbol *GetLocalDecl(const MIRSymbolTable &symbolTable, const GStrIdx &strIdx) const;
46     MIRSymbol *CreateLocalDecl(MIRSymbolTable &symbolTable, GStrIdx strIdx, const MIRType &type) const;
47     MIRSymbol *GetGlobalDecl(GStrIdx strIdx) const;
48     MIRSymbol *CreateGlobalDecl(GStrIdx strIdx, const MIRType &type, MIRStorageClass sc) const;
49     MIRSymbol *GetSymbol(TyIdx tyIdx, GStrIdx strIdx, MIRSymKind mClass, MIRStorageClass sClass,
50                          bool sameType = false) const;
51     MIRSymbol *CreateSymbol(TyIdx tyIdx, GStrIdx strIdx, MIRSymKind mClass, MIRStorageClass sClass, MIRFunction *func,
52                             uint8 scpID) const;
53     MIRSymbol *CreatePregFormalSymbol(TyIdx tyIdx, PregIdx pRegIdx, MIRFunction &func) const;
54     size_t GetSymbolTableSize(const MIRFunction *func = nullptr) const;
55     const MIRSymbol *GetSymbolFromStIdx(uint32 idx, const MIRFunction *func = nullptr) const;
56 
57 private:
58     MIRSymbolBuilder() = default;
59     ~MIRSymbolBuilder() = default;
60     MIRSymbolBuilder(const MIRSymbolBuilder &) = delete;
61     MIRSymbolBuilder(const MIRSymbolBuilder &&) = delete;
62     MIRSymbolBuilder &operator=(const MIRSymbolBuilder &) = delete;
63     MIRSymbolBuilder &operator=(const MIRSymbolBuilder &&) = delete;
64 };
65 }  // namespace maple
66 #endif  // MAPLEIR_INCLUDE_MIRSYMBOLBUILDER_H
67