diff --git a/src/bin/jbc2mpl b/src/bin/jbc2mpl index d083083b7d3334fd9d896ba8b916234a38df6ecc..12ccbc9cc82e9225100442c2696fe81d228c7f63 100755 Binary files a/src/bin/jbc2mpl and b/src/bin/jbc2mpl differ diff --git a/src/bin/maple b/src/bin/maple index 13c1eb330a95c85a8795f238c0c6a5adc3f39f25..d0f2c11052cab55047141e371e169878910a80ff 100755 Binary files a/src/bin/maple and b/src/bin/maple differ diff --git a/src/bin/mplcg b/src/bin/mplcg index 3a92cb8ca1d66ba44268d4d2a90ef6d84c8e49ea..f43959af754b6b6635fab39ca7dd783cd027f1cc 100755 Binary files a/src/bin/mplcg and b/src/bin/mplcg differ diff --git a/src/deplibs/libmaple_driverutil.a b/src/deplibs/libmaple_driverutil.a index c1262b62e5722495e3d5fbddf11140183b8f2b5c..6e7cf476c54ee38cdc620d7e91c58426fae5545b 100644 Binary files a/src/deplibs/libmaple_driverutil.a and b/src/deplibs/libmaple_driverutil.a differ diff --git a/src/deplibs/libmplutil.a b/src/deplibs/libmplutil.a index 4e28d0f891c40b01917084268b0ff2131e414064..cdf6dfac295fca151a77e778b99821a7bd60901b 100644 Binary files a/src/deplibs/libmplutil.a and b/src/deplibs/libmplutil.a differ diff --git a/src/maple_ipa/include/interleaved_manager.h b/src/maple_ipa/include/interleaved_manager.h index 84d5b4ab2d47295135dcc3d9b52fa178888486bc..887d0b48577e70af7ffdb9b35f65a651cf74b86f 100644 --- a/src/maple_ipa/include/interleaved_manager.h +++ b/src/maple_ipa/include/interleaved_manager.h @@ -53,7 +53,7 @@ class InterleavedManager { void AddPhases(std::vector &phases, bool isModulePhase, bool timePhases = false, bool genMpl = false); void AddIPAPhases(std::vector &phases, bool timePhases = false, bool genMpl = false); void Run(); - void IPARun(MeFuncPhaseManager*); + void IPARun(MeFuncPhaseManager&); PhaseManager *AccessPhaseManager(int i) const { return phaseManagers.at(i); diff --git a/src/maple_ipa/include/module_phase_manager.h b/src/maple_ipa/include/module_phase_manager.h index ccd3e87e9fad47ea96672807e4aa2548aa7e7b84..794891d699320bbdae230839c3868dfefd382d74 100644 --- a/src/maple_ipa/include/module_phase_manager.h +++ b/src/maple_ipa/include/module_phase_manager.h @@ -61,7 +61,7 @@ class ModulePhaseManager : public PhaseManager { } void Run() override; - void Emit(const char *passName); + void Emit(const std::string &passName); private: bool timePhases; diff --git a/src/maple_ipa/src/module_phase_manager.cpp b/src/maple_ipa/src/module_phase_manager.cpp index 36e5f3b7cba60b3d71314de24363a337da5fbcb6..e7477cd1777be844bed7a5748aa49ec74a2d9914 100644 --- a/src/maple_ipa/src/module_phase_manager.cpp +++ b/src/maple_ipa/src/module_phase_manager.cpp @@ -106,7 +106,7 @@ void ModulePhaseManager::Run() { } } -void ModulePhaseManager::Emit(const char *passName) { +void ModulePhaseManager::Emit(const std::string &passName) { // Form output file name. std::string outFileName; std::string moduleFileName = mirModule.GetFileName(); diff --git a/src/maple_ir/include/global_tables.h b/src/maple_ir/include/global_tables.h index 2303c0d2f5da136c2a238a6696cdf5c4c4346c31..f3713daa5c48eb9c15355670c0752943927c300c 100644 --- a/src/maple_ir/include/global_tables.h +++ b/src/maple_ir/include/global_tables.h @@ -253,39 +253,39 @@ class TypeTable { // Get or Create derived types. MIRType *GetOrCreatePointerType(TyIdx pointedTyIdx, PrimType pty = PTY_ptr); - MIRType *GetOrCreatePointerType(const MIRType *pointTo, PrimType pty = PTY_ptr); - MIRType *GetPointedTypeIfApplicable(MIRType *type) const; + MIRType *GetOrCreatePointerType(const MIRType &pointTo, PrimType pty = PTY_ptr); + MIRType *GetPointedTypeIfApplicable(MIRType &type) const; MIRType *GetVoidPtr() const { ASSERT(voidPtrType != nullptr, "voidPtrType should not be null"); return voidPtrType; } - MIRArrayType *GetOrCreateArrayType(const MIRType *elem, uint8 dim, const uint32 *sizeArray); - MIRArrayType *GetOrCreateArrayType(const MIRType *elem, uint32 size); // For one dimention array - MIRType *GetOrCreateFarrayType(const MIRType *elem); - MIRType *GetOrCreateJarrayType(const MIRType *elem); - MIRType *GetOrCreateFunctionType(MIRModule *module, TyIdx, const std::vector &, const std::vector &, + MIRArrayType *GetOrCreateArrayType(const MIRType &elem, uint8 dim, const uint32 *sizeArray); + MIRArrayType *GetOrCreateArrayType(const MIRType &elem, uint32 size); // For one dimention array + MIRType *GetOrCreateFarrayType(const MIRType &elem); + MIRType *GetOrCreateJarrayType(const MIRType &elem); + MIRType *GetOrCreateFunctionType(MIRModule &module, TyIdx, const std::vector&, const std::vector&, bool isVarg = false, bool isSimpCreate = false); - MIRType *GetOrCreateStructType(const char *name, const FieldVector &fields, const FieldVector &prntFields, - MIRModule *module) { + MIRType *GetOrCreateStructType(const std::string &name, const FieldVector &fields, const FieldVector &prntFields, + MIRModule &module) { return GetOrCreateStructOrUnion(name, fields, prntFields, module); } - MIRType *GetOrCreateUnionType(const char *name, const FieldVector &fields, const FieldVector &parentFields, - MIRModule *module) { + MIRType *GetOrCreateUnionType(const std::string &name, const FieldVector &fields, const FieldVector &parentFields, + MIRModule &module) { return GetOrCreateStructOrUnion(name, fields, parentFields, module, false); } - MIRType *GetOrCreateClassType(const char *name, MIRModule *module) { + MIRType *GetOrCreateClassType(const std::string &name, MIRModule &module) { return GetOrCreateClassOrInterface(name, module, true); } - MIRType *GetOrCreateInterfaceType(const char *name, MIRModule *module) { + MIRType *GetOrCreateInterfaceType(const std::string &name, MIRModule &module) { return GetOrCreateClassOrInterface(name, module, false); } - void PushIntoFieldVector(FieldVector *fields, const char *name, MIRType *type); - void AddFieldToStructType(MIRStructType *structType, const char *fieldName, MIRType *fieldType); + void PushIntoFieldVector(FieldVector &fields, const std::string &name, MIRType &type); + void AddFieldToStructType(MIRStructType &structType, const std::string &fieldName, MIRType &fieldType); private: using MIRTypePtr = MIRType*; @@ -304,10 +304,10 @@ class TypeTable { std::unordered_set typeHashTable; std::vector typeTable; - MIRType *CreateType(MIRType *oldType); - MIRType *GetOrCreateStructOrUnion(const char *name, const FieldVector &fields, const FieldVector &prntFields, - MIRModule *module, bool forStruct = true); - MIRType *GetOrCreateClassOrInterface(const char *name, MIRModule *module, bool forClass); + MIRType *CreateType(MIRType &oldType); + MIRType *GetOrCreateStructOrUnion(const std::string &name, const FieldVector &fields, const FieldVector &prntFields, + MIRModule &module, bool forStruct = true); + MIRType *GetOrCreateClassOrInterface(const std::string &name, MIRModule &module, bool forClass); }; class StrPtrHash { @@ -334,7 +334,7 @@ class StrPtrEqual { // T can be std::string or std::u16string // U can be GStrIdx, UStrIdx_t, or u16stridx_t -template // T can be std::string or std::u16string +template class StringTable { public: StringTable &operator = (const StringTable &) = delete; @@ -515,8 +515,8 @@ class GSymbolTable { } MIRSymbol *CreateSymbol(uint8 scopeID); - bool AddToStringSymbolMap(const MIRSymbol *st); - bool RemoveFromStringSymbolMap(const MIRSymbol *st); + bool AddToStringSymbolMap(const MIRSymbol &st); + bool RemoveFromStringSymbolMap(const MIRSymbol &st); void Dump(bool islocal, int32 indent = 0) const; private: diff --git a/src/maple_ir/include/java_eh_lower.h b/src/maple_ir/include/java_eh_lower.h index ace88f8df0bd9f8144b67e0e5e92d794ec8852b6..cb65627a3da4fc4d14e672033c50dc5caaf86545 100644 --- a/src/maple_ir/include/java_eh_lower.h +++ b/src/maple_ir/include/java_eh_lower.h @@ -42,7 +42,7 @@ class JavaEHLowerer : public FuncOptimizeImpl { return DoLowerDiv(expr, blkNode); } - void DoLowerBoundaryCheck(IntrinsiccallNode*, BlockNode*); + void DoLowerBoundaryCheck(IntrinsiccallNode&, BlockNode&); uint32 divSTIndex; // The index of divide operand and result. bool useRegTmp; // Use register to save temp variable or not. diff --git a/src/maple_ir/include/lexer.h b/src/maple_ir/include/lexer.h index fcd7ad3c28c72c98123d694a5c69cc4001fc025a..d23a57a8e326cd01b6d5844dd1571cbdfb4096a3 100644 --- a/src/maple_ir/include/lexer.h +++ b/src/maple_ir/include/lexer.h @@ -19,15 +19,15 @@ #include "mempool_allocator.h" #include "stdio.h" #include +#include "mir_module.h" namespace maple { -class MIRModule; class MIRParser; class MIRLexer { friend MIRParser; public: - explicit MIRLexer(MIRModule *mod); + explicit MIRLexer(MIRModule &mod); ~MIRLexer() { airFile = nullptr; if (airFileInternal.is_open()) { @@ -35,7 +35,7 @@ class MIRLexer { } } - void PrepareForFile(const char *filename); + void PrepareForFile(const std::string &filename); void PrepareForString(const std::string &src); TokenKind NextToken(void); TokenKind LexToken(); @@ -71,7 +71,7 @@ class MIRLexer { std::string GetTokenString() const; // for error reporting purpose private: - MIRModule *module; + MIRModule &module; // for storing the different types of constant values int64 theIntVal; // also indicates preg number under kTkPreg float theFloatVal; diff --git a/src/maple_ir/include/mir_nodes.h b/src/maple_ir/include/mir_nodes.h index bc7839e3aa116a3460deee32855bd07645732909..f4c93f2bfbf57ac9b68246e76f7d303ad41fc09f 100644 --- a/src/maple_ir/include/mir_nodes.h +++ b/src/maple_ir/include/mir_nodes.h @@ -773,7 +773,7 @@ class TernaryNode : public BaseNode { class NaryOpnds { public: - explicit NaryOpnds(MapleAllocator *mpallocter) : nOpnd(mpallocter->Adapter()) {} + explicit NaryOpnds(MapleAllocator &mpallocter) : nOpnd(mpallocter.Adapter()) {} virtual ~NaryOpnds() = default; @@ -812,18 +812,18 @@ class NaryOpnds { class NaryNode : public BaseNode, public NaryOpnds { public: - NaryNode(MapleAllocator *allocator, Opcode o) : BaseNode(o), NaryOpnds(allocator) {} + NaryNode(MapleAllocator &allocator, Opcode o) : BaseNode(o), NaryOpnds(allocator) {} - NaryNode(const MIRModule *mod, Opcode o) : NaryNode(mod->CurFuncCodeMemPoolAllocator(), o) {} + NaryNode(const MIRModule &mod, Opcode o) : NaryNode(mod.GetCurFuncCodeMPAllocator(), o) {} - NaryNode(MapleAllocator *allocator, Opcode o, PrimType typ) : BaseNode(o, typ, 0), NaryOpnds(allocator) {} + NaryNode(MapleAllocator &allocator, Opcode o, PrimType typ) : BaseNode(o, typ, 0), NaryOpnds(allocator) {} - NaryNode(const MIRModule *mod, Opcode o, PrimType typ) : NaryNode(mod->CurFuncCodeMemPoolAllocator(), o, typ) {} + NaryNode(const MIRModule &mod, Opcode o, PrimType typ) : NaryNode(mod.GetCurFuncCodeMPAllocator(), o, typ) {} - NaryNode(MapleAllocator *allocator, const NaryNode *node) - : BaseNode(node->GetOpCode(), node->GetPrimType(), node->numOpnds), NaryOpnds(allocator) {} + NaryNode(MapleAllocator &allocator, const NaryNode &node) + : BaseNode(node.GetOpCode(), node.GetPrimType(), node.numOpnds), NaryOpnds(allocator) {} - NaryNode(const MIRModule *mod, const NaryNode *node) : NaryNode(mod->CurFuncCodeMemPoolAllocator(), node) {} + NaryNode(const MIRModule &mod, const NaryNode &node) : NaryNode(mod.GetCurFuncCodeMPAllocator(), node) {} NaryNode(NaryNode &node) = delete; NaryNode &operator=(const NaryNode &node) = delete; @@ -832,7 +832,7 @@ class NaryNode : public BaseNode, public NaryOpnds { virtual void Dump(const MIRModule &mod, int32 indent) const; NaryNode *CloneTree(MapleAllocator &allocator) const { - NaryNode *nd = allocator.GetMemPool()->New(&allocator, this); + NaryNode *nd = allocator.GetMemPool()->New(allocator, *this); for (size_t i = 0; i < GetNopndSize(); i++) { nd->GetNopnd().push_back(GetNopndAt(i)->CloneTree(allocator)); } @@ -864,23 +864,23 @@ class NaryNode : public BaseNode, public NaryOpnds { class IntrinsicopNode : public NaryNode { public: - explicit IntrinsicopNode(MapleAllocator *allocator, Opcode o, TyIdx typeIdx = TyIdx()) + explicit IntrinsicopNode(MapleAllocator &allocator, Opcode o, TyIdx typeIdx = TyIdx()) : NaryNode(allocator, o), intrinsic(INTRN_UNDEFINED), tyIdx(typeIdx) {} - explicit IntrinsicopNode(const MIRModule *mod, Opcode o, TyIdx typeIdx = TyIdx()) - : IntrinsicopNode(mod->CurFuncCodeMemPoolAllocator(), o, typeIdx) {} + explicit IntrinsicopNode(const MIRModule &mod, Opcode o, TyIdx typeIdx = TyIdx()) + : IntrinsicopNode(mod.GetCurFuncCodeMPAllocator(), o, typeIdx) {} - IntrinsicopNode(MapleAllocator *allocator, Opcode o, PrimType typ, TyIdx typeIdx = TyIdx()) + IntrinsicopNode(MapleAllocator &allocator, Opcode o, PrimType typ, TyIdx typeIdx = TyIdx()) : NaryNode(allocator, o, typ), intrinsic(INTRN_UNDEFINED), tyIdx(typeIdx) {} - IntrinsicopNode(const MIRModule *mod, Opcode o, PrimType typ, TyIdx typeIdx = TyIdx()) - : IntrinsicopNode(mod->CurFuncCodeMemPoolAllocator(), o, typ, typeIdx) {} + IntrinsicopNode(const MIRModule &mod, Opcode o, PrimType typ, TyIdx typeIdx = TyIdx()) + : IntrinsicopNode(mod.GetCurFuncCodeMPAllocator(), o, typ, typeIdx) {} - IntrinsicopNode(MapleAllocator *allocator, const IntrinsicopNode *node) - : NaryNode(allocator, node), intrinsic(node->GetIntrinsic()), tyIdx(node->GetTyIdx()) {} + IntrinsicopNode(MapleAllocator &allocator, const IntrinsicopNode &node) + : NaryNode(allocator, node), intrinsic(node.GetIntrinsic()), tyIdx(node.GetTyIdx()) {} - IntrinsicopNode(const MIRModule *mod, const IntrinsicopNode *node) - : IntrinsicopNode(mod->CurFuncCodeMemPoolAllocator(), node) {} + IntrinsicopNode(const MIRModule &mod, const IntrinsicopNode &node) + : IntrinsicopNode(mod.GetCurFuncCodeMPAllocator(), node) {} IntrinsicopNode(IntrinsicopNode &node) = delete; IntrinsicopNode &operator=(const IntrinsicopNode &node) = delete; @@ -890,7 +890,7 @@ class IntrinsicopNode : public NaryNode { bool Verify() const; IntrinsicopNode *CloneTree(MapleAllocator &allocator) const { - IntrinsicopNode *nd = allocator.GetMemPool()->New(&allocator, this); + IntrinsicopNode *nd = allocator.GetMemPool()->New(allocator, *this); for (size_t i = 0; i < GetNopndSize(); i++) { nd->GetNopnd().push_back(GetNopndAt(i)->CloneTree(allocator)); } @@ -1086,25 +1086,25 @@ class FieldsDistNode : public BaseNode { class ArrayNode : public NaryNode { public: - ArrayNode(MapleAllocator *allocator) : NaryNode(allocator, OP_array), boundsCheck(true) {} + ArrayNode(MapleAllocator &allocator) : NaryNode(allocator, OP_array), boundsCheck(true) {} - explicit ArrayNode(const MIRModule *mod) : ArrayNode(mod->CurFuncCodeMemPoolAllocator()) {} + explicit ArrayNode(const MIRModule &mod) : ArrayNode(mod.GetCurFuncCodeMPAllocator()) {} - ArrayNode(MapleAllocator *allocator, PrimType typ, TyIdx idx) + ArrayNode(MapleAllocator &allocator, PrimType typ, TyIdx idx) : NaryNode(allocator, OP_array, typ), tyIdx(idx), boundsCheck(true) {} - ArrayNode(const MIRModule *mod, PrimType typ, TyIdx idx) : ArrayNode(mod->CurFuncCodeMemPoolAllocator(), typ, idx) {} + ArrayNode(const MIRModule &mod, PrimType typ, TyIdx idx) : ArrayNode(mod.GetCurFuncCodeMPAllocator(), typ, idx) {} - ArrayNode(MapleAllocator *allocator, PrimType typ, TyIdx idx, bool bcheck) + ArrayNode(MapleAllocator &allocator, PrimType typ, TyIdx idx, bool bcheck) : NaryNode(allocator, OP_array, typ), tyIdx(idx), boundsCheck(bcheck) {} - ArrayNode(const MIRModule *mod, PrimType typ, TyIdx idx, bool bcheck) - : ArrayNode(mod->CurFuncCodeMemPoolAllocator(), typ, idx, bcheck) {} + ArrayNode(const MIRModule &mod, PrimType typ, TyIdx idx, bool bcheck) + : ArrayNode(mod.GetCurFuncCodeMPAllocator(), typ, idx, bcheck) {} - ArrayNode(MapleAllocator *allocator, const ArrayNode *node) - : NaryNode(allocator, node), tyIdx(node->tyIdx), boundsCheck(node->boundsCheck) {} + ArrayNode(MapleAllocator &allocator, const ArrayNode &node) + : NaryNode(allocator, node), tyIdx(node.tyIdx), boundsCheck(node.boundsCheck) {} - ArrayNode(const MIRModule *mod, const ArrayNode *node) : ArrayNode(mod->CurFuncCodeMemPoolAllocator(), node) {} + ArrayNode(const MIRModule &mod, const ArrayNode &node) : ArrayNode(mod.GetCurFuncCodeMPAllocator(), node) {} ArrayNode(ArrayNode &node) = delete; ArrayNode &operator=(const ArrayNode &node) = delete; @@ -1120,7 +1120,7 @@ class ArrayNode : public NaryNode { } ArrayNode *CloneTree(MapleAllocator &allocator) const { - ArrayNode *nd = allocator.GetMemPool()->New(&allocator, this); + ArrayNode *nd = allocator.GetMemPool()->New(allocator, *this); for (size_t i = 0; i < GetNopndSize(); i++) { nd->GetNopnd().push_back(GetNopndAt(i)->CloneTree(allocator)); } @@ -1593,11 +1593,11 @@ class JsTryNode : public StmtNode { // try class TryNode : public StmtNode { public: - explicit TryNode(MapleAllocator *allocator) : StmtNode(OP_try), offsets(allocator->Adapter()) {} + explicit TryNode(MapleAllocator &allocator) : StmtNode(OP_try), offsets(allocator.Adapter()) {} - TryNode(MapleAllocator *allocator, const MapleVector &offsets) : StmtNode(OP_try), offsets(offsets) {} + TryNode(const MapleVector &offsets) : StmtNode(OP_try), offsets(offsets) {} - explicit TryNode(const MIRModule *mod) : TryNode(mod->CurFuncCodeMemPoolAllocator()) {} + explicit TryNode(const MIRModule &mod) : TryNode(mod.GetCurFuncCodeMPAllocator()) {} TryNode(TryNode &node) = delete; TryNode &operator=(const TryNode &node) = delete; @@ -1646,7 +1646,7 @@ class TryNode : public StmtNode { } TryNode *CloneTree(MapleAllocator &allocator) const { - TryNode *nd = allocator.GetMemPool()->New(&allocator); + TryNode *nd = allocator.GetMemPool()->New(allocator); nd->SetStmtID(stmtIDNext++); for (size_t i = 0; i < offsets.size(); i++) { nd->AddOffset(offsets[i]); @@ -1661,12 +1661,12 @@ class TryNode : public StmtNode { // catch class CatchNode : public StmtNode { public: - explicit CatchNode(MapleAllocator *allocator) : StmtNode(OP_catch), exceptionTyIdxVec(allocator->Adapter()) {} + explicit CatchNode(MapleAllocator &allocator) : StmtNode(OP_catch), exceptionTyIdxVec(allocator.Adapter()) {} - CatchNode(MapleAllocator *allocator, const MapleVector &tyIdxVec) + CatchNode(const MapleVector &tyIdxVec) : StmtNode(OP_catch), exceptionTyIdxVec(tyIdxVec) {} - explicit CatchNode(const MIRModule *mod) : CatchNode(mod->CurFuncCodeMemPoolAllocator()) {} + explicit CatchNode(const MIRModule &mod) : CatchNode(mod.GetCurFuncCodeMPAllocator()) {} CatchNode(CatchNode &node) = delete; CatchNode &operator=(const CatchNode &node) = delete; @@ -1702,7 +1702,7 @@ class CatchNode : public StmtNode { } CatchNode *CloneTree(MapleAllocator &allocator) const { - CatchNode *j = allocator.GetMemPool()->New(&allocator); + CatchNode *j = allocator.GetMemPool()->New(allocator); j->SetStmtID(stmtIDNext++); for (uint32 i = 0; i < Size(); i++) { j->PushBack(GetExceptionTyIdxVecElement(i)); @@ -1719,25 +1719,25 @@ using CasePair = std::pair; using CaseVector = MapleVector; class SwitchNode : public StmtNode { public: - explicit SwitchNode(MapleAllocator *allocator) - : StmtNode(OP_switch, 1), switchOpnd(nullptr), defaultLabel(0), switchTable(allocator->Adapter()) {} + explicit SwitchNode(MapleAllocator &allocator) + : StmtNode(OP_switch, 1), switchOpnd(nullptr), defaultLabel(0), switchTable(allocator.Adapter()) {} - explicit SwitchNode(const MIRModule *mod) : SwitchNode(mod->CurFuncCodeMemPoolAllocator()) {} + explicit SwitchNode(const MIRModule &mod) : SwitchNode(mod.GetCurFuncCodeMPAllocator()) {} - SwitchNode(MapleAllocator *allocator, LabelIdx label) : SwitchNode(allocator, label, nullptr) {} + SwitchNode(MapleAllocator &allocator, LabelIdx label) : SwitchNode(allocator, label, nullptr) {} - SwitchNode(MapleAllocator *allocator, LabelIdx label, BaseNode *opnd) - : StmtNode(OP_switch, 1), switchOpnd(opnd), defaultLabel(label), switchTable(allocator->Adapter()) {} + SwitchNode(MapleAllocator &allocator, LabelIdx label, BaseNode *opnd) + : StmtNode(OP_switch, 1), switchOpnd(opnd), defaultLabel(label), switchTable(allocator.Adapter()) {} - SwitchNode(const MIRModule *mod, LabelIdx label) : SwitchNode(mod->CurFuncCodeMemPoolAllocator(), label) {} + SwitchNode(const MIRModule &mod, LabelIdx label) : SwitchNode(mod.GetCurFuncCodeMPAllocator(), label) {} - SwitchNode(MapleAllocator *allocator, const SwitchNode *node) - : StmtNode(node->GetOpCode(), node->GetPrimType(), node->numOpnds), + SwitchNode(MapleAllocator &allocator, const SwitchNode &node) + : StmtNode(node.GetOpCode(), node.GetPrimType(), node.numOpnds), switchOpnd(nullptr), - defaultLabel(node->GetDefaultLabel()), - switchTable(allocator->Adapter()) {} + defaultLabel(node.GetDefaultLabel()), + switchTable(allocator.Adapter()) {} - SwitchNode(const MIRModule *mod, const SwitchNode *node) : SwitchNode(mod->CurFuncCodeMemPoolAllocator(), node) {} + SwitchNode(const MIRModule &mod, const SwitchNode &node) : SwitchNode(mod.GetCurFuncCodeMPAllocator(), node) {} SwitchNode(SwitchNode &node) = delete; SwitchNode &operator=(const SwitchNode &node) = delete; @@ -1747,7 +1747,7 @@ class SwitchNode : public StmtNode { bool Verify() const; SwitchNode *CloneTree(MapleAllocator &allocator) const { - SwitchNode *nd = allocator.GetMemPool()->New(&allocator, this); + SwitchNode *nd = allocator.GetMemPool()->New(allocator, *this); nd->SetSwitchOpnd(switchOpnd->CloneTree(allocator)); for (size_t i = 0; i < switchTable.size(); i++) { nd->GetSwitchTable().push_back(switchTable[i]); @@ -1807,24 +1807,24 @@ using MCasePair = std::pair; using MCaseVector = MapleVector; class MultiwayNode : public StmtNode { public: - explicit MultiwayNode(MapleAllocator *allocator) - : StmtNode(OP_multiway, 1), multiWayOpnd(nullptr), defaultLabel(0), multiWayTable(allocator->Adapter()) {} + explicit MultiwayNode(MapleAllocator &allocator) + : StmtNode(OP_multiway, 1), multiWayOpnd(nullptr), defaultLabel(0), multiWayTable(allocator.Adapter()) {} - explicit MultiwayNode(const MIRModule *mod) : MultiwayNode(mod->CurFuncCodeMemPoolAllocator()) {} + explicit MultiwayNode(const MIRModule &mod) : MultiwayNode(mod.GetCurFuncCodeMPAllocator()) {} - MultiwayNode(MapleAllocator *allocator, LabelIdx label) - : StmtNode(OP_multiway, 1), multiWayOpnd(nullptr), defaultLabel(label), multiWayTable(allocator->Adapter()) {} + MultiwayNode(MapleAllocator &allocator, LabelIdx label) + : StmtNode(OP_multiway, 1), multiWayOpnd(nullptr), defaultLabel(label), multiWayTable(allocator.Adapter()) {} - MultiwayNode(const MIRModule *mod, LabelIdx label) : MultiwayNode(mod->CurFuncCodeMemPoolAllocator(), label) {} + MultiwayNode(const MIRModule &mod, LabelIdx label) : MultiwayNode(mod.GetCurFuncCodeMPAllocator(), label) {} - MultiwayNode(MapleAllocator *allocator, const MultiwayNode *node) - : StmtNode(node->GetOpCode(), node->GetPrimType(), node->numOpnds), + MultiwayNode(MapleAllocator &allocator, const MultiwayNode &node) + : StmtNode(node.GetOpCode(), node.GetPrimType(), node.numOpnds), multiWayOpnd(nullptr), - defaultLabel(node->defaultLabel), - multiWayTable(allocator->Adapter()) {} + defaultLabel(node.defaultLabel), + multiWayTable(allocator.Adapter()) {} - MultiwayNode(const MIRModule *mod, const MultiwayNode *node) - : MultiwayNode(mod->CurFuncCodeMemPoolAllocator(), node) {} + MultiwayNode(const MIRModule &mod, const MultiwayNode &node) + : MultiwayNode(mod.GetCurFuncCodeMPAllocator(), node) {} MultiwayNode(MultiwayNode &node) = delete; MultiwayNode &operator=(const MultiwayNode &node) = delete; @@ -1833,7 +1833,7 @@ class MultiwayNode : public StmtNode { void Dump(const MIRModule &mod, int32 indent) const; MultiwayNode *CloneTree(MapleAllocator &allocator) const { - MultiwayNode *nd = allocator.GetMemPool()->New(&allocator, this); + MultiwayNode *nd = allocator.GetMemPool()->New(allocator, *this); nd->multiWayOpnd = static_cast(multiWayOpnd->CloneTree(allocator)); for (size_t i = 0; i < multiWayTable.size(); i++) { BaseNode *node = multiWayTable[i].first->CloneTree(allocator); @@ -2076,18 +2076,18 @@ using SmallCasePair = std::pair; using SmallCaseVector = MapleVector; class RangegotoNode : public UnaryStmtNode { public: - explicit RangegotoNode(MapleAllocator *allocator) - : UnaryStmtNode(OP_rangegoto), tagOffset(0), rangegotoTable(allocator->Adapter()) {} + explicit RangegotoNode(MapleAllocator &allocator) + : UnaryStmtNode(OP_rangegoto), tagOffset(0), rangegotoTable(allocator.Adapter()) {} - explicit RangegotoNode(const MIRModule *mod) : RangegotoNode(mod->CurFuncCodeMemPoolAllocator()) {} + explicit RangegotoNode(const MIRModule &mod) : RangegotoNode(mod.GetCurFuncCodeMPAllocator()) {} - RangegotoNode(MapleAllocator *allocator, const RangegotoNode *node) - : UnaryStmtNode(node->GetOpCode(), node->GetPrimType()), - tagOffset(node->tagOffset), - rangegotoTable(allocator->Adapter()) {} + RangegotoNode(MapleAllocator &allocator, const RangegotoNode &node) + : UnaryStmtNode(node.GetOpCode(), node.GetPrimType()), + tagOffset(node.tagOffset), + rangegotoTable(allocator.Adapter()) {} - RangegotoNode(const MIRModule *mod, const RangegotoNode *node) - : RangegotoNode(mod->CurFuncCodeMemPoolAllocator(), node) {} + RangegotoNode(const MIRModule &mod, const RangegotoNode &node) + : RangegotoNode(mod.GetCurFuncCodeMPAllocator(), node) {} RangegotoNode(RangegotoNode &node) = delete; RangegotoNode &operator=(const RangegotoNode &node) = delete; @@ -2096,7 +2096,7 @@ class RangegotoNode : public UnaryStmtNode { void Dump(const MIRModule &mod, int32 indent) const; bool Verify() const; RangegotoNode *CloneTree(MapleAllocator &allocator) const { - RangegotoNode *nd = allocator.GetMemPool()->New(&allocator, this); + RangegotoNode *nd = allocator.GetMemPool()->New(allocator, *this); nd->SetOpnd(Opnd()->CloneTree(allocator)); for (size_t i = 0; i < rangegotoTable.size(); i++) { nd->rangegotoTable.push_back(rangegotoTable[i]); @@ -2602,15 +2602,15 @@ class IassignFPoffNode : public UnaryStmtNode { // used by return, syncenter, syncexit class NaryStmtNode : public StmtNode, public NaryOpnds { public: - NaryStmtNode(MapleAllocator *allocator, Opcode o) : StmtNode(o), NaryOpnds(allocator) {} + NaryStmtNode(MapleAllocator &allocator, Opcode o) : StmtNode(o), NaryOpnds(allocator) {} - NaryStmtNode(const MIRModule *mod, Opcode o) : NaryStmtNode(mod->CurFuncCodeMemPoolAllocator(), o) {} + NaryStmtNode(const MIRModule &mod, Opcode o) : NaryStmtNode(mod.GetCurFuncCodeMPAllocator(), o) {} - NaryStmtNode(MapleAllocator *allocator, const NaryStmtNode *node) - : StmtNode(node->GetOpCode(), node->GetPrimType(), node->numOpnds), NaryOpnds(allocator) {} + NaryStmtNode(MapleAllocator &allocator, const NaryStmtNode &node) + : StmtNode(node.GetOpCode(), node.GetPrimType(), node.numOpnds), NaryOpnds(allocator) {} - NaryStmtNode(const MIRModule *mod, const NaryStmtNode *node) - : NaryStmtNode(mod->CurFuncCodeMemPoolAllocator(), node) {} + NaryStmtNode(const MIRModule &mod, const NaryStmtNode &node) + : NaryStmtNode(mod.GetCurFuncCodeMPAllocator(), node) {} NaryStmtNode(NaryStmtNode &node) = delete; NaryStmtNode &operator=(const NaryStmtNode &node) = delete; @@ -2620,7 +2620,7 @@ class NaryStmtNode : public StmtNode, public NaryOpnds { virtual bool Verify() const; NaryStmtNode *CloneTree(MapleAllocator &allocator) const { - NaryStmtNode *nd = allocator.GetMemPool()->New(&allocator, this); + NaryStmtNode *nd = allocator.GetMemPool()->New(allocator, *this); for (size_t i = 0; i < GetNopndSize(); i++) { nd->GetNopnd().push_back(GetNopndAt(i)->CloneTree(allocator)); } @@ -2657,7 +2657,7 @@ class NaryStmtNode : public StmtNode, public NaryOpnds { class ReturnValuePart { public: - explicit ReturnValuePart(MapleAllocator *allocator) : returnValues(allocator->Adapter()) {} + explicit ReturnValuePart(MapleAllocator &allocator) : returnValues(allocator.Adapter()) {} virtual ~ReturnValuePart() = default; @@ -2672,26 +2672,26 @@ class ReturnValuePart { // customcallassigned class CallNode : public NaryStmtNode { public: - CallNode(MapleAllocator *allocator, Opcode o) - : NaryStmtNode(allocator, o), puIdx(0), tyIdx(0), returnValues(allocator->Adapter()) {} + CallNode(MapleAllocator &allocator, Opcode o) + : NaryStmtNode(allocator, o), puIdx(0), tyIdx(0), returnValues(allocator.Adapter()) {} - CallNode(MapleAllocator *allocator, Opcode o, PUIdx idx) : CallNode(allocator, o, idx, TyIdx()) {} + CallNode(MapleAllocator &allocator, Opcode o, PUIdx idx) : CallNode(allocator, o, idx, TyIdx()) {} - CallNode(MapleAllocator *allocator, Opcode o, PUIdx idx, TyIdx tdx) - : NaryStmtNode(allocator, o), puIdx(idx), tyIdx(tdx), returnValues(allocator->Adapter()) {} + CallNode(MapleAllocator &allocator, Opcode o, PUIdx idx, TyIdx tdx) + : NaryStmtNode(allocator, o), puIdx(idx), tyIdx(tdx), returnValues(allocator.Adapter()) {} - CallNode(const MIRModule *mod, Opcode o) : CallNode(mod->CurFuncCodeMemPoolAllocator(), o) {} + CallNode(const MIRModule &mod, Opcode o) : CallNode(mod.GetCurFuncCodeMPAllocator(), o) {} - CallNode(const MIRModule *mod, Opcode o, PUIdx idx, TyIdx tdx) - : CallNode(mod->CurFuncCodeMemPoolAllocator(), o, idx, tdx) {} + CallNode(const MIRModule &mod, Opcode o, PUIdx idx, TyIdx tdx) + : CallNode(mod.GetCurFuncCodeMPAllocator(), o, idx, tdx) {} - CallNode(MapleAllocator *allocator, const CallNode *node) + CallNode(MapleAllocator &allocator, const CallNode &node) : NaryStmtNode(allocator, node), - puIdx(node->GetPUIdx()), - tyIdx(node->tyIdx), - returnValues(allocator->Adapter()) {} + puIdx(node.GetPUIdx()), + tyIdx(node.tyIdx), + returnValues(allocator.Adapter()) {} - CallNode(const MIRModule *mod, const CallNode *node) : CallNode(mod->CurFuncCodeMemPoolAllocator(), node) {} + CallNode(const MIRModule &mod, const CallNode &node) : CallNode(mod.GetCurFuncCodeMPAllocator(), node) {} CallNode(CallNode &node) = delete; CallNode &operator=(const CallNode &node) = delete; @@ -2701,7 +2701,7 @@ class CallNode : public NaryStmtNode { MIRType *GetCallReturnType(); CallNode *CloneTree(MapleAllocator &allocator) const { - CallNode *nd = allocator.GetMemPool()->New(&allocator, this); + CallNode *nd = allocator.GetMemPool()->New(allocator, *this); for (size_t i = 0; i < GetNopndSize(); i++) { nd->GetNopnd().push_back(GetNopndAt(i)->CloneTree(allocator)); } @@ -2776,24 +2776,24 @@ class CallNode : public NaryStmtNode { class IcallNode : public NaryStmtNode { public: - IcallNode(MapleAllocator *allocator, Opcode o) - : NaryStmtNode(allocator, o), retTyIdx(0), returnValues(allocator->Adapter()) { + IcallNode(MapleAllocator &allocator, Opcode o) + : NaryStmtNode(allocator, o), retTyIdx(0), returnValues(allocator.Adapter()) { SetNumOpnds(kOprandNumUnary); } - IcallNode(MapleAllocator *allocator, Opcode o, TyIdx idx) - : NaryStmtNode(allocator, o), retTyIdx(idx), returnValues(allocator->Adapter()) { + IcallNode(MapleAllocator &allocator, Opcode o, TyIdx idx) + : NaryStmtNode(allocator, o), retTyIdx(idx), returnValues(allocator.Adapter()) { SetNumOpnds(kOprandNumUnary); } - IcallNode(const MIRModule *mod, Opcode o) : IcallNode(mod->CurFuncCodeMemPoolAllocator(), o) {} + IcallNode(const MIRModule &mod, Opcode o) : IcallNode(mod.GetCurFuncCodeMPAllocator(), o) {} - IcallNode(const MIRModule *mod, Opcode o, TyIdx idx) : IcallNode(mod->CurFuncCodeMemPoolAllocator(), o, idx) {} + IcallNode(const MIRModule &mod, Opcode o, TyIdx idx) : IcallNode(mod.GetCurFuncCodeMPAllocator(), o, idx) {} - IcallNode(MapleAllocator *allocator, const IcallNode *node) - : NaryStmtNode(allocator, node), retTyIdx(node->retTyIdx), returnValues(allocator->Adapter()) {} + IcallNode(MapleAllocator &allocator, const IcallNode &node) + : NaryStmtNode(allocator, node), retTyIdx(node.retTyIdx), returnValues(allocator.Adapter()) {} - IcallNode(const MIRModule *mod, const IcallNode *node) : IcallNode(mod->CurFuncCodeMemPoolAllocator(), node) {} + IcallNode(const MIRModule &mod, const IcallNode &node) : IcallNode(mod.GetCurFuncCodeMPAllocator(), node) {} IcallNode(IcallNode &node) = delete; IcallNode &operator=(const IcallNode &node) = delete; @@ -2803,7 +2803,7 @@ class IcallNode : public NaryStmtNode { bool Verify() const; MIRType *GetCallReturnType(); IcallNode *CloneTree(MapleAllocator &allocator) const { - IcallNode *nd = allocator.GetMemPool()->New(&allocator, this); + IcallNode *nd = allocator.GetMemPool()->New(allocator, *this); for (size_t i = 0; i < GetNopndSize(); i++) { nd->GetNopnd().push_back(GetNopndAt(i)->CloneTree(allocator)); } @@ -2856,25 +2856,25 @@ class IcallNode : public NaryStmtNode { // used by intrinsiccall and xintrinsiccall class IntrinsiccallNode : public NaryStmtNode { public: - IntrinsiccallNode(MapleAllocator *allocator, Opcode o) - : NaryStmtNode(allocator, o), intrinsic(INTRN_UNDEFINED), tyIdx(0), returnValues(allocator->Adapter()) {} + IntrinsiccallNode(MapleAllocator &allocator, Opcode o) + : NaryStmtNode(allocator, o), intrinsic(INTRN_UNDEFINED), tyIdx(0), returnValues(allocator.Adapter()) {} - IntrinsiccallNode(MapleAllocator *allocator, Opcode o, MIRIntrinsicID id) - : NaryStmtNode(allocator, o), intrinsic(id), tyIdx(0), returnValues(allocator->Adapter()) {} + IntrinsiccallNode(MapleAllocator &allocator, Opcode o, MIRIntrinsicID id) + : NaryStmtNode(allocator, o), intrinsic(id), tyIdx(0), returnValues(allocator.Adapter()) {} - IntrinsiccallNode(const MIRModule *mod, Opcode o) : IntrinsiccallNode(mod->CurFuncCodeMemPoolAllocator(), o) {} + IntrinsiccallNode(const MIRModule &mod, Opcode o) : IntrinsiccallNode(mod.GetCurFuncCodeMPAllocator(), o) {} - IntrinsiccallNode(const MIRModule *mod, Opcode o, MIRIntrinsicID id) - : IntrinsiccallNode(mod->CurFuncCodeMemPoolAllocator(), o, id) {} + IntrinsiccallNode(const MIRModule &mod, Opcode o, MIRIntrinsicID id) + : IntrinsiccallNode(mod.GetCurFuncCodeMPAllocator(), o, id) {} - IntrinsiccallNode(MapleAllocator *allocator, const IntrinsiccallNode *node) + IntrinsiccallNode(MapleAllocator &allocator, const IntrinsiccallNode &node) : NaryStmtNode(allocator, node), - intrinsic(node->GetIntrinsic()), - tyIdx(node->tyIdx), - returnValues(allocator->Adapter()) {} + intrinsic(node.GetIntrinsic()), + tyIdx(node.tyIdx), + returnValues(allocator.Adapter()) {} - IntrinsiccallNode(const MIRModule *mod, const IntrinsiccallNode *node) - : IntrinsiccallNode(mod->CurFuncCodeMemPoolAllocator(), node) {} + IntrinsiccallNode(const MIRModule &mod, const IntrinsiccallNode &node) + : IntrinsiccallNode(mod.GetCurFuncCodeMPAllocator(), node) {} IntrinsiccallNode(IntrinsiccallNode &node) = delete; IntrinsiccallNode &operator=(const IntrinsiccallNode &node) = delete; @@ -2885,7 +2885,7 @@ class IntrinsiccallNode : public NaryStmtNode { MIRType *GetCallReturnType(); IntrinsiccallNode *CloneTree(MapleAllocator &allocator) const { - IntrinsiccallNode *nd = allocator.GetMemPool()->New(&allocator, this); + IntrinsiccallNode *nd = allocator.GetMemPool()->New(allocator, *this); for (size_t i = 0; i < GetNopndSize(); i++) { nd->GetNopnd().push_back(GetNopndAt(i)->CloneTree(allocator)); } @@ -2954,16 +2954,16 @@ class IntrinsiccallNode : public NaryStmtNode { // superclasscallinstantassigned and interfacecallinstantassigned class CallinstantNode : public CallNode { public: - CallinstantNode(MapleAllocator *allocator, Opcode o, TyIdx tIdx) : CallNode(allocator, o), instVecTyIdx(tIdx) {} + CallinstantNode(MapleAllocator &allocator, Opcode o, TyIdx tIdx) : CallNode(allocator, o), instVecTyIdx(tIdx) {} - CallinstantNode(const MIRModule *mod, Opcode o, TyIdx tIdx) - : CallinstantNode(mod->CurFuncCodeMemPoolAllocator(), o, tIdx) {} + CallinstantNode(const MIRModule &mod, Opcode o, TyIdx tIdx) + : CallinstantNode(mod.GetCurFuncCodeMPAllocator(), o, tIdx) {} - CallinstantNode(MapleAllocator *allocator, const CallinstantNode *node) - : CallNode(allocator, node), instVecTyIdx(node->instVecTyIdx) {} + CallinstantNode(MapleAllocator &allocator, const CallinstantNode &node) + : CallNode(allocator, node), instVecTyIdx(node.instVecTyIdx) {} - CallinstantNode(const MIRModule *mod, const CallinstantNode *node) - : CallinstantNode(mod->CurFuncCodeMemPoolAllocator(), node) {} + CallinstantNode(const MIRModule &mod, const CallinstantNode &node) + : CallinstantNode(mod.GetCurFuncCodeMPAllocator(), node) {} CallinstantNode(CallinstantNode &node) = delete; CallinstantNode &operator=(const CallinstantNode &node) = delete; @@ -2975,7 +2975,7 @@ class CallinstantNode : public CallNode { } CallinstantNode *CloneTree(MapleAllocator &allocator) const { - CallinstantNode *nd = allocator.GetMemPool()->New(&allocator, this); + CallinstantNode *nd = allocator.GetMemPool()->New(allocator, *this); for (size_t i = 0; i < GetNopndSize(); i++) { nd->GetNopnd().push_back(GetNopndAt(i)->CloneTree(allocator)); } @@ -3039,20 +3039,20 @@ class LabelNode : public StmtNode { class CommentNode : public StmtNode { public: - explicit CommentNode(MapleAllocator *allocator) : StmtNode(OP_comment), comment(allocator->GetMemPool()) {} + explicit CommentNode(MapleAllocator &allocator) : StmtNode(OP_comment), comment(allocator.GetMemPool()) {} - explicit CommentNode(const MIRModule *mod) : CommentNode(mod->CurFuncCodeMemPoolAllocator()) {} + explicit CommentNode(const MIRModule &mod) : CommentNode(mod.GetCurFuncCodeMPAllocator()) {} - CommentNode(MapleAllocator *allocator, const std::string &cmt) - : StmtNode(OP_comment), comment(cmt, allocator->GetMemPool()) {} + CommentNode(MapleAllocator &allocator, const std::string &cmt) + : StmtNode(OP_comment), comment(cmt, allocator.GetMemPool()) {} - CommentNode(const MIRModule *mod, const std::string &cmt) : CommentNode(mod->CurFuncCodeMemPoolAllocator(), cmt) {} + CommentNode(const MIRModule &mod, const std::string &cmt) : CommentNode(mod.GetCurFuncCodeMPAllocator(), cmt) {} - CommentNode(MapleAllocator *allocator, const CommentNode *node) - : StmtNode(node->GetOpCode(), node->GetPrimType(), node->numOpnds), - comment(node->comment, allocator->GetMemPool()) {} + CommentNode(MapleAllocator &allocator, const CommentNode &node) + : StmtNode(node.GetOpCode(), node.GetPrimType(), node.numOpnds), + comment(node.comment, allocator.GetMemPool()) {} - CommentNode(const MIRModule *mod, const CommentNode *node) : CommentNode(mod->CurFuncCodeMemPoolAllocator(), node) {} + CommentNode(const MIRModule &mod, const CommentNode &node) : CommentNode(mod.GetCurFuncCodeMPAllocator(), node) {} CommentNode(CommentNode &node) = delete; CommentNode &operator=(const CommentNode &node) = delete; @@ -3061,7 +3061,7 @@ class CommentNode : public StmtNode { void Dump(const MIRModule &mod, int32 indent) const; CommentNode *CloneTree(MapleAllocator &allocator) const { - CommentNode *c = allocator.GetMemPool()->New(&allocator, this); + CommentNode *c = allocator.GetMemPool()->New(allocator, *this); return c; } diff --git a/src/maple_ir/include/mir_parser.h b/src/maple_ir/include/mir_parser.h index 8e1fede512c35306c6d8f0c01973fbbb15f45290..a06b751fcd9e4bdb4952848360ca5b0ae5b6e341 100644 --- a/src/maple_ir/include/mir_parser.h +++ b/src/maple_ir/include/mir_parser.h @@ -28,7 +28,7 @@ using BlockNodePtr = BlockNode*; class MIRParser { public: explicit MIRParser(MIRModule &md) - : lexer(&md), + : lexer(md), mod(md), options(kKeepFirst), definedLabels(mod.GetMPAllocator().Adapter()), @@ -48,8 +48,8 @@ class MIRParser { ~MIRParser() {} MIRPreg *CreateMirPreg(uint32 pregNo) const; - PregIdx LookupOrCreatePregIdx(uint32 pregNo, bool isref, MIRFunction *curfunc); - void ResetMaxPregNo(MIRFunction*); + PregIdx LookupOrCreatePregIdx(uint32 pregNo, bool isref, MIRFunction &curfunc); + void ResetMaxPregNo(MIRFunction&); MIRFunction *CreateDummyFunction(); void ResetCurrentFunction() { mod.SetCurFunction(dummyFunction); @@ -73,7 +73,7 @@ class MIRParser { bool ParseDeclaredSt(StIdx&); bool ParseDeclaredFunc(PUIdx&); bool ParseTypeAttrs(TypeAttrs&); - bool ParseVarTypeAttrs(MIRSymbol *st); + bool ParseVarTypeAttrs(MIRSymbol &st); bool CheckAlignTk(); bool ParseAlignAttrs(TypeAttrs &tA); bool ParseFieldAttrs(FieldAttrs &tA); @@ -83,9 +83,9 @@ class MIRParser { bool ParseFarrayType(TyIdx &tyIdx); bool ParseArrayType(TyIdx &tyIdx); bool ParseBitFieldType(TyIdx &tyIdx); - bool ParsePragmaElement(MIRPragmaElement *elem); - bool ParsePragmaElementForArray(MIRPragmaElement *elem); - bool ParsePragmaElementForAnnotation(MIRPragmaElement *elem); + bool ParsePragmaElement(MIRPragmaElement &lem); + bool ParsePragmaElementForArray(MIRPragmaElement &elem); + bool ParsePragmaElementForAnnotation(MIRPragmaElement &elem); bool ParsePragma(MIRStructType &type); bool ParseFields(MIRStructType &type); bool ParseStructType(TyIdx &tyIdx); @@ -103,12 +103,12 @@ class MIRParser { bool ParsePseudoReg(PrimType pty, PregIdx &pregIdx); bool ParseRefPseudoReg(PregIdx&); bool ParseStmtBlock(BlockNodePtr &blk); - bool ParsePrototype(MIRFunction *fn, MIRSymbol *funcSt, TyIdx &funcTyIdx); + bool ParsePrototype(MIRFunction &fn, MIRSymbol &funcSt, TyIdx &funcTyIdx); bool ParseFunction(uint32 fileIdx = 0); - bool ParseStorageClass(MIRSymbol *st) const; - bool ParseDeclareVar(MIRSymbol*); - bool ParseDeclareReg(MIRSymbol*, MIRFunction*); - bool ParsePrototypeRemaining(MIRFunction*, std::vector &, std::vector&, bool&); + bool ParseStorageClass(MIRSymbol &st) const; + bool ParseDeclareVar(MIRSymbol&); + bool ParseDeclareReg(MIRSymbol&, MIRFunction&); + bool ParsePrototypeRemaining(MIRFunction&, std::vector &, std::vector&, bool&); // Stmt Parser bool ParseStmtDassign(StmtNodePtr &stmt); @@ -193,7 +193,7 @@ class MIRParser { bool ParseExprIntrinsicop(BaseNodePtr &expr); bool ParseTypedef(); - bool ParseJavaClassInterface(MIRSymbol*, bool); + bool ParseJavaClassInterface(MIRSymbol&, bool); bool ParseIntrinsicId(IntrinsicopNode*); void Error(const std::string&); void Warning(const std::string&); @@ -205,9 +205,9 @@ class MIRParser { bool ParseFuncInfo(void); void PrepareParsingMIR(); bool ParseMIR(uint32 fileIdx = 0, uint32 option = 0, bool isIpa = false, bool isComb = false); - bool ParseMIR(std::ifstream*); // the main entry point - bool ParseMPLT(std::ifstream*, const std::string&); - bool ParseMPLTStandalone(std::ifstream *mpltfile, const std::string &importfilename); + bool ParseMIR(std::ifstream&); // the main entry point + bool ParseMPLT(std::ifstream&, const std::string&); + bool ParseMPLTStandalone(std::ifstream &mpltfile, const std::string &importfilename); bool ParseTypeFromString(const std::string&, TyIdx&); void EmitError(const std::string&); void EmitWarning(const std::string&); diff --git a/src/maple_ir/include/mir_type.h b/src/maple_ir/include/mir_type.h index fed05a6ae5175baf44447275b0cbc36f8fb7dcd8..1b80dc89b3061a3947260cdb028e3225b0e7222f 100644 --- a/src/maple_ir/include/mir_type.h +++ b/src/maple_ir/include/mir_type.h @@ -476,6 +476,43 @@ class MIRType { return false; } + bool IsMIRPtrType() const { + return (typeKind == kTypePointer); + } + + bool IsMIRStructType() const { + return ((typeKind == kTypeStruct) || (typeKind == kTypeStructIncomplete)); + } + + bool IsMIRClassType() const { + return ((typeKind == kTypeClass) || (typeKind == kTypeClassIncomplete)); + } + + bool IsMIRInterfaceType() const { + return ((typeKind == kTypeInterface) || (typeKind == kTypeInterfaceIncomplete)); + } + + bool IsInstanceOfMIRStructType() const { + return (IsMIRStructType() || IsMIRClassType() || IsMIRInterfaceType()); + } + + bool IsMIRJarrayType() const { + return (typeKind == kTypeJArray); + } + + bool IsMIRFuncType() const { + return (typeKind == kTypeFunction); + } + + bool IsScalarType() const { + return (typeKind == kTypeScalar); + } + + bool IsIncomplete() const { + return ((typeKind == kTypeStructIncomplete) || (typeKind == kTypeClassIncomplete) || + (typeKind == kTypeInterfaceIncomplete)); + } + virtual bool ValidateClassOrInterface(const char *className, bool noWarning); const std::string &GetName(void) const; virtual std::string GetMplTypeName() const; diff --git a/src/maple_ir/src/bin_mpl_import.cpp b/src/maple_ir/src/bin_mpl_import.cpp index 1bc76bea45c0a0937a641438f093f66e97aa3226..49d21352a76b4fcbd520ec26cdcc8a07fe050865 100644 --- a/src/maple_ir/src/bin_mpl_import.cpp +++ b/src/maple_ir/src/bin_mpl_import.cpp @@ -283,7 +283,7 @@ void BinaryMplImport::ImportMethodPair(MethodPair &memPool) { } else { funcSt = GlobalTables::GetGsymTable().CreateSymbol(kScopeGlobal); funcSt->SetNameStrIdx(stridx); - GlobalTables::GetGsymTable().AddToStringSymbolMap(funcSt); + GlobalTables::GetGsymTable().AddToStringSymbolMap(*funcSt); funcSt->SetStorageClass(kScText); funcSt->SetSKind(kStFunc); funcSt->SetTyIdx(funcTyidx); diff --git a/src/maple_ir/src/global_tables.cpp b/src/maple_ir/src/global_tables.cpp index ab413206d046d63ed62b7bde380216630d9e258b..24c26ce620135dbf4a8cf98cf6a2ad8744ccff8a 100644 --- a/src/maple_ir/src/global_tables.cpp +++ b/src/maple_ir/src/global_tables.cpp @@ -38,7 +38,7 @@ TypeTable::TypeTable() { PutToHashTable(type); } if (voidPtrType == nullptr) { - voidPtrType = GetOrCreatePointerType(GetVoid(), PTY_ptr); + voidPtrType = GetOrCreatePointerType(*GetVoid(), PTY_ptr); } } @@ -54,9 +54,8 @@ void TypeTable::PutToHashTable(MIRType *mirtype) { } // create an entry in type_table_ for the type node -inline MIRType *TypeTable::CreateType(MIRType *oldType) { - ASSERT(oldType != nullptr, "oldType is null"); - MIRType *newType = oldType->CopyMIRTypeNode(); +inline MIRType *TypeTable::CreateType(MIRType &oldType) { + MIRType *newType = oldType.CopyMIRTypeNode(); newType->SetTypeIndex(TyIdx(typeTable.size())); typeTable.push_back(newType); return newType; @@ -68,7 +67,7 @@ TyIdx TypeTable::GetOrCreateMIRType(MIRType *ptype) { return (*it)->GetTypeIndex(); } - MIRType *newTy = CreateType(ptype); + MIRType *newTy = CreateType(*ptype); PutToHashTable(newTy); return newTy->GetTypeIndex(); } @@ -82,56 +81,55 @@ MIRType *TypeTable::GetOrCreatePointerType(TyIdx pointedTyIdx, PrimType pty) { return typeTable.at(tyidx.GetIdx()); } -MIRType *TypeTable::GetOrCreatePointerType(const MIRType *pointTo, PrimType pty) { - if (pointTo->GetPrimType() == PTY_constStr) { +MIRType *TypeTable::GetOrCreatePointerType(const MIRType &pointTo, PrimType pty) { + if (pointTo.GetPrimType() == PTY_constStr) { pty = PTY_ptr; } - return GetOrCreatePointerType(pointTo->GetTypeIndex(), pty); + return GetOrCreatePointerType(pointTo.GetTypeIndex(), pty); } -MIRType *TypeTable::GetPointedTypeIfApplicable(MIRType *type) const { - if (type->GetKind() != kTypePointer) { - return type; +MIRType *TypeTable::GetPointedTypeIfApplicable(MIRType &type) const { + if (type.GetKind() != kTypePointer) { + return &type; } - MIRPtrType *ptype = static_cast(type); - return GetTypeFromTyIdx(ptype->GetPointedTyIdx()); + MIRPtrType &ptype = static_cast(type); + return GetTypeFromTyIdx(ptype.GetPointedTyIdx()); } -MIRArrayType *TypeTable::GetOrCreateArrayType(const MIRType *elem, uint8 dim, const uint32 *sizeArray) { +MIRArrayType *TypeTable::GetOrCreateArrayType(const MIRType &elem, uint8 dim, const uint32 *sizeArray) { std::vector sizeVector; for (uint8 i = 0; i < dim; i++) { sizeVector.push_back(sizeArray != nullptr ? sizeArray[i] : 0); } - MIRArrayType type(elem->GetTypeIndex(), sizeVector); + MIRArrayType type(elem.GetTypeIndex(), sizeVector); TyIdx tyidx = GetOrCreateMIRType(&type); return static_cast(typeTable[tyidx.GetIdx()]); } // For one dimension array -MIRArrayType *TypeTable::GetOrCreateArrayType(const MIRType *elem, uint32 size) { +MIRArrayType *TypeTable::GetOrCreateArrayType(const MIRType &elem, uint32 size) { return GetOrCreateArrayType(elem, 1, &size); } -MIRType *TypeTable::GetOrCreateFarrayType(const MIRType *elem) { +MIRType *TypeTable::GetOrCreateFarrayType(const MIRType &elem) { MIRFarrayType type; - type.SetElemtTyIdx(elem->GetTypeIndex()); + type.SetElemtTyIdx(elem.GetTypeIndex()); TyIdx tyidx = GetOrCreateMIRType(&type); ASSERT(tyidx.GetIdx() < typeTable.size(), "index out of range in TypeTable::GetOrCreateFarrayType"); return typeTable.at(tyidx.GetIdx()); } -MIRType *TypeTable::GetOrCreateJarrayType(const MIRType *elem) { +MIRType *TypeTable::GetOrCreateJarrayType(const MIRType &elem) { MIRJarrayType type; - type.SetElemtTyIdx(elem->GetTypeIndex()); + type.SetElemtTyIdx(elem.GetTypeIndex()); TyIdx tyidx = GetOrCreateMIRType(&type); ASSERT(tyidx.GetIdx() < typeTable.size(), "index out of range in TypeTable::GetOrCreateJarrayType"); return typeTable.at(tyidx.GetIdx()); } -MIRType *TypeTable::GetOrCreateFunctionType(MIRModule *module, TyIdx retTyidx, const std::vector &vecType, +MIRType *TypeTable::GetOrCreateFunctionType(MIRModule &module, TyIdx retTyidx, const std::vector &vecType, const std::vector &vecAttrs, bool isVarg, bool isSimpCreate) { - ASSERT(module != nullptr, "module is null"); - MIRFuncType *funcType = module->GetMemPool()->New(retTyidx, vecType, vecAttrs); + MIRFuncType *funcType = module.GetMemPool()->New(retTyidx, vecType, vecAttrs); funcType->SetVarArgs(isVarg); if (isSimpCreate) { return funcType; @@ -141,31 +139,28 @@ MIRType *TypeTable::GetOrCreateFunctionType(MIRModule *module, TyIdx retTyidx, c return typeTable.at(tyidx.GetIdx()); } -MIRType *TypeTable::GetOrCreateStructOrUnion(const char *name, const FieldVector &fields, const FieldVector &prntFields, - MIRModule *module, bool forStruct) { - ASSERT(module != nullptr, "module is null"); +MIRType *TypeTable::GetOrCreateStructOrUnion(const std::string &name, const FieldVector &fields, + const FieldVector &prntFields, MIRModule &module, bool forStruct) { GStrIdx stridx = GlobalTables::GetStrTable().GetOrCreateStrIdxFromName(name); MIRStructType type(forStruct ? kTypeStruct : kTypeUnion, stridx); type.GetFields() = fields; type.GetParentFields() = prntFields; TyIdx tyidx = GetOrCreateMIRType(&type); // Global? - module->GetTypeNameTab()->SetGStrIdxToTyIdx(stridx, tyidx); - module->GetTypeDefOrder().push_back(stridx); + module.GetTypeNameTab()->SetGStrIdxToTyIdx(stridx, tyidx); + module.GetTypeDefOrder().push_back(stridx); ASSERT(tyidx.GetIdx() < typeTable.size(), "index out of range in TypeTable::GetOrCreateStructOrUnion"); return typeTable.at(tyidx.GetIdx()); } -void TypeTable::PushIntoFieldVector(FieldVector *fields, const char *name, MIRType *type) { - ASSERT(fields != nullptr, "fields is null"); +void TypeTable::PushIntoFieldVector(FieldVector &fields, const std::string &name, MIRType &type) { GStrIdx stridx = GlobalTables::GetStrTable().GetOrCreateStrIdxFromName(name); - fields->push_back(FieldPair(stridx, TyIdxFieldAttrPair(type->GetTypeIndex(), FieldAttrs()))); + fields.push_back(FieldPair(stridx, TyIdxFieldAttrPair(type.GetTypeIndex(), FieldAttrs()))); } -MIRType *TypeTable::GetOrCreateClassOrInterface(const char *name, MIRModule *module, bool forClass) { - ASSERT(module != nullptr, "module is null"); +MIRType *TypeTable::GetOrCreateClassOrInterface(const std::string &name, MIRModule &module, bool forClass) { GStrIdx stridx = GlobalTables::GetStrTable().GetOrCreateStrIdxFromName(name); - TyIdx tyidx = module->GetTypeNameTab()->GetTyIdxFromGStrIdx(stridx); + TyIdx tyidx = module.GetTypeNameTab()->GetTyIdxFromGStrIdx(stridx); if (!tyidx.GetIdx()) { if (forClass) { MIRClassType type(kTypeClassIncomplete, stridx); // for class type @@ -174,8 +169,8 @@ MIRType *TypeTable::GetOrCreateClassOrInterface(const char *name, MIRModule *mod MIRInterfaceType type(kTypeInterfaceIncomplete, stridx); // for interface type tyidx = GetOrCreateMIRType(&type); } - module->GetTypeDefOrder().push_back(stridx); - module->GetTypeNameTab()->SetGStrIdxToTyIdx(stridx, tyidx); + module.GetTypeDefOrder().push_back(stridx); + module.GetTypeNameTab()->SetGStrIdxToTyIdx(stridx, tyidx); if (typeTable[tyidx.GetIdx()]->GetNameStrIdx() == 0) { typeTable[tyidx.GetIdx()]->SetNameStrIdx(stridx); } @@ -184,13 +179,11 @@ MIRType *TypeTable::GetOrCreateClassOrInterface(const char *name, MIRModule *mod return typeTable.at(tyidx.GetIdx()); } -void TypeTable::AddFieldToStructType(MIRStructType *structType, const char *fieldName, MIRType *fieldType) { - if (structType != nullptr && fieldType != nullptr) { - GStrIdx strIdx = GlobalTables::GetStrTable().GetOrCreateStrIdxFromName(fieldName); - FieldAttrs fieldAttrs; - fieldAttrs.SetAttr(FLDATTR_final); // Mark compiler-generated struct fields as final to improve AliasAnalysis - structType->GetFields().push_back(FieldPair(strIdx, TyIdxFieldAttrPair(fieldType->GetTypeIndex(), fieldAttrs))); - } +void TypeTable::AddFieldToStructType(MIRStructType &structType, const std::string &fieldName, MIRType &fieldType) { + GStrIdx strIdx = GlobalTables::GetStrTable().GetOrCreateStrIdxFromName(fieldName); + FieldAttrs fieldAttrs; + fieldAttrs.SetAttr(FLDATTR_final); // Mark compiler-generated struct fields as final to improve AliasAnalysis + structType.GetFields().push_back(FieldPair(strIdx, TyIdxFieldAttrPair(fieldType.GetTypeIndex(), fieldAttrs))); } void FPConstTable::PostInit() { @@ -284,17 +277,17 @@ MIRSymbol *GSymbolTable::CreateSymbol(uint8 scopeID) { return st; } -bool GSymbolTable::AddToStringSymbolMap(const MIRSymbol *st) { - GStrIdx strIdx = st->GetNameStrIdx(); +bool GSymbolTable::AddToStringSymbolMap(const MIRSymbol &st) { + GStrIdx strIdx = st.GetNameStrIdx(); if (strIdxToStIdxMap[strIdx].FullIdx() != 0) { return false; } - strIdxToStIdxMap[strIdx] = st->GetStIdx(); + strIdxToStIdxMap[strIdx] = st.GetStIdx(); return true; } -bool GSymbolTable::RemoveFromStringSymbolMap(const MIRSymbol *st) { - auto it = strIdxToStIdxMap.find(st->GetNameStrIdx()); +bool GSymbolTable::RemoveFromStringSymbolMap(const MIRSymbol &st) { + auto it = strIdxToStIdxMap.find(st.GetNameStrIdx()); if (it != strIdxToStIdxMap.end()) { strIdxToStIdxMap.erase(it); return true; diff --git a/src/maple_ir/src/intrinsics.cpp b/src/maple_ir/src/intrinsics.cpp index f53e163a9c894f533b1daba42d8fb6cf26ed370e..0388bdde445bd6373b6cfae042094cbf1ebebf77 100644 --- a/src/maple_ir/src/intrinsics.cpp +++ b/src/maple_ir/src/intrinsics.cpp @@ -45,15 +45,15 @@ MIRType *IntrinDesc::GetOrCreateJSValueType() { payloadFields.push_back( FieldPair(ptr, TyIdxFieldAttrPair(GlobalTables::GetTypeTable().GetVoidPtr()->GetTypeIndex(), FieldAttrs()))); FieldVector parentFields; - MIRType *payloadType = - GlobalTables::GetTypeTable().GetOrCreateUnionType("payload_type", payloadFields, parentFields, mirModule); + MIRType *payloadType = GlobalTables::GetTypeTable().GetOrCreateUnionType("payload_type", payloadFields, + parentFields, *mirModule); FieldVector sFields; GStrIdx payload = jsBuilder->GetOrCreateStringIndex("payload"); GStrIdx tag = jsBuilder->GetOrCreateStringIndex("tag"); sFields.push_back(FieldPair(payload, TyIdxFieldAttrPair(payloadType->GetTypeIndex(), FieldAttrs()))); sFields.push_back( FieldPair(tag, TyIdxFieldAttrPair(GlobalTables::GetTypeTable().GetUInt32()->GetTypeIndex(), FieldAttrs()))); - MIRType *sType = GlobalTables::GetTypeTable().GetOrCreateStructType("s_type", sFields, parentFields, mirModule); + MIRType *sType = GlobalTables::GetTypeTable().GetOrCreateStructType("s_type", sFields, parentFields, *mirModule); CHECK_FATAL(sType != nullptr, "can't get struct type, check it!"); FieldVector jsValLayoutFields; GStrIdx asBits = jsBuilder->GetOrCreateStringIndex("asBits"); @@ -67,8 +67,9 @@ MIRType *IntrinDesc::GetOrCreateJSValueType() { FieldPair(asDouble, TyIdxFieldAttrPair(GlobalTables::GetTypeTable().GetDouble()->GetTypeIndex(), FieldAttrs()))); jsValLayoutFields.push_back( FieldPair(asPtr, TyIdxFieldAttrPair(GlobalTables::GetTypeTable().GetVoidPtr()->GetTypeIndex(), FieldAttrs()))); - MIRType *jsValLayoutType = GlobalTables::GetTypeTable().GetOrCreateUnionType("jsval_layout_type", jsValLayoutFields, - parentFields, mirModule); + MIRType *jsValLayoutType = GlobalTables::GetTypeTable().GetOrCreateUnionType("jsval_layout_type", + jsValLayoutFields, + parentFields, *mirModule); return jsValLayoutType; } diff --git a/src/maple_ir/src/lexer.cpp b/src/maple_ir/src/lexer.cpp index 8ec70ebcc5ffaee661e8f4b8eb2fc767d01b0349..ed63db21cbb5778253c955cbea7254babc359de9 100644 --- a/src/maple_ir/src/lexer.cpp +++ b/src/maple_ir/src/lexer.cpp @@ -61,12 +61,12 @@ int MIRLexer::ReadALine() { return currentLineSize; } -MIRLexer::MIRLexer(MIRModule *mod) +MIRLexer::MIRLexer(MIRModule &mod) : module(mod), theIntVal(0), theFloatVal(0.0f), theDoubleVal(0), - seenComments(mod->GetMPAllocator().Adapter()), + seenComments(mod.GetMPAllocator().Adapter()), airFile(nullptr), lineBufSize(0), currentLineSize(0), @@ -74,7 +74,7 @@ MIRLexer::MIRLexer(MIRModule *mod) lineNum(0), kind(kTkInvalid), name(""), - keywordMap(mod->GetMPAllocator().Adapter()) { + keywordMap(mod.GetMPAllocator().Adapter()) { // initialize keywordMap keywordMap.clear(); #define KEYWORD(STR) \ @@ -87,10 +87,10 @@ MIRLexer::MIRLexer(MIRModule *mod) #undef KEYWORD } -void MIRLexer::PrepareForFile(const char *filename) { +void MIRLexer::PrepareForFile(const std::string &filename) { // open MIR file airFileInternal.open(filename); - CHECK_FATAL(airFileInternal.is_open(), "cannot open MIR file %s\n", filename); + CHECK_FATAL(airFileInternal.is_open(), "cannot open MIR file %s\n", &filename); airFile = &airFileInternal; // try to read the first line diff --git a/src/maple_ir/src/mir_builder.cpp b/src/maple_ir/src/mir_builder.cpp index 8f77636fa989207e1056ec0e5125a4fa1bb37138..0301679f6b9d3e7c6bdcbecf747667559e563c29 100644 --- a/src/maple_ir/src/mir_builder.cpp +++ b/src/maple_ir/src/mir_builder.cpp @@ -304,7 +304,7 @@ MIRSymbol *MIRBuilder::GetOrCreateGlobalDecl(const std::string &str, const TyIdx MIRSymbol *st = GlobalTables::GetGsymTable().CreateSymbol(kScopeGlobal); st->SetNameStrIdx(strIdx); st->SetTyIdx(tyIdx); - (void)GlobalTables::GetGsymTable().AddToStringSymbolMap(st); + (void)GlobalTables::GetGsymTable().AddToStringSymbolMap(*st); return st; } @@ -405,7 +405,7 @@ MIRSymbol *MIRBuilder::CreateGlobalDecl(const std::string &str, const MIRType *t MIRSymbol *st = GlobalTables::GetGsymTable().CreateSymbol(kScopeGlobal); st->SetNameStrIdx(strIdx); st->SetTyIdx(type->GetTypeIndex()); - (void)GlobalTables::GetGsymTable().AddToStringSymbolMap(st); + (void)GlobalTables::GetGsymTable().AddToStringSymbolMap(*st); st->SetStorageClass(sc); st->SetSKind(kStVar); return st; @@ -598,7 +598,7 @@ MIRSymbol *MIRBuilder::CreateSymbol(TyIdx tyIdx, GStrIdx strIdx, MIRSymKind mCla if (func) { (void)func->GetSymTab()->AddToStringSymbolMap(st); } else { - (void)GlobalTables::GetGsymTable().AddToStringSymbolMap(st); + (void)GlobalTables::GetGsymTable().AddToStringSymbolMap(*st); } return st; } @@ -620,7 +620,7 @@ MIRFunction *MIRBuilder::CreateFunction(const std::string &name, const MIRType * CHECK_FATAL(funcSymbol != nullptr, "Failed to create MIRSymbol"); GStrIdx strIdx = GetOrCreateStringIndex(name.c_str()); funcSymbol->SetNameStrIdx(strIdx); - if (!GlobalTables::GetGsymTable().AddToStringSymbolMap(funcSymbol)) { + if (!GlobalTables::GetGsymTable().AddToStringSymbolMap(*funcSymbol)) { return nullptr; } funcSymbol->SetStorageClass(kScText); @@ -643,10 +643,8 @@ MIRFunction *MIRBuilder::CreateFunction(const std::string &name, const MIRType * funcVecType.push_back(ty->GetTypeIndex()); funcVecAttrs.push_back(TypeAttrs()); } - funcSymbol->SetTyIdx( - GlobalTables::GetTypeTable() - .GetOrCreateFunctionType(mirModule, returnType->GetTypeIndex(), funcVecType, funcVecAttrs, isVarg) - ->GetTypeIndex()); + funcSymbol->SetTyIdx(GlobalTables::GetTypeTable().GetOrCreateFunctionType( + *mirModule, returnType->GetTypeIndex(), funcVecType, funcVecAttrs, isVarg)->GetTypeIndex()); MIRFuncType *funcType = dynamic_cast(funcSymbol->GetType()); fn->SetMIRFuncType(funcType); funcSymbol->SetFunction(fn); @@ -801,9 +799,9 @@ CompareNode *MIRBuilder::CreateExprCompare(Opcode opcode, const MIRType *type, c } ArrayNode *MIRBuilder::CreateExprArray(const MIRType *arrayType) { - MIRType *addrType = GlobalTables::GetTypeTable().GetOrCreatePointerType(arrayType); + MIRType *addrType = GlobalTables::GetTypeTable().GetOrCreatePointerType(*arrayType); ASSERT(addrType != nullptr, "addrType is null"); - ArrayNode *arrayNode = GetCurrentFuncCodeMp()->New(GetCurrentFuncCodeMpAllocator(), + ArrayNode *arrayNode = GetCurrentFuncCodeMp()->New(*GetCurrentFuncCodeMpAllocator(), addrType->GetPrimType(), addrType->GetTypeIndex()); arrayNode->SetNumOpnds(0); return arrayNode; @@ -826,7 +824,7 @@ ArrayNode *MIRBuilder::CreateExprArray(const MIRType *arrayType, BaseNode *op1, IntrinsicopNode *MIRBuilder::CreateExprIntrinsicop(MIRIntrinsicID idx, Opcode opCode, const MIRType *type, const MapleVector &ops) { IntrinsicopNode *expr = - GetCurrentFuncCodeMp()->New(GetCurrentFuncCodeMpAllocator(), opCode, type->GetPrimType()); + GetCurrentFuncCodeMp()->New(*GetCurrentFuncCodeMpAllocator(), opCode, type->GetPrimType()); expr->SetIntrinsic(idx); expr->SetNOpnd(ops); expr->SetNumOpnds(ops.size()); @@ -861,7 +859,7 @@ IassignFPoffNode *MIRBuilder::CreateStmtIassignFPoff(PrimType pty, int32 offset, } CallNode *MIRBuilder::CreateStmtCall(PUIdx puIdx, const MapleVector &args, Opcode opCode) { - CallNode *stmt = GetCurrentFuncCodeMp()->New(GetCurrentFuncCodeMpAllocator(), opCode, puIdx, TyIdx()); + CallNode *stmt = GetCurrentFuncCodeMp()->New(*GetCurrentFuncCodeMpAllocator(), opCode, puIdx, TyIdx()); stmt->SetNOpnd(args); stmt->SetNumOpnds(args.size()); return stmt; @@ -877,7 +875,7 @@ CallNode *MIRBuilder::CreateStmtCall(const std::string &callee, const MapleVecto } IcallNode *MIRBuilder::CreateStmtIcall(const MapleVector &args) { - IcallNode *stmt = GetCurrentFuncCodeMp()->New(GetCurrentFuncCodeMpAllocator(), OP_icall); + IcallNode *stmt = GetCurrentFuncCodeMp()->New(*GetCurrentFuncCodeMpAllocator(), OP_icall); ASSERT(stmt != nullptr, "stmt is null"); stmt->SetOpnds(args); return stmt; @@ -886,7 +884,7 @@ IcallNode *MIRBuilder::CreateStmtIcall(const MapleVector &args) { IntrinsiccallNode *MIRBuilder::CreateStmtIntrinsicCall(MIRIntrinsicID idx, const MapleVector &arguments, TyIdx tyIdx) { IntrinsiccallNode *stmt = GetCurrentFuncCodeMp()->New( - GetCurrentFuncCodeMpAllocator(), tyIdx == 0 ? OP_intrinsiccall : OP_intrinsiccallwithtype, idx); + *GetCurrentFuncCodeMpAllocator(), tyIdx == 0 ? OP_intrinsiccall : OP_intrinsiccallwithtype, idx); stmt->SetTyIdx(tyIdx); stmt->SetOpnds(arguments); return stmt; @@ -894,14 +892,14 @@ IntrinsiccallNode *MIRBuilder::CreateStmtIntrinsicCall(MIRIntrinsicID idx, const IntrinsiccallNode *MIRBuilder::CreateStmtXintrinsicCall(MIRIntrinsicID idx, const MapleVector &arguments) { IntrinsiccallNode *stmt = - GetCurrentFuncCodeMp()->New(GetCurrentFuncCodeMpAllocator(), OP_xintrinsiccall, idx); + GetCurrentFuncCodeMp()->New(*GetCurrentFuncCodeMpAllocator(), OP_xintrinsiccall, idx); ASSERT(stmt != nullptr, "stmt is null"); stmt->SetOpnds(arguments); return stmt; } CallNode *MIRBuilder::CreateStmtCallAssigned(PUIdx puIdx, const MIRSymbol *ret, Opcode op) { - CallNode *stmt = GetCurrentFuncCodeMp()->New(GetCurrentFuncCodeMpAllocator(), op, puIdx); + CallNode *stmt = GetCurrentFuncCodeMp()->New(*GetCurrentFuncCodeMpAllocator(), op, puIdx); if (ret) { ASSERT(IsValidCallReturn(*ret), "Not Excepted ret"); stmt->GetReturnVec().push_back(CallReturnPair(ret->GetStIdx(), RegFieldPair(0, 0))); @@ -911,7 +909,7 @@ CallNode *MIRBuilder::CreateStmtCallAssigned(PUIdx puIdx, const MIRSymbol *ret, CallNode *MIRBuilder::CreateStmtCallAssigned(PUIdx puIdx, const MapleVector &args, const MIRSymbol *ret, Opcode opcode, TyIdx tyIdx) { - CallNode *stmt = GetCurrentFuncCodeMp()->New(GetCurrentFuncCodeMpAllocator(), opcode, puIdx, tyIdx); + CallNode *stmt = GetCurrentFuncCodeMp()->New(*GetCurrentFuncCodeMpAllocator(), opcode, puIdx, tyIdx); ASSERT(stmt != nullptr, "stmt is null"); stmt->SetOpnds(args); if (ret != nullptr) { @@ -922,7 +920,7 @@ CallNode *MIRBuilder::CreateStmtCallAssigned(PUIdx puIdx, const MapleVectorNew(GetCurrentFuncCodeMpAllocator(), opcode, puIdx); + CallNode *stmt = GetCurrentFuncCodeMp()->New(*GetCurrentFuncCodeMpAllocator(), opcode, puIdx); stmt->GetNopnd().push_back(arg); stmt->SetNumOpnds(stmt->GetNopndSize()); if (pRegIdxt > 0) { @@ -933,7 +931,7 @@ CallNode *MIRBuilder::CreateStmtCallRegassigned(PUIdx puIdx, PregIdx pRegIdxt, O CallNode *MIRBuilder::CreateStmtCallRegassigned(PUIdx puIdx, const MapleVector &args, PregIdx pRegIdxt, Opcode opcode) { - CallNode *stmt = GetCurrentFuncCodeMp()->New(GetCurrentFuncCodeMpAllocator(), opcode, puIdx); + CallNode *stmt = GetCurrentFuncCodeMp()->New(*GetCurrentFuncCodeMpAllocator(), opcode, puIdx); ASSERT(stmt != nullptr, "stmt is null"); stmt->SetOpnds(args); if (pRegIdxt > 0) { @@ -945,7 +943,7 @@ CallNode *MIRBuilder::CreateStmtCallRegassigned(PUIdx puIdx, const MapleVector &args, PregIdx retPregIdx) { IntrinsiccallNode *stmt = - GetCurrentFuncCodeMp()->New(GetCurrentFuncCodeMpAllocator(), OP_intrinsiccallassigned, idx); + GetCurrentFuncCodeMp()->New(*GetCurrentFuncCodeMpAllocator(), OP_intrinsiccallassigned, idx); ASSERT(stmt != nullptr, "stmt is null"); stmt->SetOpnds(args); if (retPregIdx > 0) { @@ -957,7 +955,7 @@ IntrinsiccallNode *MIRBuilder::CreateStmtIntrinsicCallAssigned(MIRIntrinsicID id IntrinsiccallNode *MIRBuilder::CreateStmtIntrinsicCallAssigned(MIRIntrinsicID idx, const MapleVector &args, const MIRSymbol *ret, TyIdx tyIdx) { IntrinsiccallNode *stmt = GetCurrentFuncCodeMp()->New( - GetCurrentFuncCodeMpAllocator(), tyIdx == 0 ? OP_intrinsiccallassigned : OP_intrinsiccallwithtypeassigned, idx); + *GetCurrentFuncCodeMpAllocator(), tyIdx == 0 ? OP_intrinsiccallassigned : OP_intrinsiccallwithtypeassigned, idx); stmt->SetTyIdx(tyIdx); stmt->SetOpnds(args); CallReturnVector nrets(GetCurrentFuncCodeMpAllocator()->Adapter()); @@ -972,7 +970,7 @@ IntrinsiccallNode *MIRBuilder::CreateStmtIntrinsicCallAssigned(MIRIntrinsicID id IntrinsiccallNode *MIRBuilder::CreateStmtXintrinsicCallAssigned(MIRIntrinsicID idx, const MapleVector &args, const MIRSymbol *ret) { IntrinsiccallNode *stmt = - GetCurrentFuncCodeMp()->New(GetCurrentFuncCodeMpAllocator(), OP_xintrinsiccallassigned, idx); + GetCurrentFuncCodeMp()->New(*GetCurrentFuncCodeMpAllocator(), OP_xintrinsiccallassigned, idx); ASSERT(stmt != nullptr, "stmt is null"); stmt->SetOpnds(args); CallReturnVector nrets(GetCurrentFuncCodeMpAllocator()->Adapter()); @@ -985,21 +983,21 @@ IntrinsiccallNode *MIRBuilder::CreateStmtXintrinsicCallAssigned(MIRIntrinsicID i } NaryStmtNode *MIRBuilder::CreateStmtReturn(BaseNode *rVal) { - NaryStmtNode *stmt = GetCurrentFuncCodeMp()->New(GetCurrentFuncCodeMpAllocator(), OP_return); + NaryStmtNode *stmt = GetCurrentFuncCodeMp()->New(*GetCurrentFuncCodeMpAllocator(), OP_return); ASSERT(stmt != nullptr, "stmt is null"); stmt->PushOpnd(rVal); return stmt; } NaryStmtNode *MIRBuilder::CreateStmtNary(Opcode op, const MapleVector &rVals) { - NaryStmtNode *stmt = GetCurrentFuncCodeMp()->New(GetCurrentFuncCodeMpAllocator(), op); + NaryStmtNode *stmt = GetCurrentFuncCodeMp()->New(*GetCurrentFuncCodeMpAllocator(), op); ASSERT(stmt != nullptr, "stmt is null"); stmt->SetOpnds(rVals); return stmt; } NaryStmtNode *MIRBuilder::CreateStmtNary(Opcode op, BaseNode *rVal) { - NaryStmtNode *stmt = GetCurrentFuncCodeMp()->New(GetCurrentFuncCodeMpAllocator(), op); + NaryStmtNode *stmt = GetCurrentFuncCodeMp()->New(*GetCurrentFuncCodeMpAllocator(), op); ASSERT(stmt != nullptr, "stmt is null"); stmt->PushOpnd(rVal); return stmt; @@ -1039,7 +1037,8 @@ DoloopNode *MIRBuilder::CreateStmtDoloop(StIdx doVarStIdx, bool isPReg, BaseNode } SwitchNode *MIRBuilder::CreateStmtSwitch(BaseNode *opnd, LabelIdx defaultLabel, const CaseVector &switchTable) { - SwitchNode *switchNode = GetCurrentFuncCodeMp()->New(GetCurrentFuncCodeMpAllocator(), defaultLabel, opnd); + SwitchNode *switchNode = GetCurrentFuncCodeMp()->New(*GetCurrentFuncCodeMpAllocator(), + defaultLabel, opnd); switchNode->SetSwitchTable(switchTable); switchNode->SetNumOpnds(switchTable.size()); return switchNode; @@ -1054,11 +1053,11 @@ JsTryNode *MIRBuilder::CreateStmtJsTry(Opcode o, LabelIdx cLabIdx, LabelIdx fLab } TryNode *MIRBuilder::CreateStmtTry(const MapleVector &cLabIdxs) { - return GetCurrentFuncCodeMp()->New(GetCurrentFuncCodeMpAllocator(), cLabIdxs); + return GetCurrentFuncCodeMp()->New(cLabIdxs); } CatchNode *MIRBuilder::CreateStmtCatch(const MapleVector &tyIdxVec) { - return GetCurrentFuncCodeMp()->New(GetCurrentFuncCodeMpAllocator(), tyIdxVec); + return GetCurrentFuncCodeMp()->New(tyIdxVec); } LabelIdx MIRBuilder::GetOrCreateMIRLabel(const std::string &name) { @@ -1084,7 +1083,7 @@ LabelNode *MIRBuilder::CreateStmtLabel(LabelIdx labIdx) { } StmtNode *MIRBuilder::CreateStmtComment(const std::string &cmnt) { - return GetCurrentFuncCodeMp()->New(GetCurrentFuncCodeMpAllocator(), cmnt); + return GetCurrentFuncCodeMp()->New(*GetCurrentFuncCodeMpAllocator(), cmnt); } void MIRBuilder::AddStmtInCurrentFunctionBody(StmtNode *stmt) { diff --git a/src/maple_ir/src/mir_parser.cpp b/src/maple_ir/src/mir_parser.cpp index 64d6c15e7a61ca6775c7dbcdaefa115e4b7aa1c1..48a789bcd9c9fd93962f51a1b5cad9404b753ea5 100644 --- a/src/maple_ir/src/mir_parser.cpp +++ b/src/maple_ir/src/mir_parser.cpp @@ -194,7 +194,7 @@ bool MIRParser::ParseStmtDoloop(StmtNodePtr &stmt) { stmt = doloopnode; lexer.NextToken(); if (lexer.GetTokenKind() == kTkPreg) { - PregIdx pregidx = LookupOrCreatePregIdx(static_cast(lexer.GetTheIntVal()), false, mod.CurFunction()); + PregIdx pregidx = LookupOrCreatePregIdx(static_cast(lexer.GetTheIntVal()), false, *mod.CurFunction()); doloopnode->SetIsPreg(true); doloopnode->GetDoVarStIdx().SetFullIdx(pregidx); // let other appearances handle the preg primitive type @@ -510,7 +510,7 @@ bool MIRParser::ParseSwitchCase(int32 &constval, LabelIdx &lblIdx) { } bool MIRParser::ParseStmtSwitch(StmtNodePtr &stmt) { - SwitchNode *switchnode = mod.CurFuncCodeMemPool()->New(&mod); + SwitchNode *switchnode = mod.CurFuncCodeMemPool()->New(mod); stmt = switchnode; lexer.NextToken(); BaseNode *expr = nullptr; @@ -559,7 +559,7 @@ bool MIRParser::ParseStmtSwitch(StmtNodePtr &stmt) { } bool MIRParser::ParseStmtRangegoto(StmtNodePtr &stmt) { - RangegotoNode *rangegotonode = mod.CurFuncCodeMemPool()->New(&mod); + RangegotoNode *rangegotonode = mod.CurFuncCodeMemPool()->New(mod); stmt = rangegotonode; lexer.NextToken(); BaseNode *expr = nullptr; @@ -625,7 +625,7 @@ bool MIRParser::ParseStmtRangegoto(StmtNodePtr &stmt) { } bool MIRParser::ParseStmtMultiway(StmtNodePtr &stmt) { - MultiwayNode *multiwaynode = mod.CurFuncCodeMemPool()->New(&mod); + MultiwayNode *multiwaynode = mod.CurFuncCodeMemPool()->New(mod); stmt = multiwaynode; lexer.NextToken(); BaseNode *expr = nullptr; @@ -687,7 +687,7 @@ PUIdx MIRParser::EnterUndeclaredFunction(bool isMcount) { GStrIdx stridx = GlobalTables::GetStrTable().GetOrCreateStrIdxFromName(funcName); MIRSymbol *funcSt = GlobalTables::GetGsymTable().CreateSymbol(kScopeGlobal); funcSt->SetNameStrIdx(stridx); - (void)GlobalTables::GetGsymTable().AddToStringSymbolMap(funcSt); + (void)GlobalTables::GetGsymTable().AddToStringSymbolMap(*funcSt); funcSt->SetStorageClass(kScText); funcSt->SetSKind(kStFunc); MIRFunction *fn = mod.GetMemPool()->New(&mod, funcSt->GetStIdx()); @@ -708,7 +708,7 @@ bool MIRParser::ParseStmtCallMcount(StmtNodePtr &stmt) { // syntax: call (, ..., ) Opcode o = OP_call; PUIdx pidx = EnterUndeclaredFunction(true); - CallNode *callstmt = mod.CurFuncCodeMemPool()->New(&mod, o); + CallNode *callstmt = mod.CurFuncCodeMemPool()->New(mod, o); callstmt->SetPUIdx(pidx); MapleVector opndsvec(mod.CurFuncCodeMemPoolAllocator()->Adapter()); callstmt->SetNOpnd(opndsvec); @@ -779,7 +779,7 @@ bool MIRParser::ParseStmtCall(StmtNodePtr &stmt) { CallNode *callstmt = nullptr; CallinstantNode *callinstantstmt = nullptr; if (withtype) { - callstmt = mod.CurFuncCodeMemPool()->New(&mod, o); + callstmt = mod.CurFuncCodeMemPool()->New(mod, o); callstmt->SetTyIdx(polymophictyidx); } else if (hasinstant) { TokenKind langleTk = lexer.GetTokenKind(); @@ -803,11 +803,11 @@ bool MIRParser::ParseStmtCall(StmtNodePtr &stmt) { return false; } TyIdx tyidx = GlobalTables::GetTypeTable().GetOrCreateMIRType(&instvecty); - callinstantstmt = mod.CurFuncCodeMemPool()->New(&mod, o, tyidx); + callinstantstmt = mod.CurFuncCodeMemPool()->New(mod, o, tyidx); callstmt = callinstantstmt; lexer.NextToken(); // skip the > } else { - callstmt = mod.CurFuncCodeMemPool()->New(&mod, o); + callstmt = mod.CurFuncCodeMemPool()->New(mod, o); } callstmt->SetPUIdx(pidx); MapleVector opndsvec(mod.CurFuncCodeMemPoolAllocator()->Adapter()); @@ -841,7 +841,7 @@ bool MIRParser::ParseStmtIcall(StmtNodePtr &stmt, bool isAssigned) { // dassign // . . . // dassign } - IcallNode *icallStmt = mod.CurFuncCodeMemPool()->New(&mod, !isAssigned ? OP_icall : OP_icallassigned); + IcallNode *icallStmt = mod.CurFuncCodeMemPool()->New(mod, !isAssigned ? OP_icall : OP_icallassigned); lexer.NextToken(); MapleVector opndsvec(mod.CurFuncCodeMemPoolAllocator()->Adapter()); if (!ParseExprNaryOperand(opndsvec)) { @@ -873,7 +873,7 @@ bool MIRParser::ParseStmtIntrinsiccall(StmtNodePtr &stmt, bool isAssigned) { Opcode o = !isAssigned ? (lexer.GetTokenKind() == TK_intrinsiccall ? OP_intrinsiccall : OP_xintrinsiccall) : (lexer.GetTokenKind() == TK_intrinsiccallassigned ? OP_intrinsiccallassigned : OP_xintrinsiccallassigned); - IntrinsiccallNode *intrncallnode = mod.CurFuncCodeMemPool()->New(&mod, o); + IntrinsiccallNode *intrncallnode = mod.CurFuncCodeMemPool()->New(mod, o); lexer.NextToken(); if (o == !isAssigned ? OP_intrinsiccall : OP_intrinsiccallassigned) { intrncallnode->SetIntrinsic(GetIntrinsicId(lexer.GetTokenKind())); @@ -916,7 +916,7 @@ bool MIRParser::ParseStmtIntrinsiccallassigned(StmtNodePtr &stmt) { bool MIRParser::ParseStmtIntrinsiccallwithtype(StmtNodePtr &stmt, bool isAssigned) { Opcode o = !isAssigned ? OP_intrinsiccallwithtype : OP_intrinsiccallwithtypeassigned; - IntrinsiccallNode *intrncallnode = mod.CurFuncCodeMemPool()->New(&mod, o); + IntrinsiccallNode *intrncallnode = mod.CurFuncCodeMemPool()->New(mod, o); TokenKind tk = lexer.NextToken(); TyIdx tyidx(0); if (IsPrimitiveType(tk)) { @@ -1110,7 +1110,7 @@ bool MIRParser::ParseStmtJsTry(StmtNodePtr &stmt) { } bool MIRParser::ParseStmtTry(StmtNodePtr &stmt) { - TryNode *trynode = mod.CurFuncCodeMemPool()->New(&mod); + TryNode *trynode = mod.CurFuncCodeMemPool()->New(mod); lexer.NextToken(); ASSERT(lexer.GetTokenKind() == kTkLbrace, "expect left brace in try but get "); lexer.NextToken(); @@ -1136,7 +1136,7 @@ bool MIRParser::ParseStmtTry(StmtNodePtr &stmt) { } bool MIRParser::ParseStmtCatch(StmtNodePtr &stmt) { - CatchNode *catchnode = mod.CurFuncCodeMemPool()->New(&mod); + CatchNode *catchnode = mod.CurFuncCodeMemPool()->New(mod); lexer.NextToken(); ASSERT(lexer.GetTokenKind() == kTkLbrace, "expect left brace in catch but get "); lexer.NextToken(); @@ -1277,7 +1277,7 @@ bool MIRParser::ParseBinaryStmtAssertLT(StmtNodePtr &stmt) { } bool MIRParser::ParseNaryStmt(StmtNodePtr &stmt, Opcode op) { - NaryStmtNode *stmtReturn = mod.CurFuncCodeMemPool()->New(&mod, op); + NaryStmtNode *stmtReturn = mod.CurFuncCodeMemPool()->New(mod, op); if (lexer.NextToken() != kTkLparen) { Error("expect return with ( but get "); return false; @@ -1433,7 +1433,7 @@ void MIRParser::ParseStmtBlockForSeenComment(BlockNodePtr blk, uint32 mplNum) { // collect accumulated comments into comment statement nodes if (!lexer.seenComments.empty()) { for (size_t i = 0; i < lexer.seenComments.size(); i++) { - CommentNode *cmnt = mod.CurFuncCodeMemPool()->New(&mod); + CommentNode *cmnt = mod.CurFuncCodeMemPool()->New(mod); cmnt->SetComment(lexer.seenComments[i]); SetSrcPos(cmnt, mplNum); blk->AddStatement(cmnt); @@ -1450,7 +1450,7 @@ bool MIRParser::ParseStmtBlockForVar(TokenKind stmtTK) { if (stmtTK == TK_tempvar) { st->SetIsTmp(true); } - if (!ParseDeclareVar(st)) { + if (!ParseDeclareVar(*st)) { return false; } if (!fn->GetSymTab()->AddToStringSymbolMap(st)) { @@ -2483,7 +2483,7 @@ bool MIRParser::ParseExprTernary(BaseNodePtr &expr) { bool MIRParser::ParseExprArray(BaseNodePtr &expr) { // syntax: array (, , . . . , ) - ArrayNode *arrayNode = mod.CurFuncCodeMemPool()->New(&mod); + ArrayNode *arrayNode = mod.CurFuncCodeMemPool()->New(mod); expr = arrayNode; if (lexer.GetTokenKind() != TK_array) { Error("expect array but get "); @@ -2563,7 +2563,7 @@ bool MIRParser::ParseExprIntrinsicop(BaseNodePtr &expr) { return false; } IntrinsicopNode *intrnopnode = mod.CurFuncCodeMemPool()->New( - &mod, opCode, GlobalTables::GetTypeTable().GetPrimTypeFromTyIdx(pTyIdx), tyIdx); + mod, opCode, GlobalTables::GetTypeTable().GetPrimTypeFromTyIdx(pTyIdx), tyIdx); expr = intrnopnode; if (!ParseIntrinsicId(intrnopnode)) { return false; diff --git a/src/maple_ir/src/parser.cpp b/src/maple_ir/src/parser.cpp index 7b69f18ef406414797e9d7e17226d333820e82f5..d70f586cffc520555468e39e2d98d2316e9facb1 100644 --- a/src/maple_ir/src/parser.cpp +++ b/src/maple_ir/src/parser.cpp @@ -52,10 +52,9 @@ MIRFunction *MIRParser::CreateDummyFunction() { return func; } -void MIRParser::ResetMaxPregNo(MIRFunction *func) { - ASSERT(func != nullptr, "func is null"); - for (uint32 i = 0; i < func->GetFormalCount(); i++) { - MIRSymbol *formalSt = func->GetFormal(i); +void MIRParser::ResetMaxPregNo(MIRFunction &func) { + for (uint32 i = 0; i < func.GetFormalCount(); i++) { + MIRSymbol *formalSt = func.GetFormal(i); if (formalSt->IsPreg()) { uint32 pRegNo = static_cast(formalSt->GetPreg()->GetPregNo()); // no special register appears in the formals @@ -70,9 +69,8 @@ MIRPreg *MIRParser::CreateMirPreg(uint32 pregNo) const { return mod.GetMemPool()->New(pregNo); } -PregIdx MIRParser::LookupOrCreatePregIdx(uint32 pregNo, bool isRef, MIRFunction *func) { - ASSERT(func != nullptr, "func is null"); - MIRPregTable *pRegTab = func->GetPregTab(); +PregIdx MIRParser::LookupOrCreatePregIdx(uint32 pregNo, bool isRef, MIRFunction &func) { + MIRPregTable *pRegTab = func.GetPregTab(); PregIdx idx = pRegTab->GetPregIdxFromPregno(pregNo); if (idx == 0) { if (pregNo > maxPregNo) { @@ -224,14 +222,15 @@ bool MIRParser::ParseSpecialReg(PregIdx &pRegIdx) { bool MIRParser::ParseRefPseudoReg(PregIdx &pRegIdx) { uint32 pRegNo = static_cast(lexer.GetTheIntVal()); ASSERT(pRegNo <= 0xffff, "preg number must be 16 bits"); - pRegIdx = LookupOrCreatePregIdx(pRegNo, true, mod.CurFunction()); + pRegIdx = LookupOrCreatePregIdx(pRegNo, true, *mod.CurFunction()); lexer.NextToken(); return true; } bool MIRParser::ParsePseudoReg(PrimType primType, PregIdx &pRegIdx) { MIRFunction *func = mod.CurFunction(); - pRegIdx = LookupOrCreatePregIdx(static_cast(lexer.GetTheIntVal()), false, func); + ASSERT(func != nullptr, "func nullptr check"); + pRegIdx = LookupOrCreatePregIdx(static_cast(lexer.GetTheIntVal()), false, *func); MIRPreg *preg = func->GetPregTab()->PregFromPregIdx(pRegIdx); if (primType == kPtyInvalid || preg->GetPrimType() == primType) { @@ -365,9 +364,7 @@ bool MIRParser::ParseBitFieldType(TyIdx &fieldTyIdx) { return true; } -bool MIRParser::ParsePragmaElement(MIRPragmaElement *elem) { - ASSERT(elem != nullptr, "elem is null"); - +bool MIRParser::ParsePragmaElement(MIRPragmaElement &elem) { TokenKind tk = lexer.GetTokenKind(); lexer.NextToken(); std::map tkPragmaValType = { @@ -385,39 +382,39 @@ bool MIRParser::ParsePragmaElement(MIRPragmaElement *elem) { Error("parsing pragma error: wrong element type"); return false; } - elem->SetType(tkPragmaValType[tk]); + elem.SetType(tkPragmaValType[tk]); switch (tk) { case TK_i8: case TK_i16: case TK_i32: - elem->SetI32Val(static_cast(lexer.GetTheIntVal())); + elem.SetI32Val(static_cast(lexer.GetTheIntVal())); break; case TK_u16: case TK_ref: - elem->SetU64Val(static_cast(lexer.GetTheIntVal())); + elem.SetU64Val(static_cast(lexer.GetTheIntVal())); break; case TK_i64: case TK_retype: case TK_const: case TK_u1: - elem->SetI64Val(lexer.GetTheIntVal()); + elem.SetI64Val(lexer.GetTheIntVal()); break; case TK_f32: - elem->SetFloatVal(lexer.GetTheFloatVal()); + elem.SetFloatVal(lexer.GetTheFloatVal()); break; case TK_f64: - elem->SetDoubleVal(lexer.GetTheDoubleVal()); + elem.SetDoubleVal(lexer.GetTheDoubleVal()); break; case TK_ptr: case TK_var: case TK_func: case TK_enum: - elem->SetI32Val(GlobalTables::GetStrTable().GetOrCreateStrIdxFromName(lexer.GetName()).GetIdx()); + elem.SetI32Val(GlobalTables::GetStrTable().GetOrCreateStrIdxFromName(lexer.GetName()).GetIdx()); break; case TK_type: lexer.NextToken(); - elem->SetI32Val(GlobalTables::GetStrTable().GetOrCreateStrIdxFromName(lexer.GetName()).GetIdx()); + elem.SetI32Val(GlobalTables::GetStrTable().GetOrCreateStrIdxFromName(lexer.GetName()).GetIdx()); lexer.NextToken(); break; case TK_array: @@ -436,9 +433,7 @@ bool MIRParser::ParsePragmaElement(MIRPragmaElement *elem) { return true; } -bool MIRParser::ParsePragmaElementForArray(MIRPragmaElement *elem) { - ASSERT(elem != nullptr, "elem is null"); - +bool MIRParser::ParsePragmaElementForArray(MIRPragmaElement &elem) { TokenKind tk; tk = lexer.GetTokenKind(); if (tk != kTkLbrack) { @@ -459,11 +454,11 @@ bool MIRParser::ParsePragmaElementForArray(MIRPragmaElement *elem) { for (int64 i = 0; i < size; i++) { MIRPragmaElement *e0 = mod.GetMemPool()->New(&mod); tk = lexer.NextToken(); - if (!ParsePragmaElement(e0)) { + if (!ParsePragmaElement(*e0)) { Error("parsing pragma error type "); return false; } - elem->PushSubElemVec(e0); + elem.PushSubElemVec(e0); tk = lexer.NextToken(); if (tk != kTkComa && tk != kTkRbrack) { Error("parsing pragma error: expecting , or ] but get "); @@ -473,8 +468,7 @@ bool MIRParser::ParsePragmaElementForArray(MIRPragmaElement *elem) { return true; } -bool MIRParser::ParsePragmaElementForAnnotation(MIRPragmaElement *elem) { - ASSERT(elem != nullptr, "elem is null"); +bool MIRParser::ParsePragmaElementForAnnotation(MIRPragmaElement &elem) { TokenKind tk; tk = lexer.GetTokenKind(); if (tk != kTkLangle) { @@ -482,7 +476,7 @@ bool MIRParser::ParsePragmaElementForAnnotation(MIRPragmaElement *elem) { return false; } tk = lexer.NextToken(); - elem->SetTypeStrIdx(GlobalTables::GetStrTable().GetOrCreateStrIdxFromName(lexer.GetName())); + elem.SetTypeStrIdx(GlobalTables::GetStrTable().GetOrCreateStrIdxFromName(lexer.GetName())); tk = lexer.NextToken(); if (tk != kTkRangle) { Error("parsing pragma error: expecting > but get "); @@ -513,11 +507,11 @@ bool MIRParser::ParsePragmaElementForAnnotation(MIRPragmaElement *elem) { } e0->SetNameStrIdx(GlobalTables::GetStrTable().GetOrCreateStrIdxFromName(lexer.GetName())); tk = lexer.NextToken(); - if (!ParsePragmaElement(e0)) { + if (!ParsePragmaElement(*e0)) { Error("parsing pragma error type "); return false; } - elem->PushSubElemVec(e0); + elem.PushSubElemVec(e0); tk = lexer.NextToken(); if (tk != kTkComa && tk != kTkRbrack) { Error("parsing pragma error: expecting , or ] but get "); @@ -571,7 +565,7 @@ bool MIRParser::ParsePragma(MIRStructType &type) { MIRPragmaElement *e = mod.GetMemPool()->New(&mod); e->SetNameStrIdx(GlobalTables::GetStrTable().GetOrCreateStrIdxFromName(lexer.GetName())); tk = lexer.NextToken(); - if (!ParsePragmaElement(e)) { + if (!ParsePragmaElement(*e)) { Error("parsing pragma error type "); return false; } @@ -969,19 +963,19 @@ bool MIRParser::ParseAlignAttrs(TypeAttrs &tA) { // for variable declaration type attribute specification // it has also storage-class qualifier. -bool MIRParser::ParseVarTypeAttrs(MIRSymbol *st) { +bool MIRParser::ParseVarTypeAttrs(MIRSymbol &st) { do { switch (lexer.GetTokenKind()) { #define TYPE_ATTR #define ATTR(X) \ case TK_##X: \ - st->SetAttr(ATTR_##X); \ + st.SetAttr(ATTR_##X); \ break; #include "all_attributes.def" #undef ATTR #undef TYPE_ATTR case TK_align: { - if (!ParseAlignAttrs(st->GetAttrs())) { + if (!ParseAlignAttrs(st.GetAttrs())) { return false; } break; @@ -1251,7 +1245,7 @@ bool MIRParser::ParseFuncType(TyIdx &tyIdx) { return false; } MIRType *funcType = - GlobalTables::GetTypeTable().GetOrCreateFunctionType(&mod, retTyIdx, vecTyIdx, vecAttrs, false, true); + GlobalTables::GetTypeTable().GetOrCreateFunctionType(mod, retTyIdx, vecTyIdx, vecAttrs, false, true); tyIdx = GlobalTables::GetTypeTable().GetOrCreateMIRType(funcType); return true; } @@ -1549,14 +1543,13 @@ bool MIRParser::ParseTypedef() { return true; } -bool MIRParser::ParseJavaClassInterface(MIRSymbol *symbol, bool isClass) { - ASSERT(symbol != nullptr, "symbol is null"); +bool MIRParser::ParseJavaClassInterface(MIRSymbol &symbol, bool isClass) { TokenKind tk = lexer.NextToken(); if (tk != kTkGname) { Error("expect global name for javaclass but get "); return false; } - symbol->SetNameStrIdx(lexer.GetName()); + symbol.SetNameStrIdx(lexer.GetName()); lexer.NextToken(); TyIdx tyidx(0); if (!ParseType(tyidx)) { @@ -1571,28 +1564,28 @@ bool MIRParser::ParseJavaClassInterface(MIRSymbol *symbol, bool isClass) { Error("type in javainterface declaration must be of interface type at "); return false; } - symbol->SetTyIdx(tyidx); - if (!ParseTypeAttrs(symbol->GetAttrs())) { + symbol.SetTyIdx(tyidx); + if (!ParseTypeAttrs(symbol.GetAttrs())) { Error("bad type attribute in variable declaration at "); return false; } if (GlobalTables::GetTypeTable().GetTypeFromTyIdx(tyidx)->HasTypeParam()) { - symbol->SetAttr(ATTR_generic); + symbol.SetAttr(ATTR_generic); } return true; } -bool MIRParser::ParseStorageClass(MIRSymbol *symbol) const { +bool MIRParser::ParseStorageClass(MIRSymbol &symbol) const { TokenKind tk = lexer.GetTokenKind(); switch (tk) { case TK_fstatic: - symbol->SetStorageClass(kScFstatic); + symbol.SetStorageClass(kScFstatic); return true; case TK_pstatic: - symbol->SetStorageClass(kScPstatic); + symbol.SetStorageClass(kScPstatic); return true; case TK_extern: - symbol->SetStorageClass(kScExtern); + symbol.SetStorageClass(kScExtern); return true; default: break; @@ -1600,8 +1593,7 @@ bool MIRParser::ParseStorageClass(MIRSymbol *symbol) const { return false; } -bool MIRParser::ParseDeclareReg(MIRSymbol *symbol, MIRFunction *func) { - ASSERT(symbol != nullptr, "symbol is null"); +bool MIRParser::ParseDeclareReg(MIRSymbol &symbol, MIRFunction &func) { TokenKind tk = lexer.GetTokenKind(); // i.e, reg %1 u1 if (tk != TK_reg) { // reg @@ -1626,39 +1618,38 @@ bool MIRParser::ParseDeclareReg(MIRSymbol *symbol, MIRFunction *func) { Error("type in var declaration cannot be forward-referenced at "); return false; } - symbol->SetTyIdx(tyIdx); + symbol.SetTyIdx(tyIdx); MIRType *mirType = GlobalTables::GetTypeTable().GetTypeFromTyIdx(tyIdx); PregIdx pRegIdx = LookupOrCreatePregIdx(thePRegNo, mirType->GetPrimType() == PTY_ref, func); - MIRPregTable *pRegTab = func->GetPregTab(); + MIRPregTable *pRegTab = func.GetPregTab(); MIRPreg *preg = pRegTab->PregFromPregIdx(pRegIdx); preg->SetIsRef(mirType->GetPrimType() == PTY_ref); preg->SetPrimType(mirType->GetPrimType()); - symbol->SetPreg(preg); + symbol.SetPreg(preg); if (!ParseVarTypeAttrs(symbol)) { Error("bad type attribute in variable declaration at "); return false; } if (GlobalTables::GetTypeTable().GetTypeFromTyIdx(tyIdx)->HasTypeParam()) { - symbol->SetAttr(ATTR_generic); + symbol.SetAttr(ATTR_generic); mod.CurFunction()->SetAttr(FUNCATTR_generic); } return true; } -bool MIRParser::ParseDeclareVar(MIRSymbol *symbol) { - ASSERT(symbol != nullptr, "symbol is null"); +bool MIRParser::ParseDeclareVar(MIRSymbol &symbol) { TokenKind tk = lexer.GetTokenKind(); // i.e, var %i i32 if (tk != TK_var && tk != TK_tempvar) { // var Error("expect var but get "); return false; } - bool isLocal = symbol->IsLocal(); + bool isLocal = symbol.IsLocal(); // %i TokenKind nameTk = lexer.NextToken(); if (isLocal) { if (nameTk == TK_static) { - symbol->SetStorageClass(kScPstatic); + symbol.SetStorageClass(kScPstatic); nameTk = lexer.NextToken(); } if (nameTk != kTkLname) { @@ -1672,7 +1663,7 @@ bool MIRParser::ParseDeclareVar(MIRSymbol *symbol) { } } GStrIdx symbolStrID = GlobalTables::GetStrTable().GetOrCreateStrIdxFromName(lexer.GetName()); - symbol->SetNameStrIdx(symbolStrID); + symbol.SetNameStrIdx(symbolStrID); tk = lexer.NextToken(); if (ParseStorageClass(symbol)) { lexer.NextToken(); @@ -1688,13 +1679,13 @@ bool MIRParser::ParseDeclareVar(MIRSymbol *symbol) { Error("type in var declaration cannot be forward-referenced at "); return false; } - symbol->SetTyIdx(tyIdx); + symbol.SetTyIdx(tyIdx); if (!ParseVarTypeAttrs(symbol)) { Error("bad type attribute in variable declaration at "); return false; } - if (symbol->GetStorageClass() == kScExtern && symbol->IsStatic()) { - const std::string &staticFieldName = symbol->GetName(); + if (symbol.GetStorageClass() == kScExtern && symbol.IsStatic()) { + const std::string &staticFieldName = symbol.GetName(); constexpr int kPosOffset = 3; size_t pos = staticFieldName.find(NameMangler::kClassNameSplitterStr) + kPosOffset; if (pos != 0 && pos != std::string::npos) { @@ -1702,12 +1693,12 @@ bool MIRParser::ParseDeclareVar(MIRSymbol *symbol) { MIRSymbol *classSt = GlobalTables::GetGsymTable().GetSymbolFromStrIdx(GlobalTables::GetStrTable().GetStrIdxFromName(className)); if (classSt != nullptr) { - symbol->SetStorageClass(kScGlobal); + symbol.SetStorageClass(kScGlobal); } } } if (GlobalTables::GetTypeTable().GetTypeFromTyIdx(tyIdx)->HasTypeParam()) { - symbol->SetAttr(ATTR_generic); + symbol.SetAttr(ATTR_generic); if (isLocal) { mod.CurFunction()->SetAttr(FUNCATTR_generic); } @@ -1722,14 +1713,12 @@ bool MIRParser::ParseDeclareVar(MIRSymbol *symbol) { Error("wrong initialiaton value at "); return false; } - symbol->SetKonst(mirConst); + symbol.SetKonst(mirConst); } return true; } -bool MIRParser::ParsePrototype(MIRFunction *func, MIRSymbol *funcSymbol, TyIdx &funcTyIdx) { - ASSERT(func != nullptr, "func is null"); - ASSERT(funcSymbol != nullptr, "funcSymbol is null"); +bool MIRParser::ParsePrototype(MIRFunction &func, MIRSymbol &funcSymbol, TyIdx &funcTyIdx) { if (lexer.GetTokenKind() == kTkLbrace) { if (mod.GetFlavor() < kMmpl) { Error("funcion prototype missing for non-MMPL flavor of Maple IR"); @@ -1751,24 +1740,24 @@ bool MIRParser::ParsePrototype(MIRFunction *func, MIRSymbol *funcSymbol, TyIdx & if (pmTk != kTkRparen) { if (pmTk == kTkDotdotdot) { varArgs = true; - func->SetVarArgs(); + func.SetVarArgs(); pmTk = lexer.NextToken(); if (pmTk != kTkRparen) { Error("expect ) after ... but get"); return false; } } else { - MIRSymbol *symbol = func->GetSymTab()->CreateSymbol(kScopeLocal); + MIRSymbol *symbol = func.GetSymTab()->CreateSymbol(kScopeLocal); ASSERT(symbol != nullptr, "Failed to create MIRSymbol"); symbol->SetStorageClass(kScFormal); TokenKind symbolTK = lexer.GetTokenKind(); if (symbolTK == TK_reg) { symbol->SetSKind(kStPreg); - if (!ParseDeclareReg(symbol, func)) { + if (!ParseDeclareReg(*symbol, func)) { Error("ParseFunction expect preg for parameter"); return false; } - func->AddFormal(symbol); + func.AddFormal(symbol); vecType.push_back(symbol->GetTyIdx()); vecAttrs.push_back(symbol->GetAttrs()); if (!ParsePrototypeRemaining(func, vecType, vecAttrs, varArgs)) { @@ -1776,12 +1765,12 @@ bool MIRParser::ParsePrototype(MIRFunction *func, MIRSymbol *funcSymbol, TyIdx & } } else { symbol->SetSKind(kStVar); - if (!ParseDeclareVar(symbol)) { + if (!ParseDeclareVar(*symbol)) { Error("ParseFunction expect scalar value"); return false; } - (void)func->GetSymTab()->AddToStringSymbolMap(symbol); - func->AddFormal(symbol); + (void)func.GetSymTab()->AddToStringSymbolMap(symbol); + func.AddFormal(symbol); vecType.push_back(symbol->GetTyIdx()); vecAttrs.push_back(symbol->GetAttrs()); if (!ParsePrototypeRemaining(func, vecType, vecAttrs, varArgs)) { @@ -1797,12 +1786,12 @@ bool MIRParser::ParsePrototype(MIRFunction *func, MIRSymbol *funcSymbol, TyIdx & return false; } MIRType *retType = GlobalTables::GetTypeTable().GetTypeFromTyIdx(tyIdx); - func->SetReturnStruct(retType); + func.SetReturnStruct(retType); MIRType *funcType = - GlobalTables::GetTypeTable().GetOrCreateFunctionType(&mod, tyIdx, vecType, vecAttrs, varArgs, true); + GlobalTables::GetTypeTable().GetOrCreateFunctionType(mod, tyIdx, vecType, vecAttrs, varArgs, true); funcTyIdx = GlobalTables::GetTypeTable().GetOrCreateMIRType(funcType); - funcSymbol->SetTyIdx(funcTyIdx); - func->SetMIRFuncType(static_cast(funcType)); + funcSymbol.SetTyIdx(funcTyIdx); + func.SetMIRFuncType(static_cast(funcType)); return true; } @@ -1847,7 +1836,7 @@ bool MIRParser::ParseFunction(uint32 fileIdx) { tmpFunc->Init(); tmpSymbol->SetFunction(tmpFunc); TyIdx tmpTyIdx; - if (!ParsePrototype(tmpFunc, tmpSymbol, tmpTyIdx)) { + if (!ParsePrototype(*tmpFunc, *tmpSymbol, tmpTyIdx)) { return false; } if (lexer.GetTokenKind() == kTkLbrace) { @@ -1906,13 +1895,13 @@ bool MIRParser::ParseFunction(uint32 fileIdx) { func->SetBaseClassFuncNames(funcSymbol->GetNameStrIdx()); } TyIdx funcTyidx; - if (!ParsePrototype(func, funcSymbol, funcTyidx)) { + if (!ParsePrototype(*func, *funcSymbol, funcTyidx)) { return false; } if (lexer.GetTokenKind() == kTkLbrace) { // #2 parse Function body definedLabels.clear(); maxPregNo = 0; - ResetMaxPregNo(func); // reset the maxPregNo due to the change of parameters + ResetMaxPregNo(*func); // reset the maxPregNo due to the change of parameters mod.SetCurFunction(func); mod.AddFunction(func); // set maple line number for function @@ -2199,24 +2188,24 @@ uint8 *MIRParser::ParseWordsInfo(uint32 size) { return origp; } -static void GenJStringType(MIRModule *module) { +static void GenJStringType(MIRModule &module) { MIRStructType metaClassType(kTypeStructIncomplete); GStrIdx stridx = GlobalTables::GetStrTable().GetOrCreateStrIdxFromName("dummy"); metaClassType.GetFields().push_back(FieldPair(stridx, TyIdxFieldAttrPair(TyIdx(PTY_ref), FieldAttrs()))); stridx = GlobalTables::GetStrTable().GetOrCreateStrIdxFromName("__class_meta__"); TyIdx tyidx = GlobalTables::GetTypeTable().GetOrCreateMIRType(&metaClassType); // Global? - module->GetTypeNameTab()->SetGStrIdxToTyIdx(stridx, tyidx); + module.GetTypeNameTab()->SetGStrIdxToTyIdx(stridx, tyidx); ASSERT(GlobalTables::GetTypeTable().GetTypeTable().empty() == false, "container check"); if (GlobalTables::GetTypeTable().GetTypeFromTyIdx(tyidx)->GetNameStrIdx() == 0) { GlobalTables::GetTypeTable().GetTypeFromTyIdx(tyidx)->SetNameStrIdx(stridx); } } -bool MIRParser::ParseMIR(std::ifstream *mplfile) { +bool MIRParser::ParseMIR(std::ifstream &mplfile) { std::ifstream *origFile = lexer.GetFile(); // parse mplfile - lexer.SetFile(mplfile); + lexer.SetFile(&mplfile); // try to read the first line if (lexer.ReadALine() < 0) { lexer.lineNum = 0; @@ -2286,7 +2275,7 @@ bool MIRParser::ParseMIR(uint32 fileIdx, uint32 option, bool isIPA, bool isComb) if (!mpltFile.is_open()) { FATAL(kLncFatal, "cannot open MPLT file: %s\n", importfilename.c_str()); } - bool failedParse = !ParseMPLT(&mpltFile, importfilename); + bool failedParse = !ParseMPLT(mpltFile, importfilename); mpltFile.close(); if (failedParse) { return false; @@ -2341,7 +2330,7 @@ bool MIRParser::ParseMIRForVar() { if (paramTokenKind == TK_tempvar) { st.SetIsTmp(true); } - if (!ParseDeclareVar(&st)) { + if (!ParseDeclareVar(st)) { return false; } MIRSymbol *prevSt = GlobalTables::GetGsymTable().GetSymbolFromStrIdx(st.GetNameStrIdx()); @@ -2373,12 +2362,13 @@ bool MIRParser::ParseMIRForVar() { bool MIRParser::ParseMIRForClass() { MIRSymbol *st = GlobalTables::GetGsymTable().CreateSymbol(kScopeGlobal); + ASSERT(st != nullptr, "st nullptr check"); st->SetStorageClass(kScInvalid); st->SetSKind(kStJavaClass); - if (!ParseJavaClassInterface(st, true)) { + if (!ParseJavaClassInterface(*st, true)) { return false; } - if (!GlobalTables::GetGsymTable().AddToStringSymbolMap(st)) { + if (!GlobalTables::GetGsymTable().AddToStringSymbolMap(*st)) { Error("duplicate symbol name used in javaclass at "); return false; } @@ -2387,12 +2377,13 @@ bool MIRParser::ParseMIRForClass() { bool MIRParser::ParseMIRForInterface() { MIRSymbol *st = GlobalTables::GetGsymTable().CreateSymbol(kScopeGlobal); + ASSERT(st != nullptr, "st nullptr check"); st->SetStorageClass(kScInvalid); st->SetSKind(kStJavaInterface); - if (!ParseJavaClassInterface(st, false)) { + if (!ParseJavaClassInterface(*st, false)) { return false; } - if (!GlobalTables::GetGsymTable().AddToStringSymbolMap(st)) { + if (!GlobalTables::GetGsymTable().AddToStringSymbolMap(*st)) { Error("duplicate symbol name used in javainterface at "); return false; } @@ -2636,7 +2627,7 @@ bool MIRParser::ParseMIRForImport() { if (!mpltFile.is_open()) { FATAL(kLncFatal, "cannot open MPLT file: %s\n", importFileName.c_str()); } - bool failedParse = !ParseMPLT(&mpltFile, importFileName); + bool failedParse = !ParseMPLT(mpltFile, importFileName); mpltFile.close(); if (failedParse) { // parse the mplt file return false; @@ -2649,7 +2640,7 @@ bool MIRParser::ParseMIRForImport() { if (!mpltFile.is_open()) { FATAL(kLncFatal, "cannot open MPLT file: %s\n", importFileName.c_str()); } - bool failedParse = !ParseMPLT(&mpltFile, importFileName); + bool failedParse = !ParseMPLT(mpltFile, importFileName); mpltFile.close(); if (failedParse) { // parse the mplt file return false; @@ -2657,7 +2648,7 @@ bool MIRParser::ParseMIRForImport() { } } if (GlobalTables::GetStrTable().GetStrIdxFromName("__class_meta__") == 0) { - GenJStringType(&mod); + GenJStringType(mod); } GStrIdx strIdx = GlobalTables::GetStrTable().GetOrCreateStrIdxFromName(importFileName); auto it = mod.GetImportFiles().begin(); @@ -2691,7 +2682,7 @@ bool MIRParser::ParseTypeFromString(const std::string &src, TyIdx &tyIdx) { return ParseType(tyIdx); } -bool MIRParser::ParseMPLT(std::ifstream *mpltFile, const std::string &importFileName) { +bool MIRParser::ParseMPLT(std::ifstream &mpltFile, const std::string &importFileName) { // save relevant values for the main input file std::ifstream *airFileSave = lexer.GetFile(); int lineNumSave = lexer.lineNum; @@ -2699,7 +2690,7 @@ bool MIRParser::ParseMPLT(std::ifstream *mpltFile, const std::string &importFile // set up to read next line from the import file lexer.curIdx = 0; lexer.currentLineSize = 0; - lexer.SetFile(mpltFile); + lexer.SetFile(&mpltFile); lexer.lineNum = 0; mod.SetFileName(importFileName); bool atEof = false; @@ -2743,7 +2734,7 @@ bool MIRParser::ParseMPLT(std::ifstream *mpltFile, const std::string &importFile return true; } -bool MIRParser::ParseMPLTStandalone(std::ifstream *mpltFile, const std::string &importFileName) { +bool MIRParser::ParseMPLTStandalone(std::ifstream &mpltFile, const std::string &importFileName) { PrepareParsingMIR(); if (!ParseMPLT(mpltFile, importFileName)) { return false; @@ -2754,9 +2745,8 @@ bool MIRParser::ParseMPLTStandalone(std::ifstream *mpltFile, const std::string & return true; } -bool MIRParser::ParsePrototypeRemaining(MIRFunction *func, std::vector &vecTyIdx, +bool MIRParser::ParsePrototypeRemaining(MIRFunction &func, std::vector &vecTyIdx, std::vector &vecAttrs, bool &varArgs) { - ASSERT(func != nullptr, "func is null"); TokenKind pmTk = lexer.GetTokenKind(); while (pmTk != kTkRparen) { // parse "," @@ -2767,7 +2757,7 @@ bool MIRParser::ParsePrototypeRemaining(MIRFunction *func, std::vector &v pmTk = lexer.NextToken(); if (pmTk == kTkDotdotdot) { varArgs = true; - func->SetVarArgs(); + func.SetVarArgs(); pmTk = lexer.NextToken(); if (pmTk != kTkRparen) { Error("expect ) after ... but get"); @@ -2775,24 +2765,25 @@ bool MIRParser::ParsePrototypeRemaining(MIRFunction *func, std::vector &v } break; } - MIRSymbol *symbol = func->GetSymTab()->CreateSymbol(kScopeLocal); + MIRSymbol *symbol = func.GetSymTab()->CreateSymbol(kScopeLocal); + ASSERT(symbol != nullptr, "symbol nullptr check"); symbol->SetStorageClass(kScFormal); TokenKind loopStTK = lexer.GetTokenKind(); if (loopStTK == TK_reg) { symbol->SetSKind(kStPreg); - if (!ParseDeclareReg(symbol, func)) { + if (!ParseDeclareReg(*symbol, func)) { Error("ParseFunction expect scalar value"); return false; } } else { symbol->SetSKind(kStVar); - if (!ParseDeclareVar(symbol)) { + if (!ParseDeclareVar(*symbol)) { Error("ParseFunction expect scalar value"); return false; } - (void)func->GetSymTab()->AddToStringSymbolMap(symbol); + (void)func.GetSymTab()->AddToStringSymbolMap(symbol); } - func->AddFormal(symbol); + func.AddFormal(symbol); vecTyIdx.push_back(symbol->GetTyIdx()); vecAttrs.push_back(symbol->GetAttrs()); pmTk = lexer.GetTokenKind(); diff --git a/src/maple_me/include/me_ir.h b/src/maple_me/include/me_ir.h index faa248a57beb7fa7efd9a8ade1f4c92f37155138..f4221f7edf27134e3323e002d06f7538f7dc4451 100644 --- a/src/maple_me/include/me_ir.h +++ b/src/maple_me/include/me_ir.h @@ -2119,7 +2119,6 @@ class IntrinsiccallMeStmt : public NaryMeStmt, public MuChiMePart, public Assign MuChiMePart(alloc), AssignedPart(alloc), intrinsic(static_cast(stt)->GetIntrinsic()), - oriExprInRcLowering(alloc->Adapter()), tyIdx(static_cast(stt)->GetTyIdx()), retPType(stt->GetPrimType()) {} @@ -2128,7 +2127,6 @@ class IntrinsiccallMeStmt : public NaryMeStmt, public MuChiMePart, public Assign MuChiMePart(alloc), AssignedPart(alloc), intrinsic(id), - oriExprInRcLowering(alloc->Adapter()), tyIdx(tyid), retPType(kPtyInvalid) {} @@ -2137,7 +2135,6 @@ class IntrinsiccallMeStmt : public NaryMeStmt, public MuChiMePart, public Assign MuChiMePart(alloc), AssignedPart(intrn->mustDefList), intrinsic(intrn->GetIntrinsic()), - oriExprInRcLowering(alloc->Adapter()), tyIdx(intrn->tyIdx), retPType(intrn->retPType) {} @@ -2217,13 +2214,8 @@ class IntrinsiccallMeStmt : public NaryMeStmt, public MuChiMePart, public Assign return tyIdx; } - MapleVector &GetOriExprInRcLowering() { - return oriExprInRcLowering; - } - private: MIRIntrinsicID intrinsic; - MapleVector oriExprInRcLowering; TyIdx tyIdx; // Used to store return value type PrimType retPType; diff --git a/src/maple_me/src/irmap_emit.cpp b/src/maple_me/src/irmap_emit.cpp index 1424ea896d0e2f52ac74afeb323675f3c14657bb..e66007db3e7452fce6bb78728b9fd21f1b98bb37 100644 --- a/src/maple_me/src/irmap_emit.cpp +++ b/src/maple_me/src/irmap_emit.cpp @@ -233,14 +233,14 @@ BaseNode &NaryMeExpr::EmitExpr(SSATab &ssaTab) { NaryOpnds *nopndPart = nullptr; if (GetOp() == OP_array) { ArrayNode *arrayNode = ssaTab.GetModule().CurFunction()->GetCodeMempool()->New( - &(ssaTab.GetModule()), PrimType(GetPrimType()), tyIdx); + ssaTab.GetModule(), PrimType(GetPrimType()), tyIdx); arrayNode->SetNumOpnds(GetNumOpnds()); arrayNode->SetBoundsCheck(GetBoundCheck()); nopndPart = arrayNode; nodeToReturn = arrayNode; } else { IntrinsicopNode *intrinNode = ssaTab.GetModule().CurFunction()->GetCodeMempool()->New( - &(ssaTab.GetModule()), GetOp(), PrimType(GetPrimType()), tyIdx); + ssaTab.GetModule(), GetOp(), PrimType(GetPrimType()), tyIdx); intrinNode->SetNumOpnds(GetNumOpnds()); intrinNode->SetIntrinsic(intrinsic); nopndPart = intrinNode; @@ -331,7 +331,7 @@ StmtNode &IassignMeStmt::EmitStmt(SSATab &ssaTab) { StmtNode &CallMeStmt::EmitStmt(SSATab &ssaTab) { if (GetOp() != OP_icall && GetOp() != OP_icallassigned) { CallNode *callNode = - ssaTab.GetModule().CurFunction()->GetCodeMempool()->New(&(ssaTab.GetModule()), Opcode(GetOp())); + ssaTab.GetModule().CurFunction()->GetCodeMempool()->New(ssaTab.GetModule(), Opcode(GetOp())); callNode->SetPUIdx(puIdx); callNode->SetTyIdx(tyIdx); callNode->GetNopnd().resize(NumMeStmtOpnds()); @@ -357,7 +357,7 @@ StmtNode &CallMeStmt::EmitStmt(SSATab &ssaTab) { return *callNode; } else { IcallNode *icallNode = - ssaTab.GetModule().CurFunction()->GetCodeMempool()->New(&(ssaTab.GetModule()), Opcode(GetOp())); + ssaTab.GetModule().CurFunction()->GetCodeMempool()->New(ssaTab.GetModule(), Opcode(GetOp())); icallNode->GetNopnd().resize(NumMeStmtOpnds()); for (size_t i = 0; i < NumMeStmtOpnds(); i++) { icallNode->SetOpnd(&GetOpnd(i)->EmitExpr(ssaTab), i); @@ -390,7 +390,7 @@ StmtNode &CallMeStmt::EmitStmt(SSATab &ssaTab) { StmtNode &IcallMeStmt::EmitStmt(SSATab &ssaTab) { IcallNode *icallNode = - ssaTab.GetModule().CurFunction()->GetCodeMempool()->New(&(ssaTab.GetModule()), Opcode(GetOp())); + ssaTab.GetModule().CurFunction()->GetCodeMempool()->New(ssaTab.GetModule(), Opcode(GetOp())); icallNode->GetNopnd().resize(NumMeStmtOpnds()); for (size_t i = 0; i < NumMeStmtOpnds(); i++) { icallNode->SetOpnd(&GetOpnd(i)->EmitExpr(ssaTab), i); @@ -422,7 +422,7 @@ StmtNode &IcallMeStmt::EmitStmt(SSATab &ssaTab) { StmtNode &IntrinsiccallMeStmt::EmitStmt(SSATab &ssaTab) { IntrinsiccallNode *callNode = - ssaTab.GetModule().CurFunction()->GetCodeMempool()->New(&(ssaTab.GetModule()), + ssaTab.GetModule().CurFunction()->GetCodeMempool()->New(ssaTab.GetModule(), Opcode(GetOp())); callNode->SetIntrinsic(intrinsic); callNode->SetTyIdx(tyIdx); @@ -451,7 +451,7 @@ StmtNode &IntrinsiccallMeStmt::EmitStmt(SSATab &ssaTab) { StmtNode &NaryMeStmt::EmitStmt(SSATab &ssaTab) { NaryStmtNode *naryStmt = - ssaTab.GetModule().CurFunction()->GetCodeMempool()->New(&(ssaTab.GetModule()), Opcode(GetOp())); + ssaTab.GetModule().CurFunction()->GetCodeMempool()->New(ssaTab.GetModule(), Opcode(GetOp())); naryStmt->GetNopnd().resize(NumMeStmtOpnds()); for (size_t i = 0; i < NumMeStmtOpnds(); i++) { naryStmt->SetOpnd(&opnds[i]->EmitExpr(ssaTab), i); @@ -492,7 +492,7 @@ StmtNode &JsTryMeStmt::EmitStmt(SSATab &ssaTab) { } StmtNode &TryMeStmt::EmitStmt(SSATab &ssaTab) { - TryNode *tryNode = ssaTab.GetModule().CurFunction()->GetCodeMempool()->New(&(ssaTab.GetModule())); + TryNode *tryNode = ssaTab.GetModule().CurFunction()->GetCodeMempool()->New(ssaTab.GetModule()); tryNode->ResizeOffsets(offsets.size()); for (size_t i = 0; i < offsets.size(); i++) { tryNode->SetOffset(offsets[i], i); @@ -502,14 +502,14 @@ StmtNode &TryMeStmt::EmitStmt(SSATab &ssaTab) { } StmtNode &CatchMeStmt::EmitStmt(SSATab &ssaTab) { - CatchNode *catchNode = ssaTab.GetModule().CurFunction()->GetCodeMempool()->New(&(ssaTab.GetModule())); + CatchNode *catchNode = ssaTab.GetModule().CurFunction()->GetCodeMempool()->New(ssaTab.GetModule()); catchNode->SetExceptionTyIdxVec(exceptionTyIdxVec); catchNode->SetSrcPos(GetSrcPosition()); return *catchNode; } StmtNode &SwitchMeStmt::EmitStmt(SSATab &ssaTab) { - SwitchNode *switchNode = ssaTab.GetModule().CurFunction()->GetCodeMempool()->New(&(ssaTab.GetModule())); + SwitchNode *switchNode = ssaTab.GetModule().CurFunction()->GetCodeMempool()->New(ssaTab.GetModule()); switchNode->SetDefaultLabel(defaultLabel); switchNode->SetSwitchTable(switchTable); switchNode->SetSwitchOpnd(&GetOpnd()->EmitExpr(ssaTab)); @@ -519,7 +519,7 @@ StmtNode &SwitchMeStmt::EmitStmt(SSATab &ssaTab) { StmtNode &CommentMeStmt::EmitStmt(SSATab &ssaTab) { CommentNode *commentNode = - ssaTab.GetModule().CurFunction()->GetCodeMempool()->New(&(ssaTab.GetModule())); + ssaTab.GetModule().CurFunction()->GetCodeMempool()->New(ssaTab.GetModule()); commentNode->SetComment(comment); commentNode->SetSrcPos(GetSrcPosition()); return *commentNode; diff --git a/src/maple_me/src/me_rc_lowering.cpp b/src/maple_me/src/me_rc_lowering.cpp index 70deadecc6196f6a5f7f4a1583ca041e15c2c0cc..79eb0920b072e283cde264ef51123ddb73d5b139 100644 --- a/src/maple_me/src/me_rc_lowering.cpp +++ b/src/maple_me/src/me_rc_lowering.cpp @@ -192,7 +192,6 @@ void RCLowering::HandleAssignMeStmtRHS(MeStmt &stmt) { if (loadCall == nullptr) { return; } - loadCall->GetOriExprInRcLowering().push_back(rhs); if (stmt.GetOp() == OP_regassign) { stmt.GetBB()->ReplaceMeStmt(&stmt, loadCall); if (rhs->IsVolatile(ssaTab)) { @@ -244,7 +243,6 @@ void RCLowering::IntroduceRegRetIntoCallAssigned(MeStmt &stmt) { stmt.GetMustDefList()->push_back(MustDefMeNode(curTmp, &stmt)); std::vector opnds = { curTmp }; IntrinsiccallMeStmt *decrefCall = CreateRCIntrinsic(INTRN_MCCDecRef, stmt, opnds); - decrefCall->GetOriExprInRcLowering().push_back(curTmp); stmt.GetBB()->InsertMeStmtAfter(&stmt, decrefCall); } @@ -254,7 +252,6 @@ void RCLowering::HandleRetOfCallAssignedMeStmt(MeStmt &stmt, MeExpr &pendingDec) RegassignMeStmt *backup = irMap.CreateRegassignMeStmt(*irMap.CreateRegMeExpr(PTY_ref), pendingDec, *bb); std::vector opnds = { backup->GetRegLHS() }; IntrinsiccallMeStmt *decrefCall = CreateRCIntrinsic(INTRN_MCCDecRef, stmt, opnds); - decrefCall->GetOriExprInRcLowering().push_back(backup->GetRegLHS()); if (!dynamic_cast(&stmt)) { bb->InsertMeStmtBefore(&stmt, backup); bb->InsertMeStmtAfter(&stmt, decrefCall); @@ -325,7 +322,6 @@ void RCLowering::HandleAssignMeStmtRegLHS(MeStmt &stmt) { } std::vector opnds = { stmt.GetLHS() }; IntrinsiccallMeStmt *incCall = CreateRCIntrinsic(INTRN_MCCIncRef, stmt, opnds); - incCall->GetOriExprInRcLowering().push_back(stmt.GetLHS()); stmt.GetBB()->InsertMeStmtAfter(&stmt, incCall); } @@ -351,7 +347,6 @@ void RCLowering::HandleAssignToGlobalVar(MeStmt &stmt) { std::vector opnds = { irMap.CreateAddrofMeExpr(*lhs), rhs }; IntrinsiccallMeStmt *writeRefCall = CreateRCIntrinsic(SelectWriteBarrier(stmt), stmt, opnds); - writeRefCall->GetOriExprInRcLowering().push_back(lhs); bb->ReplaceMeStmt(&stmt, writeRefCall); } @@ -375,21 +370,18 @@ void RCLowering::HandleAssignToLocalVar(MeStmt &stmt, MeExpr *pendingDec) { } std::vector opnds = { pendingDec }; IntrinsiccallMeStmt *decCall = CreateRCIntrinsic(INTRN_MCCDecRef, stmt, opnds); - decCall->GetOriExprInRcLowering().push_back(pendingDec); bb->InsertMeStmtBefore(&stmt, decCall); } else { RegassignMeStmt *backup = irMap.CreateRegassignMeStmt(*irMap.CreateRegMeExpr(PTY_ref), *pendingDec, *bb); bb->InsertMeStmtBefore(&stmt, backup); std::vector opnds = { backup->GetLHS() }; IntrinsiccallMeStmt *decCall = CreateRCIntrinsic(INTRN_MCCDecRef, stmt, opnds); - decCall->GetOriExprInRcLowering().push_back(backup->GetLHS()); bb->InsertMeStmtAfter(&stmt, decCall); } } if (incWithLHS) { std::vector opnds = { lhs }; IntrinsiccallMeStmt *incCall = CreateRCIntrinsic(INTRN_MCCIncRef, stmt, opnds); - incCall->GetOriExprInRcLowering().push_back(lhs); bb->InsertMeStmtAfter(&stmt, incCall); } } @@ -440,7 +432,6 @@ void RCLowering::HandleAssignMeStmtIvarLHS(MeStmt &stmt) { std::vector opnds = { &lhsInner->GetBase()->GetAddrExprBase(), irMap.CreateAddrofMeExpr(*lhsInner), rhsInner }; IntrinsiccallMeStmt *writeRefCall = CreateRCIntrinsic(intrinsicID, stmt, opnds); - writeRefCall->GetOriExprInRcLowering().push_back(lhsInner); stmt.GetBB()->ReplaceMeStmt(&stmt, writeRefCall); } @@ -568,7 +559,6 @@ void RCLowering::BBLower(BB &bb) { MeStmt *firstMeStmt = to_ptr(bb.GetMeStmts().begin()); std::vector opnds = { regreadExpr }; IntrinsiccallMeStmt *decRefcall = CreateRCIntrinsic(INTRN_MCCDecRef, *firstMeStmt, opnds); - decRefcall->GetOriExprInRcLowering().push_back(regreadExpr); bb.InsertMeStmtAfter(firstMeStmt, decRefcall); } } @@ -614,7 +604,6 @@ void RCLowering::HandleReturnGlobal(RetMeStmt &ret) { CHECK_FATAL(retVar != nullptr, "retVal null ptr check"); std::vector opnds = { irMap.CreateAddrofMeExpr(*retVar) }; IntrinsiccallMeStmt *loadCall = CreateRCIntrinsic(INTRN_MCCLoadRefS, ret, opnds, true); - loadCall->GetOriExprInRcLowering().push_back(retVar); bb->InsertMeStmtBefore(&ret, loadCall); ret.SetOpnd(0, loadCall->GetMustDefList()->front().GetLHS()); } @@ -628,7 +617,6 @@ void RCLowering::HandleReturnRegread(RetMeStmt &ret) { if (cleanup == nullptr) { std::vector opnds = { retVar }; IntrinsiccallMeStmt *incCall = CreateRCIntrinsic(INTRN_MCCIncRef, ret, opnds); - incCall->GetOriExprInRcLowering().push_back(retVar); bb->InsertMeStmtBefore(&ret, incCall); } else { // remove argument from intrinsiccall MPL_CLEANUP_LOCALREFVARS (dread ref %Reg1_R5678, ... @@ -651,7 +639,6 @@ void RCLowering::HandleReturnFormal(RetMeStmt &ret) { CHECK_FATAL(retVar != nullptr, "retVal null ptr check"); std::vector opnds = { retVar }; IntrinsiccallMeStmt *increfStmt = CreateRCIntrinsic(INTRN_MCCIncRef, ret, opnds, true); - increfStmt->GetOriExprInRcLowering().push_back(retVar); ret.SetOpnd(0, increfStmt->GetMustDefList()->front().GetLHS()); IntrinsiccallMeStmt *cleanup = FindCleanupIntrinsic(ret); if (cleanup == nullptr) { @@ -669,7 +656,6 @@ void RCLowering::HandleReturnIvar(RetMeStmt &ret) { IntrinsiccallMeStmt *loadCall = CreateRCIntrinsic(PrepareVolatileCall(ret, INTRN_MCCLoadRefVol), ret, opnds, true); ret.GetBB()->InsertMeStmtBefore(&ret, loadCall); ret.SetOpnd(0, loadCall->GetMustDefList()->front().GetLHS()); - loadCall->GetOriExprInRcLowering().push_back(retIvar); } else { std::vector opnds = { &retIvar->GetBase()->GetAddrExprBase(), irMap.CreateAddrofMeExpr(*retIvar) }; MeStmt *loadCall = CreateRCIntrinsic(INTRN_MCCLoadRef, ret, opnds, true); @@ -696,7 +682,6 @@ void RCLowering::HandleReturnReg(RetMeStmt &ret) { } std::vector opnds = { regRet }; IntrinsiccallMeStmt *incCall = CreateRCIntrinsic(INTRN_MCCIncRef, ret, opnds, true); - incCall->GetOriExprInRcLowering().push_back(regRet); ret.SetOpnd(0, incCall->GetMustDefList()->front().GetLHS()); ret.GetBB()->InsertMeStmtBefore(&ret, incCall); } @@ -731,7 +716,6 @@ void RCLowering::HandleReturnWithCleanup() { stmt->GetBB()->InsertMeStmtBefore(stmt, temp); std::vector opnds = { tmpReg }; IntrinsiccallMeStmt *incCall = CreateRCIntrinsic(INTRN_MCCIncRef, *stmt, opnds); - incCall->GetOriExprInRcLowering().push_back(tmpReg); stmt->GetBB()->InsertMeStmtBefore(stmt, incCall); ret->SetOpnd(0, tmpReg); } @@ -788,7 +772,6 @@ void RCLowering::HandleArguments() { if (firstMestmt != nullptr) { std::vector opnds = { argVar }; incCall = CreateRCIntrinsic(INTRN_MCCIncRef, *firstMestmt, opnds); - incCall->GetOriExprInRcLowering().push_back(argVar); firstBB->InsertMeStmtBefore(firstMestmt, incCall); } TypeAttrs typeAttr = mirFunc->GetNthParamAttr(i); @@ -799,7 +782,6 @@ void RCLowering::HandleArguments() { for (auto *stmt : rets) { std::vector opnds = { argVar }; IntrinsiccallMeStmt *decrefCall = CreateRCIntrinsic(INTRN_MCCDecRef, *stmt, opnds); - decrefCall->GetOriExprInRcLowering().push_back(argVar); stmt->GetBB()->InsertMeStmtBefore(stmt, decrefCall); } } diff --git a/src/maple_phase/include/phase_manager.h b/src/maple_phase/include/phase_manager.h index 6e85faa4993a64f10d60b52fcca53a4717e07979..f2eba40bb8ada3aed1925849e6cc60cc5cacc957 100644 --- a/src/maple_phase/include/phase_manager.h +++ b/src/maple_phase/include/phase_manager.h @@ -154,6 +154,5 @@ class PhaseManager { MapleVector phaseSequences; MapleVector phaseTimers; }; - } // namespace maple #endif // MAPLE_PHASE_INCLUDE_PHASE_MANAGER_H diff --git a/src/maple_util/include/muid.h b/src/maple_util/include/muid.h index bafa0e16d6e9a52185fd5b2a290cd0040ea8abfa..f1892607dec7640a58a9bcac643a9c6d34bc1f6f 100644 --- a/src/maple_util/include/muid.h +++ b/src/maple_util/include/muid.h @@ -120,7 +120,7 @@ struct MUID { void MuidInit(MuidContext *status); void MuidDecode(MuidContext *status, const void *data, uint64_t size); -void MuidEncode(unsigned char *result, MuidContext *status, bool use64bit = false); +void MuidEncode(unsigned char *result, MuidContext *status, bool use64Bit = false); MUID GetMUID(const std::string &symbolName, bool forSystem = true); #endif diff --git a/src/maple_util/include/name_mangler.h b/src/maple_util/include/name_mangler.h index e3b319a54c00e9369c615bee9a1b1e5c17858b0a..8658f833e11361be9d8199f75fc79b65f3d97269 100644 --- a/src/maple_util/include/name_mangler.h +++ b/src/maple_util/include/name_mangler.h @@ -144,12 +144,12 @@ std::string DecodeName(const std::string &name); std::string DecodeName(const char *name); void DecodeMapleNameToJavaDescriptor(const std::string &nameIn, std::string &nameOut); -std::string NativeJavaName(const char *name, bool overloaded = true); +std::string NativeJavaName(const char *name, bool overLoaded = true); __attribute__((visibility("default"))) unsigned UTF16ToUTF8(std::string &str, const std::u16string &str16, - unsigned short num = 0, bool isbigendian = false); + unsigned short num = 0, bool isBigEndian = false); __attribute__((visibility("default"))) unsigned UTF8ToUTF16(std::u16string &str16, const std::string &str, - unsigned short num = 0, bool isbigendian = false); + unsigned short num = 0, bool isBigEndian = false); void GetUnsignedLeb128Encode(std::vector &dest, uint32_t value); uint32_t GetUnsignedLeb128Decode(const uint8_t **data); uint64_t GetUleb128Encode(uint64_t val); diff --git a/src/mpl2mpl/src/class_init.cpp b/src/mpl2mpl/src/class_init.cpp index 5123e3f0d477b997f373980492a94137a30de9b2..9764f77af3be289ec5fafd0e1fe2bf16b56157ae 100644 --- a/src/mpl2mpl/src/class_init.cpp +++ b/src/mpl2mpl/src/class_init.cpp @@ -160,7 +160,7 @@ void ClassInit::ProcessFunc(MIRFunction *func) { MIRSymbol *ClassInit::GetClassInfo(const std::string &classname) { const std::string &classInfoName = CLASSINFO_PREFIX_STR + classname; MIRType *classInfoType = - GlobalTables::GetTypeTable().GetOrCreateClassType(NameMangler::kClassMetadataTypeName, GetModule()); + GlobalTables::GetTypeTable().GetOrCreateClassType(NameMangler::kClassMetadataTypeName, *GetModule()); MIRSymbol *classInfo = builder->GetOrCreateGlobalDecl(classInfoName.c_str(), classInfoType); Klass *klass = klassHierarchy->GetKlassFromName(classname); if (klass == nullptr || !klass->GetMIRStructType()->IsLocal()) { diff --git a/src/mpl2mpl/src/gen_check_cast.cpp b/src/mpl2mpl/src/gen_check_cast.cpp index 8e313ff0083f3987f57d5b4596c6469f199f2852..a8d0471b04d965559f169231686ad9098eea132c 100644 --- a/src/mpl2mpl/src/gen_check_cast.cpp +++ b/src/mpl2mpl/src/gen_check_cast.cpp @@ -37,9 +37,9 @@ CheckCastGenerator::CheckCastGenerator(MIRModule *mod, KlassHierarchy *kh, bool void CheckCastGenerator::InitTypes() { - pointerObjType = GlobalTables::GetTypeTable().GetOrCreatePointerType(WKTypes::Util::GetJavaLangObjectType()); - classinfoType = GlobalTables::GetTypeTable().GetOrCreateClassType(NameMangler::kClassMetadataTypeName, GetModule()); - pointerClassMetaType = GlobalTables::GetTypeTable().GetOrCreatePointerType(classinfoType); + pointerObjType = GlobalTables::GetTypeTable().GetOrCreatePointerType(*WKTypes::Util::GetJavaLangObjectType()); + classinfoType = GlobalTables::GetTypeTable().GetOrCreateClassType(NameMangler::kClassMetadataTypeName, *GetModule()); + pointerClassMetaType = GlobalTables::GetTypeTable().GetOrCreatePointerType(*classinfoType); } void CheckCastGenerator::InitFuncs() { diff --git a/src/mpl2mpl/src/java_eh_lower.cpp b/src/mpl2mpl/src/java_eh_lower.cpp index 7c15e820f03fd17fc1745c8df5712b3674490295..5bd9f987fe42d4b885036bc0c84c15d71fa34564 100644 --- a/src/mpl2mpl/src/java_eh_lower.cpp +++ b/src/mpl2mpl/src/java_eh_lower.cpp @@ -110,25 +110,25 @@ BaseNode *JavaEHLowerer::DoLowerExpr(BaseNode *expr, BlockNode *curblk) { } } -void JavaEHLowerer::DoLowerBoundaryCheck(IntrinsiccallNode *intrincall, BlockNode *newblk) { - const size_t intrincallNopndSize = intrincall->GetNopndSize(); +void JavaEHLowerer::DoLowerBoundaryCheck(IntrinsiccallNode &intrincall, BlockNode &newblk) { + const size_t intrincallNopndSize = intrincall.GetNopndSize(); CHECK_FATAL(intrincallNopndSize > 0, "null ptr check"); - BaseNode *opnd0 = intrincall->GetNopndAt(0); + BaseNode *opnd0 = intrincall.GetNopndAt(0); CondGotoNode *brFalseStmt = GetModule()->CurFuncCodeMemPool()->New(OP_brfalse); - brFalseStmt->SetOpnd(DoLowerExpr(opnd0, newblk)); - brFalseStmt->SetSrcPos(intrincall->GetSrcPos()); + brFalseStmt->SetOpnd(DoLowerExpr(opnd0, &newblk)); + brFalseStmt->SetSrcPos(intrincall.GetSrcPos()); LabelIdx lbidx = GetModule()->CurFunction()->GetLabelTab()->CreateLabel(); GetModule()->CurFunction()->GetLabelTab()->AddToStringLabelMap(lbidx); brFalseStmt->SetOffset(lbidx); - newblk->AddStatement(brFalseStmt); + newblk.AddStatement(brFalseStmt); LabelNode *labStmt = GetModule()->CurFuncCodeMemPool()->New(); labStmt->SetLabelIdx(lbidx); MIRFunction *func = GetModule()->GetMIRBuilder()->GetOrCreateFunction(strMCCThrowArrayIndexOutOfBoundsException, TyIdx(PTY_void)); MapleVector args(GetModule()->GetMIRBuilder()->GetCurrentFuncCodeMpAllocator()->Adapter()); CallNode *callStmt = GetModule()->GetMIRBuilder()->CreateStmtCall(func->GetPuidx(), args); - newblk->AddStatement(callStmt); - newblk->AddStatement(labStmt); + newblk.AddStatement(callStmt); + newblk.AddStatement(labStmt); } BlockNode *JavaEHLowerer::DoLowerBlock(BlockNode *block) { @@ -206,7 +206,7 @@ BlockNode *JavaEHLowerer::DoLowerBlock(BlockNode *block) { case OP_intrinsiccall: { IntrinsiccallNode *intrinCall = static_cast(stmt); if (intrinCall->GetIntrinsic() == INTRN_MPL_BOUNDARY_CHECK) { - DoLowerBoundaryCheck(intrinCall, newBlock); + DoLowerBoundaryCheck(*intrinCall, *newBlock); break; } // fallthrough; diff --git a/src/mpl2mpl/src/muid_replacement.cpp b/src/mpl2mpl/src/muid_replacement.cpp index b0ea5e504c8637f6b5ebafec637e8568c48ad9a6..f23ac07b883af7e151f6c0255ffea092feea6fd8 100644 --- a/src/mpl2mpl/src/muid_replacement.cpp +++ b/src/mpl2mpl/src/muid_replacement.cpp @@ -256,7 +256,7 @@ void MUIDReplacement::GenericFuncDefTable() { uint32 idx = 0; size_t arraySize = funcDefMap.size(); MIRArrayType *muidIdxArrayType = - GlobalTables::GetTypeTable().GetOrCreateArrayType(GlobalTables::GetTypeTable().GetUInt32(), arraySize); + GlobalTables::GetTypeTable().GetOrCreateArrayType(*GlobalTables::GetTypeTable().GetUInt32(), arraySize); MIRAggConst *muidIdxTabConst = GetModule()->GetMemPool()->New(GetModule(), muidIdxArrayType); for (auto &keyVal : funcDefMap) { // Fill in the real index @@ -268,33 +268,33 @@ void MUIDReplacement::GenericFuncDefTable() { } FieldVector parentFields; FieldVector fields; - GlobalTables::GetTypeTable().PushIntoFieldVector(&fields, "funcUnifiedAddr", - GlobalTables::GetTypeTable().GetCompactPtr()); + GlobalTables::GetTypeTable().PushIntoFieldVector(fields, "funcUnifiedAddr", + *GlobalTables::GetTypeTable().GetCompactPtr()); MIRStructType *funcDefTabEntryType = static_cast( - GlobalTables::GetTypeTable().GetOrCreateStructType("MUIDFuncDefTabEntry", fields, parentFields, GetModule())); + GlobalTables::GetTypeTable().GetOrCreateStructType("MUIDFuncDefTabEntry", fields, parentFields, *GetModule())); FieldVector funcinffields; - GlobalTables::GetTypeTable().PushIntoFieldVector(&funcinffields, "funcSize", - GlobalTables::GetTypeTable().GetUInt32()); - GlobalTables::GetTypeTable().PushIntoFieldVector(&funcinffields, "funcName", - GlobalTables::GetTypeTable().GetUInt32()); + GlobalTables::GetTypeTable().PushIntoFieldVector(funcinffields, "funcSize", + *GlobalTables::GetTypeTable().GetUInt32()); + GlobalTables::GetTypeTable().PushIntoFieldVector(funcinffields, "funcName", + *GlobalTables::GetTypeTable().GetUInt32()); MIRStructType *funcInfTabEntryType = static_cast(GlobalTables::GetTypeTable().GetOrCreateStructType( - "MUIDFuncInfTabEntry", funcinffields, parentFields, GetModule())); + "MUIDFuncInfTabEntry", funcinffields, parentFields, *GetModule())); FieldVector muidFields; #ifdef USE_64BIT_MUID - GlobalTables::GetTypeTable().PushIntoFieldVector(&muidFields, "muidLow", GlobalTables::GetTypeTable().GetUInt32()); - GlobalTables::GetTypeTable().PushIntoFieldVector(&muidFields, "muidHigh", GlobalTables::GetTypeTable().GetUInt32()); + GlobalTables::GetTypeTable().PushIntoFieldVector(muidFields, "muidLow", *GlobalTables::GetTypeTable().GetUInt32()); + GlobalTables::GetTypeTable().PushIntoFieldVector(muidFields, "muidHigh", *GlobalTables::GetTypeTable().GetUInt32()); #else - GlobalTables::GetTypeTable().PushIntoFieldVector(&muidFields, "muidLow", GlobalTables::GetTypeTable().GetUInt64()); - GlobalTables::GetTypeTable().PushIntoFieldVector(&muidFields, "muidHigh", GlobalTables::GetTypeTable().GetUInt64()); + GlobalTables::GetTypeTable().PushIntoFieldVector(muidFields, "muidLow", *GlobalTables::GetTypeTable().GetUInt64()); + GlobalTables::GetTypeTable().PushIntoFieldVector(muidFields, "muidHigh", *GlobalTables::GetTypeTable().GetUInt64()); #endif // USE_64BIT_MUID MIRStructType *funcDefMuidTabEntryType = static_cast(GlobalTables::GetTypeTable().GetOrCreateStructType( - "MUIDFuncDefMuidTabEntry", muidFields, parentFields, GetModule())); - MIRArrayType *arrayType = GlobalTables::GetTypeTable().GetOrCreateArrayType(funcDefTabEntryType, arraySize); + "MUIDFuncDefMuidTabEntry", muidFields, parentFields, *GetModule())); + MIRArrayType *arrayType = GlobalTables::GetTypeTable().GetOrCreateArrayType(*funcDefTabEntryType, arraySize); MIRAggConst *funcDefTabConst = GetModule()->GetMemPool()->New(GetModule(), arrayType); - MIRArrayType *funcInfArrayType = GlobalTables::GetTypeTable().GetOrCreateArrayType(funcInfTabEntryType, arraySize); + MIRArrayType *funcInfArrayType = GlobalTables::GetTypeTable().GetOrCreateArrayType(*funcInfTabEntryType, arraySize); MIRAggConst *funcInfTabConst = GetModule()->GetMemPool()->New(GetModule(), funcInfArrayType); - MIRArrayType *muidArrayType = GlobalTables::GetTypeTable().GetOrCreateArrayType(funcDefMuidTabEntryType, arraySize); + MIRArrayType *muidArrayType = GlobalTables::GetTypeTable().GetOrCreateArrayType(*funcDefMuidTabEntryType, arraySize); MIRAggConst *funcDefMuidTabConst = GetModule()->GetMemPool()->New(GetModule(), muidArrayType); // Create funcDefSet to store functions sorted by address std::vector> funcDefArray; @@ -397,25 +397,25 @@ void MUIDReplacement::GenericDataDefTable() { } FieldVector parentFields; FieldVector fields; - GlobalTables::GetTypeTable().PushIntoFieldVector(&fields, "dataUnifiedAddr", - GlobalTables::GetTypeTable().GetCompactPtr()); + GlobalTables::GetTypeTable().PushIntoFieldVector(fields, "dataUnifiedAddr", + *GlobalTables::GetTypeTable().GetCompactPtr()); MIRStructType *dataDefTabEntryType = static_cast( - GlobalTables::GetTypeTable().GetOrCreateStructType("MUIDDataDefTabEntry", fields, parentFields, GetModule())); + GlobalTables::GetTypeTable().GetOrCreateStructType("MUIDDataDefTabEntry", fields, parentFields, *GetModule())); FieldVector muidFields; #ifdef USE_64BIT_MUID // USE_64BIT_MUID - GlobalTables::GetTypeTable().PushIntoFieldVector(&muidFields, "muidLow", GlobalTables::GetTypeTable().GetUInt32()); - GlobalTables::GetTypeTable().PushIntoFieldVector(&muidFields, "muidHigh", GlobalTables::GetTypeTable().GetUInt32()); + GlobalTables::GetTypeTable().PushIntoFieldVector(muidFields, "muidLow", *GlobalTables::GetTypeTable().GetUInt32()); + GlobalTables::GetTypeTable().PushIntoFieldVector(muidFields, "muidHigh", *GlobalTables::GetTypeTable().GetUInt32()); #else // USE_128BIT_MUID - GlobalTables::GetTypeTable().PushIntoFieldVector(&muidFields, "muidLow", GlobalTables::GetTypeTable().GetUInt64()); - GlobalTables::GetTypeTable().PushIntoFieldVector(&muidFields, "muidHigh", GlobalTables::GetTypeTable().GetUInt64()); + GlobalTables::GetTypeTable().PushIntoFieldVector(muidFields, "muidLow", *GlobalTables::GetTypeTable().GetUInt64()); + GlobalTables::GetTypeTable().PushIntoFieldVector(muidFields, "muidHigh", *GlobalTables::GetTypeTable().GetUInt64()); #endif MIRStructType *dataDefMuidTabEntryType = static_cast(GlobalTables::GetTypeTable().GetOrCreateStructType( - "MUIDDataDefMuidTabEntry", muidFields, parentFields, GetModule())); + std::string("MUIDDataDefMuidTabEntry"), muidFields, parentFields, *GetModule())); size_t arraySize = dataDefMap.size(); - MIRArrayType *arrayType = GlobalTables::GetTypeTable().GetOrCreateArrayType(dataDefTabEntryType, arraySize); + MIRArrayType *arrayType = GlobalTables::GetTypeTable().GetOrCreateArrayType(*dataDefTabEntryType, arraySize); MIRAggConst *dataDefTabConst = GetModule()->GetMemPool()->New(GetModule(), arrayType); - MIRArrayType *muidArrayType = GlobalTables::GetTypeTable().GetOrCreateArrayType(dataDefMuidTabEntryType, arraySize); + MIRArrayType *muidArrayType = GlobalTables::GetTypeTable().GetOrCreateArrayType(*dataDefMuidTabEntryType, arraySize); MIRAggConst *dataDefMuidTabConst = GetModule()->GetMemPool()->New(GetModule(), muidArrayType); for (auto keyVal : dataDefMap) { MIRSymbol *mirSymbol = keyVal.second.first; @@ -477,27 +477,27 @@ void MUIDReplacement::GenericUnifiedUndefTable() { } FieldVector parentFields; FieldVector fields; - GlobalTables::GetTypeTable().PushIntoFieldVector(&fields, "globalAddress", - GlobalTables::GetTypeTable().GetCompactPtr()); + GlobalTables::GetTypeTable().PushIntoFieldVector(fields, "globalAddress", + *GlobalTables::GetTypeTable().GetCompactPtr()); MIRStructType *unifiedUndefTabEntryType = static_cast(GlobalTables::GetTypeTable().GetOrCreateStructType( - "MUIDUnifiedUndefTabEntry", fields, parentFields, GetModule())); + std::string("MUIDUnifiedUndefTabEntry"), fields, parentFields, *GetModule())); FieldVector muidFields; #ifdef USE_64BIT_MUID - GlobalTables::GetTypeTable().PushIntoFieldVector(&muidFields, "muidLow", GlobalTables::GetTypeTable().GetUInt32()); - GlobalTables::GetTypeTable().PushIntoFieldVector(&muidFields, "muidHigh", GlobalTables::GetTypeTable().GetUInt32()); + GlobalTables::GetTypeTable().PushIntoFieldVector(muidFields, "muidLow", *GlobalTables::GetTypeTable().GetUInt32()); + GlobalTables::GetTypeTable().PushIntoFieldVector(muidFields, "muidHigh", *GlobalTables::GetTypeTable().GetUInt32()); #else - GlobalTables::GetTypeTable().PushIntoFieldVector(&muidFields, "muidLow", GlobalTables::GetTypeTable().GetUInt64()); - GlobalTables::GetTypeTable().PushIntoFieldVector(&muidFields, "muidHigh", GlobalTables::GetTypeTable().GetUInt64()); + GlobalTables::GetTypeTable().PushIntoFieldVector(muidFields, "muidLow", *GlobalTables::GetTypeTable().GetUInt64()); + GlobalTables::GetTypeTable().PushIntoFieldVector(muidFields, "muidHigh", *GlobalTables::GetTypeTable().GetUInt64()); #endif MIRStructType *unifiedUndefMuidTabEntryType = static_cast(GlobalTables::GetTypeTable().GetOrCreateStructType( - "MUIDUnifiedUndefMuidTabEntry", muidFields, parentFields, GetModule())); + "MUIDUnifiedUndefMuidTabEntry", muidFields, parentFields, *GetModule())); size_t arraySize = funcUndefMap.size(); - MIRArrayType *funcArrayType = GlobalTables::GetTypeTable().GetOrCreateArrayType(unifiedUndefTabEntryType, arraySize); + MIRArrayType *funcArrayType = GlobalTables::GetTypeTable().GetOrCreateArrayType(*unifiedUndefTabEntryType, arraySize); MIRAggConst *funcUndefTabConst = GetModule()->GetMemPool()->New(GetModule(), funcArrayType); MIRArrayType *funcMuidArrayType = - GlobalTables::GetTypeTable().GetOrCreateArrayType(unifiedUndefMuidTabEntryType, arraySize); + GlobalTables::GetTypeTable().GetOrCreateArrayType(*unifiedUndefMuidTabEntryType, arraySize); MIRAggConst *funcUndefMuidTabConst = GetModule()->GetMemPool()->New(GetModule(), funcMuidArrayType); for (auto keyVal : funcUndefMap) { MUID muid = keyVal.first; @@ -534,10 +534,10 @@ void MUIDReplacement::GenericUnifiedUndefTable() { } // Continue to generate dataUndefTab arraySize = dataUndefMap.size(); - MIRArrayType *dataArrayType = GlobalTables::GetTypeTable().GetOrCreateArrayType(unifiedUndefTabEntryType, arraySize); + MIRArrayType *dataArrayType = GlobalTables::GetTypeTable().GetOrCreateArrayType(*unifiedUndefTabEntryType, arraySize); MIRAggConst *dataUndefTabConst = GetModule()->GetMemPool()->New(GetModule(), dataArrayType); MIRArrayType *dataMuidArrayType = - GlobalTables::GetTypeTable().GetOrCreateArrayType(unifiedUndefMuidTabEntryType, arraySize); + GlobalTables::GetTypeTable().GetOrCreateArrayType(*unifiedUndefMuidTabEntryType, arraySize); MIRAggConst *dataUndefMuidTabConst = GetModule()->GetMemPool()->New(GetModule(), dataMuidArrayType); for (auto keyVal : dataUndefMap) { MIRAggConst *entryConst = GetModule()->GetMemPool()->New(GetModule(), unifiedUndefTabEntryType); @@ -578,11 +578,11 @@ void MUIDReplacement::GenericUnifiedUndefTable() { void MUIDReplacement::GenericRangeTable() { FieldVector parentFields; FieldVector fields; - GlobalTables::GetTypeTable().PushIntoFieldVector(&fields, "tabBegin", GlobalTables::GetTypeTable().GetVoidPtr()); - GlobalTables::GetTypeTable().PushIntoFieldVector(&fields, "tabEnd", GlobalTables::GetTypeTable().GetVoidPtr()); + GlobalTables::GetTypeTable().PushIntoFieldVector(fields, "tabBegin", *GlobalTables::GetTypeTable().GetVoidPtr()); + GlobalTables::GetTypeTable().PushIntoFieldVector(fields, "tabEnd", *GlobalTables::GetTypeTable().GetVoidPtr()); MIRStructType *rangeTabEntryType = static_cast( - GlobalTables::GetTypeTable().GetOrCreateStructType("MUIDRangeTabEntry", fields, parentFields, GetModule())); - MIRArrayType *rangeArrayType = GlobalTables::GetTypeTable().GetOrCreateArrayType(rangeTabEntryType, 0); + GlobalTables::GetTypeTable().GetOrCreateStructType("MUIDRangeTabEntry", fields, parentFields, *GetModule())); + MIRArrayType *rangeArrayType = GlobalTables::GetTypeTable().GetOrCreateArrayType(*rangeTabEntryType, 0); MIRAggConst *rangeTabConst = GetModule()->GetMemPool()->New(GetModule(), rangeArrayType); // First entry is reserved for a compile-time-stamp // Second entry is reserved for a decouple-stamp @@ -847,7 +847,7 @@ void MUIDReplacement::ReplaceDirectInvokeOrAddroffunc(MIRFunction ¤tFunc, MIRType *elemType = arrayType->GetElemType(); BaseNode *ireadPtrExpr = builder->CreateExprIread(GlobalTables::GetTypeTable().GetVoidPtr(), - GlobalTables::GetTypeTable().GetOrCreatePointerType(elemType), 1, arrayExpr); + GlobalTables::GetTypeTable().GetOrCreatePointerType(*elemType), 1, arrayExpr); PregIdx funcPtrPreg = 0; MIRSymbol *funcPtrSym = nullptr; BaseNode *readFuncPtr = nullptr; @@ -865,7 +865,7 @@ void MUIDReplacement::ReplaceDirectInvokeOrAddroffunc(MIRFunction ¤tFunc, if (callNode != nullptr) { // Create icallNode to replace callNode IcallNode *icallNode = GetModule()->CurFuncCodeMemPool()->New( - GetModule(), callNode->GetOpCode() == OP_call ? OP_icall : OP_icallassigned); + *GetModule(), callNode->GetOpCode() == OP_call ? OP_icall : OP_icallassigned); icallNode->SetNumOpnds(callNode->GetNumOpnds() + 1); icallNode->GetNopnd().resize(icallNode->GetNumOpnds()); icallNode->SetNOpndAt(0, readFuncPtr); @@ -915,7 +915,7 @@ void MUIDReplacement::ReplaceDassign(MIRFunction ¤tFunc, DassignNode &dass MIRType *mVoidPtr = GlobalTables::GetTypeTable().GetVoidPtr(); CHECK_FATAL(mVoidPtr != nullptr, "null ptr check"); BaseNode *ireadPtrExpr = - builder->CreateExprIread(mVoidPtr, GlobalTables::GetTypeTable().GetOrCreatePointerType(elemType), 1, arrayExpr); + builder->CreateExprIread(mVoidPtr, GlobalTables::GetTypeTable().GetOrCreatePointerType(*elemType), 1, arrayExpr); PregIdx symPtrPreg = 0; MIRSymbol *symPtrSym = nullptr; BaseNode *destExpr = nullptr; @@ -931,7 +931,7 @@ void MUIDReplacement::ReplaceDassign(MIRFunction ¤tFunc, DassignNode &dass destExpr = builder->CreateExprDread(symPtrSym); } // Replace dassignNode with iassignNode - MIRType *destPtrType = GlobalTables::GetTypeTable().GetOrCreatePointerType(mirSymbol->GetType()); + MIRType *destPtrType = GlobalTables::GetTypeTable().GetOrCreatePointerType(*mirSymbol->GetType()); StmtNode *iassignNode = builder->CreateStmtIassign(destPtrType, 0, destExpr, dassignNode.Opnd(0)); currentFunc.GetBody()->ReplaceStmt1WithStmt2(&dassignNode, iassignNode); } @@ -1046,12 +1046,12 @@ BaseNode *MUIDReplacement::ReplaceDread(MIRFunction ¤tFunc, StmtNode *stmt MIRType *elemType = arrayType->GetElemType(); BaseNode *ireadPtrExpr = builder->CreateExprIread(GlobalTables::GetTypeTable().GetVoidPtr(), - GlobalTables::GetTypeTable().GetOrCreatePointerType(elemType), 1, arrayExpr); + GlobalTables::GetTypeTable().GetOrCreatePointerType(*elemType), 1, arrayExpr); if (opnd->GetOpCode() == OP_addrof) { return ireadPtrExpr; } MIRType *destType = mirSymbol->GetType(); - MIRType *destPtrType = GlobalTables::GetTypeTable().GetOrCreatePointerType(destType); + MIRType *destPtrType = GlobalTables::GetTypeTable().GetOrCreatePointerType(*destType); return builder->CreateExprIread(destType, destPtrType, 0, ireadPtrExpr); } @@ -1084,7 +1084,7 @@ void MUIDReplacement::ProcessFunc(MIRFunction *func) { // Create GC Root void MUIDReplacement::GenericGlobalRootList() { MIRType *voidType = GlobalTables::GetTypeTable().GetVoidPtr(); - MIRArrayType *arrayType = GlobalTables::GetTypeTable().GetOrCreateArrayType(voidType, 0); + MIRArrayType *arrayType = GlobalTables::GetTypeTable().GetOrCreateArrayType(*voidType, 0); MIRAggConst *newConst = GetModule()->GetMemPool()->New(GetModule(), arrayType); for (StIdx stidx : GetModule()->GetSymbolSet()) { MIRSymbol *symbol = GlobalTables::GetGsymTable().GetSymbolFromStidx(stidx.Idx()); @@ -1127,7 +1127,7 @@ void MUIDReplacement::GenericGlobalRootList() { void MUIDReplacement::GenericCompilerVersionNum() { MIRType *ptrType = GlobalTables::GetTypeTable().GetVoidPtr(); - MIRArrayType *arrayType = GlobalTables::GetTypeTable().GetOrCreateArrayType(ptrType, 0); + MIRArrayType *arrayType = GlobalTables::GetTypeTable().GetOrCreateArrayType(*ptrType, 0); MIRAggConst *newConst = GetModule()->GetMemPool()->New(GetModule(), arrayType); MIRType *type = GlobalTables::GetTypeTable().GetInt32(); MIRConst *firstConst = GetModule()->GetMemPool()->New(Version::kMajorMplVersion, type); diff --git a/src/mpl2mpl/src/native_stub_func.cpp b/src/mpl2mpl/src/native_stub_func.cpp index 61879c4d25c636a04d72917f9de662daeeab9565..198f48d1b44ac76a70a364148657d68281a3f9e8 100644 --- a/src/mpl2mpl/src/native_stub_func.cpp +++ b/src/mpl2mpl/src/native_stub_func.cpp @@ -28,9 +28,9 @@ namespace maple { GenericNativeStubFunc::GenericNativeStubFunc(MIRModule *mod, KlassHierarchy *kh, bool dump) : FuncOptimizeImpl(mod, kh, dump) { MIRType *jstrType = GlobalTables::GetTypeTable().GetOrCreateClassType( - NameMangler::GetInternalNameLiteral(NameMangler::kJavaLangStringStr).c_str(), mod); + NameMangler::GetInternalNameLiteral(NameMangler::kJavaLangStringStr), *mod); MIRPtrType *jstrPointerType = - static_cast(GlobalTables::GetTypeTable().GetOrCreatePointerType(jstrType, PTY_ref)); + static_cast(GlobalTables::GetTypeTable().GetOrCreatePointerType(*jstrType, PTY_ref)); jstrPointerTypeIdx = jstrPointerType->GetTypeIndex(); GenericRegTableEntryType(); GenericHelperFuncDecl(); @@ -288,7 +288,7 @@ void GenericNativeStubFunc::ProcessFunc(MIRFunction *func) { void GenericNativeStubFunc::GenericRegFuncTabEntryType() { MIRArrayType *arrayType = - GlobalTables::GetTypeTable().GetOrCreateArrayType(GlobalTables::GetTypeTable().GetVoidPtr(), 0); + GlobalTables::GetTypeTable().GetOrCreateArrayType(*GlobalTables::GetTypeTable().GetVoidPtr(), 0); regFuncTabConst = GetModule()->GetMemPool()->New(GetModule(), arrayType); std::string regFuncTab = NameMangler::kRegJNIFuncTabPrefixStr + GetModule()->GetFileNameAsPostfix(); regFuncSymbol = builder->CreateSymbol(regFuncTabConst->GetType()->GetTypeIndex(), regFuncTab.c_str(), kStVar, @@ -351,7 +351,7 @@ void GenericNativeStubFunc::GenericRegisteredNativeFuncCall(MIRFunction &func, c arrayExpr->SetBoundsCheck(false); MIRType *elemType = static_cast(regArrayType)->GetElemType(); BaseNode *ireadExpr = - builder->CreateExprIread(elemType, GlobalTables::GetTypeTable().GetOrCreatePointerType(elemType), 0, arrayExpr); + builder->CreateExprIread(elemType, GlobalTables::GetTypeTable().GetOrCreatePointerType(*elemType), 0, arrayExpr); // assign registered func ptr to a preg. auto funcptrPreg = func.GetPregTab()->CreatePreg(PTY_ptr); RegassignNode *funcptrAssign = builder->CreateStmtRegassign(PTY_ptr, funcptrPreg, ireadExpr); @@ -420,7 +420,7 @@ void GenericNativeStubFunc::GenericRegisteredNativeFuncCall(MIRFunction &func, c // Rewrite reg_jni_func_tab with current funcIdx_ptr(weak/strong symbol address) auto nativeMethodPtr = builder->CreateExprRegread(PTY_ptr, funcptrPreg); IassignNode *nativeFuncTableEntry = builder->CreateStmtIassign( - GlobalTables::GetTypeTable().GetOrCreatePointerType(elemType), 0, arrayExpr, nativeMethodPtr); + GlobalTables::GetTypeTable().GetOrCreatePointerType(*elemType), 0, arrayExpr, nativeMethodPtr); subIfStmt->GetThenPart()->AddStatement(nativeFuncTableEntry); // Add if-statement to function body if (!needNativeCall) { @@ -480,7 +480,7 @@ void GenericNativeStubFunc::GenericRegisteredNativeFuncCall(MIRFunction &func, c return; } // Without native wrapper - IcallNode *icall = func.GetCodeMempool()->New(GetModule(), OP_icallassigned); + IcallNode *icall = func.GetCodeMempool()->New(*GetModule(), OP_icallassigned); icall->SetNumOpnds(args.size() + 1); icall->GetNopnd().resize(icall->GetNumOpnds()); icall->SetReturnVec(nrets); @@ -518,7 +518,7 @@ StmtNode *GenericNativeStubFunc::CreateNativeWrapperCallNode(MIRFunction &func, // if num_of_args < 8 constexpr size_t kNumOfArgs = 8; if (func.GetAttr(FUNCATTR_critical_native) && args.size() < kNumOfArgs) { - IcallNode *icall = func.GetCodeMempool()->New(GetModule(), OP_icallassigned); + IcallNode *icall = func.GetCodeMempool()->New(*GetModule(), OP_icallassigned); CallReturnVector nrets(func.GetCodeMempoolAllocator()->Adapter()); if (ret != nullptr) { CHECK_FATAL((ret->GetStorageClass() == kScAuto || ret->GetStorageClass() == kScFormal || @@ -566,7 +566,7 @@ void GenericNativeStubFunc::GenericNativeWrapperFuncCall(MIRFunction &func, cons void GenericNativeStubFunc::GenericRegTableEntryType() { // Use MIRIntType instead of MIRStructType in RegTableEntry MIRArrayType *arrayType = - GlobalTables::GetTypeTable().GetOrCreateArrayType(GlobalTables::GetTypeTable().GetVoidPtr(), 0); + GlobalTables::GetTypeTable().GetOrCreateArrayType(*GlobalTables::GetTypeTable().GetVoidPtr(), 0); regTableConst = GetModule()->GetMemPool()->New(GetModule(), arrayType); } diff --git a/src/mpl2mpl/src/reflection_analysis.cpp b/src/mpl2mpl/src/reflection_analysis.cpp index ea622ed388db81ec142d681f2ae5632a99e0ec49..9bee02476a354bfa647e9446748be157fae5b15c 100644 --- a/src/mpl2mpl/src/reflection_analysis.cpp +++ b/src/mpl2mpl/src/reflection_analysis.cpp @@ -100,14 +100,14 @@ BaseNode *ReflectionAnalysis::GenClassInfoAddr(BaseNode *obj, MIRBuilder *builde BaseNode *classinfoAddress = nullptr; if (objectType != nullptr && objectType->GetKind() != kTypeClassIncomplete) { classinfoAddress = builder->CreateExprIread(GlobalTables::GetTypeTable().GetRef(), - GlobalTables::GetTypeTable().GetOrCreatePointerType(objectType), + GlobalTables::GetTypeTable().GetOrCreatePointerType(*objectType), OBJ_KLASS_FIELDID, obj); } else { // If java.lang.Object type is not defined, fall back to use the classinfo struct to retrieve the first field. MIRStructType *classMetadataType = static_cast( GlobalTables::GetTypeTable().GetTypeFromTyIdx(ReflectionAnalysis::classMetadataTyIdx)); classinfoAddress = builder->CreateExprIread(GlobalTables::GetTypeTable().GetRef(), - GlobalTables::GetTypeTable().GetOrCreatePointerType(classMetadataType), + GlobalTables::GetTypeTable().GetOrCreatePointerType(*classMetadataType), METADATA_KLASS_FIELDID, obj); } return classinfoAddress; @@ -486,7 +486,7 @@ MIRSymbol *ReflectionAnalysis::CreateSymbol(GStrIdx strIdx, TyIdx tyIdx) { st->SetStorageClass(kScGlobal); st->SetSKind(kStVar); st->SetNameStrIdx(strIdx); - GlobalTables::GetGsymTable().AddToStringSymbolMap(st); + GlobalTables::GetGsymTable().AddToStringSymbolMap(*st); st->SetAttr(ATTR_public); st->SetTyIdx(tyIdx); return st; @@ -658,7 +658,7 @@ MIRSymbol *ReflectionAnalysis::GenMethodsMetaData(const Klass *klass) { size_t arraySize = classType->GetMethods().size(); MIRStructType *methodsInfoType = static_cast(GlobalTables::GetTypeTable().GetTypeFromTyIdx(methodsInfoTyIdx)); - MIRArrayType *arraytype = GlobalTables::GetTypeTable().GetOrCreateArrayType(methodsInfoType, arraySize); + MIRArrayType *arraytype = GlobalTables::GetTypeTable().GetOrCreateArrayType(*methodsInfoType, arraySize); MIRAggConst *aggconst = mirModule->GetMemPool()->New(mirModule, arraytype); std::vector> methodinfoVec; for (MethodPair &methodPair : classType->GetMethods()) { @@ -746,7 +746,7 @@ MIRSymbol *ReflectionAnalysis::GenSuperClassMetaData(const Klass *klass, std::li size_t size = superClassList.size(); MIRStructType *superclassMetadataType = static_cast(GlobalTables::GetTypeTable().GetTypeFromTyIdx(superclassMetadataTyIdx)); - MIRArrayType *arrayType = GlobalTables::GetTypeTable().GetOrCreateArrayType(superclassMetadataType, size); + MIRArrayType *arrayType = GlobalTables::GetTypeTable().GetOrCreateArrayType(*superclassMetadataType, size); MIRAggConst *aggconst = mirModule->GetMemPool()->New(mirModule, arrayType); for (auto it = superClassList.begin(); it != superClassList.end(); ++it) { MIRSymbol *dklassSt = GetOrCreateSymbol(CLASSINFO_PREFIX_STR + (*it)->GetKlassName(), classMetadataTyIdx); @@ -789,7 +789,7 @@ MIRSymbol *ReflectionAnalysis::GenFieldsMetaData(const Klass *klass) { } MIRStructType *fieldsInfoType = static_cast(GlobalTables::GetTypeTable().GetTypeFromTyIdx(fieldsInfoTyIdx)); - MIRArrayType *arraytype = GlobalTables::GetTypeTable().GetOrCreateArrayType(fieldsInfoType, size); + MIRArrayType *arraytype = GlobalTables::GetTypeTable().GetOrCreateArrayType(*fieldsInfoType, size); MIRAggConst *aggconst = mirModule->GetMemPool()->New(mirModule, arraytype); std::vector> fieldHashvec(size); size_t i = 0; @@ -1487,92 +1487,92 @@ void ReflectionAnalysis::GenMetadataType(MIRModule *mirModule) { MIRType *typeU64 = GlobalTables::GetTypeTable().GetUInt64(); MIRType *typeVoidPtr = GlobalTables::GetTypeTable().GetVoidPtr(); MIRStructType classMetadataType(kTypeStruct); - GlobalTables::GetTypeTable().AddFieldToStructType(&classMetadataType, kShadowStr, GetRefFieldType(&mirBuilder)); - GlobalTables::GetTypeTable().AddFieldToStructType(&classMetadataType, kMonitorStr, typeI32); - GlobalTables::GetTypeTable().AddFieldToStructType(&classMetadataType, kClassloaderStr, typeU16); - GlobalTables::GetTypeTable().AddFieldToStructType(&classMetadataType, kObjsizeStr, typeU16); + GlobalTables::GetTypeTable().AddFieldToStructType(classMetadataType, kShadowStr, *GetRefFieldType(&mirBuilder)); + GlobalTables::GetTypeTable().AddFieldToStructType(classMetadataType, kMonitorStr, *typeI32); + GlobalTables::GetTypeTable().AddFieldToStructType(classMetadataType, kClassloaderStr, *typeU16); + GlobalTables::GetTypeTable().AddFieldToStructType(classMetadataType, kObjsizeStr, *typeU16); #ifdef USE_32BIT_REF - GlobalTables::GetTypeTable().AddFieldToStructType(&classMetadataType, kFlagStr, typeU16); - GlobalTables::GetTypeTable().AddFieldToStructType(&classMetadataType, kNumofsuperclassesStr, typeU16); + GlobalTables::GetTypeTable().AddFieldToStructType(classMetadataType, kFlagStr, *typeU16); + GlobalTables::GetTypeTable().AddFieldToStructType(classMetadataType, kNumofsuperclassesStr, *typeU16); #endif // USE_32BIT_REF - GlobalTables::GetTypeTable().AddFieldToStructType(&classMetadataType, kItabStr, typeVoidPtr); - GlobalTables::GetTypeTable().AddFieldToStructType(&classMetadataType, kVtabStr, typeVoidPtr); - GlobalTables::GetTypeTable().AddFieldToStructType(&classMetadataType, kGctibStr, typeVoidPtr); - GlobalTables::GetTypeTable().AddFieldToStructType(&classMetadataType, kClassinforoStr, typeVoidPtr); - GlobalTables::GetTypeTable().AddFieldToStructType(&classMetadataType, kClinitbridgeStr, typeVoidPtr); + GlobalTables::GetTypeTable().AddFieldToStructType(classMetadataType, kItabStr, *typeVoidPtr); + GlobalTables::GetTypeTable().AddFieldToStructType(classMetadataType, kVtabStr, *typeVoidPtr); + GlobalTables::GetTypeTable().AddFieldToStructType(classMetadataType, kGctibStr, *typeVoidPtr); + GlobalTables::GetTypeTable().AddFieldToStructType(classMetadataType, kClassinforoStr, *typeVoidPtr); + GlobalTables::GetTypeTable().AddFieldToStructType(classMetadataType, kClinitbridgeStr, *typeVoidPtr); classMetadataTyIdx = GenMetaStructType(mirModule, classMetadataType, kClassMetadataTypeName); MIRStructType classMetadataROType(kTypeStruct); - GlobalTables::GetTypeTable().AddFieldToStructType(&classMetadataROType, kClassnameStr, typeVoidPtr); - GlobalTables::GetTypeTable().AddFieldToStructType(&classMetadataROType, kIfieldsStr, typeVoidPtr); - GlobalTables::GetTypeTable().AddFieldToStructType(&classMetadataROType, kMethodsStr, typeVoidPtr); + GlobalTables::GetTypeTable().AddFieldToStructType(classMetadataROType, kClassnameStr, *typeVoidPtr); + GlobalTables::GetTypeTable().AddFieldToStructType(classMetadataROType, kIfieldsStr, *typeVoidPtr); + GlobalTables::GetTypeTable().AddFieldToStructType(classMetadataROType, kMethodsStr, *typeVoidPtr); // For array, this is component class; For primitive type, this is nullptr; // For general class, this is superclass (only one superclass), this is a pointer to a superclass&interface array. - GlobalTables::GetTypeTable().AddFieldToStructType(&classMetadataROType, kSuperclassOrComponentclassStr, typeVoidPtr); - GlobalTables::GetTypeTable().AddFieldToStructType(&classMetadataROType, kNumoffieldsStr, typeU16); - GlobalTables::GetTypeTable().AddFieldToStructType(&classMetadataROType, kNumofmethodsStr, typeU16); + GlobalTables::GetTypeTable().AddFieldToStructType(classMetadataROType, kSuperclassOrComponentclassStr, *typeVoidPtr); + GlobalTables::GetTypeTable().AddFieldToStructType(classMetadataROType, kNumoffieldsStr, *typeU16); + GlobalTables::GetTypeTable().AddFieldToStructType(classMetadataROType, kNumofmethodsStr, *typeU16); #ifndef USE_32BIT_REF - GlobalTables::GetTypeTable().AddFieldToStructType(&classMetadataROType, kFlagStr, typeU16); - GlobalTables::GetTypeTable().AddFieldToStructType(&classMetadataROType, kNumofsuperclassesStr, typeU16); - GlobalTables::GetTypeTable().AddFieldToStructType(&classMetadataROType, kPaddingStr, typeU32); + GlobalTables::GetTypeTable().AddFieldToStructType(classMetadataROType, kFlagStr, *typeU16); + GlobalTables::GetTypeTable().AddFieldToStructType(classMetadataROType, kNumofsuperclassesStr, *typeU16); + GlobalTables::GetTypeTable().AddFieldToStructType(classMetadataROType, kPaddingStr, *typeU32); #endif // USE_32BIT_REF - GlobalTables::GetTypeTable().AddFieldToStructType(&classMetadataROType, kModStr, typeI32); - GlobalTables::GetTypeTable().AddFieldToStructType(&classMetadataROType, kAnnotationStr, typeI32); - GlobalTables::GetTypeTable().AddFieldToStructType(&classMetadataROType, kClinitAddrStr, typeI32); + GlobalTables::GetTypeTable().AddFieldToStructType(classMetadataROType, kModStr, *typeI32); + GlobalTables::GetTypeTable().AddFieldToStructType(classMetadataROType, kAnnotationStr, *typeI32); + GlobalTables::GetTypeTable().AddFieldToStructType(classMetadataROType, kClinitAddrStr, *typeI32); classMetadataRoTyIdx = GenMetaStructType(mirModule, classMetadataROType, kClassMetadataRoTypeName); // MethodInfoType. MIRStructType methodInfoType(kTypeStruct); #ifdef USE_32BIT_REF - GlobalTables::GetTypeTable().AddFieldToStructType(&methodInfoType, kMethodInVtabIndexStr, typeI32); - GlobalTables::GetTypeTable().AddFieldToStructType(&methodInfoType, kDeclaringclassStr, typeI32); - GlobalTables::GetTypeTable().AddFieldToStructType(&methodInfoType, kAddrStr, typeI32); + GlobalTables::GetTypeTable().AddFieldToStructType(methodInfoType, kMethodInVtabIndexStr, *typeI32); + GlobalTables::GetTypeTable().AddFieldToStructType(methodInfoType, kDeclaringclassStr, *typeI32); + GlobalTables::GetTypeTable().AddFieldToStructType(methodInfoType, kAddrStr, *typeI32); #else - GlobalTables::GetTypeTable().AddFieldToStructType(&methodInfoType, kMethodInVtabIndexStr, typeI64); - GlobalTables::GetTypeTable().AddFieldToStructType(&methodInfoType, kDeclaringclassStr, typeI64); - GlobalTables::GetTypeTable().AddFieldToStructType(&methodInfoType, kAddrStr, typeI64); + GlobalTables::GetTypeTable().AddFieldToStructType(methodInfoType, kMethodInVtabIndexStr, *typeI64); + GlobalTables::GetTypeTable().AddFieldToStructType(methodInfoType, kDeclaringclassStr, *typeI64); + GlobalTables::GetTypeTable().AddFieldToStructType(methodInfoType, kAddrStr, *typeI64); #endif - GlobalTables::GetTypeTable().AddFieldToStructType(&methodInfoType, kModStr, typeI32); - GlobalTables::GetTypeTable().AddFieldToStructType(&methodInfoType, kMethodnameStr, typeI32); - GlobalTables::GetTypeTable().AddFieldToStructType(&methodInfoType, kSignaturenameStr, typeI32); - GlobalTables::GetTypeTable().AddFieldToStructType(&methodInfoType, kAnnotationvalueStr, typeI32); - GlobalTables::GetTypeTable().AddFieldToStructType(&methodInfoType, kFlagStr, typeU16); - GlobalTables::GetTypeTable().AddFieldToStructType(&methodInfoType, kArgsizeStr, typeU16); + GlobalTables::GetTypeTable().AddFieldToStructType(methodInfoType, kModStr, *typeI32); + GlobalTables::GetTypeTable().AddFieldToStructType(methodInfoType, kMethodnameStr, *typeI32); + GlobalTables::GetTypeTable().AddFieldToStructType(methodInfoType, kSignaturenameStr, *typeI32); + GlobalTables::GetTypeTable().AddFieldToStructType(methodInfoType, kAnnotationvalueStr, *typeI32); + GlobalTables::GetTypeTable().AddFieldToStructType(methodInfoType, kFlagStr, *typeU16); + GlobalTables::GetTypeTable().AddFieldToStructType(methodInfoType, kArgsizeStr, *typeU16); #ifndef USE_32BIT_REF - GlobalTables::GetTypeTable().AddFieldToStructType(&methodInfoType, kPaddingStr, typeU32); + GlobalTables::GetTypeTable().AddFieldToStructType(methodInfoType, kPaddingStr, *typeU32); #endif // USE_32BIT_REF methodsInfoTyIdx = GenMetaStructType(mirModule, methodInfoType, kMethodInfoTypeName); // MethodInfoCompactType. MIRStructType methodInfoCompactType(kTypeStruct); - GlobalTables::GetTypeTable().AddFieldToStructType(&methodInfoCompactType, kMethodInVtabIndexStr, typeI32); - GlobalTables::GetTypeTable().AddFieldToStructType(&methodInfoCompactType, kAddrStr, typeI32); - GlobalTables::GetTypeTable().AddFieldToStructType(&methodInfoCompactType, kLebPadding0Str, typeU8); + GlobalTables::GetTypeTable().AddFieldToStructType(methodInfoCompactType, kMethodInVtabIndexStr, *typeI32); + GlobalTables::GetTypeTable().AddFieldToStructType(methodInfoCompactType, kAddrStr, *typeI32); + GlobalTables::GetTypeTable().AddFieldToStructType(methodInfoCompactType, kLebPadding0Str, *typeU8); methodsInfoCompactTyIdx = GenMetaStructType(mirModule, methodInfoCompactType, kMethodInfoCompactTypeName); // FieldInfoType. MIRStructType fieldInfoType(kTypeStruct); #ifndef USE_32BIT_REF - GlobalTables::GetTypeTable().AddFieldToStructType(&fieldInfoType, kOffsetStr, typeU64); + GlobalTables::GetTypeTable().AddFieldToStructType(fieldInfoType, kOffsetStr, *typeU64); #else - GlobalTables::GetTypeTable().AddFieldToStructType(&fieldInfoType, kOffsetStr, typeI32); + GlobalTables::GetTypeTable().AddFieldToStructType(fieldInfoType, kOffsetStr, *typeI32); #endif // USE_32BIT_REF - GlobalTables::GetTypeTable().AddFieldToStructType(&fieldInfoType, kModStr, typeU32); - GlobalTables::GetTypeTable().AddFieldToStructType(&fieldInfoType, kFlagStr, typeU16); - GlobalTables::GetTypeTable().AddFieldToStructType(&fieldInfoType, kIndexStr, typeU16); + GlobalTables::GetTypeTable().AddFieldToStructType(fieldInfoType, kModStr, *typeU32); + GlobalTables::GetTypeTable().AddFieldToStructType(fieldInfoType, kFlagStr, *typeU16); + GlobalTables::GetTypeTable().AddFieldToStructType(fieldInfoType, kIndexStr, *typeU16); #ifndef USE_32BIT_REF - GlobalTables::GetTypeTable().AddFieldToStructType(&fieldInfoType, kTypeNameStr, typeI64); + GlobalTables::GetTypeTable().AddFieldToStructType(fieldInfoType, kTypeNameStr, *typeI64); #else - GlobalTables::GetTypeTable().AddFieldToStructType(&fieldInfoType, kTypeNameStr, typeI32); + GlobalTables::GetTypeTable().AddFieldToStructType(fieldInfoType, kTypeNameStr, *typeI32); #endif // USE_32BIT_REF - GlobalTables::GetTypeTable().AddFieldToStructType(&fieldInfoType, kFieldnameStr, typeU32); - GlobalTables::GetTypeTable().AddFieldToStructType(&fieldInfoType, kAnnotationStr, typeU32); - GlobalTables::GetTypeTable().AddFieldToStructType(&fieldInfoType, kDeclaringclassStr, GetRefFieldType(&mirBuilder)); + GlobalTables::GetTypeTable().AddFieldToStructType(fieldInfoType, kFieldnameStr, *typeU32); + GlobalTables::GetTypeTable().AddFieldToStructType(fieldInfoType, kAnnotationStr, *typeU32); + GlobalTables::GetTypeTable().AddFieldToStructType(fieldInfoType, kDeclaringclassStr, *GetRefFieldType(&mirBuilder)); fieldsInfoTyIdx = GenMetaStructType(mirModule, fieldInfoType, kFieldInfoTypeName); // FieldInfoType Compact. MIRStructType fieldInfoCompactType(kTypeStruct); - GlobalTables::GetTypeTable().AddFieldToStructType(&fieldInfoCompactType, kOffsetStr, typeU32); - GlobalTables::GetTypeTable().AddFieldToStructType(&fieldInfoCompactType, kLebPadding0Str, typeU8); + GlobalTables::GetTypeTable().AddFieldToStructType(fieldInfoCompactType, kOffsetStr, *typeU32); + GlobalTables::GetTypeTable().AddFieldToStructType(fieldInfoCompactType, kLebPadding0Str, *typeU8); fieldsInfoCompactTyIdx = GenMetaStructType(mirModule, fieldInfoCompactType, kFieldInfoCompactTypeName); // SuperClassMetaType. MIRStructType superclassMetadataType(kTypeStruct); - GlobalTables::GetTypeTable().AddFieldToStructType(&superclassMetadataType, kSuperclassinfoStr, typeVoidPtr); + GlobalTables::GetTypeTable().AddFieldToStructType(superclassMetadataType, kSuperclassinfoStr, *typeVoidPtr); superclassMetadataTyIdx = GenMetaStructType(mirModule, superclassMetadataType, kSuperclassMetadataTypeName); } @@ -1587,7 +1587,7 @@ void ReflectionAnalysis::GenClassHashMetaData() { } std::string bucketName = NameMangler::kMuidClassMetadataBucketPrefixStr + mirModule->GetFileNameAsPostfix(); size_t bucketArraySize = classTab.size(); - MIRArrayType *bucketArraytype = GlobalTables::GetTypeTable().GetOrCreateArrayType(type, bucketArraySize); + MIRArrayType *bucketArraytype = GlobalTables::GetTypeTable().GetOrCreateArrayType(*type, bucketArraySize); MIRSymbol *bucketSt = GetOrCreateSymbol(bucketName, bucketArraytype->GetTypeIndex(), true); MIRAggConst *bucketAggconst = mirModule->GetMemPool()->New(mirModule, bucketArraytype); if (bucketAggconst == nullptr) { @@ -1611,7 +1611,7 @@ static void ReflectionAnalysisGenStrTab(MIRModule *mirModule, const std::string return; } MIRArrayType *strtabType = - GlobalTables::GetTypeTable().GetOrCreateArrayType(GlobalTables::GetTypeTable().GetUInt8(), strtabSize); + GlobalTables::GetTypeTable().GetOrCreateArrayType(*GlobalTables::GetTypeTable().GetUInt8(), strtabSize); MIRSymbol *strtabSt = mirBuilder.CreateGlobalDecl(strtabName.c_str(), strtabType); MIRAggConst *strtabAggconst = mirModule->GetMemPool()->New(mirModule, strtabType); if (strtabAggconst == nullptr) { diff --git a/src/mpl2mpl/src/vtable_analysis.cpp b/src/mpl2mpl/src/vtable_analysis.cpp index 2a7d531e6493e626b97809a37c4246c4f0925337..f02699d8c2058445d565977e6c5a97dd89dfd649 100644 --- a/src/mpl2mpl/src/vtable_analysis.cpp +++ b/src/mpl2mpl/src/vtable_analysis.cpp @@ -313,7 +313,7 @@ void VtableAnalysis::GenItableDefinition(const Klass *klass) { void VtableAnalysis::GenTableSymbol(const std::string &prefix, const std::string klassName, MIRAggConst *newconst) { size_t arraySize = newconst->GetConstVec().size(); - MIRArrayType *arrayType = GlobalTables::GetTypeTable().GetOrCreateArrayType(voidPtrType, arraySize); + MIRArrayType *arrayType = GlobalTables::GetTypeTable().GetOrCreateArrayType(*voidPtrType, arraySize); MIRSymbol *vtabSt = builder->CreateGlobalDecl((prefix + klassName).c_str(), arrayType); if (klassName == NameMangler::GetInternalNameLiteral(NameMangler::kJavaLangObjectStr)) { vtabSt->SetStorageClass(kScGlobal); @@ -400,7 +400,7 @@ void VtableAnalysis::ReplaceSuperclassInvoke(CallNode *stmt) { void VtableAnalysis::ReplacePolymorphicInvoke(CallNode *stmt) { IntrinsiccallNode *intrinCall = - GetModule()->CurFuncCodeMemPool()->New(GetModule(), OP_xintrinsiccallassigned); + GetModule()->CurFuncCodeMemPool()->New(*GetModule(), OP_xintrinsiccallassigned); intrinCall->SetIntrinsic(INTRN_JAVA_POLYMORPHIC_CALL); intrinCall->SetNumOpnds(stmt->GetNumOpnds()); intrinCall->SetReturnVec(stmt->GetReturnVec()); @@ -412,7 +412,7 @@ BaseNode *VtableAnalysis::GenVtabItabBaseAddr(BaseNode *obj, bool isVirtual) { BaseNode *classInfoAddress = ReflectionAnalysis::GenClassInfoAddr(obj, builder); MIRStructType *classMetadataType = static_cast( GlobalTables::GetTypeTable().GetTypeFromTyIdx(ReflectionAnalysis::GetClassMetaDataTyIdx())); - return builder->CreateExprIread(voidPtrType, GlobalTables::GetTypeTable().GetOrCreatePointerType(classMetadataType), + return builder->CreateExprIread(voidPtrType, GlobalTables::GetTypeTable().GetOrCreatePointerType(*classMetadataType), (isVirtual ? KLASS_VTAB_FIELDID : KLASS_ITAB_FIELDID), classInfoAddress); } @@ -455,7 +455,7 @@ void VtableAnalysis::ReplaceVirtualInvoke(CallNode *stmt) { builder->CreateExprBinary(OP_add, GlobalTables::GetTypeTable().GetPtr(), tabBaseAddress, offsetNode); BaseNode *readFuncPtr = builder->CreateExprIread( GlobalTables::GetTypeTable().GetCompactPtr(), - GlobalTables::GetTypeTable().GetOrCreatePointerType(GlobalTables::GetTypeTable().GetCompactPtr()), 0, addrNode); + GlobalTables::GetTypeTable().GetOrCreatePointerType(*GlobalTables::GetTypeTable().GetCompactPtr()), 0, addrNode); stmt->SetOpCode(OP_virtualicallassigned); stmt->GetNopnd().insert(stmt->GetNopnd().begin(), readFuncPtr); stmt->SetNumOpnds(stmt->GetNumOpnds() + 1); diff --git a/src/mpl2mpl/src/vtable_impl.cpp b/src/mpl2mpl/src/vtable_impl.cpp index e4048ef242987592921a6dabf0e09fd5c57d4a6b..7fe08919372488451ef75820a2e34a1e5770db93 100644 --- a/src/mpl2mpl/src/vtable_impl.cpp +++ b/src/mpl2mpl/src/vtable_impl.cpp @@ -52,7 +52,7 @@ void VtableImpl::ProcessFunc(MIRFunction *func) { MIRFunction *callee = GlobalTables::GetFunctionTable().GetFunctionFromPuidx(callNode->GetPUIdx()); MemPool *currentFuncCodeMempool = builder->GetCurrentFuncCodeMp(); IcallNode *icallNode = - currentFuncCodeMempool->New(builder->GetCurrentFuncCodeMpAllocator(), OP_icallassigned); + currentFuncCodeMempool->New(*builder->GetCurrentFuncCodeMpAllocator(), OP_icallassigned); icallNode->SetReturnVec(callNode->GetReturnVec()); icallNode->SetRetTyIdx(callee->GetReturnTyIdx()); icallNode->SetSrcPos(callNode->GetSrcPos()); @@ -113,7 +113,7 @@ void VtableImpl::ReplaceResolveInterface(StmtNode *stmt, const ResolveFuncNode * BaseNode *addrNode = builder->CreateExprBinary(OP_add, GlobalTables::GetTypeTable().GetPtr(), builder->CreateExprRegread(PTY_ptr, pregItabAddress), offsetNode); BaseNode *readFuncPtr = builder->CreateExprIread( - compactPtrType, GlobalTables::GetTypeTable().GetOrCreatePointerType(compactPtrType), 0, addrNode); + compactPtrType, GlobalTables::GetTypeTable().GetOrCreatePointerType(*compactPtrType), 0, addrNode); PregIdx pregFuncPtr = currFunc->GetPregTab()->CreatePreg(compactPtrPrim); RegassignNode *funcPtrAssign = builder->CreateStmtRegassign(compactPtrPrim, pregFuncPtr, readFuncPtr); currFunc->GetBody()->InsertBefore(stmt, funcPtrAssign);