diff --git a/src/mapleall/bin/dex2mpl b/src/mapleall/bin/dex2mpl index 218ef48d15bef623849daacd78a223fbd5ae1aee..b707beb10e1ffae0f3859ec930fa2c7300ab5868 100755 Binary files a/src/mapleall/bin/dex2mpl and b/src/mapleall/bin/dex2mpl differ diff --git a/src/mapleall/bin/dex2mpl_android b/src/mapleall/bin/dex2mpl_android index 2001cab77d15defb742611fd8e938009d6bef1be..059efa42d7e34f1d3329fbe55b16760fe3e5b0a8 100755 Binary files a/src/mapleall/bin/dex2mpl_android and b/src/mapleall/bin/dex2mpl_android differ diff --git a/src/mapleall/bin/jbc2mpl b/src/mapleall/bin/jbc2mpl index 818e8dd2cbfb71f1106c7b8d50f2dc18e6782f0a..52d92a6d1d87fddd97edddb0c182b353a353d6b7 100755 Binary files a/src/mapleall/bin/jbc2mpl and b/src/mapleall/bin/jbc2mpl differ diff --git a/src/mapleall/maple_be/src/be/lower.cpp b/src/mapleall/maple_be/src/be/lower.cpp index d9ce9e6c8db3b60d108c041530daf9dc9ae08cc0..38b8f96344aeaef2f06747634867a5b33c299de8 100644 --- a/src/mapleall/maple_be/src/be/lower.cpp +++ b/src/mapleall/maple_be/src/be/lower.cpp @@ -104,6 +104,7 @@ void CGLowerer::RegisterExternalLibraryFunctions() { MIRFunction *func = mirModule.GetMIRBuilder()->GetOrCreateFunction(extFnDescrs[i].name, TyIdx(extFnDescrs[i].retType)); + beCommon.UpdateTypeTable(*func->GetMIRFuncType()); func->AllocSymTab(); MIRSymbol *funcSym = func->GetFuncSymbol(); funcSym->SetStorageClass(kScExtern); @@ -175,7 +176,7 @@ BaseNode *CGLowerer::LowerIaddrof(const IreadNode &iaddrof) { uint32 loweredPtrType = static_cast(LOWERED_PTR_TYPE); MIRIntConst *offsetConst = GlobalTables::GetIntConstTable().GetOrCreateIntConst( - offset, *GlobalTables::GetTypeTable().GetTypeTable().at(loweredPtrType), 0/*fieldID*/); + offset, *GlobalTables::GetTypeTable().GetTypeTable().at(loweredPtrType), 0 /* fieldID */); BaseNode *offsetNode = mirModule.CurFuncCodeMemPool()->New(offsetConst); offsetNode->SetPrimType(LOWERED_PTR_TYPE); @@ -214,7 +215,8 @@ BaseNode *CGLowerer::LowerFarray(ArrayNode &array) { return baseNode; } - MIRIntConst *eleConst = GlobalTables::GetIntConstTable().GetOrCreateIntConst(eleOffset, arrayType, 0/*fieldID*/); + MIRIntConst *eleConst = + GlobalTables::GetIntConstTable().GetOrCreateIntConst(eleOffset, arrayType, 0 /* fieldID */); BaseNode *offsetNode = mirModule.CurFuncCodeMemPool()->New(eleConst); offsetNode->SetPrimType(array.GetPrimType()); @@ -232,11 +234,11 @@ BaseNode *CGLowerer::LowerFarray(ArrayNode &array) { if ((farrayType->GetKind() == kTypeJArray) && (resNode->GetOpCode() == OP_constval)) { ConstvalNode *idxNode = static_cast(resNode); int64 idx = safe_cast(idxNode->GetConstVal())->GetValue(); - MIRIntConst *eConst = GlobalTables::GetIntConstTable().GetOrCreateIntConst(idx * eSize, arrayType, 0/*fieldID*/); + MIRIntConst *eConst = GlobalTables::GetIntConstTable().GetOrCreateIntConst(idx * eSize, arrayType, 0 /* fieldID */); rMul = mirModule.CurFuncCodeMemPool()->New(eConst); rMul->SetPrimType(array.GetPrimType()); } else { - MIRIntConst *eConst = GlobalTables::GetIntConstTable().GetOrCreateIntConst(eSize, arrayType, 0/*fieldID*/); + MIRIntConst *eConst = GlobalTables::GetIntConstTable().GetOrCreateIntConst(eSize, arrayType, 0 /* fieldID */); BaseNode *eSizeNode = mirModule.CurFuncCodeMemPool()->New(eConst); eSizeNode->SetPrimType(array.GetPrimType()); rMul = mirModule.CurFuncCodeMemPool()->New(OP_mul); @@ -250,7 +252,7 @@ BaseNode *CGLowerer::LowerFarray(ArrayNode &array) { if (farrayType->GetKind() == kTypeJArray) { BaseNode *jarrayBaseNode = mirModule.CurFuncCodeMemPool()->New(OP_add); MIRIntConst *arrayHeaderNode = GlobalTables::GetIntConstTable().GetOrCreateIntConst( - static_cast(AArch64RTSupport::kArrayContentOffset), arrayType, 0/*fieldID*/); + static_cast(AArch64RTSupport::kArrayContentOffset), arrayType, 0 /* fieldID */); BaseNode *arrayHeaderCstNode = mirModule.CurFuncCodeMemPool()->New(arrayHeaderNode); arrayHeaderCstNode->SetPrimType(array.GetPrimType()); jarrayBaseNode->SetPrimType(array.GetPrimType()); @@ -349,14 +351,16 @@ BaseNode *CGLowerer::LowerArray(ArrayNode &array, const BaseNode &parent) { /* index is a constant, we can calculate the offset now */ ConstvalNode *idxNode = static_cast(resNode); int64 idx = safe_cast(idxNode->GetConstVal())->GetValue(); - MIRIntConst *eConst = GlobalTables::GetIntConstTable().GetOrCreateIntConst(idx * eSize, arrayTypes, 0/*fieldID*/); + MIRIntConst *eConst = + GlobalTables::GetIntConstTable().GetOrCreateIntConst(idx * eSize, arrayTypes, 0 /* fieldID */); rMul = mirModule.CurFuncCodeMemPool()->New(eConst); rMul->SetPrimType(array.GetPrimType()); if (dim == 1) { opAdd = OP_CG_array_elem_add; } } else { - MIRIntConst *eConst = GlobalTables::GetIntConstTable().GetOrCreateIntConst(eSize, arrayTypes, 0/*fieldID*/); + MIRIntConst *eConst = + GlobalTables::GetIntConstTable().GetOrCreateIntConst(eSize, arrayTypes, 0 /* fieldID */); BaseNode *tmpNode = mirModule.CurFuncCodeMemPool()->New(eConst); tmpNode->SetPrimType(array.GetPrimType()); rMul = mirModule.CurFuncCodeMemPool()->New(OP_mul); @@ -555,7 +559,8 @@ BaseNode *CGLowerer::LowerDreadBitfield(DreadNode &dread) { CHECK_FATAL(loweredPtrType < GlobalTables::GetTypeTable().GetTypeTable().size(), "LowerIassignBitField: subscript out of range"); MIRType &type = *GlobalTables::GetTypeTable().GetTypeFromTyIdx(loweredPtrType); - constNode->SetConstVal(GlobalTables::GetIntConstTable().GetOrCreateIntConst(byteBitOffsets.first, type, 0/*fieldID*/)); + constNode->SetConstVal( + GlobalTables::GetIntConstTable().GetOrCreateIntConst(byteBitOffsets.first, type, 0 /* fieldID */)); BinaryNode *addNode = mirModule.CurFuncCodeMemPool()->New(OP_add); addNode->SetPrimType(LOWERED_PTR_TYPE); @@ -611,7 +616,8 @@ BaseNode *CGLowerer::LowerIreadBitfield(IreadNode &iread) { constNode->SetPrimType(LOWERED_PTR_TYPE); uint32 loweredPtrType = static_cast(LOWERED_PTR_TYPE); MIRType &mirType = *GlobalTables::GetTypeTable().GetTypeFromTyIdx(loweredPtrType); - constNode->SetConstVal(GlobalTables::GetIntConstTable().GetOrCreateIntConst(byteBitOffsets.first, mirType, 0/*fieldID*/)); + constNode->SetConstVal( + GlobalTables::GetIntConstTable().GetOrCreateIntConst(byteBitOffsets.first, mirType, 0 /* fieldID */)); BinaryNode *addNode = mirModule.CurFuncCodeMemPool()->New(OP_add); addNode->SetPrimType(LOWERED_PTR_TYPE); @@ -746,7 +752,8 @@ StmtNode *CGLowerer::LowerDassignBitfield(DassignNode &dassign, BlockNode &newBl CHECK_FATAL(loweredPtrType < GlobalTables::GetTypeTable().GetTypeTable().size(), "LowerIassignBitField: subscript out of range"); MIRType &mirType = *GlobalTables::GetTypeTable().GetTypeFromTyIdx(loweredPtrType); - constNode->SetConstVal(GlobalTables::GetIntConstTable().GetOrCreateIntConst(byteBitOffsets.first, mirType, 0/*fieldID*/)); + constNode->SetConstVal( + GlobalTables::GetIntConstTable().GetOrCreateIntConst(byteBitOffsets.first, mirType, 0 /* fieldID */)); BinaryNode *addNode = mirModule.CurFuncCodeMemPool()->New(OP_add); addNode->SetPrimType(LOWERED_PTR_TYPE); @@ -816,7 +823,8 @@ StmtNode *CGLowerer::LowerIassignBitfield(IassignNode &iassign, BlockNode &newBl constNode->SetPrimType(LOWERED_PTR_TYPE); uint32 loweredPtrType = static_cast(LOWERED_PTR_TYPE); MIRType &mirType = *GlobalTables::GetTypeTable().GetTypeFromTyIdx(loweredPtrType); - constNode->SetConstVal(GlobalTables::GetIntConstTable().GetOrCreateIntConst(byteBitOffsets.first, mirType, 0/*fieldID*/)); + constNode->SetConstVal( + GlobalTables::GetIntConstTable().GetOrCreateIntConst(byteBitOffsets.first, mirType, 0 /* fieldID */)); BinaryNode *addNode = mirModule.CurFuncCodeMemPool()->New(OP_add); addNode->SetPrimType(LOWERED_PTR_TYPE); @@ -1344,6 +1352,7 @@ StmtNode *CGLowerer::LowerCall(CallNode &callNode, StmtNode *&nextStmt, BlockNod if (needCheckStore) { MIRFunction *fn = mirModule.GetMIRBuilder()->GetOrCreateFunction("MCC_Reflect_Check_Arraystore", TyIdx(PTY_void)); + beCommon.UpdateTypeTable(*fn->GetMIRFuncType()); fn->AllocSymTab(); MapleVector args(mirModule.GetMIRBuilder()->GetCurrentFuncCodeMpAllocator()->Adapter()); args.emplace_back(callNode.Opnd(0)); @@ -1634,6 +1643,7 @@ std::unordered_map CGLowerer::arrayClassCacheIndex; MIRFunction *CGLowerer::RegisterFunctionVoidStarToVoid(BuiltinFunctionID id, const std::string &name, const std::string ¶mName) { MIRFunction *func = mirBuilder->GetOrCreateFunction(name, GlobalTables::GetTypeTable().GetVoid()->GetTypeIndex()); + beCommon.UpdateTypeTable(*func->GetMIRFuncType()); func->AllocSymTab(); MIRSymbol *funcSym = func->GetFuncSymbol(); funcSym->SetStorageClass(kScExtern); @@ -1674,6 +1684,7 @@ void CGLowerer::RegisterBuiltIns() { MIRFunction *func = mirBuilder->GetOrCreateFunction(cgBuiltins[i].second, GlobalTables::GetTypeTable().GetVoid()->GetTypeIndex()); + beCommon.UpdateTypeTable(*func->GetMIRFuncType()); func->AllocSymTab(); MIRSymbol *funcSym = func->GetFuncSymbol(); funcSym->SetStorageClass(kScExtern); @@ -1784,7 +1795,7 @@ BaseNode *CGLowerer::MergeToCvtType(PrimType dType, PrimType sType, BaseNode &sr IreadNode &CGLowerer::GetLenNode(BaseNode &opnd0) { MIRIntConst *arrayHeaderNode = GlobalTables::GetIntConstTable().GetOrCreateIntConst( static_cast(AArch64RTSupport::kArrayLengthOffset), - *GlobalTables::GetTypeTable().GetTypeFromTyIdx(opnd0.GetPrimType()), 0/*fieldID*/); + *GlobalTables::GetTypeTable().GetTypeFromTyIdx(opnd0.GetPrimType()), 0 /* fieldID */); BaseNode *arrayHeaderCstNode = mirModule.CurFuncCodeMemPool()->New(arrayHeaderNode); arrayHeaderCstNode->SetPrimType(opnd0.GetPrimType()); MIRType *addrType = GlobalTables::GetTypeTable().GetTypeFromTyIdx(opnd0.GetPrimType()); @@ -1832,6 +1843,7 @@ void CGLowerer::ProcessArrayExpr(BaseNode &expr, BlockNode &blkNode) { arrayNode.GetNopndAt(1), lenRegreadNode); CondGotoNode *brFalseNode = mirBuilder->CreateStmtCondGoto(cond, OP_brfalse, labIdx); MIRFunction *fn = mirBuilder->GetOrCreateFunction("MCC_Array_Boundary_Check", TyIdx(PTY_void)); + beCommon.UpdateTypeTable(*fn->GetMIRFuncType()); fn->AllocSymTab(); MapleVector args(mirBuilder->GetCurrentFuncCodeMpAllocator()->Adapter()); args.emplace_back(arrayNode.GetNopndAt(0)); @@ -2008,7 +2020,7 @@ void CGLowerer::LowerResetStmt(StmtNode &stmt, BlockNode &block) { UnaryStmtNode &unaryStmtNode = static_cast(stmt); AddrofNode *addrofNode = static_cast(unaryStmtNode.GetRHS()); MIRType &type = *GlobalTables::GetTypeTable().GetPrimType(PTY_ref); - MIRConst *constVal = GlobalTables::GetIntConstTable().GetOrCreateIntConst(0, type, 0/*fieldID*/); + MIRConst *constVal = GlobalTables::GetIntConstTable().GetOrCreateIntConst(0, type, 0 /* fieldID */); ConstvalNode *exprConst = mirModule.CurFuncCodeMemPool()->New(); exprConst->SetPrimType(type.GetPrimType()); exprConst->SetConstVal(constVal); @@ -2249,7 +2261,7 @@ BaseNode *CGLowerer::LowerIntrinJavaArrayLength(const BaseNode &parent, Intrinsi ((parent.GetOpCode() == OP_regassign) || (parent.GetOpCode() == OP_dassign) || (parent.GetOpCode() == OP_ge))) { MIRType *addrType = GlobalTables::GetTypeTable().GetTypeFromTyIdx(TyIdx(arrAddr->GetPrimType())); MIRIntConst *arrayHeaderNode = GlobalTables::GetIntConstTable().GetOrCreateIntConst( - static_cast(AArch64RTSupport::kArrayLengthOffset), *addrType, 0/*fieldID*/); + static_cast(AArch64RTSupport::kArrayLengthOffset), *addrType, 0 /* fieldID */); BaseNode *arrayHeaderCstNode = mirModule.CurFuncCodeMemPool()->New(arrayHeaderNode); arrayHeaderCstNode->SetPrimType(arrAddr->GetPrimType()); @@ -2272,6 +2284,7 @@ BaseNode *CGLowerer::LowerIntrinJavaArrayLength(const BaseNode &parent, Intrinsi MIRFunction *newFunc = mirBuilder->GetOrCreateFunction("MCC_ThrowNullArrayNullPointerException", GlobalTables::GetTypeTable().GetVoid()->GetTypeIndex()); + beCommon.UpdateTypeTable(*newFunc->GetMIRFuncType()); newFunc->AllocSymTab(); MapleVector args(mirBuilder->GetCurrentFuncCodeMpAllocator()->Adapter()); StmtNode *call = mirBuilder->CreateStmtCallAssigned(newFunc->GetPuidx(), args, nullptr, OP_callassigned); @@ -2630,6 +2643,7 @@ StmtNode *CGLowerer::LowerIntrinsicRCCall(IntrinsiccallNode &intrincall) { if (intrinFuncIDs.find(intrinDesc) == intrinFuncIDs.end()) { /* add funcid into map */ MIRFunction *fn = mirBuilder->GetOrCreateFunction(intrinDesc->name, TyIdx(PTY_void)); + beCommon.UpdateTypeTable(*fn->GetMIRFuncType()); fn->AllocSymTab(); intrinFuncIDs[intrinDesc] = fn->GetPuidx(); } @@ -2657,6 +2671,7 @@ void CGLowerer::LowerArrayStore(IntrinsiccallNode &intrincall, BlockNode &newBlk if (needCheckStore) { MIRFunction *fn = mirBuilder->GetOrCreateFunction("MCC_Reflect_Check_Arraystore", TyIdx(PTY_void)); + beCommon.UpdateTypeTable(*fn->GetMIRFuncType()); fn->AllocSymTab(); MapleVector args(mirBuilder->GetCurrentFuncCodeMpAllocator()->Adapter()); args.emplace_back(intrincall.Opnd(0)); @@ -2742,6 +2757,7 @@ StmtNode *CGLowerer::LowerIntrinsiccall(IntrinsiccallNode &intrincall, BlockNode st->SetStorageClass(kScText); st->SetSKind(kStFunc); MIRFunction *fn = mirBuilder->GetOrCreateFunction(intrinDesc->name, TyIdx(0)); + beCommon.UpdateTypeTable(*fn->GetMIRFuncType()); fn->AllocSymTab(); st->SetFunction(fn); return LowerDefaultIntrinsicCall(intrincall, *st, *fn); @@ -2758,7 +2774,7 @@ StmtNode *CGLowerer::LowerSyncEnterSyncExit(StmtNode &stmt) { /* Just as ParseNaryStmt do for syncenter */ MIRType &intType = *GlobalTables::GetTypeTable().GetTypeFromTyIdx((TyIdx)PTY_i32); /* default 2 for __sync_enter_fast() */ - MIRIntConst *intConst = GlobalTables::GetIntConstTable().GetOrCreateIntConst(2, intType, 0/*fieldID*/); + MIRIntConst *intConst = GlobalTables::GetIntConstTable().GetOrCreateIntConst(2, intType, 0 /* fieldID */); ConstvalNode *exprConst = mirModule.GetMemPool()->New(); exprConst->SetPrimType(PTY_i32); exprConst->SetConstVal(intConst); @@ -2814,6 +2830,7 @@ PUIdx CGLowerer::GetBuiltinToUse(BuiltinFunctionID id) const { void CGLowerer::LowerGCMalloc(const BaseNode &node, const GCMallocNode &gcmalloc, BlockNode &blkNode, bool perm) { MIRFunction *func = mirBuilder->GetOrCreateFunction((perm ? "MCC_NewPermanentObject" : "MCC_NewObj_fixed_class"), (TyIdx)(LOWERED_PTR_TYPE)); + beCommon.UpdateTypeTable(*func->GetMIRFuncType()); func->AllocSymTab(); /* Get the classinfo */ MIRStructType *classType = static_cast( @@ -2831,6 +2848,7 @@ void CGLowerer::LowerGCMalloc(const BaseNode &node, const GCMallocNode &gcmalloc if (classSym->GetAttr(ATTR_abstract) || classSym->GetAttr(ATTR_interface)) { MIRFunction *funcSecond = mirBuilder->GetOrCreateFunction("MCC_Reflect_ThrowInstantiationError", (TyIdx)(LOWERED_PTR_TYPE)); + beCommon.UpdateTypeTable(*funcSecond->GetMIRFuncType()); funcSecond->AllocSymTab(); BaseNode *arg = mirBuilder->CreateExprAddrof(0, *classSym); if (node.GetOpCode() == OP_dassign) { @@ -2948,6 +2966,7 @@ void CGLowerer::LowerJarrayMalloc(const StmtNode &stmt, const JarrayMallocNode & args.emplace_back(mirBuilder->CreateIntConst(0, PTY_u32)); } MIRFunction *func = mirBuilder->GetOrCreateFunction(funcName, (TyIdx)(LOWERED_PTR_TYPE)); + beCommon.UpdateTypeTable(*func->GetMIRFuncType()); func->AllocSymTab(); CallNode *callAssign = nullptr; if (stmt.GetOpCode() == OP_dassign) { diff --git a/src/mapleall/maple_be/src/be/switch_lowerer.cpp b/src/mapleall/maple_be/src/be/switch_lowerer.cpp index 0fab9c7c0b2f8310733a40f0ee7f83dd4c5acb19..4d240489d761a24a240ef387e3b024e20d8c11d8 100644 --- a/src/mapleall/maple_be/src/be/switch_lowerer.cpp +++ b/src/mapleall/maple_be/src/be/switch_lowerer.cpp @@ -131,7 +131,8 @@ CompareNode *SwitchLowerer::BuildCmpNode(Opcode opCode, uint32 idx) { binaryExpr->SetOpndType(stmt->GetSwitchOpnd()->GetPrimType()); MIRType &type = *GlobalTables::GetTypeTable().GetTypeFromTyIdx(TyIdx(stmt->GetSwitchOpnd()->GetPrimType())); - MIRConst *constVal = GlobalTables::GetIntConstTable().GetOrCreateIntConst(stmt->GetCasePair(idx).first, type, 0/*fieldID*/); + MIRConst *constVal = + GlobalTables::GetIntConstTable().GetOrCreateIntConst(stmt->GetCasePair(idx).first, type, 0 /* fieldID */); ConstvalNode *exprConst = mirModule.CurFuncCodeMemPool()->New(); exprConst->SetPrimType(stmt->GetSwitchOpnd()->GetPrimType()); exprConst->SetConstVal(constVal); diff --git a/src/mapleall/maple_be/src/cg/eh_func.cpp b/src/mapleall/maple_be/src/cg/eh_func.cpp index e8d1f2e71412eff38affc1895a4c8e92d6e73b85..5531a6a588be180c17d7b1ee5c708317249a1257 100644 --- a/src/mapleall/maple_be/src/cg/eh_func.cpp +++ b/src/mapleall/maple_be/src/cg/eh_func.cpp @@ -117,6 +117,7 @@ void EHThrow::ConvertThrowToRuntime(CGFunc &cgFunc, BaseNode &arg) { MIRFunction &mirFunc = cgFunc.GetFunction(); MIRModule *mirModule = mirFunc.GetModule(); MIRFunction *calleeFunc = mirModule->GetMIRBuilder()->GetOrCreateFunction("MCC_ThrowException", (TyIdx)(PTY_void)); + cgFunc.GetBecommon().UpdateTypeTable(*calleeFunc->GetMIRFuncType()); calleeFunc->SetNoReturn(); MapleVector args(mirModule->GetMIRBuilder()->GetCurrentFuncCodeMpAllocator()->Adapter()); args.emplace_back(&arg); @@ -129,6 +130,7 @@ void EHThrow::ConvertThrowToRethrow(CGFunc &cgFunc) { MIRModule *mirModule = mirFunc.GetModule(); MIRBuilder *mirBuilder = mirModule->GetMIRBuilder(); MIRFunction *unFunc = mirBuilder->GetOrCreateFunction("MCC_RethrowException", (TyIdx)PTY_void); + cgFunc.GetBecommon().UpdateTypeTable(*unFunc->GetMIRFuncType()); unFunc->SetNoReturn(); MapleVector args(mirBuilder->GetCurrentFuncCodeMpAllocator()->Adapter()); args.emplace_back(rethrow->Opnd(0)); @@ -508,6 +510,7 @@ void EHFunc::InsertDefaultLabelAndAbortFunc(BlockNode &blkNode, SwitchNode &swit StmtNode *dfLabStmt = mirModule.GetMIRBuilder()->CreateStmtLabel(dfLabIdx); blkNode.InsertAfter(&beforeEndLabel, dfLabStmt); MIRFunction *calleeFunc = mirModule.GetMIRBuilder()->GetOrCreateFunction("abort", (TyIdx)(PTY_void)); + cgFunc->GetBecommon().UpdateTypeTable(*calleeFunc->GetMIRFuncType()); MapleVector args(mirModule.GetMIRBuilder()->GetCurrentFuncCodeMpAllocator()->Adapter()); CallNode *callExit = mirModule.GetMIRBuilder()->CreateStmtCall(calleeFunc->GetPuidx(), args); blkNode.InsertAfter(dfLabStmt, callExit); @@ -591,6 +594,7 @@ void EHFunc::InsertCxaAfterEachCatch(const std::vectorGetOrCreateFunction("MCC_JavaBeginCatch", voidPTy); + cgFunc->GetBecommon().UpdateTypeTable(*calleeFunc->GetMIRFuncType()); RegreadNode *retRegRead0 = mirModule.CurFuncCodeMemPool()->New(); retRegRead0->SetRegIdx(-kSregRetval0); retRegRead0->SetPrimType(LOWERED_PTR_TYPE); diff --git a/src/mapleall/maple_ipa/include/call_graph.h b/src/mapleall/maple_ipa/include/call_graph.h index a81db2b8a27e63a0b438b2d90fd216409fe26167..532bd8f9ff64169ffbba7857465a3686f4d09ee6 100644 --- a/src/mapleall/maple_ipa/include/call_graph.h +++ b/src/mapleall/maple_ipa/include/call_graph.h @@ -74,7 +74,7 @@ class CallInfo { return callStmt; } - const MIRFunction *GetFunc() const { + MIRFunction *GetFunc() { return mirFunc; } diff --git a/src/mapleall/maple_ir/BUILD.gn b/src/mapleall/maple_ir/BUILD.gn index 7eb046b85d00507db4ac39192afc397b84f288b6..78624667e625bdccd7dbb87e153b664003a27461 100755 --- a/src/mapleall/maple_ir/BUILD.gn +++ b/src/mapleall/maple_ir/BUILD.gn @@ -46,10 +46,10 @@ src_libmplir = [ "src/mir_parser.cpp", "src/mir_pragma.cpp", "src/printing.cpp", + "src/bin_func_import.cpp", + "src/bin_func_export.cpp", "src/bin_mpl_import.cpp", "src/bin_mpl_export.cpp", - "src/bin_func_export.cpp", - "src/bin_func_import.cpp", ] src_irbuild = [ "src/driver.cpp" ] diff --git a/src/mapleall/maple_ir/include/bin_mpl_export.h b/src/mapleall/maple_ir/include/bin_mpl_export.h index 82ff9bfeefb8a271d9acaff2c501f73f05143693..b8771fc62a382e0e3d8a3048007771a54ef50056 100644 --- a/src/mapleall/maple_ir/include/bin_mpl_export.h +++ b/src/mapleall/maple_ir/include/bin_mpl_export.h @@ -132,13 +132,13 @@ class BinaryMplExport { void OutputInterfaceTypeData(const MIRInterfaceType &type); void OutputSrcPos(const SrcPosition &pos); void OutputAliasMap(MapleMap &aliasVarMap); - void OutputInfoVector(const MIRInfoVector &infovector, const MapleVector &infovector_isstring); + void OutputInfoVector(const MIRInfoVector &infoVector, const MapleVector &infoVectorIsString); void OutputFuncIdInfo(MIRFunction *func); void OutputLocalSymbol(MIRSymbol *sym); void OutputLocalSymTab(const MIRFunction *func); void OutputPregTab(const MIRFunction *func); void OutputLabelTab(const MIRFunction *func); - void OutputLocalTypeNameTab(const MIRTypeNameTable *tnametab); + void OutputLocalTypeNameTab(const MIRTypeNameTable *tyNameTab); void OutputFormalsStIdx(MIRFunction *func); void OutputFuncViaSymName(PUIdx puIdx); void OutputExpression(BaseNode *e); @@ -150,6 +150,8 @@ class BinaryMplExport { return mod; } + bool not2mplt; // this export is not to an mplt file + private: void WriteContentField4mplt(int fieldNum, uint64 *fieldStartP); void WriteContentField4nonmplt(int fieldNum, uint64 *fieldStartP); @@ -178,11 +180,12 @@ class BinaryMplExport { std::unordered_map uStrMark; std::unordered_map symMark; std::unordered_map typMark; - static int typeMarkOffset; // offset of mark (tag in binmplimport) resulting from duplicated function - - public: - bool not2mplt; // this export is not to an mplt file + friend class DoUpdateMplt; std::unordered_map callInfoMark; + std::map *func2SEMap = nullptr; + std::unordered_map eaNodeMark; + bool inIPA = false; + static int typeMarkOffset; // offset of mark (tag in binmplimport) resulting from duplicated function }; } // namespace maple diff --git a/src/mapleall/maple_ir/include/bin_mpl_import.h b/src/mapleall/maple_ir/include/bin_mpl_import.h index fcd1ba11a7e5475cde1f1433504dcc8236c8de57..fdced8f4f975b81fad62d7a710e854707ad2fe66 100644 --- a/src/mapleall/maple_ir/include/bin_mpl_import.h +++ b/src/mapleall/maple_ir/include/bin_mpl_import.h @@ -122,25 +122,22 @@ class BinaryMplImport { void ImportInterfaceTypeData(MIRInterfaceType &type); PUIdx ImportFunction(); MIRSymbol *InSymbol(MIRFunction *func); - - void ImportInfoVector(MIRInfoVector &infovector, MapleVector &infovector_isstring); + void ImportInfoVector(MIRInfoVector &infoVector, MapleVector &infoVectorIsString); void ImportLocalTypeNameTable(MIRTypeNameTable *typeNameTab); void ImportFuncIdInfo(MIRFunction *func); void ImportLocalSymbol(MIRFunction *func); void ImportLocalSymTab(MIRFunction *func); - void ImportPregTab(MIRFunction *func); + void ImportPregTab(const MIRFunction *func); void ImportLabelTab(MIRFunction *func); void ImportFormalsStIdx(MIRFunction *func); void ImportAliasMap(MIRFunction *func); void ImportSrcPos(SrcPosition &pos); - void ImportBaseNode(Opcode &o, PrimType &typ, uint8 &numopr); + void ImportBaseNode(Opcode &o, PrimType &typ, uint8 &numOpr); PUIdx ImportFuncViaSymName(); BaseNode *ImportExpression(MIRFunction *func); - void ImportReturnValues(MIRFunction *func, CallReturnVector *retv); BlockNode *ImportBlockNode(MIRFunction *fn); void ReadFunctionBodyField(); - void ReadFileAt(const std::string &modid, int32 offset); uint8 Read(); int64 ReadInt64(); diff --git a/src/mapleall/maple_ir/include/bin_mplt.h b/src/mapleall/maple_ir/include/bin_mplt.h index fbe2603baa9924e74d39b01e77c0f82fc752b8e4..e3e8359c1f9280775c68c1ae3c8b657172afdc7a 100644 --- a/src/mapleall/maple_ir/include/bin_mplt.h +++ b/src/mapleall/maple_ir/include/bin_mplt.h @@ -54,7 +54,7 @@ class BinaryMplt { return importFileName; } - void SetImportFileName(std::string fileName) { + void SetImportFileName(const std::string &fileName) { importFileName = fileName; } diff --git a/src/mapleall/maple_ir/include/mir_function.h b/src/mapleall/maple_ir/include/mir_function.h index e1853cf6e03e55ac235081ff338b416fef094372..bdb9b167334617d78eceb0f3054cecfafb17ca7b 100644 --- a/src/mapleall/maple_ir/include/mir_function.h +++ b/src/mapleall/maple_ir/include/mir_function.h @@ -577,7 +577,7 @@ class MIRFunction { return GetFuncSymbol()->GetSrcPosition(); } - void SetSrcPosition(SrcPosition &position) { + void SetSrcPosition(const SrcPosition &position) { GetFuncSymbol()->SetSrcPosition(position); } diff --git a/src/mapleall/maple_ir/include/mir_module.h b/src/mapleall/maple_ir/include/mir_module.h index 657bcfd6377036cfd52009ea226ff907cc5277a1..1de78ffb7db1a852c90b7a4ffe6735b038754871 100644 --- a/src/mapleall/maple_ir/include/mir_module.h +++ b/src/mapleall/maple_ir/include/mir_module.h @@ -249,7 +249,7 @@ class MIRModule { } void DumpGlobals(bool emitStructureType = true) const; - void Dump(bool emitStructureType = true, std::unordered_set *dumpFuncSet = nullptr) const; + void Dump(bool emitStructureType = true, const std::unordered_set *dumpFuncSet = nullptr) const; void DumpToFile(const std::string &fileNameStr, bool emitStructureType = true) const; void DumpInlineCandidateToFile(const std::string &fileNameStr) const; const std::string &GetFileNameFromFileNum(uint32 fileNum) const; @@ -275,7 +275,7 @@ class MIRModule { MIRFunction *FindEntryFunction(); uint32 GetFileinfo(GStrIdx strIdx) const; void OutputAsciiMpl(const char *phaseName, const char *suffix, - std::unordered_set *dumpFuncSet = nullptr, + const std::unordered_set *dumpFuncSet = nullptr, bool emitStructureType = true, bool binaryform = false); void OutputFunctionListAsciiMpl(const std::string &phaseName); const std::string &GetFileName() const { diff --git a/src/mapleall/maple_ir/include/mir_nodes.h b/src/mapleall/maple_ir/include/mir_nodes.h index 081841db4c4603cd9e33a730a2c537b21ded0be6..80791526272998b836bcbe5d4bd620bbe313feae 100644 --- a/src/mapleall/maple_ir/include/mir_nodes.h +++ b/src/mapleall/maple_ir/include/mir_nodes.h @@ -1816,6 +1816,10 @@ class SwitchNode : public StmtNode { defaultLabel = idx; } + const CaseVector &GetSwitchTable() const { + return switchTable; + } + CaseVector &GetSwitchTable() { return switchTable; } diff --git a/src/mapleall/maple_ir/include/mir_symbol.h b/src/mapleall/maple_ir/include/mir_symbol.h index 02eb665173d5ec5d10a2bf237b910004ebf9ffca..849443aafee7739921f8ac20de091f12f1a8356f 100644 --- a/src/mapleall/maple_ir/include/mir_symbol.h +++ b/src/mapleall/maple_ir/include/mir_symbol.h @@ -313,7 +313,7 @@ class MIRSymbol { return srcPosition; } - void SetSrcPosition(SrcPosition &position) { + void SetSrcPosition(const SrcPosition &position) { srcPosition = position; } @@ -552,10 +552,10 @@ class MIRSymbolTable { class MIRLabelTable { public: explicit MIRLabelTable(MapleAllocator &allocator) - : mAllocator(allocator), + : addrTakenLabels(allocator.Adapter()), + mAllocator(allocator), strIdxToLabIdxMap(std::less(), mAllocator.Adapter()), - labelTable(mAllocator.Adapter()), - addrTakenLabels(mAllocator.Adapter()) { + labelTable(mAllocator.Adapter()) { labelTable.push_back(GStrIdx(kDummyLabel)); // push dummy label index 0 } @@ -628,13 +628,13 @@ class MIRLabelTable { strIdxToLabIdxMap.erase(idx); } + MapleUnorderedSet addrTakenLabels; // those appeared in addroflabel or MIRLblConst + private: static constexpr uint32 kDummyLabel = 0; MapleAllocator mAllocator; MapleMap strIdxToLabIdxMap; MapleVector labelTable; // map label idx to label name - public: - MapleUnorderedSet addrTakenLabels; // those appeared in addroflabel or MIRLblConst }; } // namespace maple #endif // MAPLE_IR_INCLUDE_MIR_SYMBOL_H diff --git a/src/mapleall/maple_ir/include/mir_type.h b/src/mapleall/maple_ir/include/mir_type.h index 4df09ba802869cfe1fa80a35a1ef0b2a48353db9..f9eecc12b589323994dfc04cb4e5966d1c85c1a6 100644 --- a/src/mapleall/maple_ir/include/mir_type.h +++ b/src/mapleall/maple_ir/include/mir_type.h @@ -517,6 +517,10 @@ class MIRType { return typeKind == kTypeScalar; } + bool IsMIRTypeByName() const { + return typeKind == kTypeByName; + } + bool ValidateClassOrInterface(const std::string &className, bool noWarning) const; bool IsOfSameType(MIRType &type); const std::string &GetName() const; diff --git a/src/mapleall/maple_ir/src/bin_func_export.cpp b/src/mapleall/maple_ir/src/bin_func_export.cpp index 76577084642146e4556f92ed0ab9adfbe880d29a..545ba053feb335534f0415874b20338c3579a070 100644 --- a/src/mapleall/maple_ir/src/bin_func_export.cpp +++ b/src/mapleall/maple_ir/src/bin_func_export.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) [2020] Huawei Technologies Co., Ltd. All rights reserved. + * Copyright (c) [2021] Huawei Technologies Co., Ltd. All rights reserved. * * OpenArkCompiler is licensed under the Mulan Permissive Software License v2. * You can use this software according to the terms and conditions of the MulanPSL - 2.0. @@ -13,28 +13,25 @@ * See the MulanPSL - 2.0 for more details. */ - #include "mir_function.h" #include "opcode_info.h" #include "mir_pragma.h" #include "mir_builder.h" #include "bin_mplt.h" - #include #include using namespace std; namespace maple { - -void BinaryMplExport::OutputInfoVector(const MIRInfoVector &infovector, const MapleVector &infovector_isstring) { - WriteNum(infovector.size()); - for (uint32 i = 0; i < infovector.size(); i++) { - OutputStr(infovector[i].first); - WriteNum(infovector_isstring[i]); - if (!infovector_isstring[i]) { - WriteNum(infovector[i].second); +void BinaryMplExport::OutputInfoVector(const MIRInfoVector &infoVector, const MapleVector &infoVectorIsString) { + WriteNum(infoVector.size()); + for (uint32 i = 0; i < infoVector.size(); i++) { + OutputStr(infoVector[i].first); + WriteNum(infoVectorIsString[i]); + if (!infoVectorIsString[i]) { + WriteNum(infoVector[i].second); } else { - OutputStr(GStrIdx(infovector[i].second)); + OutputStr(GStrIdx(infoVector[i].second)); } } } @@ -133,10 +130,10 @@ void BinaryMplExport::OutputLabelTab(const MIRFunction *func) { WriteNum(~kBinLabelStart); } -void BinaryMplExport::OutputLocalTypeNameTab(const MIRTypeNameTable *tnametab) { +void BinaryMplExport::OutputLocalTypeNameTab(const MIRTypeNameTable *typeNameTab) { WriteNum(kBinTypenameStart); - WriteNum(tnametab->Size()); - for (std::pair it : tnametab->GetGStrIdxToTyIdxMap()) { + WriteNum(typeNameTab->Size()); + for (std::pair it : typeNameTab->GetGStrIdxToTyIdxMap()) { OutputStr(it.first); OutputTypeViaTypeName(it.second); } @@ -329,7 +326,7 @@ void BinaryMplExport::OutputExpression(BaseNode *e) { default: break; } - for (int32 i = 0; i < e->NumOpnds(); i++) { + for (uint32 i = 0; i < e->NumOpnds(); ++i) { OutputExpression(e->Opnd(i)); } } @@ -593,7 +590,7 @@ void BinaryMplExport::OutputBlockNode(BlockNode *block) { } num++; if (!doneWithOpnds) { - for (int32 i = 0; i < s->NumOpnds(); i++) { + for (uint32 i = 0; i < s->NumOpnds(); ++i) { OutputExpression(s->Opnd(i)); } } @@ -653,5 +650,4 @@ void BinaryMplExport::WriteFunctionBodyField(uint64 contentIdx, std::unordered_s WriteNum(~kBinFunctionBodyStart); return; } - } // namespace maple diff --git a/src/mapleall/maple_ir/src/bin_func_import.cpp b/src/mapleall/maple_ir/src/bin_func_import.cpp index 076470db8c8d7e5709fdd7b1ee8cb31b0283926a..a010a98e4bb8104ed5537d0bd751f12ac9410d0f 100644 --- a/src/mapleall/maple_ir/src/bin_func_import.cpp +++ b/src/mapleall/maple_ir/src/bin_func_import.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) [2020] Huawei Technologies Co., Ltd. All rights reserved. + * Copyright (c) [2021] Huawei Technologies Co., Ltd. All rights reserved. * * OpenArkCompiler is licensed under the Mulan Permissive Software License v2. * You can use this software according to the terms and conditions of the MulanPSL - 2.0. @@ -19,26 +19,24 @@ #include "opcode_info.h" #include "mir_pragma.h" #include "mir_builder.h" - #include #include #include using namespace std; namespace maple { - -void BinaryMplImport::ImportInfoVector(MIRInfoVector &infovector, MapleVector &infovector_isstring) { +void BinaryMplImport::ImportInfoVector(MIRInfoVector &infoVector, MapleVector &infoVectorIsString) { int64 size = ReadNum(); for (int64 i = 0; i < size; i++) { GStrIdx gStrIdx = ImportStr(); bool isstring = ReadNum(); - infovector_isstring.push_back(isstring); + infoVectorIsString.push_back(isstring); if (isstring) { GStrIdx fieldval = ImportStr(); - infovector.push_back(MIRInfoPair(gStrIdx, fieldval.GetIdx())); + infoVector.push_back(MIRInfoPair(gStrIdx, fieldval.GetIdx())); } else { uint32 fieldval = ReadNum(); - infovector.push_back(MIRInfoPair(gStrIdx, fieldval)); + infoVector.push_back(MIRInfoPair(gStrIdx, fieldval)); } } } @@ -69,7 +67,7 @@ void BinaryMplImport::ImportLocalSymbol(MIRFunction *func) { CHECK_FATAL(indx == func->GetSymTab()->GetSymbolTableSize(), "inconsistant local stIdx"); MIRSymbol *sym = func->GetSymTab()->CreateSymbol(kScopeLocal); sym->SetNameStrIdx(ImportStr()); - func->GetSymTab()->AddToStringSymbolMap(*sym); + (void)func->GetSymTab()->AddToStringSymbolMap(*sym); sym->SetSKind((MIRSymKind)ReadNum()); sym->SetStorageClass((MIRStorageClass)ReadNum()); sym->SetAttrs(ImportTypeAttrs()); @@ -107,7 +105,7 @@ void BinaryMplImport::ImportLocalSymTab(MIRFunction *func) { CHECK_FATAL(tag == ~kBinSymStart, "pattern mismatch in ImportLocalSymTab()"); } -void BinaryMplImport::ImportPregTab(MIRFunction *func) { +void BinaryMplImport::ImportPregTab(const MIRFunction *func) { int64 tag = ReadNum(); CHECK_FATAL(tag == kBinPregStart, "kBinPregStart expected in ImportPregTab()"); int32 size = ReadInt(); @@ -123,7 +121,7 @@ void BinaryMplImport::ImportPregTab(MIRFunction *func) { MIRType *ty = (tyIdx == 0) ? nullptr : GlobalTables::GetTypeTable().GetTypeFromTyIdx(tyIdx); PrimType primType = (PrimType)ReadNum(); CHECK_FATAL(ty == nullptr || primType == ty->GetPrimType(), "ImportPregTab: inconsistent primitive type"); - func->GetPregTab()->EnterPregNo(pregNo, primType, ty); + (void)func->GetPregTab()->EnterPregNo(pregNo, primType, ty); } tag = ReadNum(); CHECK_FATAL(tag == ~kBinPregStart, "pattern mismatch in ImportPregTab()"); @@ -135,7 +133,7 @@ void BinaryMplImport::ImportLabelTab(MIRFunction *func) { int32 size = ReadNum(); for (int64 i = 0; i < size; i++) { GStrIdx gStrIdx = ImportStr(); - func->GetLabelTab()->AddLabel(gStrIdx); + (void)func->GetLabelTab()->AddLabel(gStrIdx); } tag = ReadNum(); CHECK_FATAL(tag == ~kBinLabelStart, "pattern mismatch in ImportLabelTab()"); @@ -175,7 +173,7 @@ void BinaryMplImport::ImportAliasMap(MIRFunction *func) { GStrIdx strIdx = ImportStr(); aliasvars.memPoolStrIdx = ImportStr(); aliasvars.tyIdx = ImportType(); - /* aliasvars.sigStrIdx = */ ImportStr(); // not assigning to mimic parser + (void)ImportStr(); // not assigning to mimic parser func->GetAliasVarMap()[strIdx] = aliasvars; } tag = ReadNum(); @@ -196,8 +194,8 @@ BaseNode *BinaryMplImport::ImportExpression(MIRFunction *func) { CHECK_FATAL(tag == kBinOpExpression, "kBinOpExpression expected"); Opcode op; PrimType typ; - uint8 numopr; - ImportBaseNode(op, typ, numopr); + uint8 numOpr; + ImportBaseNode(op, typ, numOpr); switch (op) { // leaf case OP_constval: { @@ -216,7 +214,7 @@ BaseNode *BinaryMplImport::ImportExpression(MIRFunction *func) { AddroflabelNode *alabNode = mod.CurFuncCodeMemPool()->New(); alabNode->SetOffset(ReadNum()); alabNode->SetPrimType(typ); - func->GetLabelTab()->addrTakenLabels.insert(alabNode->GetOffset()); + (void)func->GetLabelTab()->addrTakenLabels.insert(alabNode->GetOffset()); return alabNode; } case OP_addroffunc: { @@ -270,7 +268,7 @@ BaseNode *BinaryMplImport::ImportExpression(MIRFunction *func) { case OP_sqrt: case OP_alloca: case OP_malloc: { - CHECK_FATAL(numopr == 1, "expected numOpnds to be 1"); + CHECK_FATAL(numOpr == 1, "expected numOpnds to be 1"); UnaryNode *unNode = mod.CurFuncCodeMemPool()->New(op, typ); unNode->SetOpnd(ImportExpression(func), 0); return unNode; @@ -279,14 +277,14 @@ BaseNode *BinaryMplImport::ImportExpression(MIRFunction *func) { case OP_cvt: case OP_floor: case OP_trunc: { - CHECK_FATAL(numopr == 1, "expected numOpnds to be 1"); + CHECK_FATAL(numOpr == 1, "expected numOpnds to be 1"); TypeCvtNode *typecvtNode = mod.CurFuncCodeMemPool()->New(op, typ); typecvtNode->SetFromType((PrimType)ReadNum()); typecvtNode->SetOpnd(ImportExpression(func), 0); return typecvtNode; } case OP_retype: { - CHECK_FATAL(numopr == 1, "expected numOpnds to be 1"); + CHECK_FATAL(numOpr == 1, "expected numOpnds to be 1"); RetypeNode *retypeNode = mod.CurFuncCodeMemPool()->New(typ); retypeNode->SetTyIdx(ImportType()); retypeNode->SetOpnd(ImportExpression(func), 0); @@ -294,7 +292,7 @@ BaseNode *BinaryMplImport::ImportExpression(MIRFunction *func) { } case OP_iread: case OP_iaddrof: { - CHECK_FATAL(numopr == 1, "expected numOpnds to be 1"); + CHECK_FATAL(numOpr == 1, "expected numOpnds to be 1"); IreadNode *irNode = mod.CurFuncCodeMemPool()->New(op, typ); irNode->SetTyIdx(ImportType()); irNode->SetFieldID(ReadNum()); @@ -304,7 +302,7 @@ BaseNode *BinaryMplImport::ImportExpression(MIRFunction *func) { case OP_sext: case OP_zext: case OP_extractbits: { - CHECK_FATAL(numopr == 1, "expected numOpnds to be 1"); + CHECK_FATAL(numOpr == 1, "expected numOpnds to be 1"); ExtractbitsNode *extNode = mod.CurFuncCodeMemPool()->New(op, typ); extNode->SetBitsOffset(ReadNum()); extNode->SetBitsSize(ReadNum()); @@ -313,7 +311,7 @@ BaseNode *BinaryMplImport::ImportExpression(MIRFunction *func) { } case OP_gcmallocjarray: case OP_gcpermallocjarray: { - CHECK_FATAL(numopr == 1, "expected numOpnds to be 1"); + CHECK_FATAL(numOpr == 1, "expected numOpnds to be 1"); JarrayMallocNode *gcNode = mod.CurFuncCodeMemPool()->New(op, typ); gcNode->SetTyIdx(ImportType()); gcNode->SetOpnd(ImportExpression(func), 0); @@ -337,7 +335,7 @@ BaseNode *BinaryMplImport::ImportExpression(MIRFunction *func) { case OP_land: case OP_lior: case OP_add: { - CHECK_FATAL(numopr == 2, "expected numOpnds to be 2"); + CHECK_FATAL(numOpr == 2, "expected numOpnds to be 2"); BinaryNode *binNode = mod.CurFuncCodeMemPool()->New(op, typ); binNode->SetOpnd(ImportExpression(func), 0); binNode->SetOpnd(ImportExpression(func), 1); @@ -352,7 +350,7 @@ BaseNode *BinaryMplImport::ImportExpression(MIRFunction *func) { case OP_cmpg: case OP_cmpl: case OP_cmp: { - CHECK_FATAL(numopr == 2, "expected numOpnds to be 2"); + CHECK_FATAL(numOpr == 2, "expected numOpnds to be 2"); CompareNode *cmpNode = mod.CurFuncCodeMemPool()->New(op, typ); cmpNode->SetOpndType((PrimType)ReadNum()); cmpNode->SetOpnd(ImportExpression(func), 0); @@ -361,7 +359,7 @@ BaseNode *BinaryMplImport::ImportExpression(MIRFunction *func) { } case OP_resolveinterfacefunc: case OP_resolvevirtualfunc: { - CHECK_FATAL(numopr == 2, "expected numOpnds to be 2"); + CHECK_FATAL(numOpr == 2, "expected numOpnds to be 2"); ResolveFuncNode *rsNode = mod.CurFuncCodeMemPool()->New(op, typ); rsNode->SetPUIdx(ImportFuncViaSymName()); rsNode->SetOpnd(ImportExpression(func), 0); @@ -370,7 +368,7 @@ BaseNode *BinaryMplImport::ImportExpression(MIRFunction *func) { } // ternary case OP_select: { - CHECK_FATAL(numopr == 3, "expected numOpnds to be 3"); + CHECK_FATAL(numOpr == 3, "expected numOpnds to be 3"); TernaryNode *tNode = mod.CurFuncCodeMemPool()->New(op, typ); tNode->SetOpnd(ImportExpression(func), 0); tNode->SetOpnd(ImportExpression(func), 1); @@ -380,8 +378,9 @@ BaseNode *BinaryMplImport::ImportExpression(MIRFunction *func) { // nary case OP_array: { TyIdx tidx = ImportType(); - uint32 bchk = ReadNum(); - ArrayNode *arrNode = mod.CurFuncCodeMemPool()->New(func->GetCodeMPAllocator(), typ, tidx, bchk); + uint32 boundsCheck = ReadNum(); + ArrayNode *arrNode = + mod.CurFuncCodeMemPool()->New(func->GetCodeMPAllocator(), typ, tidx, boundsCheck); uint32 n = ReadNum(); for (uint32 i = 0; i < n; i++) { arrNode->GetNopnd().push_back(ImportExpression(func)); @@ -400,7 +399,8 @@ BaseNode *BinaryMplImport::ImportExpression(MIRFunction *func) { return intrnNode; } case OP_intrinsicopwithtype: { - IntrinsicopNode *intrnNode = mod.CurFuncCodeMemPool()->New(func->GetCodeMPAllocator(), OP_intrinsicopwithtype, typ); + IntrinsicopNode *intrnNode = + mod.CurFuncCodeMemPool()->New(func->GetCodeMPAllocator(), OP_intrinsicopwithtype, typ); intrnNode->SetIntrinsic((MIRIntrinsicID)ReadNum()); intrnNode->SetTyIdx(ImportType()); uint32 n = ReadNum(); @@ -426,11 +426,10 @@ void BinaryMplImport::ImportReturnValues(MIRFunction *func, CallReturnVector *re CHECK_FATAL(tag == kBinReturnvals, "expecting return values"); uint32 size = ReadNum(); for (uint32 i = 0; i < size; i++) { - CallReturnPair crPair; uint32 idx = ReadNum(); FieldID fid = ReadNum(); PregIdx16 ridx = ReadNum(); - retv->push_back(std::make_pair(StIdx(kScopeLocal, idx), RegFieldPair(fid,ridx))); + retv->push_back(std::make_pair(StIdx(kScopeLocal, idx), RegFieldPair(fid, ridx))); if (idx == 0) { continue; } @@ -451,10 +450,10 @@ BlockNode *BinaryMplImport::ImportBlockNode(MIRFunction *func) { BlockNode *block = func->GetCodeMemPool()->New(); Opcode op; - uint8 numopr; + uint8 numOpr; ImportSrcPos(block->GetSrcPos()); int32 size = ReadInt(); - for (int32 i = 0; i < size; i++) { + for (int32 k = 0; k < size; ++k) { tag = ReadNum(); CHECK_FATAL(tag == kBinOpStatement, "kBinOpStatement expected"); SrcPosition thesrcPosition; @@ -507,9 +506,9 @@ BlockNode *BinaryMplImport::ImportBlockNode(MIRFunction *func) { case OP_customcall: { CallNode *s = func->GetCodeMemPool()->New(mod, op); s->SetPUIdx(ImportFuncViaSymName()); - numopr = ReadNum(); - s->SetNumOpnds(numopr); - for (int32 i = 0; i < numopr; i++) { + numOpr = ReadNum(); + s->SetNumOpnds(numOpr); + for (int32 i = 0; i < numOpr; i++) { s->GetNopnd().push_back(ImportExpression(func)); } stmt = s; @@ -525,9 +524,9 @@ BlockNode *BinaryMplImport::ImportBlockNode(MIRFunction *func) { CallNode *s = func->GetCodeMemPool()->New(mod, op); s->SetPUIdx(ImportFuncViaSymName()); ImportReturnValues(func, &s->GetReturnVec()); - numopr = ReadNum(); - s->SetNumOpnds(numopr); - for (int32 i = 0; i < numopr; i++) { + numOpr = ReadNum(); + s->SetNumOpnds(numOpr); + for (int32 i = 0; i < numOpr; i++) { s->GetNopnd().push_back(ImportExpression(func)); } stmt = s; @@ -537,9 +536,9 @@ BlockNode *BinaryMplImport::ImportBlockNode(MIRFunction *func) { CallNode *s = func->GetCodeMemPool()->New(mod, op); s->SetPUIdx(ImportFuncViaSymName()); s->SetTyIdx(ImportType()); - numopr = ReadNum(); - s->SetNumOpnds(numopr); - for (int32 i = 0; i < numopr; i++) { + numOpr = ReadNum(); + s->SetNumOpnds(numOpr); + for (int32 i = 0; i < numOpr; i++) { s->GetNopnd().push_back(ImportExpression(func)); } stmt = s; @@ -550,9 +549,9 @@ BlockNode *BinaryMplImport::ImportBlockNode(MIRFunction *func) { s->SetPUIdx(ImportFuncViaSymName()); s->SetTyIdx(ImportType()); ImportReturnValues(func, &s->GetReturnVec()); - numopr = ReadNum(); - s->SetNumOpnds(numopr); - for (int32 i = 0; i < numopr; i++) { + numOpr = ReadNum(); + s->SetNumOpnds(numOpr); + for (int32 i = 0; i < numOpr; i++) { s->GetNopnd().push_back(ImportExpression(func)); } stmt = s; @@ -561,9 +560,9 @@ BlockNode *BinaryMplImport::ImportBlockNode(MIRFunction *func) { case OP_icall: { IcallNode *s = func->GetCodeMemPool()->New(mod, op); s->SetRetTyIdx(ImportType()); - numopr = ReadNum(); - s->SetNumOpnds(numopr); - for (int32 i = 0; i < numopr; i++) { + numOpr = ReadNum(); + s->SetNumOpnds(numOpr); + for (int32 i = 0; i < numOpr; i++) { s->GetNopnd().push_back(ImportExpression(func)); } stmt = s; @@ -573,9 +572,9 @@ BlockNode *BinaryMplImport::ImportBlockNode(MIRFunction *func) { IcallNode *s = func->GetCodeMemPool()->New(mod, op); s->SetRetTyIdx(ImportType()); ImportReturnValues(func, &s->GetReturnVec()); - numopr = ReadNum(); - s->SetNumOpnds(numopr); - for (int32 i = 0; i < numopr; i++) { + numOpr = ReadNum(); + s->SetNumOpnds(numOpr); + for (int32 i = 0; i < numOpr; i++) { s->GetNopnd().push_back(ImportExpression(func)); } stmt = s; @@ -585,9 +584,9 @@ BlockNode *BinaryMplImport::ImportBlockNode(MIRFunction *func) { case OP_xintrinsiccall: { IntrinsiccallNode *s = func->GetCodeMemPool()->New(mod, op); s->SetIntrinsic((MIRIntrinsicID)ReadNum()); - numopr = ReadNum(); - s->SetNumOpnds(numopr); - for (int32 i = 0; i < numopr; i++) { + numOpr = ReadNum(); + s->SetNumOpnds(numOpr); + for (int32 i = 0; i < numOpr; i++) { s->GetNopnd().push_back(ImportExpression(func)); } stmt = s; @@ -598,9 +597,9 @@ BlockNode *BinaryMplImport::ImportBlockNode(MIRFunction *func) { IntrinsiccallNode *s = func->GetCodeMemPool()->New(mod, op); s->SetIntrinsic((MIRIntrinsicID)ReadNum()); ImportReturnValues(func, &s->GetReturnVec()); - numopr = ReadNum(); - s->SetNumOpnds(numopr); - for (int32 i = 0; i < numopr; i++) { + numOpr = ReadNum(); + s->SetNumOpnds(numOpr); + for (int32 i = 0; i < numOpr; i++) { s->GetNopnd().push_back(ImportExpression(func)); } if (s->GetReturnVec().size() == 1 && s->GetReturnVec()[0].first.Idx() != 0) { @@ -616,9 +615,9 @@ BlockNode *BinaryMplImport::ImportBlockNode(MIRFunction *func) { IntrinsiccallNode *s = func->GetCodeMemPool()->New(mod, op); s->SetIntrinsic((MIRIntrinsicID)ReadNum()); s->SetTyIdx(ImportType()); - numopr = ReadNum(); - s->SetNumOpnds(numopr); - for (int32 i = 0; i < numopr; i++) { + numOpr = ReadNum(); + s->SetNumOpnds(numOpr); + for (int32 i = 0; i < numOpr; i++) { s->GetNopnd().push_back(ImportExpression(func)); } stmt = s; @@ -629,9 +628,9 @@ BlockNode *BinaryMplImport::ImportBlockNode(MIRFunction *func) { s->SetIntrinsic((MIRIntrinsicID)ReadNum()); s->SetTyIdx(ImportType()); ImportReturnValues(func, &s->GetReturnVec()); - numopr = ReadNum(); - s->SetNumOpnds(numopr); - for (int32 i = 0; i < numopr; i++) { + numOpr = ReadNum(); + s->SetNumOpnds(numOpr); + for (int32 i = 0; i < numOpr; i++) { s->GetNopnd().push_back(ImportExpression(func)); } if (s->GetReturnVec().size() == 1 && s->GetReturnVec()[0].first.Idx() != 0) { @@ -647,9 +646,9 @@ BlockNode *BinaryMplImport::ImportBlockNode(MIRFunction *func) { case OP_syncexit: case OP_return: { NaryStmtNode *s = func->GetCodeMemPool()->New(mod, op); - numopr = ReadNum(); - s->SetNumOpnds(numopr); - for (int32 i = 0; i < numopr; i++) { + numOpr = ReadNum(); + s->SetNumOpnds(numOpr); + for (int32 i = 0; i < numOpr; i++) { s->GetNopnd().push_back(ImportExpression(func)); } stmt = s; @@ -705,8 +704,8 @@ BlockNode *BinaryMplImport::ImportBlockNode(MIRFunction *func) { case OP_switch: { SwitchNode *s = mod.CurFuncCodeMemPool()->New(mod); s->SetDefaultLabel(ReadNum()); - uint32 size = ReadNum(); - for (uint32 i = 0; i < size; i++) { + uint32 tagSize = ReadNum(); + for (uint32 i = 0; i < tagSize; i++) { int32 casetag = ReadNum(); LabelIdx lidx(ReadNum()); CasePair cpair = std::make_pair(casetag, lidx); @@ -727,7 +726,7 @@ BlockNode *BinaryMplImport::ImportBlockNode(MIRFunction *func) { case OP_try: { TryNode *s = mod.CurFuncCodeMemPool()->New(mod); uint32 numLabels = ReadNum(); - for (uint32 i = 0; i < numLabels; i++) { + for (uint32 i = 0; i < numLabels; ++i) { s->GetOffsets().push_back(ReadNum()); } stmt = s; @@ -787,7 +786,7 @@ BlockNode *BinaryMplImport::ImportBlockNode(MIRFunction *func) { } void BinaryMplImport::ReadFunctionBodyField() { - ReadInt(); /// skip total size + (void)ReadInt(); /// skip total size int32 size = ReadInt(); for (int64 i = 0; i < size; i++) { PUIdx puIdx = ImportFunction(); @@ -806,12 +805,11 @@ void BinaryMplImport::ReadFunctionBodyField() { ImportLocalTypeNameTable(fn->GetTypeNameTab()); ImportFormalsStIdx(fn); ImportAliasMap(fn); - ImportBlockNode(fn); + (void)ImportBlockNode(fn); mod.AddFunction(fn); } int64 tag = ReadNum(); CHECK_FATAL(tag == ~kBinFunctionBodyStart, "pattern mismatch in Read FunctionBody"); return; } - } // namespace maple diff --git a/src/mapleall/maple_ir/src/bin_mpl_export.cpp b/src/mapleall/maple_ir/src/bin_mpl_export.cpp index 4dcfa1976943afe7a736101465bd0ff7c9156f4a..6a1bae0e0328f4d4cbb4feb2994f4174ba593419 100644 --- a/src/mapleall/maple_ir/src/bin_mpl_export.cpp +++ b/src/mapleall/maple_ir/src/bin_mpl_export.cpp @@ -62,8 +62,7 @@ void OutputConstLbl(const MIRConst &constVal, BinaryMplExport &mplExport) { mplExport.WriteNum(kBinKindConstAddrofLabel); mplExport.OutputConstBase(constVal); const MIRLblConst &lblConst = static_cast(constVal); - mplExport.WriteNum(lblConst.GetValue()); // LabelIdx - // not needed to output puIdx + mplExport.WriteNum(lblConst.GetValue()); // LabelIdx not needed to output puIdx } void OutputConstStr(const MIRConst &constVal, BinaryMplExport &mplExport) { @@ -114,7 +113,7 @@ void OutputConstAgg(const MIRConst &constVal, BinaryMplExport &mplExport) { void OutputConstSt(MIRConst &constVal, BinaryMplExport &mplExport) { mplExport.WriteNum(kBinKindConstSt); mplExport.OutputConstBase(constVal); - MIRStConst &stConst = static_cast(constVal); + auto &stConst = static_cast(constVal); size_t size = stConst.GetStVec().size(); mplExport.WriteNum(size); for (size_t i = 0; i < size; ++i) { @@ -141,7 +140,7 @@ static bool InitOutputConstFactory() { return true; } -void OutputTypeScalar(const MIRType &ty, BinaryMplExport &mplExport, bool canUseTypename) { +void OutputTypeScalar(const MIRType &ty, BinaryMplExport &mplExport, bool) { mplExport.WriteNum(kBinKindTypeScalar); mplExport.OutputTypeBase(ty); } @@ -150,11 +149,11 @@ void OutputTypePointer(const MIRType &ty, BinaryMplExport &mplExport, bool canUs const auto &type = static_cast(ty); mplExport.WriteNum(kBinKindTypePointer); mplExport.OutputTypeBase(type); - mplExport.OutputType(type.GetPointedTyIdx(), canUseTypename); mplExport.OutputTypeAttrs(type.GetTypeAttrs()); + mplExport.OutputType(type.GetPointedTyIdx(), canUseTypename); } -void OutputTypeByName(const MIRType &ty, BinaryMplExport &mplExport, bool canUseTypename) { +void OutputTypeByName(const MIRType &ty, BinaryMplExport &mplExport, bool) { mplExport.WriteNum(kBinKindTypeByName); mplExport.OutputTypeBase(ty); } @@ -203,13 +202,13 @@ void OutputTypeFunction(const MIRType &ty, BinaryMplExport &mplExport, bool canU } } -void OutputTypeParam(const MIRType &ty, BinaryMplExport &mplExport, bool canUseTypename) { +void OutputTypeParam(const MIRType &ty, BinaryMplExport &mplExport, bool) { const auto &type = static_cast(ty); mplExport.WriteNum(kBinKindTypeParam); mplExport.OutputTypeBase(type); } -void OutputTypeInstantVector(const MIRType &ty, BinaryMplExport &mplExport, bool canUseTypename) { +void OutputTypeInstantVector(const MIRType &ty, BinaryMplExport &mplExport, bool) { const auto &type = static_cast(ty); mplExport.WriteNum(kBinKindTypeInstantVector); mplExport.OutputTypeBase(type); @@ -225,7 +224,7 @@ void OutputTypeGenericInstant(const MIRType &ty, BinaryMplExport &mplExport, boo mplExport.OutputType(type.GetGenericTyIdx(), canUseTypename); } -void OutputTypeBitField(const MIRType &ty, BinaryMplExport &mplExport, bool canUseTypename) { +void OutputTypeBitField(const MIRType &ty, BinaryMplExport &mplExport, bool) { const auto &type = static_cast(ty); mplExport.WriteNum(kBinKindTypeBitField); mplExport.OutputTypeBase(type); @@ -233,7 +232,7 @@ void OutputTypeBitField(const MIRType &ty, BinaryMplExport &mplExport, bool canU } // for Struct/StructIncomplete/Union -void OutputTypeStruct(const MIRType &ty, BinaryMplExport &mplExport, bool canUseTypename) { +void OutputTypeStruct(const MIRType &ty, BinaryMplExport &mplExport, bool) { const auto &type = static_cast(ty); mplExport.WriteNum(kBinKindTypeStruct); mplExport.OutputTypeBase(type); @@ -248,7 +247,7 @@ void OutputTypeStruct(const MIRType &ty, BinaryMplExport &mplExport, bool canUse } } -void OutputTypeClass(const MIRType &ty, BinaryMplExport &mplExport, bool canUseTypename) { +void OutputTypeClass(const MIRType &ty, BinaryMplExport &mplExport, bool) { const auto &type = static_cast(ty); mplExport.WriteNum(kBinKindTypeClass); mplExport.OutputTypeBase(type); @@ -263,7 +262,7 @@ void OutputTypeClass(const MIRType &ty, BinaryMplExport &mplExport, bool canUseT } } -void OutputTypeInterface(const MIRType &ty, BinaryMplExport &mplExport, bool canUseTypename) { +void OutputTypeInterface(const MIRType &ty, BinaryMplExport &mplExport, bool) { const auto &type = static_cast(ty); mplExport.WriteNum(kBinKindTypeInterface); mplExport.OutputTypeBase(type); @@ -278,8 +277,9 @@ void OutputTypeInterface(const MIRType &ty, BinaryMplExport &mplExport, bool can } } -void OutputTypeConstString(const MIRType &ty, BinaryMplExport &mplExport, bool canUseTypename) { +void OutputTypeConstString(const MIRType &ty, BinaryMplExport&, bool) { ASSERT(false, "Type's kind not yet implemented: %d", ty.GetKind()); + (void)ty; } static bool InitOutputTypeFactory() { @@ -498,7 +498,6 @@ void BinaryMplExport::OutputFieldPair(const FieldPair &fp) { if ((fieldVar != nullptr) && (fieldVar->GetKonst() != nullptr) && (fieldVar->GetKonst()->GetKind() == kConstStr16Const)) { WriteNum(kBinInitConst); - fieldVar->GetKonst()->SetType(*fieldVar->GetType()); OutputConst(fieldVar->GetKonst()); } else { WriteNum(0); @@ -675,7 +674,6 @@ void BinaryMplExport::OutputFunction(PUIdx puIdx) { OutputType(formalDef.formalTyIdx, false); WriteNum(formalDef.formalAttrs.GetAttrFlag()); } - mod.SetCurFunction(savedFunc); } @@ -704,7 +702,7 @@ void BinaryMplExport::WriteHeaderField(uint64 contentIdx) { Fixup(contentIdx, buf.size()); WriteNum(kBinHeaderStart); size_t totalSizeIdx = buf.size(); - ExpandFourBuffSize(); /// total size of this field to ~BIN_IMPORT_START + ExpandFourBuffSize(); // total size of this field to ~BIN_IMPORT_START WriteNum(mod.GetFlavor()); WriteNum(mod.GetSrcLang()); WriteNum(mod.GetID()); @@ -762,31 +760,30 @@ void BinaryMplExport::WriteTypeField(uint64 contentIdx, bool useClassList) { WriteNum(~kBinTypeStart); } + void BinaryMplExport::WriteSymField(uint64 contentIdx) { Fixup(contentIdx, buf.size()); - // LogInfo::MapleLogger() << "Write SYM Field " << std::endl; WriteNum(kBinSymStart); uint64 totalSizeIdx = buf.size(); - ExpandFourBuffSize(); /// total size of this field to ~BIN_SYM_START + ExpandFourBuffSize(); // total size of this field to ~BIN_SYM_START uint64 outsymSizeIdx = buf.size(); - ExpandFourBuffSize(); /// size of OutSym + ExpandFourBuffSize(); // size of OutSym int32 size = 0; if (not2mplt) { - for (auto sit = GetMIRModule().GetSymbolDefOrder().begin(); sit != GetMIRModule().GetSymbolDefOrder().end(); sit++) { + for (auto sit = GetMIRModule().GetSymbolDefOrder().begin(); + sit != GetMIRModule().GetSymbolDefOrder().end(); ++sit) { MIRSymbol *s = GlobalTables::GetGsymTable().GetSymbolFromStidx(sit->Idx()); // Verify: all wpofake variables should have been deleted from globaltable ASSERT(!(s->IsWpoFakeParm() || s->IsWpoFakeRet()) || s->IsDeleted(), "wpofake var not deleted"); MIRStorageClass storageClass = s->GetStorageClass(); MIRSymKind sKind = s->GetSKind(); - if (s->IsDeleted() || - storageClass == kScUnused || + if (s->IsDeleted() || storageClass == kScUnused || (s->GetIsImported() && !s->GetAppearsInCode()) || (storageClass == kScExtern && sKind == kStFunc)) { continue; } - // printf("EXPORT Writing symbol %s\n", s->GetName().c_str()); OutputSymbol(s); size++; } @@ -825,9 +822,9 @@ void BinaryMplExport::WriteContentField4nonmplt(int fieldNum, uint64 *fieldStart CHECK_FATAL(fieldStartP != nullptr, "fieldStartP is null."); WriteNum(kBinContentStart); size_t totalSizeIdx = buf.size(); - ExpandFourBuffSize(); /// total size of this field to ~BIN_SYM_START + ExpandFourBuffSize(); // total size of this field to ~BIN_SYM_START - WriteInt(fieldNum); /// size of Content item + WriteInt(fieldNum); // size of Content item WriteNum(kBinHeaderStart); fieldStartP[0] = buf.size(); @@ -849,9 +846,9 @@ void BinaryMplExport::WriteContentField4nonJava(int fieldNum, uint64 *fieldStart CHECK_FATAL(fieldStartP != nullptr, "fieldStartP is null."); WriteNum(kBinContentStart); size_t totalSizeIdx = buf.size(); - ExpandFourBuffSize(); /// total size of this field to ~BIN_SYM_START + ExpandFourBuffSize(); // total size of this field to ~BIN_SYM_START - WriteInt(fieldNum); /// size of Content item + WriteInt(fieldNum); // size of Content item WriteNum(kBinHeaderStart); fieldStartP[0] = buf.size(); @@ -886,7 +883,7 @@ void BinaryMplExport::Export(const std::string &fname, std::unordered_setsecond)); - return; + if (ty->GetKind() != kTypeFunction) { + WriteNum(-(it->second)); + return; + } + ++BinaryMplExport::typeMarkOffset; + } else { + size_t mark = typMark.size() + BinaryMplExport::typeMarkOffset; + typMark[ty] = mark; } - size_t mark = typMark.size(); - typMark[ty] = mark; if (canUseTypename && !ty->IsNameIsLocal() && ty->GetNameStrIdx() != GStrIdx(0)) { WriteNum(kBinKindTypeViaTypename); diff --git a/src/mapleall/maple_ir/src/bin_mpl_import.cpp b/src/mapleall/maple_ir/src/bin_mpl_import.cpp index 67c91533ac980d722aa97298daee644d2fdb225a..df94e65b3326bcd5ad7250a1401fc6370a51bd1c 100644 --- a/src/mapleall/maple_ir/src/bin_mpl_import.cpp +++ b/src/mapleall/maple_ir/src/bin_mpl_import.cpp @@ -135,7 +135,7 @@ MIRConst *BinaryMplImport::ImportConst(MIRFunction *func) { LabelIdx lidx = ReadNum(); PUIdx puIdx = func->GetPuidx(); MIRLblConst *lblConst = memPool->New(lidx, puIdx, *type, fieldID); - func->GetLabelTab()->addrTakenLabels.insert(lidx); + (void)func->GetLabelTab()->addrTakenLabels.insert(lidx); return lblConst; } case kBinKindConstStr: { @@ -333,7 +333,7 @@ void BinaryMplImport::UpdateMethodSymbols() { if (fn->GetFormalDefVec().size() != 0) { continue; // already updated in ImportFunction() } - for (size_t i = 0; i < funcType->GetParamTypeList().size(); i++ ) { + for (size_t i = 0; i < funcType->GetParamTypeList().size(); ++i) { FormalDef formalDef(nullptr, funcType->GetParamTypeList()[i], funcType->GetParamAttrsList()[i]); fn->GetFormalDefVec().push_back(formalDef); } @@ -554,10 +554,10 @@ TyIdx BinaryMplImport::ImportType(bool forPointedType) { type.SetNameIsLocal(nameIsLocal); size_t idx = typTab.size(); typTab.push_back(nullptr); + type.SetTypeAttrs(ImportTypeAttrs()); ++ptrLev; type.SetPointedTyIdx(ImportType(true)); --ptrLev; - type.SetTypeAttrs(ImportTypeAttrs()); MIRType *origType = &InsertInTypeTables(type); typTab[idx] = origType; if (typeNeedsComplete != nullptr && ptrLev == 0) { @@ -735,8 +735,10 @@ MIRType &BinaryMplImport::InsertInTypeTables(MIRType &type) { TyIdx prevTyIdx = mod.GetTypeNameTab()->GetTyIdxFromGStrIdx(type.GetNameStrIdx()); if (prevTyIdx != 0u && !type.IsNameIsLocal()) { MIRType *prevType = GlobalTables::GetTypeTable().GetTypeFromTyIdx(prevTyIdx); - if ((IsIncomplete(*prevType) && IsIncomplete(type)) || (!IsIncomplete(*prevType) && !IsIncomplete(type)) || - (!IsIncomplete(*prevType) && IsIncomplete(type))) { + if (!prevType->IsMIRTypeByName() && + ((IsIncomplete(*prevType) && IsIncomplete(type)) || + (!IsIncomplete(*prevType) && !IsIncomplete(type)) || + (!IsIncomplete(*prevType) && IsIncomplete(type)))) { resultTypePtr = prevType->CopyMIRTypeNode(); if (resultTypePtr->GetKind() == kTypeStruct || resultTypePtr->GetKind() == kTypeStructIncomplete) { tmpStruct.push_back(static_cast(resultTypePtr)); @@ -888,8 +890,7 @@ PUIdx BinaryMplImport::ImportFunction() { func->SetStIdx(funcSt->GetStIdx()); func->SetFuncAttrs(ReadNum()); func->SetFlag(ReadNum()); - /*func->SetClassTyIdx(*/ImportType(); // not set the field to mimic parser - // import formal parameter informcation + (void)ImportType(); // not set the field to mimic parser size_t size = ReadNum(); if (func->GetFormalDefVec().size() == 0) { for (size_t i = 0; i < size; i++) { @@ -986,11 +987,12 @@ void BinaryMplImport::ReadTypeField() { CHECK_FATAL(tag == ~kBinTypeStart, "pattern mismatch in Read TYPE"); } + void BinaryMplImport::ReadSymField() { SkipTotalSize(); int32 size = ReadInt(); for (int64 i = 0; i < size; i++) { - InSymbol(nullptr); + (void)InSymbol(nullptr); } int64 tag = ReadNum(); CHECK_FATAL(tag == ~kBinSymStart, "pattern mismatch in Read SYM"); @@ -1033,7 +1035,7 @@ bool BinaryMplImport::Import(const std::string &fname, bool readSymbols, bool re Reset(); ReadFileAt(fname, 0); int32 magic = ReadInt(); - if (kMpltMagicNumber != magic && (kMpltMagicNumber+0x10) != magic) { + if (kMpltMagicNumber != magic && (kMpltMagicNumber + 0x10) != magic) { buf.clear(); return false; } diff --git a/src/mapleall/maple_ir/src/driver.cpp b/src/mapleall/maple_ir/src/driver.cpp index 7cc9a1af47da82da36901f703f3c39d357cd7b26..8711dcb00ebd93811538a74f3f0df50c49c3c4c6 100644 --- a/src/mapleall/maple_ir/src/driver.cpp +++ b/src/mapleall/maple_ir/src/driver.cpp @@ -19,6 +19,7 @@ #include "bin_mplt.h" #include "opcode_info.h" #include "mir_function.h" +#include "constantfold.h" #include "mir_type.h" using namespace maple; @@ -31,23 +32,24 @@ int main(int argc, char **argv) { constexpr int judgeNumber = 2; if (argc < judgeNumber) { (void)MIR_PRINTF( - "usage: ./irbuild [-b] [-dumpfunc=] [-srclang=] \n" - " By default, the files are converted to corresponding ascii format.\n" - " If -b is specified, output is binary format instead.\n" -// " If -fold is specified, constant folding is performed before outputing the IR.\n" - " If -dumpfunc= is specified, only functions with name containing the string is output.\n" - " -dumpfunc= can be specified multiple times to give multiple strings.\n" - " -srclang specifies the source language that produces the mpl file. \n" - " Each output file has .irb added after its file stem.\n"); + "usage: ./irbuild [-b] [-dumpfunc=] [-srclang=] \n" + " By default, the files are converted to corresponding ascii format.\n" + " If -b is specified, output is binary format instead.\n" + " If -dumpfunc= is specified, only functions with name containing the string is output.\n" + " -dumpfunc= can be specified multiple times to give multiple strings.\n" + " -srclang specifies the source language that produces the mpl file. \n" + " Each output file has .irb added after its file stem.\n"); exit(1); } + std::vector themodule(argc, nullptr); bool useBinary = false; bool doConstantFold = false; MIRSrcLang srcLang = kSrcLangUnknown; // process the options which must come first maple::int32 i = 1; - while (argv[i][0] == '-' ) { + while (argv[i][0] == '-') { if (argv[i][1] == 'b' && argv[i][2] == '\0') { useBinary = true; } else if (strcmp(argv[i], "-fold") == 0) { @@ -55,17 +57,17 @@ int main(int argc, char **argv) { } else if (strncmp(argv[i], "-dumpfunc=", 10) == 0 && strlen(argv[i]) > 10) { std::string funcName(&argv[i][10]); dumpFuncSet.insert(funcName); - } else if (strcmp(argv[i], "-srclang=java") == 0 ) { + } else if (strcmp(argv[i], "-srclang=java") == 0) { srcLang = kSrcLangJava; - } else if (strcmp(argv[i], "-srclang=c") == 0 ) { + } else if (strcmp(argv[i], "-srclang=c") == 0) { srcLang = kSrcLangC; - } else if (strcmp(argv[i], "-srclang=c++") == 0 ) { + } else if (strcmp(argv[i], "-srclang=c++") == 0) { srcLang = kSrcLangCPlusPlus; } else { ERR(kLncErr, "irbuild: unrecognized command line option"); return 1; } - i++; + ++i; } // process the input files while (i < argc) { diff --git a/src/mapleall/maple_ir/src/mir_builder.cpp b/src/mapleall/maple_ir/src/mir_builder.cpp index ae9fbc1a4d4c602bff1ec4027371b9c68a89302c..a4c92ca4231c5d6d6066e23ec98df56b64eae3bc 100644 --- a/src/mapleall/maple_ir/src/mir_builder.cpp +++ b/src/mapleall/maple_ir/src/mir_builder.cpp @@ -228,11 +228,15 @@ MIRFunction *MIRBuilder::GetOrCreateFunction(const std::string &str, TyIdx retTy } auto *fn = mirModule->GetMemPool()->New(mirModule, funcSt->GetStIdx()); fn->SetPuidx(GlobalTables::GetFunctionTable().GetFuncTable().size()); - auto *funcType = mirModule->GetMemPool()->New(mirModule->GetMPAllocator()); - fn->SetMIRFuncType(funcType); + MIRFuncType funcType(mirModule->GetMPAllocator()); + funcType.SetRetTyIdx(retTyIdx); + auto funcTyIdx = GlobalTables::GetTypeTable().GetOrCreateMIRType(&funcType); + auto *funcTypeInTypeTable = static_cast(GlobalTables::GetTypeTable().GetTypeFromTyIdx(funcTyIdx)); + fn->SetMIRFuncType(funcTypeInTypeTable); fn->SetReturnTyIdx(retTyIdx); GlobalTables::GetFunctionTable().GetFuncTable().push_back(fn); funcSt->SetFunction(fn); + funcSt->SetTyIdx(funcTyIdx); return fn; } @@ -474,7 +478,8 @@ ConstvalNode *MIRBuilder::CreateConstval(MIRConst *mirConst) { ConstvalNode *MIRBuilder::CreateIntConst(int64 val, PrimType pty) { auto *mirConst = - GlobalTables::GetIntConstTable().GetOrCreateIntConst(val, *GlobalTables::GetTypeTable().GetPrimType(pty), 0/*fieldID*/); + GlobalTables::GetIntConstTable().GetOrCreateIntConst(val, *GlobalTables::GetTypeTable().GetPrimType(pty), + 0 /* fieldID */); return GetCurrentFuncCodeMp()->New(pty, mirConst); } @@ -497,7 +502,8 @@ ConstvalNode *MIRBuilder::CreateFloat128Const(const uint64 *val) { } ConstvalNode *MIRBuilder::GetConstInt(MemPool &memPool, int val) { - auto *mirConst = GlobalTables::GetIntConstTable().GetOrCreateIntConst(val, *GlobalTables::GetTypeTable().GetInt64(), 0/*fieldID*/); + auto *mirConst = GlobalTables::GetIntConstTable().GetOrCreateIntConst(val, *GlobalTables::GetTypeTable().GetInt64(), + 0 /* fieldID */); return memPool.New(PTY_i32, mirConst); } diff --git a/src/mapleall/maple_ir/src/mir_module.cpp b/src/mapleall/maple_ir/src/mir_module.cpp index 909670fd18a00a64c2a8877dcd359e9449dc5e91..85ff1000e541d75ddcc33c7dabcf8d78a1cea0b5 100644 --- a/src/mapleall/maple_ir/src/mir_module.cpp +++ b/src/mapleall/maple_ir/src/mir_module.cpp @@ -12,6 +12,7 @@ * FIT FOR A PARTICULAR PURPOSE. * See the Mulan PSL v2 for more details. */ +#include "mir_module.h" #include #include #include @@ -276,8 +277,7 @@ void MIRModule::DumpGlobals(bool emitStructureType) const { } } -void MIRModule::Dump(bool emitStructureType, - std::unordered_set *dumpFuncSet) const { +void MIRModule::Dump(bool emitStructureType, const std::unordered_set *dumpFuncSet) const { DumpGlobals(emitStructureType); DumpFunctionList(dumpFuncSet); } @@ -619,7 +619,7 @@ MIRFunction *MIRModule::FindEntryFunction() { // module to the file with given file suffix, and file stem from // this->fileName appended with phaseName void MIRModule::OutputAsciiMpl(const char *phaseName, const char *suffix, - std::unordered_set *dumpFuncSet, + const std::unordered_set *dumpFuncSet, bool emitStructureType, bool binaryform) { ASSERT(!(emitStructureType && binaryform), "Cannot emit type info in .bpl"); std::string fileStem; @@ -640,9 +640,9 @@ void MIRModule::OutputAsciiMpl(const char *phaseName, const char *suffix, LogInfo::MapleLogger().rdbuf(backup); // restore LogInfo::MapleLogger()'s buffer mplFile.close(); } else { - BinaryMplt binMplt(*this); - binMplt.GetBinExport().not2mplt = true; - binMplt.Export(outfileName); + BinaryMplt binaryMplt(*this); + binaryMplt.GetBinExport().not2mplt = true; + binaryMplt.Export(outfileName); } } diff --git a/src/mapleall/maple_ir/src/mir_nodes.cpp b/src/mapleall/maple_ir/src/mir_nodes.cpp index 4e5b48864b3ce78c1c34139c2e64479256b0c0ce..bfffaa1fa2a03a8b5444a6961699360f555359d0 100644 --- a/src/mapleall/maple_ir/src/mir_nodes.cpp +++ b/src/mapleall/maple_ir/src/mir_nodes.cpp @@ -462,7 +462,7 @@ MIRType *ArrayNode::GetArrayType(const TypeTable &tt) { const BaseNode *ArrayNode::GetDim(const MIRModule &mod, TypeTable &tt, int i) const { const auto *arrayType = static_cast(GetArrayType(tt)); auto *mirConst = GlobalTables::GetIntConstTable().GetOrCreateIntConst( - i, *tt.GetTypeFromTyIdx(arrayType->GetElemTyIdx()), 0/*fieldID*/); + i, *tt.GetTypeFromTyIdx(arrayType->GetElemTyIdx()), 0 /* fieldID */); return mod.CurFuncCodeMemPool()->New(mirConst); } BaseNode *ArrayNode::GetDim(const MIRModule &mod, TypeTable &tt, int i) { diff --git a/src/mapleall/maple_ir/src/mir_parser.cpp b/src/mapleall/maple_ir/src/mir_parser.cpp index 83f8269026590dec73ef1d5300b1f691c8561563..d0f464a67eb8b2124913bcdb60bf3915aaf8bff0 100644 --- a/src/mapleall/maple_ir/src/mir_parser.cpp +++ b/src/mapleall/maple_ir/src/mir_parser.cpp @@ -1871,7 +1871,8 @@ bool MIRParser::ParseExprConstval(BaseNodePtr &expr) { exprConst->SetPrimType(GetPrimitiveType(typeTk)); lexer.NextToken(); MIRConst *constVal = nullptr; - if (!ParseScalarValue(constVal, *GlobalTables::GetTypeTable().GetPrimType(exprConst->GetPrimType()), 0/*fieldID*/)) { + if (!ParseScalarValue(constVal, *GlobalTables::GetTypeTable().GetPrimType(exprConst->GetPrimType()), + 0 /* fieldID */)) { Error("expect scalar type but get "); return false; } diff --git a/src/mapleall/maple_ir/src/parser.cpp b/src/mapleall/maple_ir/src/parser.cpp index c5f5281d64700ffe121cf9b0a3d2c98f0d363653..df4c134cc2741d7a01740d758336cc685faef954 100644 --- a/src/mapleall/maple_ir/src/parser.cpp +++ b/src/mapleall/maple_ir/src/parser.cpp @@ -2007,7 +2007,7 @@ bool MIRParser::ParseInitValue(MIRConstPtr &theConst, TyIdx tyIdx, bool allowEmp if (tokenKind != TK_lbrack) { // scalar MIRConst *mirConst = nullptr; if (IsConstValue(tokenKind)) { - if (!ParseScalarValue(mirConst, type, 0/*fieldID*/)) { + if (!ParseScalarValue(mirConst, type, 0 /* fieldID */)) { Error("ParseInitValue expect scalar value"); return false; } @@ -2044,7 +2044,7 @@ bool MIRParser::ParseInitValue(MIRConstPtr &theConst, TyIdx tyIdx, bool allowEmp // parse single const or another dimension array MIRConst *subConst = nullptr; if (IsConstValue(tokenKind)) { - if (!ParseScalarValue(subConst, *elemType, 0/*fieldID*/)) { + if (!ParseScalarValue(subConst, *elemType, 0 /* fieldID */)) { Error("ParseInitValue expect scalar value"); return false; } diff --git a/src/mapleall/maple_me/src/irmap.cpp b/src/mapleall/maple_me/src/irmap.cpp index 5d330458d9bc0d4075cf0435623207e9e0065b86..3180750b30d2765d999671b90fb0433aa785dd7b 100644 --- a/src/mapleall/maple_me/src/irmap.cpp +++ b/src/mapleall/maple_me/src/irmap.cpp @@ -462,7 +462,8 @@ MeExpr *IRMap::CreateConstMeExpr(PrimType pType, MIRConst &mirConst) { MeExpr *IRMap::CreateIntConstMeExpr(int64 value, PrimType pType) { auto *intConst = - GlobalTables::GetIntConstTable().GetOrCreateIntConst(value, *GlobalTables::GetTypeTable().GetPrimType(pType), 0/*fieldID*/); + GlobalTables::GetIntConstTable().GetOrCreateIntConst(value, *GlobalTables::GetTypeTable().GetPrimType(pType), + 0 /* fieldID */); return CreateConstMeExpr(pType, *intConst); } diff --git a/src/mapleall/mpl2mpl/src/coderelayout.cpp b/src/mapleall/mpl2mpl/src/coderelayout.cpp index d61d4ef4df803e4d23d6d10541f0472784ada733..ac3acad23a2522fc05c8d8647b11999fd0f0ca21 100644 --- a/src/mapleall/mpl2mpl/src/coderelayout.cpp +++ b/src/mapleall/mpl2mpl/src/coderelayout.cpp @@ -220,7 +220,7 @@ MIRSymbol *CodeReLayout::GenStrSym(const std::string &str) { staticSym->SetStorageClass(kScFstatic); for (const char &c : newStr) { MIRConst *newConst = GlobalTables::GetIntConstTable().GetOrCreateIntConst( - c, *GlobalTables::GetTypeTable().GetUInt8(), 0/*fieldID*/); + c, *GlobalTables::GetTypeTable().GetUInt8(), 0 /* fieldID */); strTabAggConst->PushBack(newConst); } staticSym->SetKonst(strTabAggConst); diff --git a/src/mapleall/mpl2mpl/src/constantfold.cpp b/src/mapleall/mpl2mpl/src/constantfold.cpp index 34b8b3fe25a6ac2e2b940d1b7616cc10c75669b4..42221c47c671864fc7db995b21f6bbbd6f3a4cd8 100644 --- a/src/mapleall/mpl2mpl/src/constantfold.cpp +++ b/src/mapleall/mpl2mpl/src/constantfold.cpp @@ -415,10 +415,10 @@ MIRIntConst *ConstantFold::FoldIntConstComparisonMIRConst(Opcode opcode, PrimTyp // form the constant MIRIntConst *constValue = nullptr; if (type.GetPrimType() == PTY_dyni32) { - constValue = GlobalTables::GetIntConstTable().GetOrCreateIntConst(0, type, 0/*fieldID*/); + constValue = GlobalTables::GetIntConstTable().GetOrCreateIntConst(0, type, 0 /* fieldID */); constValue->SetValue(kJsTypeNumberInHigh32Bit | (static_cast(result))); } else { - constValue = GlobalTables::GetIntConstTable().GetOrCreateIntConst(result, type, 0/*fieldID*/); + constValue = GlobalTables::GetIntConstTable().GetOrCreateIntConst(result, type, 0 /* fieldID */); } return constValue; } @@ -621,12 +621,13 @@ MIRConst *ConstantFold::FoldIntConstBinaryMIRConst(Opcode opcode, PrimType resul // form the constant MIRIntConst *constValue = nullptr; if (type.GetPrimType() == PTY_dyni32) { - constValue = GlobalTables::GetIntConstTable().GetOrCreateIntConst(0, type, 0/*fieldID*/); + constValue = GlobalTables::GetIntConstTable().GetOrCreateIntConst(0, type, 0 /* fieldID */); constValue->SetValue(kJsTypeNumberInHigh32Bit | (static_cast(result32))); } else if (useResult64) { - constValue = GlobalTables::GetIntConstTable().GetOrCreateIntConst(static_cast(result64), type, 0/*fieldID*/); + constValue = + GlobalTables::GetIntConstTable().GetOrCreateIntConst(static_cast(result64), type, 0 /* fieldID */); } else { - constValue = GlobalTables::GetIntConstTable().GetOrCreateIntConst(result32, type, 0/*fieldID*/); + constValue = GlobalTables::GetIntConstTable().GetOrCreateIntConst(result32, type, 0 /* fieldID */); } return constValue; } @@ -852,7 +853,8 @@ MIRIntConst *ConstantFold::FoldFPConstComparisonMIRConst(Opcode opcode, PrimType ASSERT(false, "Unknown opcode for FoldFPConstComparison"); break; } - MIRIntConst *resultConst = GlobalTables::GetIntConstTable().GetOrCreateIntConst(constValue, type, 0/*fieldID*/); + MIRIntConst *resultConst = + GlobalTables::GetIntConstTable().GetOrCreateIntConst(constValue, type, 0 /* fieldID */); return resultConst; } @@ -975,12 +977,13 @@ ConstvalNode *ConstantFold::FoldIntConstUnary(Opcode opcode, PrimType resultType // form the constant MIRIntConst *constValue = nullptr; if (type.GetPrimType() == PTY_dyni32) { - constValue = GlobalTables::GetIntConstTable().GetOrCreateIntConst(0, type, 0/*fieldID*/); + constValue = GlobalTables::GetIntConstTable().GetOrCreateIntConst(0, type, 0 /* fieldID */); constValue->SetValue(kJsTypeNumberInHigh32Bit | (static_cast(result32))); } else if (useResult64) { - constValue = GlobalTables::GetIntConstTable().GetOrCreateIntConst(static_cast(result64), type, 0/*fieldID*/); + constValue = + GlobalTables::GetIntConstTable().GetOrCreateIntConst(static_cast(result64), type, 0 /* fieldID */); } else { - constValue = GlobalTables::GetIntConstTable().GetOrCreateIntConst(result32, type, 0/*fieldID*/); + constValue = GlobalTables::GetIntConstTable().GetOrCreateIntConst(result32, type, 0 /* fieldID */); } // form the ConstvalNode ConstvalNode *resultConst = mirModule->CurFuncCodeMemPool()->New(); @@ -1058,7 +1061,7 @@ std::pair ConstantFold::FoldSizeoftype(SizeoftypeNode *node) c ConstvalNode *constValueNode = mirModule->CurFuncCodeMemPool()->New(); constValueNode->SetPrimType(node->GetPrimType()); constValueNode->SetConstVal(GlobalTables::GetIntConstTable().GetOrCreateIntConst( - static_cast(size), resultType, 0/*fieldID*/)); + static_cast(size), resultType, 0 /* fieldID */)); result = constValueNode; } return std::make_pair(result, 0); @@ -1170,7 +1173,7 @@ ConstvalNode *ConstantFold::FoldCeil(const ConstvalNode &cst, PrimType fromType, return nullptr; } resultConst->SetConstVal(GlobalTables::GetIntConstTable().GetOrCreateIntConst( - static_cast(floatValue), resultType, 0/*fieldID*/)); + static_cast(floatValue), resultType, 0 /* fieldID */)); } else { const MIRDoubleConst *constValue = safe_cast(cst.GetConstVal()); ASSERT_NOT_NULL(constValue); @@ -1179,7 +1182,7 @@ ConstvalNode *ConstantFold::FoldCeil(const ConstvalNode &cst, PrimType fromType, return nullptr; } resultConst->SetConstVal(GlobalTables::GetIntConstTable().GetOrCreateIntConst( - static_cast(doubleValue), resultType, 0/*fieldID*/)); + static_cast(doubleValue), resultType, 0 /* fieldID */)); } return resultConst; } @@ -1213,7 +1216,8 @@ MIRConst *ConstantFold::FoldFloorMIRConst(const MIRConst &cst, PrimType fromType return nullptr; } floatValue = CalIntValueFromFloatValue(floatValue, resultType); - return GlobalTables::GetIntConstTable().GetOrCreateIntConst(static_cast(floatValue), resultType, 0/*fieldID*/); + return GlobalTables::GetIntConstTable().GetOrCreateIntConst(static_cast(floatValue), resultType, + 0 /* fieldID */); } else { const auto &constValue = static_cast(cst); double doubleValue = floor(constValue.GetValue()); @@ -1221,7 +1225,8 @@ MIRConst *ConstantFold::FoldFloorMIRConst(const MIRConst &cst, PrimType fromType return nullptr; } doubleValue = CalIntValueFromFloatValue(doubleValue, resultType); - return GlobalTables::GetIntConstTable().GetOrCreateIntConst(static_cast(doubleValue), resultType, 0/*fieldID*/); + return GlobalTables::GetIntConstTable().GetOrCreateIntConst(static_cast(doubleValue), resultType, + 0 /* fieldID */); } } @@ -1240,14 +1245,16 @@ MIRConst *ConstantFold::FoldRoundMIRConst(const MIRConst &cst, PrimType fromType if (FloatToIntOverflow(floatValue, toType)) { return nullptr; } - return GlobalTables::GetIntConstTable().GetOrCreateIntConst(static_cast(floatValue), resultType, 0/*fieldID*/); + return GlobalTables::GetIntConstTable().GetOrCreateIntConst(static_cast(floatValue), resultType, + 0 /* fieldID */); } else if (fromType == PTY_f64) { const auto &constValue = static_cast(cst); double doubleValue = round(constValue.GetValue()); if (DoubleToIntOverflow(doubleValue, toType)) { return nullptr; } - return GlobalTables::GetIntConstTable().GetOrCreateIntConst(static_cast(doubleValue), resultType, 0/*fieldID*/); + return GlobalTables::GetIntConstTable().GetOrCreateIntConst(static_cast(doubleValue), resultType, + 0 /* fieldID */); } else if (toType == PTY_f32 && IsPrimitiveInteger(fromType)) { const auto &constValue = static_cast(cst); if (IsSignedInteger(fromType)) { @@ -1301,7 +1308,7 @@ ConstvalNode *ConstantFold::FoldTrunk(const ConstvalNode &cst, PrimType fromType return nullptr; } resultConst->SetConstVal(GlobalTables::GetIntConstTable().GetOrCreateIntConst( - static_cast(floatValue), resultType, 0/*fieldID*/)); + static_cast(floatValue), resultType, 0 /* fieldID */)); } else { const MIRDoubleConst *constValue = safe_cast(cst.GetConstVal()); CHECK_NULL_FATAL(constValue); @@ -1310,7 +1317,7 @@ ConstvalNode *ConstantFold::FoldTrunk(const ConstvalNode &cst, PrimType fromType return nullptr; } resultConst->SetConstVal(GlobalTables::GetIntConstTable().GetOrCreateIntConst( - static_cast(doubleValue), resultType, 0/*fieldID*/)); + static_cast(doubleValue), resultType, 0 /* fieldID */)); } return resultConst; } @@ -1334,7 +1341,8 @@ MIRConst *ConstantFold::FoldTypeCvtMIRConst(const MIRConst &cst, PrimType fromTy const MIRIntConst *constVal = safe_cast(cst); ASSERT_NOT_NULL(constVal); MIRType &type = *GlobalTables::GetTypeTable().GetPrimType(toType); - toConst = GlobalTables::GetIntConstTable().GetOrCreateIntConst(constVal->GetValue(), type, 0/*fieldID*/); + toConst = + GlobalTables::GetIntConstTable().GetOrCreateIntConst(constVal->GetValue(), type, 0 /* fieldID */); } return toConst; } @@ -1440,7 +1448,8 @@ MIRConst *ConstantFold::FoldSignExtendMIRConst(Opcode opcode, PrimType resultTyp result64 = ((static_cast(constVal->GetValue())) << (64u - size)) >> (64u - size); } MIRType &type = *GlobalTables::GetTypeTable().GetPrimType(resultType); - MIRIntConst *constValue = GlobalTables::GetIntConstTable().GetOrCreateIntConst(static_cast(result64), type, 0/*fieldID*/); + MIRIntConst *constValue = + GlobalTables::GetIntConstTable().GetOrCreateIntConst(static_cast(result64), type, 0 /* fieldID */); return constValue; } @@ -1816,7 +1825,8 @@ std::pair ConstantFold::FoldDepositbits(DepositbitsNode *node) ConstvalNode *resultConst = mirModule->CurFuncCodeMemPool()->New(); resultConst->SetPrimType(node->GetPrimType()); MIRType &type = *GlobalTables::GetTypeTable().GetPrimType(node->GetPrimType()); - MIRIntConst *constValue = GlobalTables::GetIntConstTable().GetOrCreateIntConst(0, type, 0/*fieldID*/); + MIRIntConst *constValue = + GlobalTables::GetIntConstTable().GetOrCreateIntConst(0, type, 0 /* fieldID */); uint64 op0ExtractVal = 0; uint64 op1ExtractVal = 0; uint64 mask0 = (1LLU << (bitsSize + bitsOffset)) - 1; diff --git a/src/mapleall/mpl2mpl/src/muid_replacement.cpp b/src/mapleall/mpl2mpl/src/muid_replacement.cpp index d8c52998d99254baa0de666680f9c5dcbd0168ea..48453ad65a60669cb9f96512721b6fe919c352a7 100644 --- a/src/mapleall/mpl2mpl/src/muid_replacement.cpp +++ b/src/mapleall/mpl2mpl/src/muid_replacement.cpp @@ -187,10 +187,11 @@ void MUIDReplacement::GenArrayClassCache() { constexpr int32 arrayClassCacheMagicNumber = 0x1a3; for (auto arrayClassName : arrayClassSet) { uint32 typeNameIdx = ReflectionAnalysis::FindOrInsertRepeatString(arrayClassName); - MIRIntConst *nameConstValue = GlobalTables::GetIntConstTable().GetOrCreateIntConst(typeNameIdx, *mType, 0/*fieldID*/); + MIRIntConst *nameConstValue = + GlobalTables::GetIntConstTable().GetOrCreateIntConst(typeNameIdx, *mType, 0 /* fieldID */); arrayClassNameConst->PushBack(nameConstValue); MIRIntConst *constValue = - GlobalTables::GetIntConstTable().GetOrCreateIntConst(arrayClassCacheMagicNumber, *mType, 0/*fieldID*/); + GlobalTables::GetIntConstTable().GetOrCreateIntConst(arrayClassCacheMagicNumber, *mType, 0 /* fieldID */); arrayClassConst->PushBack(constValue); } MIRSymbol *arrayClassNameSt = GetMIRModule().GetMIRBuilder()->CreateGlobalDecl( @@ -394,7 +395,8 @@ void MUIDReplacement::GenerateFuncDefTable() { // Use the muid index for now. It will be back-filled once we have the whole vector. MIRIntConst *indexConst = GlobalTables::GetIntConstTable().GetOrCreateIntConst(keyVal.second.second, - *GlobalTables::GetTypeTable().GetUInt32(), 0/*fieldID*/); + *GlobalTables::GetTypeTable().GetUInt32(), + 0 /* fieldID */); muidIdxTabConst->PushBack(indexConst); } FieldVector parentFields; @@ -460,13 +462,15 @@ void MUIDReplacement::GenerateFuncDefTable() { auto *indexConst = safe_cast(muidIdxTabConst->GetConstVecItem(muidIdx)); uint32 tempIdx = (static_cast(indexConst->GetValue()) & weakFuncFlag) | idx; indexConst = GlobalTables::GetIntConstTable().GetOrCreateIntConst(tempIdx, - *GlobalTables::GetTypeTable().GetUInt32(), 0/*fieldID*/); + *GlobalTables::GetTypeTable().GetUInt32(), + 0 /* fieldID */); muidIdxTabConst->SetConstVecItem(muidIdx, *indexConst); if (reflectionList.find(mirFunc->GetName()) != reflectionList.end()) { auto *tempConst = safe_cast(muidIdxTabConst->GetConstVecItem(idx)); tempIdx = weakFuncFlag | static_cast(tempConst->GetValue()); tempConst = GlobalTables::GetIntConstTable().GetOrCreateIntConst(tempIdx, - *GlobalTables::GetTypeTable().GetUInt32(), 0/*fieldID*/); + *GlobalTables::GetTypeTable().GetUInt32(), + 0 /* fieldID */); muidIdxTabConst->SetConstVecItem(idx, *tempConst); } if (Options::genIRProfile) { @@ -999,17 +1003,17 @@ void MUIDReplacement::ReplaceAddroffuncConst(MIRConst *&entry, uint32 fieldID, b // this is an index into the funcDefTab constexpr uint64 idxIntoFuncDefTabFlag = 2u; constNode = GlobalTables::GetIntConstTable().GetOrCreateIntConst( - static_cast(((offset + 1) << KReservedBits) + idxIntoFuncDefTabFlag), voidType, 0/*fieldID*/); + static_cast(((offset + 1) << KReservedBits) + idxIntoFuncDefTabFlag), voidType, 0 /* fieldID */); } else if (isVtab && func->IsAbstract()) { MIRType &type = *GlobalTables::GetTypeTable().GetVoidPtr(); - constNode = GlobalTables::GetIntConstTable().GetOrCreateIntConst(0, type, 0/*fieldID*/); + constNode = GlobalTables::GetIntConstTable().GetOrCreateIntConst(0, type, 0 /* fieldID */); } else { ASSERT(func->GetFuncSymbol() != nullptr, "null ptr check!"); offset = FindIndexFromUndefTable(*(func->GetFuncSymbol()), true); // The second least significant bit is set to 0, indicating // this is an index into the funcUndefTab constNode = GlobalTables::GetIntConstTable().GetOrCreateIntConst(static_cast((offset + 1) << KReservedBits), - voidType, 0/*fieldID*/); + voidType, 0 /* fieldID */); } if (fieldID != 0xffffffff) { constNode = GlobalTables::GetIntConstTable().GetOrCreateIntConst(constNode->GetValue(), @@ -1130,11 +1134,11 @@ void MUIDReplacement::ReplaceAddrofConst(MIRConst *&entry, bool muidIndex32Mod) if (addrSym->GetStorageClass() != kScExtern) { offset = FindIndexFromDefTable(*addrSym, false); constNode = GlobalTables::GetIntConstTable().GetOrCreateIntConst(GetDefOrUndefOffsetWithMask(offset, true, - muidIndex32Mod), voidType, 0/*fieldID*/); + muidIndex32Mod), voidType, 0 /* fieldID */); } else { offset = FindIndexFromUndefTable(*addrSym, false); constNode = GlobalTables::GetIntConstTable().GetOrCreateIntConst(GetDefOrUndefOffsetWithMask(offset, false, - muidIndex32Mod), voidType, 0/*fieldID*/); + muidIndex32Mod), voidType, 0 /* fieldID */); } entry = constNode; } @@ -1515,8 +1519,10 @@ void MUIDReplacement::GenerateCompilerVersionNum() { MIRArrayType &arrayType = *GlobalTables::GetTypeTable().GetOrCreateArrayType(*ptrType, 0); MIRAggConst *newConst = GetMIRModule().GetMemPool()->New(GetMIRModule(), arrayType); MIRType &type = *GlobalTables::GetTypeTable().GetInt32(); - MIRConst *firstConst = GlobalTables::GetIntConstTable().GetOrCreateIntConst(Version::kMajorMplVersion, type, 0/*fieldID*/); - MIRConst *secondConst = GlobalTables::GetIntConstTable().GetOrCreateIntConst(Version::kMinorCompilerVersion, type, 0/*fieldID*/); + MIRConst *firstConst = + GlobalTables::GetIntConstTable().GetOrCreateIntConst(Version::kMajorMplVersion, type, 0 /* fieldID */); + MIRConst *secondConst = + GlobalTables::GetIntConstTable().GetOrCreateIntConst(Version::kMinorCompilerVersion, type, 0 /* fieldID */); newConst->PushBack(firstConst); newConst->PushBack(secondConst); std::string symName = namemangler::kCompilerVersionNum + GetMIRModule().GetFileNameAsPostfix(); diff --git a/src/mapleall/mpl2mpl/src/native_stub_func.cpp b/src/mapleall/mpl2mpl/src/native_stub_func.cpp index 54cae03176695e2937cf4546ab0b671955612bcd..1bb10a6e0578e237336cdadffbba64c95ee0ee5e 100644 --- a/src/mapleall/mpl2mpl/src/native_stub_func.cpp +++ b/src/mapleall/mpl2mpl/src/native_stub_func.cpp @@ -309,7 +309,7 @@ void NativeStubFuncGeneration::GenerateRegFuncTabEntry() { uint64 locIdx = regFuncTabConst->GetConstVec().size(); auto *newConst = GlobalTables::GetIntConstTable().GetOrCreateIntConst(static_cast((locIdx << locIdxShift) | locIdxMask), - *GlobalTables::GetTypeTable().GetVoidPtr(), 0/*fieldID*/); + *GlobalTables::GetTypeTable().GetVoidPtr(), 0 /* fieldID */); regFuncTabConst->PushBack(newConst); } @@ -330,11 +330,11 @@ void NativeStubFuncGeneration::GenerateRegTabEntry(const MIRFunction &func) { uint32 baseFuncNameWithTypeIdx = ReflectionAnalysis::FindOrInsertRepeatString(tmp, true); // always used uint32 classIdx = ReflectionAnalysis::FindOrInsertRepeatString(base, true); // always used // Using MIRIntConst instead of MIRStruct for RegTable. - auto *baseConst = - GlobalTables::GetIntConstTable().GetOrCreateIntConst(classIdx, *GlobalTables::GetTypeTable().GetVoidPtr(), 0/*fieldID*/); + auto *baseConst = GlobalTables::GetIntConstTable().GetOrCreateIntConst( + classIdx, *GlobalTables::GetTypeTable().GetVoidPtr(), 0 /* fieldID */); regTableConst->PushBack(baseConst); - auto *newConst = GlobalTables::GetIntConstTable().GetOrCreateIntConst(baseFuncNameWithTypeIdx, - *GlobalTables::GetTypeTable().GetVoidPtr(), 0/*fieldID*/); + auto *newConst = GlobalTables::GetIntConstTable().GetOrCreateIntConst( + baseFuncNameWithTypeIdx, *GlobalTables::GetTypeTable().GetVoidPtr(), 0 /* fieldID */); regTableConst->PushBack(newConst); } diff --git a/src/mapleall/mpl2mpl/src/reflection_analysis.cpp b/src/mapleall/mpl2mpl/src/reflection_analysis.cpp index d71c0f914bfa3551b3f19ad1d094809db4ea6c05..b661ada833a69d96274210e21d48d7aa5bd31669 100644 --- a/src/mapleall/mpl2mpl/src/reflection_analysis.cpp +++ b/src/mapleall/mpl2mpl/src/reflection_analysis.cpp @@ -2146,7 +2146,7 @@ static void ReflectionAnalysisGenStrTab(MIRModule &mirModule, const std::string strTabSt->SetStorageClass(kScFstatic); for (char c : strTab) { MIRConst *newConst = GlobalTables::GetIntConstTable().GetOrCreateIntConst( - c, *GlobalTables::GetTypeTable().GetUInt8(), 0/*fieldID*/); + c, *GlobalTables::GetTypeTable().GetUInt8(), 0 /* fieldID */); strTabAggconst->PushBack(newConst); } strTabSt->SetKonst(strTabAggconst); diff --git a/src/mapleall/mpl2mpl/src/vtable_analysis.cpp b/src/mapleall/mpl2mpl/src/vtable_analysis.cpp index 80635f3a1e04754c93d429b759434bc3a0b9af84..83cd1afe6b1196697394d4489873aae65c611510 100644 --- a/src/mapleall/mpl2mpl/src/vtable_analysis.cpp +++ b/src/mapleall/mpl2mpl/src/vtable_analysis.cpp @@ -35,8 +35,8 @@ VtableAnalysis::VtableAnalysis(MIRModule &mod, KlassHierarchy *kh, bool dump) : voidPtrType = GlobalTables::GetTypeTable().GetVoidPtr(); // zeroConst and oneConst are shared amony itab entries. It is safe to share them because // they are never removed by anybody. - zeroConst = GlobalTables::GetIntConstTable().GetOrCreateIntConst(0, *voidPtrType, 0/*fieldID*/); - oneConst = GlobalTables::GetIntConstTable().GetOrCreateIntConst(1, *voidPtrType, 0/*fieldID*/); + zeroConst = GlobalTables::GetIntConstTable().GetOrCreateIntConst(0, *voidPtrType, 0 /* fieldID */); + oneConst = GlobalTables::GetIntConstTable().GetOrCreateIntConst(1, *voidPtrType, 0 /* fieldID */); for (Klass *klass : klassHierarchy->GetTopoSortedKlasses()) { ASSERT(klass != nullptr, "null ptr check!"); GenVtableList(*klass); @@ -310,14 +310,16 @@ void VtableAnalysis::GenItableDefinition(const Klass &klass) { auto *secondItabEmitArray = GetMIRModule().GetMemPool()->New(GetMIRModule(), *voidPtrType); // remember count in secondItabVec count = ((secondConflictList.size() | (1ULL << (kShiftCountBit - 1))) << kShiftCountBit) + count; - secondItabEmitArray->PushBack(GlobalTables::GetIntConstTable().GetOrCreateIntConst(static_cast(count), - *voidPtrType, 0/*fieldID*/)); + secondItabEmitArray->PushBack( + GlobalTables::GetIntConstTable().GetOrCreateIntConst(static_cast(count), + *voidPtrType, 0 /* fieldID */)); secondItabEmitArray->PushBack(oneConst); // padding for (uint32 i = 0; i < kItabSecondHashSize; ++i) { if (!secondItab[i] && !secondConflictFlag[i]) { continue; } else { - secondItabEmitArray->PushBack(GlobalTables::GetIntConstTable().GetOrCreateIntConst(i, *voidPtrType, 0/*fieldID*/)); + secondItabEmitArray->PushBack( + GlobalTables::GetIntConstTable().GetOrCreateIntConst(i, *voidPtrType, 0 /* fieldID */)); if (secondItab[i]) { secondItabEmitArray->PushBack( GetMIRModule().GetMemPool()->New(secondItab[i]->GetPuidx(), *voidPtrType)); @@ -331,9 +333,10 @@ void VtableAnalysis::GenItableDefinition(const Klass &klass) { ASSERT_NOT_NULL(func); const std::string &signatureName = DecodeBaseNameWithType(*func); uint32 nameIdx = ReflectionAnalysis::FindOrInsertRepeatString(signatureName); - secondItabEmitArray->PushBack(GlobalTables::GetIntConstTable().GetOrCreateIntConst(nameIdx, *voidPtrType, 0/*fieldID*/)); secondItabEmitArray->PushBack( - GetMIRModule().GetMemPool()->New(func->GetPuidx(), *voidPtrType)); + GlobalTables::GetIntConstTable().GetOrCreateIntConst(nameIdx, *voidPtrType, 0 /* fieldID */)); + secondItabEmitArray->PushBack( + GetMIRModule().GetMemPool()->New(func->GetPuidx(), *voidPtrType)); } // Create the second-level itable, in which hashcode is looked up by binary searching GenTableSymbol(ITAB_CONFLICT_PREFIX_STR, klass.GetKlassName(), *secondItabEmitArray); diff --git a/src/mplfe/common/src/mplfe_compiler.cpp b/src/mplfe/common/src/mplfe_compiler.cpp index 9813ec8ccb0e527c46a6b77fe0dd9acc2eaa9493..91745e2fbdaf58a0d9db0f8583b1834e70a094c6 100644 --- a/src/mplfe/common/src/mplfe_compiler.cpp +++ b/src/mplfe/common/src/mplfe_compiler.cpp @@ -197,7 +197,7 @@ void MPLFECompiler::ExportMpltFile() { void MPLFECompiler::ExportMplFile() { FETimer timer; timer.StartAndDump("Output mpl"); - module.OutputAsciiMpl("", false); + module.OutputAsciiMpl("", ".mpl", nullptr, false, false); timer.StopAndDumpTimeMS("Output mpl"); }