diff --git a/src/bin/jbc2mpl b/src/bin/jbc2mpl index db9ba51a1bfe858befdea1b402bf3d0229e7ed3e..00e6b4d9b3a27aeeca2eeed0a7c5740efd747f7e 100755 Binary files a/src/bin/jbc2mpl and b/src/bin/jbc2mpl differ diff --git a/src/bin/maple b/src/bin/maple index ac6404b4536804c413fdf1a87f909be4e839c668..12d5dab3696190e60b6315cfe012df2aec362c9e 100755 Binary files a/src/bin/maple and b/src/bin/maple differ diff --git a/src/bin/mplcg b/src/bin/mplcg index 701d8a4e0ef1d758094d0887a33ef83cb8680fb9..db718428c8942b5bb253e1e87071031943e366da 100755 Binary files a/src/bin/mplcg and b/src/bin/mplcg differ diff --git a/src/maple_ir/BUILD.gn b/src/maple_ir/BUILD.gn index 0d5fa07eb62f6ee8ae1c0403c77a65038d3553d8..274dd23188e56e58611fbb4c580138d78f7e9a71 100644 --- a/src/maple_ir/BUILD.gn +++ b/src/maple_ir/BUILD.gn @@ -13,6 +13,7 @@ src_libmplir = [ "src/global_tables.cpp", "src/intrinsics.cpp", "src/lexer.cpp", + "src/mir_symbol_builder.cpp", "src/mir_builder.cpp", "src/mir_const.cpp", "src/mir_function.cpp", diff --git a/src/maple_ir/include/mir_builder.h b/src/maple_ir/include/mir_builder.h index a119fb4f437c66e7f690de44fcadf20e67cd443a..f775abc7750df56c7631a3da1b2cc13b20fb8625 100644 --- a/src/maple_ir/include/mir_builder.h +++ b/src/maple_ir/include/mir_builder.h @@ -55,8 +55,8 @@ class MIRBuilder { virtual ~MIRBuilder() {} - virtual void SetCurrentFunction(MIRFunction *fun) { - mirModule->SetCurFunction(fun); + virtual void SetCurrentFunction(MIRFunction &fun) { + mirModule->SetCurFunction(&fun); } virtual MIRFunction *GetCurrentFunction() const { @@ -127,19 +127,19 @@ class MIRBuilder { void SetStructFieldIDFromFieldName(MIRType &structtype, const std::string &name, GStrIdx newStrIdx, const MIRType &newFieldType); // for creating Function. - MIRSymbol *GetFunctionArgument(MIRFunction *fun, uint32 index) const { - CHECK(index < fun->GetFormalCount(), "index out of range in GetFunctionArgument"); - return fun->GetFormal(index); + MIRSymbol *GetFunctionArgument(MIRFunction &fun, uint32 index) const { + CHECK(index < fun.GetFormalCount(), "index out of range in GetFunctionArgument"); + return fun.GetFormal(index); } MIRFunction *CreateFunction(const std::string &name, const MIRType &returnType, const ArgVector &arguments, - bool isvarg = false, bool createBody = true); - MIRFunction *CreateFunction(const StIdx stIdx, bool addToTable = true); - virtual void UpdateFunction(MIRFunction *func, MIRType *returnType, const ArgVector &arguments) { + bool isvarg = false, bool createBody = true) const; + MIRFunction *CreateFunction(const StIdx stIdx, bool addToTable = true) const; + virtual void UpdateFunction(MIRFunction &func, MIRType *returnType, const ArgVector &arguments) { return; } - MIRSymbol *GetSymbolFromEnclosingScope(StIdx stIdx); + MIRSymbol *GetSymbolFromEnclosingScope(StIdx stIdx) const; virtual MIRSymbol *GetOrCreateLocalDecl(const std::string &str, MIRType &type); MIRSymbol *GetLocalDecl(const std::string &str); MIRSymbol *CreateLocalDecl(const std::string &str, const MIRType &type); @@ -178,7 +178,6 @@ class MIRBuilder { return CreateIntConst(i, PTY_u64); } - ConstvalNode *GetConstArray(MIRType*, BaseNode*, uint32 length); ConstvalNode *CreateAddrofConst(BaseNode&); ConstvalNode *CreateAddroffuncConst(const BaseNode&); ConstvalNode *CreateStrConst(const BaseNode&); @@ -195,7 +194,6 @@ class MIRBuilder { AddrofNode *CreateExprDread(MIRSymbol&, uint16); RegreadNode *CreateExprRegread(PrimType pty, PregIdx regIdx); IreadNode *CreateExprIread(const MIRType &returnType, const MIRType &ptrType, FieldID fieldID, BaseNode *addr); - IreadNode *CreateExprIread(TyIdx *returnTypeIdx, TyIdx *ptrTypeIdx, FieldID fieldID, BaseNode *addr); IreadoffNode *CreateExprIreadoff(PrimType pty, int32 offset, BaseNode *opnd0); IreadFPoffNode *CreateExprIreadFPoff(PrimType pty, int32 offset); IaddrofNode *CreateExprIaddrof(const MIRType &returnType, const MIRType &ptrType, FieldID fieldID, BaseNode *addr); @@ -272,14 +270,14 @@ class MIRBuilder { StmtNode *CreateStmtComment(const std::string &cmnt); CondGotoNode *CreateStmtCondGoto(BaseNode *cond, Opcode op, LabelIdx labIdx); void AddStmtInCurrentFunctionBody(StmtNode &stmt); - MIRSymbol *GetSymbol(TyIdx, const std::string&, MIRSymKind, MIRStorageClass, uint8, bool); - MIRSymbol *GetSymbol(TyIdx, GStrIdx, MIRSymKind, MIRStorageClass, uint8, bool); - MIRSymbol *GetOrCreateSymbol(TyIdx, const std::string&, MIRSymKind, MIRStorageClass, MIRFunction*, uint8, bool); - MIRSymbol *GetOrCreateSymbol(TyIdx, GStrIdx, MIRSymKind, MIRStorageClass, MIRFunction*, uint8, bool); - MIRSymbol *CreatePregFormalSymbol(TyIdx, PregIdx, MIRFunction&); + MIRSymbol *GetSymbol(TyIdx, const std::string&, MIRSymKind, MIRStorageClass, uint8, bool) const; + MIRSymbol *GetSymbol(TyIdx, GStrIdx, MIRSymKind, MIRStorageClass, uint8, bool) const; + MIRSymbol *GetOrCreateSymbol(TyIdx, const std::string&, MIRSymKind, MIRStorageClass, MIRFunction*, uint8, bool) const; + MIRSymbol *GetOrCreateSymbol(TyIdx, GStrIdx, MIRSymKind, MIRStorageClass, MIRFunction*, uint8, bool) const; + MIRSymbol *CreatePregFormalSymbol(TyIdx, PregIdx, MIRFunction&) const; // for creating symbol - MIRSymbol *CreateSymbol(TyIdx, const std::string&, MIRSymKind, MIRStorageClass, MIRFunction*, uint8); - MIRSymbol *CreateSymbol(TyIdx, GStrIdx, MIRSymKind, MIRStorageClass, MIRFunction*, uint8); + MIRSymbol *CreateSymbol(TyIdx, const std::string&, MIRSymKind, MIRStorageClass, MIRFunction*, uint8) const; + MIRSymbol *CreateSymbol(TyIdx, GStrIdx, MIRSymKind, MIRStorageClass, MIRFunction*, uint8) const; // for creating nodes AddrofNode *CreateAddrof(const MIRSymbol &st, PrimType pty = PTY_ptr); AddrofNode *CreateDread(const MIRSymbol &st, PrimType pty); diff --git a/src/maple_ir/include/mir_symbol_builder.h b/src/maple_ir/include/mir_symbol_builder.h new file mode 100644 index 0000000000000000000000000000000000000000..709f9aa665775dd890dd6cb984c39eeb026c6667 --- /dev/null +++ b/src/maple_ir/include/mir_symbol_builder.h @@ -0,0 +1,63 @@ +/* + * Copyright (c) [2019] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + */ +#ifndef MAPLE_IR_INCLUDE_MIR_SYMBOL_BUILDER_H +#define MAPLE_IR_INCLUDE_MIR_SYMBOL_BUILDER_H +#include +#include +#include +#include +#include "opcodes.h" +#include "prim_types.h" +#include "mir_type.h" +#include "mir_const.h" +#include "mir_symbol.h" +#include "mir_nodes.h" +#include "mir_module.h" +#include "mir_preg.h" +#include "mir_function.h" +#include "printing.h" +#include "intrinsic_op.h" +#include "opcode_info.h" +#include "global_tables.h" + +namespace maple { +class MIRSymbolBuilder { + public: + static MIRSymbolBuilder &Instance() { + static MIRSymbolBuilder builder; + return builder; + } + + MIRSymbol *GetLocalDecl(const MIRSymbolTable &symbolTable, GStrIdx strIdx) const; + MIRSymbol *CreateLocalDecl(MIRSymbolTable &symbolTable, GStrIdx strIdx, const MIRType &type) const; + MIRSymbol *GetGlobalDecl(GStrIdx strIdx) const; + MIRSymbol *CreateGlobalDecl(GStrIdx strIdx, const MIRType &type, MIRStorageClass sc) const; + MIRSymbol *GetSymbol(TyIdx tyIdx, GStrIdx strIdx, MIRSymKind mClass, MIRStorageClass sClass, uint8 scpID, + bool sameType = false) const; + MIRSymbol *CreateSymbol(TyIdx tyIdx, GStrIdx strIdx, MIRSymKind mClass, MIRStorageClass sClass, + MIRFunction *func, uint8 scpID) const; + MIRSymbol *CreatePregFormalSymbol(TyIdx tyIdx, PregIdx pRegIdx, MIRFunction &func) const; + + private: + MIRSymbolBuilder() = default; + ~MIRSymbolBuilder() = default; + MIRSymbolBuilder(const MIRSymbolBuilder&) = delete; + MIRSymbolBuilder(const MIRSymbolBuilder&&) = delete; + MIRSymbolBuilder &operator=(const MIRSymbolBuilder&) = delete; + MIRSymbolBuilder &operator=(const MIRSymbolBuilder&&) = delete; +}; +} // maple + +#endif // MAPLEIR_INCLUDE_MIRSYMBOLBUILDER_H \ No newline at end of file diff --git a/src/maple_ir/include/mir_type.h b/src/maple_ir/include/mir_type.h index 78c4f338274d74fd35943a034184c0fcf4213800..33c9bc281514f02559a7c8608f09b848791290e0 100644 --- a/src/maple_ir/include/mir_type.h +++ b/src/maple_ir/include/mir_type.h @@ -495,6 +495,7 @@ class MIRType { } bool ValidateClassOrInterface(const std::string &className, bool noWarning) const; + bool IsOfSameType(MIRType &type); const std::string &GetName(void) const; virtual std::string GetMplTypeName() const; virtual std::string GetCompactMplTypeName() const; diff --git a/src/maple_ir/src/mir_builder.cpp b/src/maple_ir/src/mir_builder.cpp index 71d6bd31b404842821f0973e4a41a6702b82deb4..255a1ee8ebc641769619c8758bdde47397e7fe47 100644 --- a/src/maple_ir/src/mir_builder.cpp +++ b/src/maple_ir/src/mir_builder.cpp @@ -15,11 +15,13 @@ #include "mir_builder.h" #include #include +#include "mir_symbol_builder.h" namespace maple { // This is for compiler-generated metadata 1-level struct void MIRBuilder::AddIntFieldConst(const MIRStructType &sType, MIRAggConst &newConst, uint32 fieldID, int64 constValue) { - MIRConst *fieldConst = mirModule->GetMemPool()->New(constValue, *sType.GetElemType(fieldID - 1), fieldID); + MIRConst *fieldConst = + mirModule->GetMemPool()->New(constValue, *sType.GetElemType(fieldID - 1), fieldID); newConst.GetConstVec().push_back(fieldConst); } @@ -57,35 +59,7 @@ bool MIRBuilder::TraverseToNamedField(MIRStructType &structType, GStrIdx nameIdx } bool MIRBuilder::IsOfSameType(MIRType &type1, MIRType &type2) { - if (type2.GetKind() != type1.GetKind()) { - return false; - } - switch (type1.GetKind()) { - case kTypeScalar: { - return (type1.GetTypeIndex() == type2.GetTypeIndex()); - } - case kTypePointer: { - MIRPtrType &ptrType = static_cast(type1); - MIRPtrType &ptrTypeIt = static_cast(type2); - if (ptrType.GetPointedTyIdx() == ptrTypeIt.GetPointedTyIdx()) { - return true; - } else { - return IsOfSameType(*GlobalTables::GetTypeTable().GetTypeFromTyIdx(ptrType.GetPointedTyIdx()), - *GlobalTables::GetTypeTable().GetTypeFromTyIdx(ptrTypeIt.GetPointedTyIdx())); - } - } - case kTypeJArray: { - MIRJarrayType &atype1 = static_cast(type1); - MIRJarrayType &atype2 = static_cast(type2); - if (atype1.GetDim() != atype2.GetDim()) { - return false; - } - return IsOfSameType(*atype1.GetElemType(), *atype2.GetElemType()); - } - default: { - return type1.GetTypeIndex() == type2.GetTypeIndex(); - } - } + return type1.IsOfSameType(type2); } // traverse parent first but match self first. @@ -120,9 +94,7 @@ void MIRBuilder::TraverseToNamedFieldWithType(MIRStructType &structType, GStrIdx } } - if (fieldType->GetKind() == kTypeStruct || fieldType->GetKind() == kTypeStructIncomplete || - fieldType->GetKind() == kTypeClass || fieldType->GetKind() == kTypeClassIncomplete || - fieldType->GetKind() == kTypeInterface || fieldType->GetKind() == kTypeInterfaceIncomplete) { + if (fieldType->IsStructType()) { MIRStructType *subStructType = static_cast(fieldType); TraverseToNamedFieldWithType(*subStructType, nameIdx, typeIdx, fieldID, idx); } @@ -172,19 +144,13 @@ bool MIRBuilder::TraverseToNamedFieldWithTypeAndMatchStyle(MIRStructType &struct MIRType *fieldType = GlobalTables::GetTypeTable().GetTypeFromTyIdx(fieldTyIdx); ASSERT(fieldType != nullptr, "fieldType is null"); if (matchStyle && structType.GetFieldsElemt(fieldIdx).first == nameIdx) { - if ((typeIdx == 0 || fieldTyIdx == typeIdx)) { - return true; - } - // for pointer type, check their pointed type - MIRType *type = GlobalTables::GetTypeTable().GetTypeFromTyIdx(typeIdx); - if (IsOfSameType(*type, *fieldType)) { + if (typeIdx == 0 || fieldTyIdx == typeIdx || + IsOfSameType(*GlobalTables::GetTypeTable().GetTypeFromTyIdx(typeIdx), *fieldType)) { return true; } } unsigned int style = matchStyle & kMatchAnyField; - if (fieldType->GetKind() == kTypeStruct || fieldType->GetKind() == kTypeStructIncomplete || - fieldType->GetKind() == kTypeClass || fieldType->GetKind() == kTypeClassIncomplete || - fieldType->GetKind() == kTypeInterface || fieldType->GetKind() == kTypeInterfaceIncomplete) { + if (fieldType->IsStructType()) { MIRStructType *subStructType = static_cast(fieldType); if (TraverseToNamedFieldWithTypeAndMatchStyle(*subStructType, nameIdx, typeIdx, fieldID, style)) { return true; @@ -290,6 +256,59 @@ MIRFunction *MIRBuilder::GetFunctionFromStidx(StIdx stIdx) { return funcSymbol != nullptr ? GetFunctionFromSymbol(*funcSymbol) : nullptr; } +MIRFunction *MIRBuilder::CreateFunction(const std::string &name, const MIRType &returnType, const ArgVector &arguments, + bool isVarg, bool createBody) const { + MIRSymbol *funcSymbol = GlobalTables::GetGsymTable().CreateSymbol(kScopeGlobal); + CHECK_FATAL(funcSymbol != nullptr, "Failed to create MIRSymbol"); + GStrIdx strIdx = GetOrCreateStringIndex(name.c_str()); + funcSymbol->SetNameStrIdx(strIdx); + if (!GlobalTables::GetGsymTable().AddToStringSymbolMap(*funcSymbol)) { + return nullptr; + } + funcSymbol->SetStorageClass(kScText); + funcSymbol->SetSKind(kStFunc); + MIRFunction *fn = mirModule->GetMemPool()->New(mirModule, funcSymbol->GetStIdx()); + fn->Init(); + fn->SetPuidx(GlobalTables::GetFunctionTable().GetFuncTable().size()); + GlobalTables::GetFunctionTable().GetFuncTable().push_back(fn); + std::vector funcVecType; + std::vector funcVecAttrs; + for (size_t i = 0; i < arguments.size(); i++) { + MIRSymbol *argSymbol = fn->GetSymTab()->CreateSymbol(kScopeLocal); + argSymbol->SetNameStrIdx(GetOrCreateStringIndex(arguments[i].first.c_str())); + MIRType *ty = arguments[i].second; + argSymbol->SetTyIdx(ty->GetTypeIndex()); + argSymbol->SetStorageClass(kScFormal); + argSymbol->SetSKind(kStVar); + (void)fn->GetSymTab()->AddToStringSymbolMap(*argSymbol); + fn->AddFormal(argSymbol); + funcVecType.push_back(ty->GetTypeIndex()); + funcVecAttrs.push_back(TypeAttrs()); + } + funcSymbol->SetTyIdx(GlobalTables::GetTypeTable().GetOrCreateFunctionType( + *mirModule, returnType.GetTypeIndex(), funcVecType, funcVecAttrs, isVarg)->GetTypeIndex()); + MIRFuncType *funcType = static_cast(funcSymbol->GetType()); + fn->SetMIRFuncType(funcType); + funcSymbol->SetFunction(fn); + if (createBody) { + fn->NewBody(); + } + return fn; +} + +MIRFunction *MIRBuilder::CreateFunction(const StIdx stIdx, bool addToTable) const { + MIRFunction *fn = mirModule->GetMemPool()->New(mirModule, stIdx); + fn->Init(); + fn->SetPuidx(GlobalTables::GetFunctionTable().GetFuncTable().size()); + if (addToTable) { + GlobalTables::GetFunctionTable().GetFuncTable().push_back(fn); + } + + MIRFuncType *funcType = mirModule->GetMemPool()->New(); + fn->SetMIRFuncType(funcType); + return fn; +} + MIRSymbol *MIRBuilder::GetOrCreateGlobalDecl(const std::string &str, const TyIdx &tyIdx, bool &created) const { GStrIdx strIdx = GetStringIndex(str); if (strIdx != 0) { @@ -346,40 +365,18 @@ MIRSymbol *MIRBuilder::GetOrCreateLocalDecl(const std::string &str, MIRType &typ } MIRSymbol *MIRBuilder::CreateLocalDecl(const std::string &str, const MIRType &type) { - GStrIdx stridx = GetOrCreateStringIndex(str); MIRFunction *currentFunctionInner = GetCurrentFunctionNotNull(); - MIRSymbolTable *symbolTable = currentFunctionInner->GetSymTab(); - MIRSymbol *st = symbolTable->CreateSymbol(kScopeLocal); - st->SetNameStrIdx(stridx); - st->SetTyIdx(type.GetTypeIndex()); - (void)symbolTable->AddToStringSymbolMap(*st); - st->SetStorageClass(kScAuto); - st->SetSKind(kStVar); - return st; + return MIRSymbolBuilder::Instance().CreateLocalDecl(*currentFunctionInner->GetSymTab(), + GetOrCreateStringIndex(str), type); } MIRSymbol *MIRBuilder::GetGlobalDecl(const std::string &str) { - GStrIdx strIdx = GetStringIndex(str); - if (strIdx != 0) { - StIdx stidx = GlobalTables::GetGsymTable().GetStIdxFromStrIdx(strIdx); - if (stidx.FullIdx() != 0) { - return GlobalTables::GetGsymTable().GetSymbolFromStidx(stidx.Idx()); - } - } - return nullptr; + return MIRSymbolBuilder::Instance().GetGlobalDecl(GetStringIndex(str)); } MIRSymbol *MIRBuilder::GetLocalDecl(const std::string &str) { MIRFunction *currentFunctionInner = GetCurrentFunctionNotNull(); - MIRSymbolTable *symbolTable = currentFunctionInner->GetSymTab(); - GStrIdx strIdx = GetStringIndex(str); - if (strIdx != 0) { - StIdx stidx = symbolTable->GetStIdxFromStrIdx(strIdx); - if (stidx.FullIdx() != 0) { - return symbolTable->GetSymbolFromStIdx(stidx.Idx()); - } - } - return nullptr; + return MIRSymbolBuilder::Instance().GetLocalDecl(*currentFunctionInner->GetSymTab(), GetStringIndex(str)); } // search the scope hierarchy @@ -400,14 +397,7 @@ MIRSymbol *MIRBuilder::GetDecl(const std::string &str) { } MIRSymbol *MIRBuilder::CreateGlobalDecl(const std::string &str, const MIRType &type, MIRStorageClass sc) { - GStrIdx strIdx = GetOrCreateStringIndex(str); - MIRSymbol *st = GlobalTables::GetGsymTable().CreateSymbol(kScopeGlobal); - st->SetNameStrIdx(strIdx); - st->SetTyIdx(type.GetTypeIndex()); - (void)GlobalTables::GetGsymTable().AddToStringSymbolMap(*st); - st->SetStorageClass(sc); - st->SetSKind(kStVar); - return st; + return MIRSymbolBuilder::Instance().CreateGlobalDecl(GetOrCreateStringIndex(str), type, sc); } MIRSymbol *MIRBuilder::GetOrCreateGlobalDecl(const std::string &str, const MIRType &type) { @@ -428,6 +418,61 @@ MIRSymbol *MIRBuilder::GetOrCreateGlobalDecl(const std::string &str, const MIRTy return st; } +MIRSymbol *MIRBuilder::GetSymbolFromEnclosingScope(StIdx stIdx) const { + if (stIdx.FullIdx() == 0) { + return nullptr; + } + if (stIdx.Islocal()) { + MIRFunction *fun = GetCurrentFunctionNotNull(); + MIRSymbol *st = fun->GetSymTab()->GetSymbolFromStIdx(stIdx.Idx()); + if (st != nullptr) { + return st; + } + } + return GlobalTables::GetGsymTable().GetSymbolFromStidx(stIdx.Idx()); +} + +MIRSymbol *MIRBuilder::GetSymbol(TyIdx tyIdx, const std::string &name, MIRSymKind mClass, MIRStorageClass sClass, + uint8 scpID, bool sameType = false) const { + return GetSymbol(tyIdx, GetOrCreateStringIndex(name), mClass, sClass, scpID, sameType); +} + +// when sametype is true, it means match everything the of the symbol +MIRSymbol *MIRBuilder::GetSymbol(TyIdx tyIdx, GStrIdx strIdx, MIRSymKind mClass, MIRStorageClass sClass, + uint8 scpID, bool sameType = false) const { + return MIRSymbolBuilder::Instance().GetSymbol(tyIdx, strIdx, mClass, sClass, scpID, sameType); +} + +MIRSymbol *MIRBuilder::GetOrCreateSymbol(TyIdx tyIdx, const std::string &name, MIRSymKind mClass, + MIRStorageClass sClass, MIRFunction *func, uint8 scpID, + bool sametype = false) const { + return GetOrCreateSymbol(tyIdx, GetOrCreateStringIndex(name), mClass, sClass, func, scpID, sametype); +} + +MIRSymbol *MIRBuilder::GetOrCreateSymbol(TyIdx tyIdx, GStrIdx strIdx, MIRSymKind mClass, MIRStorageClass sClass, + MIRFunction *func, uint8 scpID, bool sameType = false) const { + if (MIRSymbol *st = GetSymbol(tyIdx, strIdx, mClass, sClass, scpID, sameType)) { + return st; + } + return CreateSymbol(tyIdx, strIdx, mClass, sClass, func, scpID); +} + +// when func is null, create global symbol, otherwise create local symbol +MIRSymbol *MIRBuilder::CreateSymbol(TyIdx tyIdx, const std::string &name, MIRSymKind mClass, MIRStorageClass sClass, + MIRFunction *func, uint8 scpID) const { + return CreateSymbol(tyIdx, GetOrCreateStringIndex(name), mClass, sClass, func, scpID); +} + +// when func is null, create global symbol, otherwise create local symbol +MIRSymbol *MIRBuilder::CreateSymbol(TyIdx tyIdx, GStrIdx strIdx, MIRSymKind mClass, MIRStorageClass sClass, + MIRFunction *func, uint8 scpID) const { + return MIRSymbolBuilder::Instance().CreateSymbol(tyIdx, strIdx, mClass, sClass, func, scpID); +} + +MIRSymbol *MIRBuilder::CreatePregFormalSymbol(TyIdx tyIdx, PregIdx pRegIdx, MIRFunction &func) const { + return MIRSymbolBuilder::Instance().CreatePregFormalSymbol(tyIdx, pRegIdx, func); +} + ConstvalNode *MIRBuilder::CreateIntConst(int64 val, PrimType pty) { MIRFunction *currentFunctionInner = GetCurrentFunctionNotNull(); MIRIntConst *mirConst = @@ -466,7 +511,7 @@ ConstvalNode *MIRBuilder::CreateAddrofConst(BaseNode &e) { MIRFunction *currentFunctionInner = GetCurrentFunctionNotNull(); // determine the type of 'e' and create a pointer type, accordingly - AddrofNode &aNode = static_cast(e); + AddrofNode &aNode = static_cast(e); MIRSymbol *var = currentFunctionInner->GetLocalOrGlobalSymbol(aNode.GetStIdx()); TyIdx ptyIdx = var->GetTyIdx(); MIRPtrType ptrType(ptyIdx); @@ -479,7 +524,7 @@ ConstvalNode *MIRBuilder::CreateAddrofConst(BaseNode &e) { ConstvalNode *MIRBuilder::CreateAddroffuncConst(const BaseNode &e) { ASSERT(e.GetOpCode() == OP_addroffunc, "illegal op for addroffunc const"); - const AddroffuncNode &aNode = static_cast(e); + const AddroffuncNode &aNode = static_cast(e); MIRFunction *f = GlobalTables::GetFunctionTable().GetFunctionFromPuidx(aNode.GetPUIdx()); TyIdx ptyIdx = f->GetFuncSymbol()->GetTyIdx(); MIRPtrType ptrType(ptyIdx); @@ -491,7 +536,7 @@ ConstvalNode *MIRBuilder::CreateAddroffuncConst(const BaseNode &e) { ConstvalNode *MIRBuilder::CreateStrConst(const BaseNode &e) { ASSERT(e.GetOpCode() == OP_conststr, "illegal op for conststr const"); - UStrIdx strIdx = static_cast(e).GetStrIdx(); + UStrIdx strIdx = static_cast(e).GetStrIdx(); CHECK_FATAL(PTY_u8 < GlobalTables::GetTypeTable().GetTypeTable().size(), "index is out of range in MIRBuilder::CreateStrConst"); TyIdx ptyidx = GlobalTables::GetTypeTable().GetTypeFromTyIdx(TyIdx(PTY_u8))->GetTypeIndex(); @@ -504,7 +549,7 @@ ConstvalNode *MIRBuilder::CreateStrConst(const BaseNode &e) { ConstvalNode *MIRBuilder::CreateStr16Const(const BaseNode &e) { ASSERT(e.GetOpCode() == OP_conststr16, "illegal op for conststr16 const"); - U16StrIdx strIdx = static_cast(e).GetStrIdx(); + U16StrIdx strIdx = static_cast(e).GetStrIdx(); CHECK_FATAL(PTY_u16 < GlobalTables::GetTypeTable().GetTypeTable().size(), "index out of range in MIRBuilder::CreateStr16Const"); TyIdx ptyIdx = GlobalTables::GetTypeTable().GetTypeFromTyIdx(TyIdx(PTY_u16))->GetTypeIndex(); @@ -515,157 +560,6 @@ ConstvalNode *MIRBuilder::CreateStr16Const(const BaseNode &e) { return GetCurrentFuncCodeMp()->New(PTY_ptr, mirConst); } -MIRSymbol *MIRBuilder::GetSymbolFromEnclosingScope(StIdx stIdx) { - if (stIdx.FullIdx() == 0) { - return nullptr; - } - if (stIdx.Islocal()) { - MIRFunction *fun = GetCurrentFunctionNotNull(); - MIRSymbol *st = fun->GetSymTab()->GetSymbolFromStIdx(stIdx.Idx()); - if (st != nullptr) { - return st; - } - } - return GlobalTables::GetGsymTable().GetSymbolFromStidx(stIdx.Idx()); -} - -MIRSymbol *MIRBuilder::GetSymbol(TyIdx tyIdx, const std::string &name, MIRSymKind mClass, MIRStorageClass sClass, - uint8 scpID, bool sameType = false) { - return GetSymbol(tyIdx, GetOrCreateStringIndex(name), mClass, sClass, scpID, sameType); -} - -// when sametype is true, it means match everything the of the symbol -MIRSymbol *MIRBuilder::GetSymbol(TyIdx tyIdx, GStrIdx strIdx, MIRSymKind mClass, MIRStorageClass sClass, - uint8 scpID, bool sameType = false) { - if (scpID != kScopeGlobal) { - ERR(kLncErr, "not yet implemented"); - return nullptr; - } - - MIRSymbol *st = GlobalTables::GetGsymTable().GetSymbolFromStrIdx(strIdx); - if (st == nullptr || st->GetTyIdx() != tyIdx) { - return nullptr; - } - - if (sameType) { - if (st->GetStorageClass() == sClass && st->GetSKind() == mClass) { - return st; - } - return nullptr; - } - ASSERT(mClass == st->GetSKind(), - "trying to create a new symbol that has the same name and GtyIdx. might cause problem"); - ASSERT(sClass == st->GetStorageClass(), - "trying to create a new symbol that has the same name and tyIdx. might cause problem"); - return st; -} - -MIRSymbol *MIRBuilder::GetOrCreateSymbol(TyIdx tyIdx, const std::string &name, MIRSymKind mClass, - MIRStorageClass sClass, MIRFunction *func, uint8 scpID, - bool sametype = false) { - return GetOrCreateSymbol(tyIdx, GetOrCreateStringIndex(name), mClass, sClass, func, scpID, sametype); -} - -MIRSymbol *MIRBuilder::GetOrCreateSymbol(TyIdx tyIdx, GStrIdx strIdx, MIRSymKind mClass, MIRStorageClass sClass, - MIRFunction *func, uint8 scpID, bool sameType = false) { - if (MIRSymbol *st = GetSymbol(tyIdx, strIdx, mClass, sClass, scpID, sameType)) { - return st; - } - return CreateSymbol(tyIdx, strIdx, mClass, sClass, func, scpID); -} - -// when func is null, create global symbol, otherwise create local symbol -MIRSymbol *MIRBuilder::CreateSymbol(TyIdx tyIdx, const std::string &name, MIRSymKind mClass, MIRStorageClass sClass, - MIRFunction *func, uint8 scpID) { - return CreateSymbol(tyIdx, GetOrCreateStringIndex(name), mClass, sClass, func, scpID); -} - -// when func is null, create global symbol, otherwise create local symbol -MIRSymbol *MIRBuilder::CreateSymbol(TyIdx tyIdx, GStrIdx strIdx, MIRSymKind mClass, MIRStorageClass sClass, - MIRFunction *func, uint8 scpID) { - MIRSymbol *st = nullptr; - if (func) { - st = func->GetSymTab()->CreateSymbol(scpID); - } else { - st = GlobalTables::GetGsymTable().CreateSymbol(scpID); - } - CHECK_FATAL(st != nullptr, "Failed to create MIRSymbol"); - st->SetStorageClass(sClass); - st->SetSKind(mClass); - st->SetNameStrIdx(strIdx); - st->SetTyIdx(tyIdx); - if (func) { - (void)func->GetSymTab()->AddToStringSymbolMap(*st); - } else { - (void)GlobalTables::GetGsymTable().AddToStringSymbolMap(*st); - } - return st; -} - -MIRSymbol *MIRBuilder::CreatePregFormalSymbol(TyIdx tyIdx, PregIdx pRegIdx, MIRFunction &func) { - MIRSymbol *st = func.GetSymTab()->CreateSymbol(kScopeLocal); - CHECK_FATAL(st != nullptr, "Failed to create MIRSymbol"); - st->SetStorageClass(kScFormal); - st->SetSKind(kStPreg); - st->SetTyIdx(tyIdx); - MIRPregTable *pRegTab = func.GetPregTab(); - st->SetPreg(pRegTab->PregFromPregIdx(pRegIdx)); - return st; -} - -MIRFunction *MIRBuilder::CreateFunction(const std::string &name, const MIRType &returnType, const ArgVector &arguments, - bool isVarg, bool createBody) { - MIRSymbol *funcSymbol = GlobalTables::GetGsymTable().CreateSymbol(kScopeGlobal); - CHECK_FATAL(funcSymbol != nullptr, "Failed to create MIRSymbol"); - GStrIdx strIdx = GetOrCreateStringIndex(name.c_str()); - funcSymbol->SetNameStrIdx(strIdx); - if (!GlobalTables::GetGsymTable().AddToStringSymbolMap(*funcSymbol)) { - return nullptr; - } - funcSymbol->SetStorageClass(kScText); - funcSymbol->SetSKind(kStFunc); - MIRFunction *fn = mirModule->GetMemPool()->New(mirModule, funcSymbol->GetStIdx()); - fn->Init(); - fn->SetPuidx(GlobalTables::GetFunctionTable().GetFuncTable().size()); - GlobalTables::GetFunctionTable().GetFuncTable().push_back(fn); - std::vector funcVecType; - std::vector funcVecAttrs; - for (size_t i = 0; i < arguments.size(); i++) { - MIRSymbol *argSymbol = fn->GetSymTab()->CreateSymbol(kScopeLocal); - argSymbol->SetNameStrIdx(GetOrCreateStringIndex(arguments[i].first.c_str())); - MIRType *ty = arguments[i].second; - argSymbol->SetTyIdx(ty->GetTypeIndex()); - argSymbol->SetStorageClass(kScFormal); - argSymbol->SetSKind(kStVar); - (void)fn->GetSymTab()->AddToStringSymbolMap(*argSymbol); - fn->AddFormal(argSymbol); - funcVecType.push_back(ty->GetTypeIndex()); - funcVecAttrs.push_back(TypeAttrs()); - } - funcSymbol->SetTyIdx(GlobalTables::GetTypeTable().GetOrCreateFunctionType( - *mirModule, returnType.GetTypeIndex(), funcVecType, funcVecAttrs, isVarg)->GetTypeIndex()); - MIRFuncType *funcType = dynamic_cast(funcSymbol->GetType()); - fn->SetMIRFuncType(funcType); - funcSymbol->SetFunction(fn); - if (createBody) { - fn->NewBody(); - } - return fn; -} - -MIRFunction *MIRBuilder::CreateFunction(const StIdx stIdx, bool addToTable) { - MIRFunction *fn = mirModule->GetMemPool()->New(mirModule, stIdx); - fn->Init(); - fn->SetPuidx(GlobalTables::GetFunctionTable().GetFuncTable().size()); - if (addToTable) { - GlobalTables::GetFunctionTable().GetFuncTable().push_back(fn); - } - - MIRFuncType *funcType = mirModule->GetMemPool()->New(); - fn->SetMIRFuncType(funcType); - return fn; -} - SizeoftypeNode *MIRBuilder::CreateExprSizeoftype(const MIRType &type) { return GetCurrentFuncCodeMp()->New(PTY_u32, type.GetTypeIndex()); } @@ -1059,6 +953,26 @@ CatchNode *MIRBuilder::CreateStmtCatch(const MapleVector &tyIdxVec) { return GetCurrentFuncCodeMp()->New(tyIdxVec); } +LabelNode *MIRBuilder::CreateStmtLabel(LabelIdx labIdx) { + return GetCurrentFuncCodeMp()->New(labIdx); +} + +StmtNode *MIRBuilder::CreateStmtComment(const std::string &cmnt) { + return GetCurrentFuncCodeMp()->New(*GetCurrentFuncCodeMpAllocator(), cmnt); +} + +AddrofNode *MIRBuilder::CreateAddrof(const MIRSymbol &st, PrimType pty) { + return GetCurrentFuncCodeMp()->New(OP_addrof, pty, st.GetStIdx(), 0); +} + +AddrofNode *MIRBuilder::CreateDread(const MIRSymbol &st, PrimType pty) { + return GetCurrentFuncCodeMp()->New(OP_dread, pty, st.GetStIdx(), 0); +} + +CondGotoNode *MIRBuilder::CreateStmtCondGoto(BaseNode *cond, Opcode op, LabelIdx labIdx) { + return GetCurrentFuncCodeMp()->New(op, labIdx, cond); +} + LabelIdx MIRBuilder::GetOrCreateMIRLabel(const std::string &name) { GStrIdx stridx = GlobalTables::GetStrTable().GetOrCreateStrIdxFromName(name); MIRFunction *currentFunctionInner = GetCurrentFunctionNotNull(); @@ -1077,32 +991,12 @@ LabelIdx MIRBuilder::CreateLabIdx(MIRFunction &mirFunc) { return lidx; } -LabelNode *MIRBuilder::CreateStmtLabel(LabelIdx labIdx) { - return GetCurrentFuncCodeMp()->New(labIdx); -} - -StmtNode *MIRBuilder::CreateStmtComment(const std::string &cmnt) { - return GetCurrentFuncCodeMp()->New(*GetCurrentFuncCodeMpAllocator(), cmnt); -} - void MIRBuilder::AddStmtInCurrentFunctionBody(StmtNode &stmt) { MIRFunction *fun = GetCurrentFunctionNotNull(); stmt.GetSrcPos().CondSetLineNum(lineNum); fun->GetBody()->AddStatement(&stmt); } -AddrofNode *MIRBuilder::CreateAddrof(const MIRSymbol &st, PrimType pty) { - return GetCurrentFuncCodeMp()->New(OP_addrof, pty, st.GetStIdx(), 0); -} - -AddrofNode *MIRBuilder::CreateDread(const MIRSymbol &st, PrimType pty) { - return GetCurrentFuncCodeMp()->New(OP_dread, pty, st.GetStIdx(), 0); -} - -CondGotoNode *MIRBuilder::CreateStmtCondGoto(BaseNode *cond, Opcode op, LabelIdx labIdx) { - return GetCurrentFuncCodeMp()->New(op == OP_brtrue ? OP_brtrue : OP_brfalse, labIdx, cond); -} - MemPool *MIRBuilder::GetCurrentFuncCodeMp() { return mirModule->CurFuncCodeMemPool(); } diff --git a/src/maple_ir/src/mir_symbol_builder.cpp b/src/maple_ir/src/mir_symbol_builder.cpp new file mode 100644 index 0000000000000000000000000000000000000000..425c1b9a8fe76a1b5e44a743b988c4186519f1f2 --- /dev/null +++ b/src/maple_ir/src/mir_symbol_builder.cpp @@ -0,0 +1,115 @@ +/* + * Copyright (c) [2019] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + */ +#include "mir_symbol_builder.h" +#include +#include + +namespace maple { +MIRSymbol *MIRSymbolBuilder::GetLocalDecl(const MIRSymbolTable &symbolTable, GStrIdx strIdx) const { + if (strIdx != 0) { + StIdx stIdx = symbolTable.GetStIdxFromStrIdx(strIdx); + if (stIdx.FullIdx() != 0) { + return symbolTable.GetSymbolFromStIdx(stIdx.Idx()); + } + } + return nullptr; +} + +MIRSymbol *MIRSymbolBuilder::CreateLocalDecl(MIRSymbolTable &symbolTable, GStrIdx strIdx, + const MIRType &type) const { + MIRSymbol *st = symbolTable.CreateSymbol(kScopeLocal); + st->SetNameStrIdx(strIdx); + st->SetTyIdx(type.GetTypeIndex()); + (void)symbolTable.AddToStringSymbolMap(*st); + st->SetStorageClass(kScAuto); + st->SetSKind(kStVar); + return st; +} + +MIRSymbol *MIRSymbolBuilder::GetGlobalDecl(GStrIdx strIdx) const { + if (strIdx != 0) { + StIdx stIdx = GlobalTables::GetGsymTable().GetStIdxFromStrIdx(strIdx); + if (stIdx.FullIdx() != 0) { + return GlobalTables::GetGsymTable().GetSymbolFromStidx(stIdx.Idx()); + } + } + return nullptr; +} + +MIRSymbol *MIRSymbolBuilder::CreateGlobalDecl(GStrIdx strIdx, const MIRType &type, MIRStorageClass sc) const { + MIRSymbol *st = GlobalTables::GetGsymTable().CreateSymbol(kScopeGlobal); + st->SetNameStrIdx(strIdx); + st->SetTyIdx(type.GetTypeIndex()); + (void)GlobalTables::GetGsymTable().AddToStringSymbolMap(*st); + st->SetStorageClass(sc); + st->SetSKind(kStVar); + return st; +} + +// when sametype is true, it means match everything the of the symbol +MIRSymbol *MIRSymbolBuilder::GetSymbol(TyIdx tyIdx, GStrIdx strIdx, MIRSymKind mClass, MIRStorageClass sClass, + uint8 scpID, bool sameType) const { + if (scpID != kScopeGlobal) { + ERR(kLncErr, "not yet implemented"); + return nullptr; + } + + MIRSymbol *st = GlobalTables::GetGsymTable().GetSymbolFromStrIdx(strIdx); + if (st == nullptr || st->GetTyIdx() != tyIdx) { + return nullptr; + } + + if (sameType) { + if (st->GetStorageClass() == sClass && st->GetSKind() == mClass) { + return st; + } + return nullptr; + } + ASSERT(mClass == st->GetSKind(), + "trying to create a new symbol that has the same name and GtyIdx. might cause problem"); + ASSERT(sClass == st->GetStorageClass(), + "trying to create a new symbol that has the same name and tyIdx. might cause problem"); + return st; +} + +// when func is null, create global symbol, otherwise create local symbol +MIRSymbol *MIRSymbolBuilder::CreateSymbol(TyIdx tyIdx, GStrIdx strIdx, MIRSymKind mClass, MIRStorageClass sClass, + MIRFunction *func, uint8 scpID) const { + MIRSymbol *st = + func != nullptr ? func->GetSymTab()->CreateSymbol(scpID) : GlobalTables::GetGsymTable().CreateSymbol(scpID); + CHECK_FATAL(st != nullptr, "Failed to create MIRSymbol"); + st->SetStorageClass(sClass); + st->SetSKind(mClass); + st->SetNameStrIdx(strIdx); + st->SetTyIdx(tyIdx); + if (func) { + (void)func->GetSymTab()->AddToStringSymbolMap(*st); + } else { + (void)GlobalTables::GetGsymTable().AddToStringSymbolMap(*st); + } + return st; +} + +MIRSymbol *MIRSymbolBuilder::CreatePregFormalSymbol(TyIdx tyIdx, PregIdx pRegIdx, MIRFunction &func) const { + MIRSymbol *st = func.GetSymTab()->CreateSymbol(kScopeLocal); + CHECK_FATAL(st != nullptr, "Failed to create MIRSymbol"); + st->SetStorageClass(kScFormal); + st->SetSKind(kStPreg); + st->SetTyIdx(tyIdx); + MIRPregTable *pRegTab = func.GetPregTab(); + st->SetPreg(pRegTab->PregFromPregIdx(pRegIdx)); + return st; +} +} // maple diff --git a/src/maple_ir/src/mir_type.cpp b/src/maple_ir/src/mir_type.cpp index 78a1f9abe3980d55ad025caa078b3448a2bf82c2..b6ffd4c02c186451055f8f661d7e18aa82fab025 100644 --- a/src/maple_ir/src/mir_type.cpp +++ b/src/maple_ir/src/mir_type.cpp @@ -413,6 +413,32 @@ void MIRType::DumpAsCxx(int indent) const { } } +bool MIRType::IsOfSameType(MIRType &type) { + if (typeKind != type.typeKind) { + return false; + } + + if (typeKind == kTypePointer) { + MIRPtrType &ptrType = static_cast(*this); + MIRPtrType &ptrTypeIt = static_cast(type); + if (ptrType.GetPointedTyIdx() == ptrTypeIt.GetPointedTyIdx()) { + return true; + } else { + MIRType &mirTypeIt = *GlobalTables::GetTypeTable().GetTypeFromTyIdx(ptrTypeIt.GetPointedTyIdx()); + return GlobalTables::GetTypeTable().GetTypeFromTyIdx(ptrType.GetPointedTyIdx())->IsOfSameType(mirTypeIt); + } + } else if (typeKind == kTypeJArray) { + MIRJarrayType &atype1 = static_cast(*this); + MIRJarrayType &atype2 = static_cast(type); + if (atype1.GetDim() != atype2.GetDim()) { + return false; + } + return atype1.GetElemType()->IsOfSameType(*atype2.GetElemType()); + } else { + return tyIdx == type.tyIdx; + } +} + inline void DumpTypeName(GStrIdx strIdx, bool isLocal) { LogInfo::MapleLogger() << ((isLocal) ? "%" : "$") << GlobalTables::GetStrTable().GetStringFromStrIdx(strIdx); } diff --git a/src/mpl2mpl/src/class_init.cpp b/src/mpl2mpl/src/class_init.cpp index ef4a1ace07e837c9bb7f5d3bcac886761b31eb82..bae479b6dce88f63340417957ffb768e71ba0853 100644 --- a/src/mpl2mpl/src/class_init.cpp +++ b/src/mpl2mpl/src/class_init.cpp @@ -64,7 +64,7 @@ void ClassInit::ProcessFunc(MIRFunction *func) { return; } currFunc = func; - builder->SetCurrentFunction(func); + builder->SetCurrentFunction(*func); // Insert clinit check for static methods. MIRType *selfClassType = GlobalTables::GetTypeTable().GetTypeFromTyIdx(func->GetClassTyIdx()); std::string selfClassName; diff --git a/src/mpl2mpl/src/muid_replacement.cpp b/src/mpl2mpl/src/muid_replacement.cpp index 2e26ae82491513bd77cd98af3fe299052113a730..04b1c1610e56c9259d7bef9dc4a20d489e71dac4 100644 --- a/src/mpl2mpl/src/muid_replacement.cpp +++ b/src/mpl2mpl/src/muid_replacement.cpp @@ -926,7 +926,8 @@ void MUIDReplacement::ReplaceDassign(MIRFunction ¤tFunc, DassignNode &dass MIRType *mVoidPtr = GlobalTables::GetTypeTable().GetVoidPtr(); CHECK_FATAL(mVoidPtr != nullptr, "null ptr check"); BaseNode *ireadPtrExpr = - builder->CreateExprIread(*mVoidPtr, *GlobalTables::GetTypeTable().GetOrCreatePointerType(*elemType), 1, arrayExpr); + builder->CreateExprIread(*mVoidPtr, *GlobalTables::GetTypeTable().GetOrCreatePointerType(*elemType), + 1, arrayExpr); PregIdx symPtrPreg = 0; MIRSymbol *symPtrSym = nullptr; BaseNode *destExpr = nullptr; diff --git a/src/mpl2mpl/src/native_stub_func.cpp b/src/mpl2mpl/src/native_stub_func.cpp index d57d736c81361b3764b89b063d7423e0e1812d8d..ecedfbb6b5918dd3019d36ab7e3a63140e67b239 100644 --- a/src/mpl2mpl/src/native_stub_func.cpp +++ b/src/mpl2mpl/src/native_stub_func.cpp @@ -49,7 +49,7 @@ MIRFunction &GenericNativeStubFunc::GetOrCreateDefaultNativeFunc(MIRFunction &st ASSERT(nativeFunc != nullptr, "null ptr check!"); nativeFunc->GetSrcPosition().SetMplLineNum(stubFunc.GetSrcPosition().MplLineNum()); if (nativeFunc->GetBody() == nullptr) { - builder->SetCurrentFunction(nativeFunc); + builder->SetCurrentFunction(*nativeFunc); nativeFunc->SetAttr(FUNCATTR_weak); nativeFunc->SetBody(nativeFunc->GetCodeMempool()->New()); // We would not throw exception here. @@ -85,7 +85,7 @@ MIRFunction &GenericNativeStubFunc::GetOrCreateDefaultNativeFunc(MIRFunction &st builder->CreateStmtCallAssigned(findNativeFunc->GetPuidx(), args, nullptr, OP_callassigned); nativeFunc->GetBody()->AddStatement(callGetFindNativeFunc); GetMIRModule().AddFunction(nativeFunc); - builder->SetCurrentFunction(&stubFunc); + builder->SetCurrentFunction(stubFunc); } return *nativeFunc; } @@ -350,7 +350,8 @@ void GenericNativeStubFunc::GenericRegisteredNativeFuncCall(MIRFunction &func, c arrayExpr->SetBoundsCheck(false); auto *elemType = static_cast(regArrayType).GetElemType(); BaseNode *ireadExpr = - builder->CreateExprIread(*elemType, *GlobalTables::GetTypeTable().GetOrCreatePointerType(*elemType), 0, arrayExpr); + builder->CreateExprIread(*elemType, *GlobalTables::GetTypeTable().GetOrCreatePointerType(*elemType), + 0, arrayExpr); // assign registered func ptr to a preg. auto funcptrPreg = func.GetPregTab()->CreatePreg(PTY_ptr); RegassignNode *funcptrAssign = builder->CreateStmtRegassign(PTY_ptr, funcptrPreg, ireadExpr); diff --git a/src/mpl2mpl/src/vtable_analysis.cpp b/src/mpl2mpl/src/vtable_analysis.cpp index 91e11d3048e60ff7b2d45988e048e06c58c8bc16..0ef5c4f4d3df3495870fa05236c08b771bc4a52e 100644 --- a/src/mpl2mpl/src/vtable_analysis.cpp +++ b/src/mpl2mpl/src/vtable_analysis.cpp @@ -426,7 +426,8 @@ BaseNode *VtableAnalysis::GenVtabItabBaseAddr(BaseNode *obj, bool isVirtual) { BaseNode *classInfoAddress = ReflectionAnalysis::GenClassInfoAddr(obj, *builder); auto *classMetadataType = static_cast( GlobalTables::GetTypeTable().GetTypeFromTyIdx(ReflectionAnalysis::GetClassMetaDataTyIdx())); - return builder->CreateExprIread(*voidPtrType, *GlobalTables::GetTypeTable().GetOrCreatePointerType(*classMetadataType), + return builder->CreateExprIread(*voidPtrType, + *GlobalTables::GetTypeTable().GetOrCreatePointerType(*classMetadataType), (isVirtual ? KLASS_VTAB_FIELDID : KLASS_ITAB_FIELDID), classInfoAddress); }