• 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 MAPLE_IR_INCLUDE_BIN_MPL_IMPORT_H
17 #define MAPLE_IR_INCLUDE_BIN_MPL_IMPORT_H
18 #include "mir_module.h"
19 #include "mir_nodes.h"
20 #include "mir_preg.h"
21 #include "parser_opt.h"
22 #include "mir_builder.h"
23 #include "ea_connection_graph.h"
24 namespace maple {
25 class BinaryMplImport {
26 public:
BinaryMplImport(MIRModule & md)27     explicit BinaryMplImport(MIRModule &md) : mod(md), mirBuilder(&md) {}
28     BinaryMplImport &operator=(const BinaryMplImport &) = delete;
29     BinaryMplImport(const BinaryMplImport &) = delete;
30 
~BinaryMplImport()31     virtual ~BinaryMplImport()
32     {
33         for (MIRStructType *structPtr : tmpStruct) {
34             delete structPtr;
35         }
36         for (MIRClassType *classPtr : tmpClass) {
37             delete classPtr;
38         }
39         for (MIRInterfaceType *interfacePtr : tmpInterface) {
40             delete interfacePtr;
41         }
42     }
43 
GetBufI()44     uint64 GetBufI() const
45     {
46         return bufI;
47     }
SetBufI(uint64 bufIVal)48     void SetBufI(uint64 bufIVal)
49     {
50         bufI = bufIVal;
51     }
52 
IsBufEmpty()53     bool IsBufEmpty() const
54     {
55         return buf.empty();
56     }
GetBufSize()57     size_t GetBufSize() const
58     {
59         return buf.size();
60     }
61 
GetContent(int64 key)62     int32 GetContent(int64 key) const
63     {
64         return content.at(key);
65     }
66 
SetImported(bool importedVal)67     void SetImported(bool importedVal)
68     {
69         imported = importedVal;
70     }
71 
72     bool ImportForSrcLang(const std::string &modid, MIRSrcLang &srcLang);
73     MIRSymbol *GetOrCreateSymbol(TyIdx tyIdx, GStrIdx strIdx, MIRSymKind mclass, MIRStorageClass sclass,
74                                  MIRFunction *func, uint8 scpID);
75     int32 ReadInt();
76     int64 ReadNum();
77 
78 private:
79     void ReadContentField();
80     void ReadStrField();
81     void ReadSymTabField();
82     EAConnectionGraph *ReadEaCgField();
83     void ReadEaField();
84     EACGBaseNode &InEaCgNode(EAConnectionGraph &newEaCg);
85     void InEaCgBaseNode(EACGBaseNode &base, EAConnectionGraph &newEaCg, bool firstPart);
86     void InEaCgActNode(EACGActualNode &actual);
87     void InEaCgFieldNode(EACGFieldNode &field, EAConnectionGraph &newEaCg);
88     void InEaCgObjNode(EACGObjectNode &obj, EAConnectionGraph &newEaCg);
89     void InEaCgRefNode(EACGRefNode &ref);
90     void MergeDuplicated(PUIdx methodPuidx, std::vector<CallInfo *> &targetSet, std::vector<CallInfo *> &newSet);
91     void ReadSeField();
92     void Jump2NextField();
93     void Reset();
94     void SkipTotalSize();
95     void ImportFieldsOfStructType(FieldVector &fields, uint32 methodSize);
96     void InsertInHashTable(MIRType &ptype);
97     void UpdateMethodSymbols();
98     GStrIdx ImportStr();
99     UStrIdx ImportUsrStr();
100     MIRType *CreateMirType(MIRTypeKind kind, GStrIdx strIdx, int64 tag) const;
101     MIRGenericInstantType *CreateMirGenericInstantType(GStrIdx strIdx) const;
102     MIRBitFieldType *CreateBitFieldType(uint8 fieldsize, PrimType pt, GStrIdx strIdx) const;
103     void CompleteAggInfo(TyIdx tyIdx);
104     TyIdx ImportJType(bool forPointedType = false);
105     void ImportTypeBase(PrimType &primType, GStrIdx &strIdx, bool &nameIsLocal);
106     void InSymTypeTable();
107     void ImportTypePairs(std::vector<TypePair> &insVecType);
108     TypeAttrs ImportTypeAttrs();
109     MIRPragmaElement *ImportPragmaElement();
110     MIRPragma *ImportPragma();
111     void ImportFieldPair(FieldPair &fp);
112     void ImportMethodPair(MethodPair &memPool);
113     void ImportMethodsOfStructType(MethodVector &methods);
114     void ImportStructTypeData(MIRStructType &type);
115     void ImportInterfacesOfClassType(std::vector<TyIdx> &interfaces);
116     void ImportInfoIsStringOfStructType(MIRStructType &type);
117     void ImportInfoOfStructType(MIRStructType &type);
118     void ImportPragmaOfStructType(MIRStructType &type);
119     void SetClassTyidxOfMethods(MIRStructType &type);
120     void ImportClassTypeData(MIRClassType &type);
121     void ImportInterfaceTypeData(MIRInterfaceType &type);
122     void ImportInfoVector(MIRInfoVector &infoVector, MapleVector<bool> &infoVectorIsString);
123     void ImportLocalTypeNameTable(MIRTypeNameTable *typeNameTab);
124     void ImportFuncIdInfo(MIRFunction *func);
125     MIRSymbol *ImportLocalSymbol(MIRFunction *func);
126     PregIdx ImportPreg(MIRFunction *func);
127     LabelIdx ImportLabel(MIRFunction *func);
128     void ImportFormalsStIdx(MIRFunction *func);
129     void ImportAliasMap(MIRFunction *func);
130     void ImportSrcPos(SrcPosition &pos);
131     void ImportBaseNode(Opcode &o, PrimType &typ);
132     void ImportReturnValues(MIRFunction *func, CallReturnVector *retv);
133     void ReadFileAt(const std::string &modid, int32 offset);
134     uint8 Read();
135     int64 ReadInt64();
136     void ReadAsciiStr(std::string &str);
137     int32 GetIPAFileIndex(std::string &name);
138 
139     bool inCG = false;
140     bool inIPA = false;
141     bool imported = true;            // used only by irbuild to convert to ascii
142     bool importingFromMplt = false;  // decided based on magic number
143     uint64 bufI = 0;
144     std::vector<uint8> buf;
145     std::map<int64, int32> content;
146     MIRModule &mod;
147     MIRBuilder mirBuilder;
148     std::vector<GStrIdx> gStrTab;
149     std::vector<UStrIdx> uStrTab;
150     std::vector<MIRStructType *> tmpStruct;
151     std::vector<MIRClassType *> tmpClass;
152     std::vector<MIRInterfaceType *> tmpInterface;
153     std::vector<TyIdx> typTab;
154     std::vector<MIRFunction *> funcTab;
155     std::vector<MIRSymbol *> symTab;
156     std::vector<MIRSymbol *> localSymTab;
157     std::vector<PregIdx> localPregTab;
158     std::vector<LabelIdx> localLabelTab;
159     std::vector<CallInfo *> callInfoTab;
160     std::vector<EACGBaseNode *> eaCgTab;
161     std::vector<MIRSymbol *> methodSymbols;
162     std::vector<bool> definedLabels;
163     std::string importFileName;
164 };
165 }  // namespace maple
166 #endif  // MAPLE_IR_INCLUDE_BIN_MPL_IMPORT_H
167