diff --git a/src/mapleall/bin/debug/dex2mpl.tar.gz b/src/mapleall/bin/debug/dex2mpl.tar.gz index 9ac38f960355596f5a05678a0950609d0dc6210c..32314b1eb89943b74f225873da5746756636dc0d 100644 Binary files a/src/mapleall/bin/debug/dex2mpl.tar.gz and b/src/mapleall/bin/debug/dex2mpl.tar.gz differ diff --git a/src/mapleall/bin/dex2mpl b/src/mapleall/bin/dex2mpl index 218ef48d15bef623849daacd78a223fbd5ae1aee..010b89b4c8e4b5b2b18a76e1ef41fbf79cec1f83 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..251b43c9de54a2c497028ba3e36118e75966060c 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..a5679fab7f2a28230fa8a1e5c8d3c47e0c2fdacc 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 34530486dc1f56c0740e7b8f294de706400b2456..9d497dbad24f40f8bce0b18ce17d1144d6b18a1e 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); @@ -1344,6 +1345,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 +1636,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 +1677,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); @@ -1832,6 +1836,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)); @@ -2272,6 +2277,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 +2636,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 +2664,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 +2750,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); @@ -2814,6 +2823,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 +2841,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 +2959,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/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 67da936926b92a4274391caa78cf8d54535660ab..a9d441a5f97ebe08d05377a5314e99d099af8318 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; } 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/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"); }