From 8d567cc41f6aa834660c3ee9c5b011128c44c7ba Mon Sep 17 00:00:00 2001 From: binaryfz Date: Thu, 3 Jun 2021 20:09:36 +0800 Subject: [PATCH] [alias] set nextLev NADS for escape ptr --- src/mplfe/BUILD.gn | 2 - src/mplfe/ast_input/include/ast_expr.h | 110 ++-- src/mplfe/ast_input/include/ast_parser.h | 1 + src/mplfe/ast_input/include/ast_stmt.h | 4 + src/mplfe/ast_input/lib/ast_type.cpp | 5 - src/mplfe/ast_input/lib/ast_util.cpp | 8 + src/mplfe/ast_input/lib/ast_util.h | 1 + src/mplfe/ast_input/src/ast_decl.cpp | 2 - src/mplfe/ast_input/src/ast_expr.cpp | 589 +++++++++--------- src/mplfe/ast_input/src/ast_parser.cpp | 121 ++-- .../src/ast_parser_builting_func.cpp | 11 +- src/mplfe/ast_input/src/ast_stmt.cpp | 18 +- .../ast_input/src/ast_struct2fe_helper.cpp | 12 - .../include/bc_compiler_component-inl.h | 5 - src/mplfe/bc_input/src/bc_class2fe_helper.cpp | 4 - src/mplfe/bc_input/src/rc_setter.cpp | 10 - src/mplfe/common/include/fe_file_type.h | 4 - src/mplfe/common/include/fe_input_helper.h | 1 - src/mplfe/common/include/fe_options.h | 4 - src/mplfe/common/include/fe_type_manager.h | 1 - src/mplfe/common/include/fe_utils.h | 9 +- src/mplfe/common/include/mplfe_compiler.h | 2 - src/mplfe/common/include/mplfe_options.h | 2 - src/mplfe/common/src/fe_file_type.cpp | 3 - src/mplfe/common/src/fe_function.cpp | 4 - src/mplfe/common/src/fe_input_helper.cpp | 8 - src/mplfe/common/src/fe_options.cpp | 2 - src/mplfe/common/src/fe_struct_elem_info.cpp | 12 - src/mplfe/common/src/fe_type_manager.cpp | 31 - src/mplfe/common/src/fe_utils.cpp | 113 +++- src/mplfe/common/src/feir_stmt.cpp | 44 +- src/mplfe/common/src/feir_var.cpp | 4 - src/mplfe/common/src/feir_var_reg.cpp | 7 - .../common/src/feir_var_type_scatter.cpp | 4 - src/mplfe/common/src/mplfe_compiler.cpp | 8 - src/mplfe/common/src/mplfe_options.cpp | 10 - src/mplfe/dex_input/src/dex_pragma.cpp | 4 - src/mplfe/test/fe_file_type_test.cpp | 1 + src/mplfe/test/feir_stmt_test.cpp | 2 - 39 files changed, 514 insertions(+), 669 deletions(-) diff --git a/src/mplfe/BUILD.gn b/src/mplfe/BUILD.gn index 44d4a9d8d7..492b2a90e7 100644 --- a/src/mplfe/BUILD.gn +++ b/src/mplfe/BUILD.gn @@ -20,8 +20,6 @@ if (COV_CHECK == 1) { cflags += [ "-DMIR_FEATURE_FULL=1", "-DMPLFE_FULL_INFO_DUMP=1", - "-DUSE_OPS", - "-DENABLE_MPLFE_AST", ] include_directories = [ diff --git a/src/mplfe/ast_input/include/ast_expr.h b/src/mplfe/ast_input/include/ast_expr.h index e7122d3632..1068cf9b35 100644 --- a/src/mplfe/ast_input/include/ast_expr.h +++ b/src/mplfe/ast_input/include/ast_expr.h @@ -14,6 +14,7 @@ */ #ifndef MPLFE_AST_INPUT_INCLUDE_AST_EXPR_H #define MPLFE_AST_INPUT_INCLUDE_AST_EXPR_H +#include #include "ast_op.h" #include "feir_stmt.h" @@ -113,10 +114,10 @@ class ASTExpr { uint32 srcFileLineNum = 0; }; -class ASTImplicitCastExpr : public ASTExpr { +class ASTCastExpr : public ASTExpr { public: - ASTImplicitCastExpr() : ASTExpr(kASTOpCast) {} - ~ASTImplicitCastExpr() = default; + ASTCastExpr() : ASTExpr(kASTOpCast) {} + ~ASTCastExpr() = default; void SetASTExpr(ASTExpr *expr) { child = expr; @@ -150,7 +151,13 @@ class ASTImplicitCastExpr : public ASTExpr { isNeededCvt = cvt; } - bool IsNeededCvt(const UniqueFEIRExpr &expr) const; + bool IsNeededCvt(const UniqueFEIRExpr &expr) const { + if (!isNeededCvt || expr == nullptr || dst == nullptr) { + return false; + } + PrimType srcPrimType = expr->GetPrimType(); + return srcPrimType != dst->GetPrimType() && srcPrimType != PTY_agg && srcPrimType != PTY_void; + } void SetComplexType(MIRType *type) { complexType = type; @@ -172,6 +179,10 @@ class ASTImplicitCastExpr : public ASTExpr { isBuilinFunc = flag; } + void SetUnionCast(bool flag) { + isUnoinCast = flag; + } + protected: ASTValue *GetConstantValueImpl() const override; MIRConst *GenerateMIRConstImpl() const override; @@ -195,6 +206,7 @@ class ASTImplicitCastExpr : public ASTExpr { bool imageZero = false; bool isArrayToPointerDecay = false; bool isBuilinFunc = false; + bool isUnoinCast = false; }; class ASTDeclRefExpr : public ASTExpr { @@ -480,15 +492,15 @@ class ASTInitListExpr : public ASTExpr { public: ASTInitListExpr() : ASTExpr(kASTOpInitListExpr) {} ~ASTInitListExpr() = default; - void SetFillerExprs(ASTExpr*); + void SetInitExprs(ASTExpr *astExpr); void SetInitListType(MIRType *type); MIRType *GetInitListType() { return initListType; } - std::vector GetFillers() const { - return fillers; + std::vector GetInitExprs() const { + return initExprs; } void SetInitListVarName(const std::string &argVarName) { @@ -527,19 +539,32 @@ class ASTInitListExpr : public ASTExpr { return isTransparent; } + void SetArrayFiller(ASTExpr *expr) { + arrayFillerExpr = expr; + } + + ASTExpr *GetArrayFillter() { + return arrayFillerExpr; + } + private: MIRConst *GenerateMIRConstImpl() const override; UniqueFEIRExpr Emit2FEExprImpl(std::list &stmts) const override; - void Emit2FEExprForStruct4ArrayElemIsStruct(uint32 i, std::list &stmts) const; - void Emit2FEExprForArray(std::list &stmts) const; - void Emit2FEExprForStringLiteral(UniqueFEIRVar feirVar, std::list &stmts) const; - void Emit2FEExprForArrayForNest(UniqueFEIRType typeNative, UniqueFEIRExpr arrayExpr, - std::list &stmts) const; - void Emit2FEExprForStruct(std::list &stmts) const; + void ProcessInitList(std::variant, UniqueFEIRExpr> &base, ASTInitListExpr *initList, + std::list &stmts) const; + void ProcessArrayInitList(UniqueFEIRExpr addrOfArray, ASTInitListExpr *initList, + std::list &stmts) const; + void ProcessStructInitList(std::variant, UniqueFEIRExpr> &base, + ASTInitListExpr *initList, std::list &stmts) const; + void ProcessDesignatedInitUpdater(std::variant, UniqueFEIRExpr> &base, + ASTExpr *expr, std::list &stmts) const; + void ProcessStringLiteralInitList(UniqueFEIRExpr addrOfCharArray, MIRArrayType *arrayType, + UniqueFEIRExpr addrofStringLiteral, std::list &stmts) const; MIRConst *GenerateMIRConstForArray() const; MIRConst *GenerateMIRConstForStruct() const; - std::vector fillers; - MIRType *initListType; + std::vector initExprs; + ASTExpr *arrayFillerExpr = nullptr; + MIRType *initListType = nullptr; std::string varName; ParentFlag parentFlag = kNoParent; bool isUnionInitListExpr = false; @@ -832,10 +857,18 @@ class ASTDesignatedInitUpdateExpr : public ASTExpr { baseExpr = astExpr; } + ASTExpr *GetBaseExpr() { + return baseExpr; + } + void SetUpdaterExpr(ASTExpr *astExpr) { updaterExpr = astExpr; } + ASTExpr *GetUpdaterExpr() { + return updaterExpr; + } + void SetInitListType(MIRType *type) { initListType = type; } @@ -1166,53 +1199,6 @@ class ASTConditionalOperator : public ASTExpr { ASTExpr *falseExpr = nullptr; }; -class ASTCStyleCastExpr : public ASTExpr { - public: - ASTCStyleCastExpr() : ASTExpr(kASTOpCast) {} - ~ASTCStyleCastExpr() = default; - - void SetSubExpr(ASTExpr *sub) { - child = sub; - } - - void SetSrcType(MIRType *src) { - srcType = src; - } - - void SetDestType(MIRType *dest) { - destType = dest; - } - - MIRType *GetSrcType() const { - return srcType; - } - - MIRType *SetDestType() const { - return destType; - } - - void SetCanCastArray(bool shouldCastArr) { - canCastArray = shouldCastArr; - } - - bool CanCastArray() const { - return canCastArray; - } - - void SetDecl(ASTDecl *d) { - decl = d; - } - - private: - UniqueFEIRExpr Emit2FEExprImpl(std::list &stmts) const override; - MIRConst *GenerateMIRConstImpl() const override; - ASTExpr *child = nullptr; - MIRType *srcType = nullptr; - MIRType *destType = nullptr; - bool canCastArray = false; - ASTDecl *decl = nullptr; -}; - class ASTArrayInitLoopExpr : public ASTExpr { public: ASTArrayInitLoopExpr() : ASTExpr(kASTOpArrayInitLoop) {} diff --git a/src/mplfe/ast_input/include/ast_parser.h b/src/mplfe/ast_input/include/ast_parser.h index 089dd87f6c..bbec4012a7 100644 --- a/src/mplfe/ast_input/include/ast_parser.h +++ b/src/mplfe/ast_input/include/ast_parser.h @@ -92,6 +92,7 @@ class ASTParser { ASTExpr *ProcessExpr(MapleAllocator &allocator, const clang::Expr *expr); ASTExpr *ProcessExprInType(MapleAllocator &allocator, const clang::QualType &qualType); ASTBinaryOperatorExpr *AllocBinaryOperatorExpr(MapleAllocator &allocator, const clang::BinaryOperator &bo); + ASTExpr *ProcessExprCastExpr(MapleAllocator &allocator, const clang::CastExpr &expr); #define PROCESS_EXPR(CLASS) ProcessExpr##CLASS(MapleAllocator&, const clang::CLASS&) ASTExpr *PROCESS_EXPR(UnaryOperator); ASTExpr *PROCESS_EXPR(AddrLabelExpr); diff --git a/src/mplfe/ast_input/include/ast_stmt.h b/src/mplfe/ast_input/include/ast_stmt.h index a1d441b52d..4a7ac94874 100644 --- a/src/mplfe/ast_input/include/ast_stmt.h +++ b/src/mplfe/ast_input/include/ast_stmt.h @@ -481,6 +481,10 @@ class ASTStmtExprStmt : public ASTStmt { cpdStmt = stmt; } + ASTStmt *GetBodyStmt() { + return cpdStmt; + } + private: std::list Emit2FEStmtImpl() const override; diff --git a/src/mplfe/ast_input/lib/ast_type.cpp b/src/mplfe/ast_input/lib/ast_type.cpp index 0f0813a46a..ee3f942b5a 100644 --- a/src/mplfe/ast_input/lib/ast_type.cpp +++ b/src/mplfe/ast_input/lib/ast_type.cpp @@ -215,13 +215,8 @@ MIRType *LibAstFile::CvtFunctionType(const clang::QualType srcType) { attrsVec.push_back(genAttrs.ConvertToTypeAttrs()); } } -#ifndef USE_OPS - MIRType *mirFuncType = GlobalTables::GetTypeTable().GetOrCreateFunctionType(FEManager::GetModule(), - retType->GetTypeIndex(), argsVec, attrsVec); -#else MIRType *mirFuncType = GlobalTables::GetTypeTable().GetOrCreateFunctionType( retType->GetTypeIndex(), argsVec, attrsVec); -#endif return GlobalTables::GetTypeTable().GetOrCreatePointerType(*mirFuncType); } diff --git a/src/mplfe/ast_input/lib/ast_util.cpp b/src/mplfe/ast_input/lib/ast_util.cpp index 654cf29d06..634bb41019 100644 --- a/src/mplfe/ast_input/lib/ast_util.cpp +++ b/src/mplfe/ast_input/lib/ast_util.cpp @@ -48,6 +48,14 @@ bool ASTUtil::IsValidName(const std::string &name) { return true; } +bool ASTUtil::IsSignedType(MIRType &type) { + PrimType primType = type.GetPrimType(); + if (primType == PTY_i8 || primType == PTY_i16 || primType == PTY_i32 || primType == PTY_i64) { + return true; + } + return false; +} + void ASTUtil::AdjustName(std::string &name) { for (size_t i = 0; name[i] != '\0'; ++i) { char c = name[i]; diff --git a/src/mplfe/ast_input/lib/ast_util.h b/src/mplfe/ast_input/lib/ast_util.h index 4c87116f60..35cd10047d 100644 --- a/src/mplfe/ast_input/lib/ast_util.h +++ b/src/mplfe/ast_input/lib/ast_util.h @@ -32,6 +32,7 @@ class ASTUtil { static void SetIndent(int n); static bool ValidInName(char c); static bool IsValidName(const std::string &name); + static bool IsSignedType(MIRType &type); static void AdjustName(std::string &name); static std::string GetAdjustVarName(const std::string &name, uint32_t &num); static std::string GetNameWithSuffix(const std::string &origName, const std::string &suffix); diff --git a/src/mplfe/ast_input/src/ast_decl.cpp b/src/mplfe/ast_input/src/ast_decl.cpp index 0c7a5ee125..62e31cd423 100644 --- a/src/mplfe/ast_input/src/ast_decl.cpp +++ b/src/mplfe/ast_input/src/ast_decl.cpp @@ -61,7 +61,6 @@ MIRConst *ASTVar::Translate2MIRConstImpl() const { void ASTVar::GenerateInitStmt4StringLiteral(ASTExpr *initASTExpr, UniqueFEIRVar feirVar, UniqueFEIRExpr initFeirExpr, std::list &stmts) { -#ifdef USE_OPS if (!static_cast(initASTExpr)->IsArrayToPointerDecay()) { std::unique_ptr> argExprList = std::make_unique>(); UniqueFEIRExpr dstExpr = FEIRBuilder::CreateExprAddrofVar(feirVar->Clone()); @@ -97,7 +96,6 @@ void ASTVar::GenerateInitStmt4StringLiteral(ASTExpr *initASTExpr, UniqueFEIRVar } return; } -#endif } void ASTVar::GenerateInitStmtImpl(std::list &stmts) { diff --git a/src/mplfe/ast_input/src/ast_expr.cpp b/src/mplfe/ast_input/src/ast_expr.cpp index 3a1ceff68b..baa5ff6b9d 100644 --- a/src/mplfe/ast_input/src/ast_expr.cpp +++ b/src/mplfe/ast_input/src/ast_expr.cpp @@ -122,11 +122,7 @@ MIRConst *ASTDeclRefExpr::GenerateMIRConstImpl() const { if (mirType->GetKind() == kTypePointer && static_cast(mirType)->GetPointedType()->GetKind() == kTypeFunction) { GStrIdx idx = GlobalTables::GetStrTable().GetOrCreateStrIdxFromName(refedDecl->GetName()); -#ifndef USE_OPS - MIRSymbol *funcSymbol = SymbolBuilder::Instance().GetSymbolFromStrIdx(idx); -#else MIRSymbol *funcSymbol = GlobalTables::GetGsymTable().GetSymbolFromStrIdx(idx); -#endif CHECK_FATAL(funcSymbol != nullptr, "Should process func decl before var decl"); MIRFunction *mirFunc = funcSymbol->GetFunction(); CHECK_FATAL(mirFunc != nullptr, "Same name symbol with function: %s", refedDecl->GetName().c_str()); @@ -250,12 +246,12 @@ UniqueFEIRExpr ASTCallExpr::Emit2FEExprImpl(std::list &stmts) co return nullptr; } -// ---------- ASTImplicitCastExpr ---------- -ASTValue *ASTImplicitCastExpr::GetConstantValueImpl() const { +// ---------- ASTCastExpr ---------- +ASTValue *ASTCastExpr::GetConstantValueImpl() const { return child->GetConstantValue(); } -MIRConst *ASTImplicitCastExpr::GenerateMIRConstImpl() const { +MIRConst *ASTCastExpr::GenerateMIRConstImpl() const { if (isArrayToPointerDecay && child->GetASTOp() == kASTStringLiteral) { return FEManager::GetModule().GetMemPool()->New( GetConstantValue()->val.strIdx, *GlobalTables::GetTypeTable().GetPrimType(PTY_a64)); @@ -278,7 +274,7 @@ MIRConst *ASTImplicitCastExpr::GenerateMIRConstImpl() const { } } -MIRConst *ASTImplicitCastExpr::GenerateMIRDoubleConst() const { +MIRConst *ASTCastExpr::GenerateMIRDoubleConst() const { switch (GetConstantValue()->pty) { case PTY_f32: { return FEManager::GetModule().GetMemPool()->New( @@ -299,7 +295,7 @@ MIRConst *ASTImplicitCastExpr::GenerateMIRDoubleConst() const { } } -MIRConst *ASTImplicitCastExpr::GenerateMIRFloatConst() const { +MIRConst *ASTCastExpr::GenerateMIRFloatConst() const { switch (GetConstantValue()->pty) { case PTY_f64: { return FEManager::GetModule().GetMemPool()->New( @@ -316,15 +312,37 @@ MIRConst *ASTImplicitCastExpr::GenerateMIRFloatConst() const { } } -MIRConst *ASTImplicitCastExpr::GenerateMIRIntConst() const { +MIRConst *ASTCastExpr::GenerateMIRIntConst() const { switch (GetConstantValue()->pty) { case PTY_f64: { return FEManager::GetModule().GetMemPool()->New( static_cast(GetConstantValue()->val.f64), *GlobalTables::GetTypeTable().GetPrimType(PTY_i64)); } case PTY_i64: { + PrimType srcPrimType = src->GetPrimType(); + int64 val = GetConstantValue()->val.i64; + switch (srcPrimType) { + case PTY_u8: + val = static_cast(GetConstantValue()->val.i64); + break; + case PTY_u16: + val = static_cast(GetConstantValue()->val.i64); + break; + case PTY_u32: + val = static_cast(GetConstantValue()->val.i64); + break; + case PTY_u64: + val = static_cast(GetConstantValue()->val.i64); + break; + default: + break; + } return FEManager::GetModule().GetMemPool()->New( - GetConstantValue()->val.i64, *GlobalTables::GetTypeTable().GetPrimType(PTY_i64)); + val, *GlobalTables::GetTypeTable().GetPrimType(PTY_i64)); + } + case PTY_a64: { + return FEManager::GetModule().GetMemPool()->New( + static_cast(GetConstantValue()->val.strIdx), *GlobalTables::GetTypeTable().GetPrimType(PTY_a64)); } default: { CHECK_FATAL(false, "Unsupported pty type: %d", GetConstantValue()->pty); @@ -333,8 +351,8 @@ MIRConst *ASTImplicitCastExpr::GenerateMIRIntConst() const { } } -UniqueFEIRExpr ASTImplicitCastExpr::Emit2FEExprForComplex(UniqueFEIRExpr subExpr, UniqueFEIRType srcType, - std::list &stmts) const { +UniqueFEIRExpr ASTCastExpr::Emit2FEExprForComplex(UniqueFEIRExpr subExpr, UniqueFEIRType srcType, + std::list &stmts) const { std::string tmpName = FEUtils::GetSequentialName("Complex_"); UniqueFEIRVar tmpVar = FEIRBuilder::CreateVarNameForC(tmpName, *complexType); UniqueFEIRExpr dreadAgg; @@ -373,26 +391,33 @@ UniqueFEIRExpr ASTImplicitCastExpr::Emit2FEExprForComplex(UniqueFEIRExpr subExpr return dreadAgg; } -UniqueFEIRExpr ASTImplicitCastExpr::Emit2FEExprImpl(std::list &stmts) const { +UniqueFEIRExpr ASTCastExpr::Emit2FEExprImpl(std::list &stmts) const { const ASTExpr *childExpr = child; - UniqueFEIRType srcType = std::make_unique(*src); CHECK_FATAL(childExpr != nullptr, "childExpr is nullptr"); if (isArrayToPointerDecay) { - if (child->GetASTOp() == kASTStringLiteral) { - static_cast(child)->SetIsArrayToPointerDecay(true); - } auto childFEExpr = childExpr->Emit2FEExpr(stmts); - if (childFEExpr->GetKind() == kExprIRead) { + if (childFEExpr->GetKind() == kExprDRead) { + return std::make_unique( + static_cast(childFEExpr.get())->GetVar()->Clone(), childFEExpr->GetFieldID()); + } else if (childFEExpr->GetKind() == kExprIRead) { auto iread = static_cast(childFEExpr.get()); if (iread->GetFieldID() == 0) { return iread->GetClonedOpnd(); } else { return std::make_unique(iread->GetClonedPtrType(), iread->GetFieldID(), - iread->GetClonedOpnd()); + iread->GetClonedOpnd()); } + } else if (childFEExpr->GetKind() == kExprIAddrof || childFEExpr->GetKind() == kExprAddrofVar || + childFEExpr->GetKind() == kExprAddrofFunc || childFEExpr->GetKind() == kExprAddrof) { + return childFEExpr; + } else { + CHECK_FATAL(false, "unsupported expr kind %d", childFEExpr->GetKind()); } } UniqueFEIRExpr subExpr = childExpr->Emit2FEExpr(stmts); + if (isUnoinCast && dst->GetKind() == kTypeUnion) { + return subExpr; + } if (complexType == nullptr) { if (IsNeededCvt(subExpr)) { if (IsPrimitiveFloat(subExpr->GetPrimType()) && IsPrimitiveInteger(dst->GetPrimType())) { @@ -401,19 +426,12 @@ UniqueFEIRExpr ASTImplicitCastExpr::Emit2FEExprImpl(std::list &s return FEIRBuilder::CreateExprCvtPrim(std::move(subExpr), dst->GetPrimType()); } } else { - return Emit2FEExprForComplex(subExpr->Clone(), srcType->Clone(), stmts); + UniqueFEIRType srcType = std::make_unique(*src); + return Emit2FEExprForComplex(subExpr->Clone(), std::move(srcType), stmts); } return subExpr; } -bool ASTImplicitCastExpr::IsNeededCvt(const UniqueFEIRExpr &expr) const { - if (!isNeededCvt || expr == nullptr || dst == nullptr) { - return false; - } - PrimType srcPrimType = expr->GetPrimType(); - return srcPrimType != dst->GetPrimType() && srcPrimType != PTY_agg && srcPrimType != PTY_void; -} - // ---------- ASTUnaryOperatorExpr ---------- void ASTUnaryOperatorExpr::SetUOExpr(ASTExpr *astExpr) { expr = astExpr; @@ -515,10 +533,6 @@ MIRConst *ASTUOAddrOfExpr::GenerateMIRConstImpl() const { return konst; } case kASTSubscriptExpr: { -#ifndef USE_OPS - CHECK_FATAL(false, "Unsupported"); - return nullptr; -#else ASTDecl *var = static_cast(expr)->GetBaseExpr()->GetASTDecl(); MIRSymbol *mirSymbol = FEManager::GetMIRBuilder().GetOrCreateGlobalDecl( var->GenerateUniqueVarName(), *(var->GetTypeDesc().front())); @@ -526,7 +540,6 @@ MIRConst *ASTUOAddrOfExpr::GenerateMIRConstImpl() const { MIRAddrofConst *konst = FEManager::GetModule().GetMemPool()->New( mirSymbol->GetStIdx(), 0, *(var->GetTypeDesc().front()), offset); return konst; -#endif } case kASTMemberExpr: { CHECK_FATAL(false, "MemberExpr and SubscriptExpr nested NIY"); @@ -562,15 +575,10 @@ UniqueFEIRExpr ASTUOAddrOfExpr::Emit2FEExprImpl(std::list &stmts // ---------- ASTUOAddrOfLabelExpr --------- MIRConst *ASTUOAddrOfLabelExpr::GenerateMIRConstImpl() const { -#ifndef USE_OPS - CHECK_FATAL(false, "Unsupported yet"); - return nullptr; -#else return FEManager::GetMIRBuilder().GetCurrentFuncCodeMp()->New( FEManager::GetMIRBuilder().GetOrCreateMIRLabel(labelName), FEManager::GetMIRBuilder().GetCurrentFunction()->GetPuidx(), *GlobalTables::GetTypeTable().GetVoidPtr()); -#endif } UniqueFEIRExpr ASTUOAddrOfLabelExpr::Emit2FEExprImpl(std::list &stmts) const { @@ -781,44 +789,31 @@ MIRConst *ASTInitListExpr::GenerateMIRConstImpl() const { } MIRConst *ASTInitListExpr::GenerateMIRConstForArray() const { - if (fillers.size() == 1 && fillers[0]->GetASTOp() == kASTStringLiteral) { - return fillers[0]->GenerateMIRConst(); + if (initExprs.size() == 1 && initExprs[0]->GetASTOp() == kASTStringLiteral) { + return initExprs[0]->GenerateMIRConst(); } MIRAggConst *aggConst = FEManager::GetModule().GetMemPool()->New(FEManager::GetModule(), *initListType); -#ifndef USE_OPS - CHECK_FATAL(false, "Not support"); -#else + CHECK_FATAL(initListType->GetKind() == kTypeArray, "Must be array type"); + auto arrayMirType = static_cast(initListType); + CHECK_FATAL(initExprs.size() <= arrayMirType->GetSizeArrayItem(0), "InitExpr size must less or equal array size"); + for (size_t i = 0; i < initExprs.size(); ++i) { + aggConst->AddItem(initExprs[i]->GenerateMIRConst(), 0); + } if (HasArrayFiller()) { - for (size_t i = 0; i < fillers.size(); ++i) { - if (fillers[i]->GetASTOp() == kASTImplicitValueInitExpr) { - continue; - } - if (fillers[i]->GetASTOp() == kASTOpInitListExpr) { - for (auto subFiller : static_cast(fillers[i])->fillers) { - aggConst->AddItem(subFiller->GenerateMIRConst(), 0); - } - } else { - aggConst->AddItem(fillers[i]->GenerateMIRConst(), 0); - } - } - } else { - for (size_t i = 0; i < fillers.size(); ++i) { - if (fillers[i]->GetASTOp() == kASTImplicitValueInitExpr) { - continue; - } - aggConst->AddItem(fillers[i]->GenerateMIRConst(), 0); + auto fillerConst = arrayFillerExpr->GenerateMIRConst(); + for (int i = initExprs.size(); i < arrayMirType->GetSizeArrayItem(0); ++i) { + aggConst->AddItem(fillerConst, 0); } } -#endif return aggConst; } MIRConst *ASTInitListExpr::GenerateMIRConstForStruct() const { - if (fillers.empty()) { + if (initExprs.empty()) { return nullptr; // No var constant generation } bool hasFiller = false; - for (auto e : fillers) { + for (auto e : initExprs) { if (e != nullptr) { hasFiller = true; break; @@ -828,242 +823,236 @@ MIRConst *ASTInitListExpr::GenerateMIRConstForStruct() const { return nullptr; } MIRAggConst *aggConst = FEManager::GetModule().GetMemPool()->New(FEManager::GetModule(), *initListType); -#ifndef USE_OPS - CHECK_FATAL(false, "Not support"); -#else - for (size_t i = 0; i < fillers.size(); ++i) { - if (fillers[i] == nullptr || fillers[i]->GetASTOp() == kASTImplicitValueInitExpr) { + for (size_t i = 0; i < initExprs.size(); ++i) { + if (initExprs[i] == nullptr) { continue; } - aggConst->AddItem(fillers[i]->GenerateMIRConst(), i + 1); + aggConst->AddItem(initExprs[i]->GenerateMIRConst(), i + 1); } -#endif return aggConst; } UniqueFEIRExpr ASTInitListExpr::Emit2FEExprImpl(std::list &stmts) const { + UniqueFEIRVar feirVar = FEIRBuilder::CreateVarNameForC(varName, *initListType); + std::unique_ptr> argExprList = std::make_unique>(); + UniqueFEIRExpr addrOfExpr = FEIRBuilder::CreateExprAddrofVar(feirVar->Clone()); + argExprList->emplace_back(std::move(addrOfExpr)); + argExprList->emplace_back(FEIRBuilder::CreateExprConstU32(0)); + argExprList->emplace_back(FEIRBuilder::CreateExprSizeOfType(std::make_unique(*initListType))); + std::unique_ptr stmt = std::make_unique( + INTRN_C_memset, nullptr, nullptr, std::move(argExprList)); + stmts.emplace_back(std::move(stmt)); if (initListType->GetKind() == MIRTypeKind::kTypeArray) { - Emit2FEExprForArray(stmts); + UniqueFEIRType typeNative = FEIRTypeHelper::CreateTypeNative(*initListType); + UniqueFEIRExpr arrayExpr = FEIRBuilder::CreateExprAddrofVar(feirVar->Clone()); + auto base = std::variant, UniqueFEIRExpr>(arrayExpr->Clone()); + ProcessInitList(base, const_cast(this), stmts); } else if (initListType->IsStructType()) { - Emit2FEExprForStruct(stmts); + auto base = std::variant, UniqueFEIRExpr>(std::make_pair(feirVar->Clone(), 0)); + ProcessInitList(base, const_cast(this), stmts); } else if (isTransparent) { - CHECK_FATAL(fillers.size() == 1, "Transparent init list size must be 1"); - return fillers[0]->Emit2FEExpr(stmts); + CHECK_FATAL(initExprs.size() == 1, "Transparent init list size must be 1"); + return initExprs[0]->Emit2FEExpr(stmts); } else { CHECK_FATAL(true, "Unsupported init list type"); } return nullptr; } -void ASTInitListExpr::Emit2FEExprForArrayForNest(UniqueFEIRType typeNative, UniqueFEIRExpr arrayExpr, - std::list &stmts) const { - for (int i = 0; i < fillers.size(); ++i) { - if (static_cast(fillers[i])->initListType->IsStructType()) { // array elem is struct - Emit2FEExprForStruct(stmts); - return; - } - MIRType *mirType = static_cast(fillers[i])->initListType; - std::string tmpName = FEUtils::GetSequentialName("subArray_"); - UniqueFEIRVar tmpVar = FEIRBuilder::CreateVarNameForC(tmpName, *mirType); - static_cast(fillers[i])->SetInitListVarName(tmpName); - (void)(fillers[i])->Emit2FEExpr(stmts); - UniqueFEIRType elemType = tmpVar->GetType()->Clone(); - UniqueFEIRExpr dreadAgg = FEIRBuilder::CreateExprDRead(std::move(tmpVar)); - UniqueFEIRExpr arrayExprTmp = arrayExpr->Clone(); - UniqueFEIRExpr exprIndex = FEIRBuilder::CreateExprConstI32(i); - UniqueFEIRType typeNativeTmp = typeNative->Clone(); - auto fieldStmt = FEIRBuilder::CreateStmtArrayStoreOneStmtForC(std::move(dreadAgg), std::move(arrayExprTmp), - std::move(exprIndex), std::move(typeNativeTmp), - std::move(elemType), - varName); - stmts.emplace_back(std::move(fieldStmt)); - } -} - -void ASTInitListExpr::Emit2FEExprForStringLiteral(UniqueFEIRVar feirVar, std::list &stmts) const { -#ifdef USE_OPS - auto fill0 = fillers.front(); - auto fillType = std::make_unique(*fill0->GetType()); - MIRType *mirArrayType = fillType->GenerateMIRTypeAuto(); - if (mirArrayType->GetKind() != kTypeArray) { - return; - } - auto allSize = static_cast(mirArrayType)->GetSize(); - auto elemSize = static_cast(mirArrayType)->GetElemType()->GetSize(); - CHECK_FATAL(elemSize != 0, "elemSize should not 0"); - auto allElemCnt = allSize / elemSize; - - for (int i = 0; i < fillers.size(); i++) { - auto fillExpr = fillers[i]->Emit2FEExpr(stmts); - std::unique_ptr> argExprList = std::make_unique>(); - UniqueFEIRExpr dstExpr = FEIRBuilder::CreateExprAddrofVar(feirVar->Clone()); - uint32 stringLiteralSize = static_cast(fillExpr.get())->GetStringLiteralSize(); - auto uSrcExpr = fillExpr->Clone(); - auto addExpr = FEIRBuilder::CreateExprBinary(OP_add, dstExpr->Clone(), - FEIRBuilder::CreateExprConstI32(allElemCnt * i)); - argExprList->emplace_back(std::move(addExpr)); - argExprList->emplace_back(std::move(uSrcExpr)); // src - if (stringLiteralSize > allElemCnt) { - stringLiteralSize = allElemCnt; // StringLiteral can be longer than allElemCnt - } - argExprList->emplace_back(FEIRBuilder::CreateExprConstI32(stringLiteralSize)); - std::unique_ptr memcpyStmt = std::make_unique( - INTRN_C_memcpy, nullptr, nullptr, std::move(argExprList)); - stmts.emplace_back(std::move(memcpyStmt)); - - int32 needInitFurtherCnt = allElemCnt - stringLiteralSize; - if (needInitFurtherCnt > 0) { - std::unique_ptr> argExprList = std::make_unique>(); - auto addExpr = FEIRBuilder::CreateExprBinary(OP_add, std::move(dstExpr), - FEIRBuilder::CreateExprConstI32(allElemCnt * i + stringLiteralSize)); - argExprList->emplace_back(std::move(addExpr)); - argExprList->emplace_back(FEIRBuilder::CreateExprConstI32(0)); - argExprList->emplace_back(FEIRBuilder::CreateExprConstI32(needInitFurtherCnt)); - std::unique_ptr memsetStmt = std::make_unique( - INTRN_C_memset, nullptr, nullptr, std::move(argExprList)); - stmts.emplace_back(std::move(memsetStmt)); - } - } - return; -#endif -} - -void ASTInitListExpr::Emit2FEExprForArray(std::list &stmts) const { - UniqueFEIRVar feirVar = FEIRBuilder::CreateVarNameForC(varName, *initListType); - UniqueFEIRVar feirVarTmp = feirVar->Clone(); - UniqueFEIRType typeNative = FEIRTypeHelper::CreateTypeNative(*initListType); - UniqueFEIRExpr arrayExpr = FEIRBuilder::CreateExprAddrofVar(std::move(feirVarTmp)); - - if (fillers[0]->GetASTOp() == kASTStringLiteral) { - return Emit2FEExprForStringLiteral(feirVar->Clone(), stmts); - } - - if (fillers[0]->GetASTOp() == kASTOpInitListExpr) { - Emit2FEExprForArrayForNest(typeNative->Clone(), arrayExpr->Clone(), stmts); - } else { - for (int i = 0; i < fillers.size(); ++i) { - UniqueFEIRExpr exprIndex = FEIRBuilder::CreateExprConstI32(i); - UniqueFEIRExpr exprElem = fillers[i]->Emit2FEExpr(stmts); - UniqueFEIRType typeNativeTmp = typeNative->Clone(); - UniqueFEIRExpr arrayExprTmp = arrayExpr->Clone(); - auto stmt = FEIRBuilder::CreateStmtArrayStoreOneStmtForC(std::move(exprElem), std::move(arrayExprTmp), - std::move(exprIndex), std::move(typeNativeTmp), - varName); +void ASTInitListExpr::ProcessInitList(std::variant, UniqueFEIRExpr> &base, + ASTInitListExpr *initList, + std::list &stmts) const { + if (initList->initListType->GetKind() == kTypeArray) { + if (std::holds_alternative(base)) { + ProcessArrayInitList(std::get(base)->Clone(), initList, stmts); + } else { + auto addrExpr = std::make_unique( + std::get>(base).first->Clone()); + addrExpr->SetFieldID(std::get>(base).second); + ProcessArrayInitList(addrExpr->Clone(), initList, stmts); + } + } else if (initList->initListType->GetKind() == kTypeStruct || initList->initListType->GetKind() == kTypeUnion) { + ProcessStructInitList(base, initList, stmts); + } else if (initList->isTransparent) { + CHECK_FATAL(initList->initExprs.size() == 1, "Transparent init list size must be 1"); + auto feExpr = initList->initExprs[0]->Emit2FEExpr(stmts); + MIRType *retType = initList->initListType; + MIRType *retPtrType = GlobalTables::GetTypeTable().GetOrCreatePointerType(*retType); + UniqueFEIRType fePtrType = std::make_unique(*retPtrType); + if (std::holds_alternative(base)) { + auto stmt = FEIRBuilder::CreateStmtIAssign(fePtrType->Clone(), std::get(base)->Clone(), + feExpr->Clone(), 0); stmts.emplace_back(std::move(stmt)); - } - - MIRType *ptrMIRArrayType = typeNative->GenerateMIRTypeAuto(); - auto allSize = static_cast(ptrMIRArrayType)->GetSize(); - auto elemSize = static_cast(ptrMIRArrayType)->GetElemType()->GetSize(); - CHECK_FATAL(elemSize != 0, "elemSize should not 0"); - auto allElemCnt = allSize / elemSize; - uint32 needInitFurtherCnt = allElemCnt - fillers.size(); - PrimType elemPrimType = static_cast(ptrMIRArrayType)->GetElemType()->GetPrimType(); - for (int i = 0; i < needInitFurtherCnt; ++i) { - UniqueFEIRExpr exprIndex = FEIRBuilder::CreateExprConstI32(fillers.size() + i); - UniqueFEIRType typeNativeTmp = typeNative->Clone(); - UniqueFEIRExpr arrayExprTmp = arrayExpr->Clone(); - - UniqueFEIRExpr exprElemOther = std::make_unique(static_cast(0), elemPrimType); - auto stmt = FEIRBuilder::CreateStmtArrayStoreOneStmtForC(std::move(exprElemOther), std::move(arrayExprTmp), - std::move(exprIndex), - std::move(typeNativeTmp), - varName); + } else { + UniqueFEIRVar feirVar = std::get>(base).first->Clone(); + FieldID fieldID = std::get>(base).second; + auto stmt = FEIRBuilder::CreateStmtDAssignAggField(feirVar->Clone(), feExpr->Clone(), fieldID); stmts.emplace_back(std::move(stmt)); } } } -void ASTInitListExpr::Emit2FEExprForStruct4ArrayElemIsStruct(uint32 i, std::list &stmts) const { - MIRType *ptrMIRElemType = GlobalTables::GetTypeTable().GetOrCreatePointerType(*initListType, PTY_ptr); - UniqueFEIRVar tmpVar = FEIRBuilder::CreateVarNameForC(varName, *ptrMIRElemType); - UniqueFEIRExpr dreadAddr = FEIRBuilder::CreateExprDRead(std::move(tmpVar)); - MIRArrayType* arrayType = static_cast(initListType); - UniqueFEIRType typeArray = std::make_unique(*static_cast(initListType)); - UniqueFEIRType uTypeArray = typeArray->Clone(); - std::list indexsExprs; - UniqueFEIRExpr indexExpr = FEIRBuilder::CreateExprConstAnyScalar(PTY_i32, i); - indexsExprs.push_back(std::move(indexExpr)); - UniqueFEIRExpr srcExpr = FEIRBuilder::CreateExprAddrofArray(std::move(uTypeArray), std::move(dreadAddr), - varName, indexsExprs); - MIRType *ptrElemType = GlobalTables::GetTypeTable().GetOrCreatePointerType(*arrayType->GetElemType(), PTY_ptr); - auto tmpArrayName = FEUtils::GetSequentialName("struct_tmpvar_"); - UniqueFEIRVar tmpArrayVar = FEIRBuilder::CreateVarNameForC(tmpArrayName, *ptrElemType); - UniqueFEIRStmt stmtDAssign = FEIRBuilder::CreateStmtDAssign(std::move(tmpArrayVar), std::move(srcExpr)); - stmts.emplace_back(std::move(stmtDAssign)); - static_cast(fillers[i])->SetInitListVarName(tmpArrayName); - static_cast(fillers[i])->SetParentFlag(kArrayParent); - (void)(fillers[i])->Emit2FEExpr(stmts); -} - -void ASTInitListExpr::Emit2FEExprForStruct(std::list &stmts) const { - UniqueFEIRVar feirVar = FEIRBuilder::CreateVarNameForC(varName, *initListType); - if (IsUnionInitListExpr()) { -#ifndef USE_OPS - CHECK_FATAL(false, "Unsupported INTRN_C_memset"); -#else - std::unique_ptr> argExprList = std::make_unique>(); - UniqueFEIRExpr addrOfExpr = FEIRBuilder::CreateExprAddrofVar(feirVar->Clone()); - argExprList->emplace_back(std::move(addrOfExpr)); - argExprList->emplace_back(FEIRBuilder::CreateExprConstU32(0)); - argExprList->emplace_back(FEIRBuilder::CreateExprSizeOfType(std::make_unique(*initListType))); - std::unique_ptr stmt = std::make_unique( - INTRN_C_memset, nullptr, nullptr, std::move(argExprList)); +void ASTInitListExpr::ProcessStringLiteralInitList(UniqueFEIRExpr addrOfCharArray, MIRArrayType *arrayType, + UniqueFEIRExpr addrofStringLiteral, + std::list &stmts) const { + std::unique_ptr> argExprList = std::make_unique>(); + argExprList->emplace_back(addrOfCharArray->Clone()); + argExprList->emplace_back(addrofStringLiteral->Clone()); + argExprList->emplace_back(FEIRBuilder::CreateExprConstI32(arrayType->GetSize())); + std::unique_ptr memcpyStmt = std::make_unique( + INTRN_C_memcpy, nullptr, nullptr, std::move(argExprList)); + stmts.emplace_back(std::move(memcpyStmt)); +} + +void ASTInitListExpr::ProcessDesignatedInitUpdater( + std::variant, UniqueFEIRExpr> &base, + ASTExpr *expr, std::list &stmts) const { + auto designatedInitUpdateExpr = static_cast(expr); + ASTExpr *baseExpr = designatedInitUpdateExpr->GetBaseExpr(); + ASTExpr *updaterExpr = designatedInitUpdateExpr->GetUpdaterExpr(); + auto feExpr = baseExpr->Emit2FEExpr(stmts); + if (std::holds_alternative(base)) { + MIRType *mirType = designatedInitUpdateExpr->GetInitListType(); + MIRType *mirPtrType = GlobalTables::GetTypeTable().GetOrCreatePointerType(*mirType); + UniqueFEIRType fePtrType = std::make_unique(*mirPtrType); + auto stmt = FEIRBuilder::CreateStmtIAssign(fePtrType->Clone(), std::get(base)->Clone(), + feExpr->Clone(), 0); + stmts.emplace_back(std::move(stmt)); + } else { + UniqueFEIRVar feirVar = std::get>(base).first->Clone(); + FieldID fieldID = std::get>(base).second; + auto stmt = FEIRBuilder::CreateStmtDAssignAggField(feirVar->Clone(), feExpr->Clone(), fieldID); stmts.emplace_back(std::move(stmt)); -#endif } - MIRStructType *structType = static_cast(initListType); - for (uint32 i = 0; i < fillers.size(); i++) { - if (fillers[i] == nullptr) { + ProcessInitList(base, static_cast(updaterExpr), stmts); +} + +void ASTInitListExpr::ProcessStructInitList(std::variant, UniqueFEIRExpr> &base, + ASTInitListExpr *initList, + std::list &stmts) const { + MIRType *baseStructMirPtrType = nullptr; + MIRStructType *baseStructMirType = nullptr; + UniqueFEIRType baseStructFEType = nullptr; + UniqueFEIRType baseStructFEPtrType = nullptr; + MIRStructType *curStructMirType = static_cast(initList->initListType); + if (std::holds_alternative(base)) { + baseStructMirType = static_cast(initList->initListType); + baseStructMirPtrType = GlobalTables::GetTypeTable().GetOrCreatePointerType(*baseStructMirType); + baseStructFEType = FEIRTypeHelper::CreateTypeNative(*baseStructMirType); + baseStructFEPtrType = std::make_unique(*baseStructMirPtrType); + } else { + auto var = std::get>(base).first->Clone(); + baseStructFEType = var->GetType()->Clone(); + baseStructMirType = static_cast(baseStructFEType->GenerateMIRTypeAuto()); + baseStructMirPtrType = GlobalTables::GetTypeTable().GetOrCreatePointerType(*baseStructMirType); + baseStructFEPtrType = std::make_unique(*baseStructMirPtrType); + } + FieldID baseFieldID = 0; + if (!std::holds_alternative(base)) { + baseFieldID = std::get>(base).second; + } + for (int i = 0; i < initList->initExprs.size(); ++i) { + if (initList->initExprs[i] == nullptr) { continue; // skip anonymous field } - uint32 fieldID = 0; - if (fillers[i]->GetASTOp() == kASTOpInitListExpr && !static_cast(fillers[i])->IsTransparent()) { - if (initListType->GetKind() == kTypeStruct || initListType->GetKind() == kTypeUnion) { - MIRType *mirType = static_cast(fillers[i])->GetInitListType(); - std::string tmpName = FEUtils::GetSequentialName("subInitListVar_"); - UniqueFEIRVar tmpVar = FEIRBuilder::CreateVarNameForC(tmpName, *mirType); - static_cast(fillers[i])->SetInitListVarName(tmpName); - static_cast(fillers[i])->SetParentFlag(kStructParent); - (void)(fillers[i])->Emit2FEExpr(stmts); - UniqueFEIRExpr dreadAgg = FEIRBuilder::CreateExprDRead(std::move(tmpVar)); - FEManager::GetMIRBuilder().TraverseToNamedField(*structType, structType->GetElemStrIdx(i), fieldID); - UniqueFEIRStmt fieldStmt = std::make_unique(feirVar->Clone(), std::move(dreadAgg), fieldID); - stmts.emplace_back(std::move(fieldStmt)); - } else if (initListType->GetKind() == kTypeArray) { // array elem is struct - Emit2FEExprForStruct4ArrayElemIsStruct(i, stmts); + if (initList->initExprs[i]->GetASTOp() == kASTImplicitValueInitExpr) { + continue; // skip implicitValueInit + } + FieldID curFieldID = 0; + FEUtils::TraverseToNamedField(*curStructMirType, curStructMirType->GetElemStrIdx(i), curFieldID); + uint32 fieldID = baseFieldID + curFieldID; + MIRType *fieldMirType = curStructMirType->GetFieldType(curFieldID); + if (initList->initExprs[i]->GetASTOp() == kASTOpInitListExpr || initList->initExprs[i]->GetASTOp() == kASTASTDesignatedInitUpdateExpr) { + std::variant, UniqueFEIRExpr> subBase; + if (std::holds_alternative(base)) { + auto addrOfElemExpr = std::make_unique(baseStructFEPtrType->Clone(), fieldID, + std::get(base)->Clone()); + subBase = std::variant, UniqueFEIRExpr>(addrOfElemExpr->Clone()); + } else { + auto var = std::get>(base).first->Clone(); + subBase = std::variant, UniqueFEIRExpr>(std::make_pair(var->Clone(), fieldID)); } - } else if (fillers[i]->GetASTOp() == kASTASTDesignatedInitUpdateExpr) { - MIRType *mirType = static_cast(fillers[i])->GetInitListType(); - std::string tmpName = FEUtils::GetSequentialName("subVarToBeUpdate_"); - UniqueFEIRVar tmpVar = FEIRBuilder::CreateVarNameForC(tmpName, *mirType); - static_cast(fillers[i])->SetInitListVarName(tmpName); - (void)(fillers[i])->Emit2FEExpr(stmts); - UniqueFEIRExpr dreadAgg = FEIRBuilder::CreateExprDRead(std::move(tmpVar)); - FEManager::GetMIRBuilder().TraverseToNamedField(*structType, structType->GetElemStrIdx(i), fieldID); - UniqueFEIRStmt fieldStmt = std::make_unique(feirVar->Clone(), std::move(dreadAgg), fieldID); - stmts.emplace_back(std::move(fieldStmt)); + if (initList->initExprs[i]->GetASTOp() == kASTOpInitListExpr) { + ProcessInitList(subBase, static_cast(initList->initExprs[i]), stmts); + } else { + ProcessDesignatedInitUpdater(subBase, static_cast(initList->initExprs[i]), stmts); + } + } else { + auto elemExpr = initList->initExprs[i]->Emit2FEExpr(stmts); + if (std::holds_alternative(base)) { + if (fieldMirType->GetKind() == kTypeArray && initList->initExprs[i]->GetASTOp() == kASTStringLiteral) { + auto addrOfElement = std::make_unique(baseStructFEPtrType->Clone(), fieldID, + std::get(base)->Clone()); + ProcessStringLiteralInitList(addrOfElement->Clone(), static_cast(fieldMirType), + elemExpr->Clone(), + stmts); + } else { + auto stmt = std::make_unique(baseStructFEPtrType->Clone(), + std::get(base)->Clone(), + elemExpr->Clone(), + fieldID); + stmts.emplace_back(std::move(stmt)); + } + } else { + auto var = std::get>(base).first->Clone(); + if (fieldMirType->GetKind() == kTypeArray && initList->initExprs[i]->GetASTOp() == kASTStringLiteral) { + auto addrOfElement = std::make_unique(var->Clone()); + addrOfElement->SetFieldID(fieldID); + ProcessStringLiteralInitList(addrOfElement->Clone(), static_cast(fieldMirType), + elemExpr->Clone(), + stmts); + } else { + auto stmt = std::make_unique(var->Clone(), elemExpr->Clone(), fieldID); + stmts.emplace_back(std::move(stmt)); + } + } + } + } +} + +void ASTInitListExpr::ProcessArrayInitList(UniqueFEIRExpr addrOfArray, ASTInitListExpr *initList, + std::list &stmts) const { + auto arrayMirType = static_cast(initList->initListType); + UniqueFEIRType arrayFEType = FEIRTypeHelper::CreateTypeNative(*arrayMirType); + MIRType *elementType; + if (arrayMirType->GetDim() > 1) { + uint32 subSizeArray[arrayMirType->GetDim()]; + for (int dim = 1; dim < arrayMirType->GetDim(); ++dim) { + subSizeArray[dim - 1] = arrayMirType->GetSizeArrayItem(dim); + } + elementType = GlobalTables::GetTypeTable().GetOrCreateArrayType(*arrayMirType->GetElemType(), + arrayMirType->GetDim() - 1, subSizeArray); + } else { + elementType = arrayMirType->GetElemType(); + } + auto elementPtrType = GlobalTables::GetTypeTable().GetOrCreatePointerType(*elementType); + auto elementPtrFEType = FEIRTypeHelper::CreateTypeNative(*elementPtrType); + for (int i = 0; i < initList->initExprs.size(); ++i) { + std::list indexExprs; + UniqueFEIRExpr indexExpr = FEIRBuilder::CreateExprConstI32(i); + indexExprs.emplace_back(std::move(indexExpr)); + auto addrOfElemExpr = FEIRBuilder::CreateExprAddrofArray(arrayFEType->Clone(), addrOfArray->Clone(), "", + indexExprs); + if (initList->initExprs[i]->GetASTOp() == kASTOpInitListExpr) { + auto base = std::variant, UniqueFEIRExpr>(addrOfElemExpr->Clone()); + ProcessInitList(base, static_cast(initList->initExprs[i]), stmts); } else { - if (parentFlag == kStructParent || (parentFlag == kNoParent)) { - FEManager::GetMIRBuilder().TraverseToNamedField(*structType, structType->GetElemStrIdx(i), fieldID); - UniqueFEIRExpr fieldFEExpr = fillers[i]->Emit2FEExpr(stmts); - UniqueFEIRStmt fieldStmt = std::make_unique(feirVar->Clone(), fieldFEExpr->Clone(), fieldID); - stmts.emplace_back(std::move(fieldStmt)); - } else if (parentFlag == kArrayParent) { // array elem is struct / no nest case - UniqueFEIRExpr exprIndex = FEIRBuilder::CreateExprConstI32(i); - UniqueFEIRExpr fieldFEExpr = fillers[i]->Emit2FEExpr(stmts); - MIRType *ptrBaseType = GlobalTables::GetTypeTable().GetOrCreatePointerType(*initListType, PTY_ptr); - UniqueFEIRVar tmpVar = FEIRBuilder::CreateVarNameForC(varName, *ptrBaseType); - UniqueFEIRStmt stmt = FEIRBuilder::CreateStmtFieldStoreForC(std::move(tmpVar), std::move(fieldFEExpr), - structType, i + 1); + UniqueFEIRExpr elemExpr = initList->initExprs[i]->Emit2FEExpr(stmts); + if (elementType->GetKind() == kTypeArray && initList->initExprs[i]->GetASTOp() == kASTStringLiteral) { + ProcessStringLiteralInitList(addrOfElemExpr->Clone(), static_cast(elementPtrType), + elemExpr->Clone(), stmts); + } else { + auto stmt = FEIRBuilder::CreateStmtIAssign(elementPtrFEType->Clone(), addrOfElemExpr->Clone(), + elemExpr->Clone(), + 0); stmts.emplace_back(std::move(stmt)); } } } } -void ASTInitListExpr::SetFillerExprs(ASTExpr *astExpr) { - fillers.emplace_back(astExpr); +void ASTInitListExpr::SetInitExprs(ASTExpr *astExpr) { + initExprs.emplace_back(astExpr); } void ASTInitListExpr::SetInitListType(MIRType *type) { @@ -1072,8 +1061,7 @@ void ASTInitListExpr::SetInitListType(MIRType *type) { // ---------- ASTImplicitValueInitExpr ---------- MIRConst *ASTImplicitValueInitExpr::GenerateMIRConstImpl() const { - CHECK_FATAL(false, "Should not generate const val for ImplicitValueInitExpr"); - return nullptr; + return FEUtils::CreateImplicitConst(type); } UniqueFEIRExpr ASTImplicitValueInitExpr::Emit2FEExprImpl(std::list &stmts) const { @@ -1081,10 +1069,17 @@ UniqueFEIRExpr ASTImplicitValueInitExpr::Emit2FEExprImpl(std::listNew(FEManager::GetModule(), *arrayTypeWithSize); - for (uint32 i = 0; i < codeUnits.size(); ++i) { - MIRConst *cst = FEManager::GetModule().GetMemPool()->New(codeUnits[i], *type); + auto *arrayType = static_cast(type); + uint32 arraySize = arrayType->GetSizeArrayItem(0); + auto elemType = arrayType->GetElemType(); + auto *val = FEManager::GetModule().GetMemPool()->New(FEManager::GetModule(), *arrayType); + for (uint32 i = 0; i < arraySize; ++i) { + MIRConst *cst; + if (i < codeUnits.size()) { + cst = FEManager::GetModule().GetMemPool()->New(codeUnits[i], *elemType); + } else { + cst = FEManager::GetModule().GetMemPool()->New(0, *elemType); + } val->PushBack(cst); } return val; @@ -1297,17 +1292,12 @@ MIRConst *ASTBinaryOperatorExpr::GenerateMIRConstImpl() const { return FEManager::GetModule().GetMemPool()->New( strIdx, *GlobalTables::GetTypeTable().GetPrimType(PTY_a64)); } else if (baseConst->GetKind() == kConstAddrof) { -#ifndef USE_OPS - CHECK_FATAL(false, "Unsupported"); - return nullptr; -#else MIRAddrofConst *konst = static_cast(baseConst); auto idx = konst->GetSymbolIndex(); auto id = konst->GetFieldID(); auto ty = konst->GetType(); auto offset = konst->GetOffset(); return FEManager::GetModule().GetMemPool()->New(idx, id, ty, offset + value); -#endif } else { CHECK_FATAL(false, "NIY"); } @@ -1326,9 +1316,9 @@ MIRType *ASTBinaryOperatorExpr::SelectBinaryOperatorType(UniqueFEIRExpr &left, U {PTY_u16, 4}, {PTY_i32, 5}, {PTY_u32, 6}, - {PTY_f32, 7}, - {PTY_i64, 8}, - {PTY_u64, 9}, + {PTY_i64, 7}, + {PTY_u64, 8}, + {PTY_f32, 9}, {PTY_f64, 10} }; MIRType *dstType; @@ -1460,6 +1450,7 @@ UniqueFEIRExpr ASTAssignExpr::Emit2FEExprImpl(std::list &stmts) } else if (leftFEExpr->GetKind() == FEIRNodeKind::kExprIRead) { auto ireadFEExpr = static_cast(leftFEExpr.get()); FieldID fieldID = ireadFEExpr->GetFieldID(); + GetActualRightExpr(rightFEExpr, leftFEExpr); auto preStmt = std::make_unique(ireadFEExpr->GetClonedPtrType(), ireadFEExpr->GetClonedOpnd(), std::move(rightFEExpr), fieldID); stmts.emplace_back(std::move(preStmt)); @@ -1773,32 +1764,6 @@ void ASTVAArgExpr::CvtHFA2Struct(MIRStructType &type, MIRType &fieldType, Unique stmts.emplace_back(std::move(assignVar)); } -// ---------- ASTCStyleCastExpr ---------- -UniqueFEIRExpr ASTCStyleCastExpr::Emit2FEExprImpl(std::list &stmts) const { - if (destType->GetPrimType() == PTY_void) { - std::list feExprs; - auto expr = child->Emit2FEExpr(stmts); - if (expr != nullptr) { - feExprs.emplace_back(std::move(expr)); - UniqueFEIRStmt stmt = std::make_unique(OP_eval, std::move(feExprs)); - stmts.emplace_back(std::move(stmt)); - } - return nullptr; - } - MIRType *src = canCastArray ? decl->GetTypeDesc().front() : srcType; - auto feirCStyleCastExpr = std::make_unique(src, destType, - child->Emit2FEExpr(stmts), - canCastArray); - if (decl != nullptr) { - feirCStyleCastExpr->SetRefName(decl->GenerateUniqueVarName()); - } - return feirCStyleCastExpr; -} - -MIRConst *ASTCStyleCastExpr::GenerateMIRConstImpl() const { - return child->GenerateMIRConst(); -} - // ---------- ASTArrayInitLoopExpr ---------- UniqueFEIRExpr ASTArrayInitLoopExpr::Emit2FEExprImpl(std::list &stmts) const { CHECK_FATAL(false, "NIY"); @@ -1867,9 +1832,13 @@ UniqueFEIRExpr ASTExprStmtExpr::Emit2FEExprImpl(std::list &stmts } CHECK_FATAL(cpdStmt->GetASTStmtOp() == kASTStmtCompound, "Invalid in ASTExprStmtExpr"); stmts0.clear(); - const std::list &stmtsList = static_cast(cpdStmt)->GetASTStmtList(); - if (stmtsList.size() != 0 && stmtsList.back()->GetExprs().size() != 0) { - return stmtsList.back()->GetExprs().back()->Emit2FEExpr(stmts0); + auto *lastCpdStmt = static_cast(cpdStmt); + while (lastCpdStmt->GetASTStmtList().back()->GetASTStmtOp() == kASTStmtStmtExpr) { + auto bodyStmt = static_cast(lastCpdStmt->GetASTStmtList().back())->GetBodyStmt(); + lastCpdStmt = static_cast(bodyStmt); + } + if (lastCpdStmt->GetASTStmtList().size() != 0 && lastCpdStmt->GetASTStmtList().back()->GetExprs().size() != 0) { + return lastCpdStmt->GetASTStmtList().back()->GetExprs().back()->Emit2FEExpr(stmts0); } return nullptr; } diff --git a/src/mplfe/ast_input/src/ast_parser.cpp b/src/mplfe/ast_input/src/ast_parser.cpp index 740209025a..9b340fa33c 100644 --- a/src/mplfe/ast_input/src/ast_parser.cpp +++ b/src/mplfe/ast_input/src/ast_parser.cpp @@ -587,7 +587,10 @@ ASTValue *ASTParser::TranslateLValue2ASTValue(MapleAllocator &allocator, const c const clang::APValue::LValueBase &lvBase = result.Val.getLValueBase(); if (lvBase.is()) { const clang::Expr *lvExpr = lvBase.get(); - if (lvExpr == nullptr && expr->getStmtClass() == clang::Stmt::MemberExprClass) { + if (lvExpr == nullptr) { + return astValue; + } + if (expr->getStmtClass() == clang::Stmt::MemberExprClass) { // meaningless, just for Initialization astValue->pty = PTY_i32; astValue->val.i32 = 0; @@ -926,9 +929,6 @@ ASTExpr *ASTParser::ProcessExprInitListExpr(MapleAllocator &allocator, const cla const clang::FieldDecl *fieldDecl = expr.getInitializedFieldInUnion(); astInitListExpr->SetIsUnionInitListExpr(fieldDecl != nullptr); uint32 n = expr.getNumInits(); - if (n == 0) { - return astInitListExpr; - } clang::Expr * const *le = expr.getInits(); if (aggType->isRecordType()) { const auto *recordType = llvm::cast(aggType); @@ -937,20 +937,22 @@ ASTExpr *ASTParser::ProcessExprInitListExpr(MapleAllocator &allocator, const cla CHECK_FATAL(astDecl != nullptr && astDecl->GetDeclKind() == kASTStruct, "Undefined record type"); uint i = 0; for (const auto field : static_cast(astDecl)->GetFields()) { - if (field->IsAnonymousField()) { - astInitListExpr->SetFillerExprs(nullptr); + if (field->IsAnonymousField() && fieldDecl == nullptr) { + astInitListExpr->SetInitExprs(nullptr); } else { if (i < n) { const clang::Expr *eExpr = le[i]; ASTExpr *astExpr = ProcessExpr(allocator, eExpr); CHECK_FATAL(astExpr != nullptr, "Invalid InitListExpr"); - astInitListExpr->SetFillerExprs(astExpr); + astInitListExpr->SetInitExprs(astExpr); i++; } } } } else { if (expr.hasArrayFiller()) { + auto *astFilterExpr = ProcessExpr(allocator, expr.getArrayFiller()); + astInitListExpr->SetArrayFiller(astFilterExpr); astInitListExpr->SetHasArrayFiller(true); } if (expr.isTransparent()) { @@ -962,7 +964,7 @@ ASTExpr *ASTParser::ProcessExprInitListExpr(MapleAllocator &allocator, const cla if (astExpr == nullptr) { return nullptr; } - astInitListExpr->SetFillerExprs(astExpr); + astInitListExpr->SetInitExprs(astExpr); } } return astInitListExpr; @@ -1027,7 +1029,6 @@ ASTExpr *ASTParser::ProcessExprStringLiteral(MapleAllocator &allocator, const cl for (size_t i = 0; i < expr.getLength(); ++i) { codeUnits.emplace_back(expr.getCodeUnit(i)); } - codeUnits.emplace_back(0); astStringLiteral->SetCodeUnits(codeUnits); return astStringLiteral; } @@ -1182,7 +1183,12 @@ ASTExpr *ASTParser::ProcessExprMemberExpr(MapleAllocator &allocator, const clang } astMemberExpr->SetBaseExpr(baseExpr); astMemberExpr->SetBaseType(astFile->CvtType(expr.getBase()->getType())); - astMemberExpr->SetMemberName(expr.getMemberDecl()->getNameAsString()); + auto memberName = expr.getMemberDecl()->getNameAsString(); + if (memberName.empty()) { + uint32 id = expr.getMemberDecl()->getLocation().getRawEncoding(); + memberName = astFile->GetOrCreateMappedUnnamedName(id); + } + astMemberExpr->SetMemberName(memberName); astMemberExpr->SetMemberType(astFile->CvtType(expr.getMemberDecl()->getType())); astMemberExpr->SetIsArrow(expr.isArrow()); return astMemberExpr; @@ -1457,22 +1463,26 @@ ASTExpr *ASTParser::ProcessExprFloatingLiteral(MapleAllocator &allocator, const return astFloatingLiteral; } -ASTExpr *ASTParser::ProcessExprImplicitCastExpr(MapleAllocator &allocator, const clang::ImplicitCastExpr &expr) { - ASTImplicitCastExpr *astImplicitCastExpr = ASTDeclsBuilder::ASTExprBuilder(allocator); - CHECK_FATAL(astImplicitCastExpr != nullptr, "astImplicitCastExpr is nullptr"); +ASTExpr *ASTParser::ProcessExprCastExpr(MapleAllocator &allocator, const clang::CastExpr &expr) { + ASTCastExpr *astCastExpr = ASTDeclsBuilder::ASTExprBuilder(allocator); + CHECK_FATAL(astCastExpr != nullptr, "astCastExpr is nullptr"); + MIRType *srcType = astFile->CvtType(expr.getSubExpr()->getType()); + MIRType *toType = astFile->CvtType(expr.getType()); + astCastExpr->SetSrcType(srcType); + astCastExpr->SetDstType(toType); + switch (expr.getCastKind()) { case clang::CK_NoOp: case clang::CK_ToVoid: - break; - case clang::CK_ArrayToPointerDecay: - astImplicitCastExpr->SetIsArrayToPointerDecay(true); - break; case clang::CK_FunctionToPointerDecay: case clang::CK_LValueToRValue: case clang::CK_BitCast: break; + case clang::CK_ArrayToPointerDecay: + astCastExpr->SetIsArrayToPointerDecay(true); + break; case clang::CK_BuiltinFnToFnPtr: - astImplicitCastExpr->SetBuilinFunc(true); + astCastExpr->SetBuilinFunc(true); break; case clang::CK_NullToPointer: case clang::CK_IntegralToPointer: @@ -1481,9 +1491,13 @@ ASTExpr *ASTParser::ProcessExprImplicitCastExpr(MapleAllocator &allocator, const case clang::CK_FloatingCast: case clang::CK_IntegralCast: case clang::CK_IntegralToBoolean: - astImplicitCastExpr->SetSrcType(astFile->CvtType(expr.getSubExpr()->getType())); - astImplicitCastExpr->SetDstType(astFile->CvtType(expr.getType())); - astImplicitCastExpr->SetNeededCvt(true); + case clang::CK_PointerToBoolean: + case clang::CK_FloatingToBoolean: + case clang::CK_PointerToIntegral: + astCastExpr->SetNeededCvt(true); + break; + case clang::CK_ToUnion: + astCastExpr->SetUnionCast(true); break; case clang::CK_IntegralRealToComplex: case clang::CK_FloatingRealToComplex: @@ -1496,18 +1510,18 @@ ASTExpr *ASTParser::ProcessExprImplicitCastExpr(MapleAllocator &allocator, const case clang::CK_FloatingComplexToBoolean: case clang::CK_IntegralComplexToBoolean: { clang::QualType qualType = expr.getType().getCanonicalType(); - astImplicitCastExpr->SetComplexType(astFile->CvtType(qualType)); + astCastExpr->SetComplexType(astFile->CvtType(qualType)); clang::QualType dstQualType = llvm::cast(qualType)->getElementType(); - astImplicitCastExpr->SetDstType(astFile->CvtType(dstQualType)); - astImplicitCastExpr->SetNeededCvt(true); + astCastExpr->SetDstType(astFile->CvtType(dstQualType)); + astCastExpr->SetNeededCvt(true); if (expr.getCastKind() == clang::CK_IntegralRealToComplex || expr.getCastKind() == clang::CK_FloatingRealToComplex) { - astImplicitCastExpr->SetComplexCastKind(true); - astImplicitCastExpr->SetSrcType(astFile->CvtType(expr.getSubExpr()->getType().getCanonicalType())); + astCastExpr->SetComplexCastKind(true); + astCastExpr->SetSrcType(astFile->CvtType(expr.getSubExpr()->getType().getCanonicalType())); } else { clang::QualType subQualType = expr.getSubExpr()->getType().getCanonicalType(); clang::QualType srcQualType = llvm::cast(subQualType)->getElementType(); - astImplicitCastExpr->SetSrcType(astFile->CvtType(srcQualType)); + astCastExpr->SetSrcType(astFile->CvtType(srcQualType)); } break; } @@ -1519,13 +1533,24 @@ ASTExpr *ASTParser::ProcessExprImplicitCastExpr(MapleAllocator &allocator, const if (astExpr == nullptr) { return nullptr; } - astImplicitCastExpr->SetASTExpr(astExpr); - return astImplicitCastExpr; + astCastExpr->SetASTExpr(astExpr); + return astCastExpr; +} + +ASTExpr *ASTParser::ProcessExprImplicitCastExpr(MapleAllocator &allocator, const clang::ImplicitCastExpr &expr) { + return ProcessExprCastExpr(allocator, expr); } ASTExpr *ASTParser::ProcessExprDeclRefExpr(MapleAllocator &allocator, const clang::DeclRefExpr &expr) { ASTDeclRefExpr *astRefExpr = ASTDeclsBuilder::ASTExprBuilder(allocator); CHECK_FATAL(astRefExpr != nullptr, "astRefExpr is nullptr"); + if (auto enumConst = llvm::dyn_cast(expr.getDecl())) { + const llvm::APSInt value = enumConst->getInitVal(); + ASTIntegerLiteral *astIntegerLiteral = ASTDeclsBuilder::ASTExprBuilder(allocator); + astIntegerLiteral->SetVal(value.getExtValue()); + astIntegerLiteral->SetType(astFile->CvtType(expr.getType())->GetPrimType()); + return astIntegerLiteral; + } switch (expr.getStmtClass()) { case clang::Stmt::DeclRefExprClass: { ASTDecl *astDecl = ASTDeclsBuilder::GetASTDecl(expr.getDecl()->getCanonicalDecl()->getID()); @@ -1678,40 +1703,7 @@ ASTDecl *ASTParser::GetAstDeclOfDeclRefExpr(MapleAllocator &allocator, const cla } ASTExpr *ASTParser::ProcessExprCStyleCastExpr(MapleAllocator &allocator, const clang::CStyleCastExpr &castExpr) { - if (castExpr.getCastKind() == clang::CK_FloatingRealToComplex || - castExpr.getCastKind() == clang::CK_IntegralRealToComplex) { - auto astImplicitCastExpr = ASTDeclsBuilder::ASTExprBuilder(allocator); - astImplicitCastExpr->SetASTExpr(ProcessExpr(allocator, castExpr.getSubExpr())); - clang::QualType qualType = castExpr.getType().getCanonicalType(); - astImplicitCastExpr->SetComplexType(astFile->CvtType(qualType)); - clang::QualType dstQualType = llvm::cast(qualType)->getElementType(); - astImplicitCastExpr->SetDstType(astFile->CvtType(dstQualType)); - astImplicitCastExpr->SetNeededCvt(true); - astImplicitCastExpr->SetComplexCastKind(true); - astImplicitCastExpr->SetSrcType(astFile->CvtType(castExpr.getSubExpr()->getType().getCanonicalType())); - return astImplicitCastExpr; - } - ASTCStyleCastExpr *astCastExpr = ASTDeclsBuilder::ASTExprBuilder(allocator); - clang::QualType fType = castExpr.getSubExpr()->getType(); - clang::QualType tType = castExpr.getType(); - bool shouldCastArr = false; - if (fType->isPointerType() && tType->isPointerType()) { - const clang::Type *fromType = fType->getPointeeType().getTypePtrOrNull(); - const clang::Type *toType = tType->getPointeeType().getTypePtrOrNull(); - bool asFlag = fromType != nullptr && toType != nullptr; - CHECK_FATAL(asFlag, "ERROR:null pointer!"); - auto *implicit = llvm::dyn_cast(castExpr.getSubExpr()); - if ((fromType->getTypeClass() == clang::Type::ConstantArray && toType->getTypeClass() == clang::Type::Builtin) || - (implicit != nullptr && implicit->getCastKind() == clang::CK_ArrayToPointerDecay)) { - astCastExpr->SetDecl(GetAstDeclOfDeclRefExpr(allocator, *implicit)); - shouldCastArr = true; - } - } - astCastExpr->SetSrcType(astFile->CvtType(fType)); - astCastExpr->SetDestType(astFile->CvtType(tType)); - astCastExpr->SetSubExpr(ProcessExpr(allocator, castExpr.getSubExpr())); - astCastExpr->SetCanCastArray(shouldCastArr); - return astCastExpr; + return ProcessExprCastExpr(allocator, castExpr); } ASTExpr *ASTParser::ProcessExprArrayInitLoopExpr(MapleAllocator &allocator, @@ -2023,6 +2015,9 @@ ASTDecl *ASTParser::ProcessDeclFieldDecl(MapleAllocator &allocator, const clang: return nullptr; } if (decl.isBitField()) { + if (qualType->isEnumeralType()) { + fieldType = GlobalTables::GetTypeTable().GetUInt32(); + } unsigned bitSize = decl.getBitWidthValue(*(astFile->GetContext())); MIRBitFieldType mirBFType(static_cast(bitSize), fieldType->GetPrimType()); auto bfTypeIdx = GlobalTables::GetTypeTable().GetOrCreateMIRType(&mirBFType); diff --git a/src/mplfe/ast_input/src/ast_parser_builting_func.cpp b/src/mplfe/ast_input/src/ast_parser_builting_func.cpp index fa3926cd02..525ed9bf3b 100644 --- a/src/mplfe/ast_input/src/ast_parser_builting_func.cpp +++ b/src/mplfe/ast_input/src/ast_parser_builting_func.cpp @@ -50,16 +50,11 @@ UniqueFEIRExpr ASTCallExpr::EmitBuiltinCtz(std::list &stmts) con for (auto arg : args) { argOpnds.push_back(arg->Emit2FEExpr(stmts)); } -#ifndef USE_OPS - CHECK_FATAL(false, "implemention in ops branch"); - return nullptr; -#else if (mirType->GetSize() == 4) { // 32 bit return std::make_unique(std::move(feTy), INTRN_C_ctz32, argOpnds); } return std::make_unique(std::move(feTy), INTRN_C_ctz32, argOpnds); -#endif } UniqueFEIRExpr ASTCallExpr::EmitBuiltinClz(std::list &stmts) const { @@ -68,16 +63,11 @@ UniqueFEIRExpr ASTCallExpr::EmitBuiltinClz(std::list &stmts) con for (auto arg : args) { argOpnds.push_back(arg->Emit2FEExpr(stmts)); } -#ifndef USE_OPS - CHECK_FATAL(false, "implemention in ops branch"); - return nullptr; -#else if (mirType->GetSize() == 4) { // 32 bit return std::make_unique(std::move(feTy), INTRN_C_clz32, argOpnds); } return std::make_unique(std::move(feTy), INTRN_C_clz64, argOpnds); -#endif } UniqueFEIRExpr ASTCallExpr::EmitBuiltinAlloca(std::list &stmts) const { @@ -92,6 +82,7 @@ UniqueFEIRExpr ASTCallExpr::EmitBuiltinExpect(std::list &stmts) std::list> argExprsIn; argExprsIn.push_back(std::move(arg1Expr)); auto stmt = std::make_unique(OP_eval, std::move(argExprsIn)); + stmts.emplace_back(std::move(stmt)); return args[0]->Emit2FEExpr(stmts); } diff --git a/src/mplfe/ast_input/src/ast_stmt.cpp b/src/mplfe/ast_input/src/ast_stmt.cpp index 9df82da445..50a0939484 100644 --- a/src/mplfe/ast_input/src/ast_stmt.cpp +++ b/src/mplfe/ast_input/src/ast_stmt.cpp @@ -310,7 +310,7 @@ std::list ASTCallExprStmt::Emit2FEStmtImpl() const { ASTCallExpr *callExpr = static_cast(exprs.front()); if (!callExpr->IsIcall()) { if (callExpr->GetCalleeExpr() != nullptr && callExpr->GetCalleeExpr()->GetASTOp() == kASTOpCast && - static_cast(callExpr->GetCalleeExpr())->IsBuilinFunc()) { + static_cast(callExpr->GetCalleeExpr())->IsBuilinFunc()) { auto ptrFunc = funcPtrMap.find(callExpr->GetFuncName()); if (ptrFunc != funcPtrMap.end()) { return (this->*(ptrFunc->second))(); @@ -340,14 +340,10 @@ std::list ASTCallExprStmt::ProcessBuiltinVaStart() const { } // addrof va_list instead of dread va_list exprArgList->front()->SetAddrof(true); -#ifndef USE_OPS - CHECK_FATAL(false, "implemention in ops branch"); -#else std::unique_ptr stmt = std::make_unique( INTRN_C_va_start, nullptr /* type */, nullptr /* retVar */, std::move(exprArgList)); stmt->SetSrcFileInfo(GetSrcFileIdx(), GetSrcFileLineNum()); stmts.emplace_back(std::move(stmt)); -#endif return stmts; } @@ -387,14 +383,10 @@ std::list ASTCallExprStmt::ProcessBuiltinVaCopy() const { // Add the size of the va_list structure as the size to memcpy. UniqueFEIRExpr sizeExpr = FEIRBuilder::CreateExprConstI32(vaListType->GenerateMIRTypeAuto()->GetSize()); exprArgList->emplace_back(std::move(sizeExpr)); -#ifndef USE_OPS - CHECK_FATAL(false, "implemention in ops branch"); -#else std::unique_ptr stmt = std::make_unique( INTRN_C_memcpy, nullptr /* type */, nullptr /* retVar */, std::move(exprArgList)); stmt->SetSrcFileInfo(GetSrcFileIdx(), GetSrcFileLineNum()); stmts.emplace_back(std::move(stmt)); -#endif return stmts; } @@ -422,13 +414,7 @@ std::list ASTImplicitCastExprStmt::Emit2FEStmtImpl() const { std::list ASTParenExprStmt::Emit2FEStmtImpl() const { std::list stmts; std::list feExprs; - auto feExpr = exprs.front()->Emit2FEExpr(stmts); - if (feExpr != nullptr) { - feExprs.emplace_back(std::move(feExpr)); - auto stmt = std::make_unique(OP_eval, std::move(feExprs)); - stmt->SetSrcFileInfo(GetSrcFileIdx(), GetSrcFileLineNum()); - stmts.emplace_back(std::move(stmt)); - } + exprs.front()->Emit2FEExpr(stmts); return stmts; } diff --git a/src/mplfe/ast_input/src/ast_struct2fe_helper.cpp b/src/mplfe/ast_input/src/ast_struct2fe_helper.cpp index e92d75332b..a1bd8f38f1 100644 --- a/src/mplfe/ast_input/src/ast_struct2fe_helper.cpp +++ b/src/mplfe/ast_input/src/ast_struct2fe_helper.cpp @@ -168,11 +168,9 @@ bool ASTFunc2FEHelper::ProcessDeclImpl(MapleAllocator &allocator) { } SolveReturnAndArgTypes(allocator); FuncAttrs attrs = GetAttrs(); -#ifdef USE_OPS if (firstArgRet) { attrs.SetAttr(FUNCATTR_firstarg_return); } -#endif bool isStatic = IsStatic(); bool isVarg = IsVarg(); CHECK_FATAL(retMIRType != nullptr, "function must have return type"); @@ -186,15 +184,6 @@ bool ASTFunc2FEHelper::ProcessDeclImpl(MapleAllocator &allocator) { if (firstArgRet) { parmNames.insert(parmNames.begin(), "first_arg_return"); } -#ifndef USE_OPS - for (uint32 i = 0; i < parmNames.size(); ++i) { - MIRSymbol *sym = SymbolBuilder::Instance().GetOrCreateLocalSymbol(*argMIRTypes[i], parmNames[i], *mirFunc); - sym->SetStorageClass(kScFormal); - sym->SetSKind(kStVar); - mirFunc->AddFormal(sym); - } - mirMethodPair.first = mirFunc; -#else for (uint32 i = 0; i < parmNames.size(); ++i) { MIRSymbol *sym = FEManager::GetMIRBuilder().GetOrCreateDeclInFunc(parmNames[i], *argMIRTypes[i], *mirFunc); sym->SetStorageClass(kScFormal); @@ -202,7 +191,6 @@ bool ASTFunc2FEHelper::ProcessDeclImpl(MapleAllocator &allocator) { mirFunc->AddArgument(sym); } mirMethodPair.first = mirFunc->GetStIdx(); -#endif mirMethodPair.second.first = mirFunc->GetMIRFuncType()->GetTypeIndex(); mirMethodPair.second.second = attrs; mirFunc->SetFuncAttrs(attrs); diff --git a/src/mplfe/bc_input/include/bc_compiler_component-inl.h b/src/mplfe/bc_input/include/bc_compiler_component-inl.h index 49fdc98135..29c242f906 100644 --- a/src/mplfe/bc_input/include/bc_compiler_component-inl.h +++ b/src/mplfe/bc_input/include/bc_compiler_component-inl.h @@ -173,13 +173,8 @@ bool BCCompilerComponent::LoadOnDemandBCClass2FEClass( FEManager::GetTypeManager().SetMirImportedTypes(FETypeFlag::kSrcMplt); break; } -#ifndef USE_OPS - for (uint32 i = 1; i < SymbolBuilder::Instance().GetSymbolTableSize(); ++i) { - MIRSymbol *symbol = SymbolBuilder::Instance().GetSymbolFromStIdx(i); -#else for (uint32 i = 1; i < GlobalTables::GetGsymTable().GetSymbolTableSize(); ++i) { MIRSymbol *symbol = GlobalTables::GetGsymTable().GetSymbol(i); -#endif if ((symbol != nullptr) && (symbol->GetSKind() == kStFunc)) { symbol->SetIsImportedDecl(true); } diff --git a/src/mplfe/bc_input/src/bc_class2fe_helper.cpp b/src/mplfe/bc_input/src/bc_class2fe_helper.cpp index 47f493a6ef..e029ea1bab 100644 --- a/src/mplfe/bc_input/src/bc_class2fe_helper.cpp +++ b/src/mplfe/bc_input/src/bc_class2fe_helper.cpp @@ -234,11 +234,7 @@ bool BCClassMethod2FEHelper::ProcessDeclImpl(MapleAllocator &allocator) { elemInfo->SetFromDex(); mirFunc = FEManager::GetTypeManager().CreateFunction(methodNameIdx, mirReturnType->GetTypeIndex(), argsTypeIdx, isVarg, isStatic); -#ifndef USE_OPS - mirMethodPair.first = mirFunc; -#else mirMethodPair.first = mirFunc->GetStIdx(); -#endif mirMethodPair.second.first = mirFunc->GetMIRFuncType()->GetTypeIndex(); mirMethodPair.second.second = attrs; mirFunc->SetFuncAttrs(attrs); diff --git a/src/mplfe/bc_input/src/rc_setter.cpp b/src/mplfe/bc_input/src/rc_setter.cpp index 06c59d1e98..b7dfda5c46 100644 --- a/src/mplfe/bc_input/src/rc_setter.cpp +++ b/src/mplfe/bc_input/src/rc_setter.cpp @@ -147,13 +147,8 @@ void RCSetter::SetAttrRCunowned(MIRFunction &mirFunction, const std::set if (symTab == nullptr) { return; } -#ifndef USE_OPS - for (uint32 i = 0; i < SymbolBuilder::Instance().GetSymbolTableSize(&mirFunction); ++i) { - MIRSymbol *symbol = SymbolBuilder::Instance().GetSymbolFromStIdx(i, &mirFunction); -#else for (uint32 i = 0; i < mirFunction.GetSymTab()->GetSymbolTableSize(); ++i) { MIRSymbol *symbol = mirFunction.GetSymTab()->GetSymbolFromStIdx(i); -#endif if (symbol == nullptr) { continue; } @@ -170,13 +165,8 @@ void RCSetter::SetAttrRCunowned(MIRFunction &mirFunction, const std::set void RCSetter::MarkRCUnownedForUnownedLocalFunctions() const { // mark all local variables unowned for @UnownedLocal functions. for (auto func : unownedLocalFuncs) { -#ifndef USE_OPS - for (uint32 idx = 0; idx < SymbolBuilder::Instance().GetSymbolTableSize(func); idx++) { - MIRSymbol *sym = SymbolBuilder::Instance().GetSymbolFromStIdx(idx, func); -#else for (uint32 idx = 0; idx < func->GetSymTab()->GetSymbolTableSize(); idx++) { MIRSymbol *sym = func->GetSymTab()->GetSymbolFromStIdx(idx); -#endif if (sym == nullptr) { continue; } diff --git a/src/mplfe/common/include/fe_file_type.h b/src/mplfe/common/include/fe_file_type.h index 89377d4cca..93d3e419f7 100644 --- a/src/mplfe/common/include/fe_file_type.h +++ b/src/mplfe/common/include/fe_file_type.h @@ -27,9 +27,7 @@ class FEFileType { kClass, kJar, kDex, -#ifdef ENABLE_MPLFE_AST kAST -#endif // ~/ENABLE_MPLFE_AST }; inline static FEFileType &GetInstance() { @@ -54,9 +52,7 @@ class FEFileType { static const uint32 kMagicClass = 0xBEBAFECA; static const uint32 kMagicZip = 0x04034B50; static const uint32 kMagicDex = 0x0A786564; -#ifdef ENABLE_MPLFE_AST static const uint32 kMagicAST = 0x48435043; -#endif // ~/ENABLE_MPLFE_AST std::map mapExtNameType; std::map mapTypeMagic; std::map mapMagicType; diff --git a/src/mplfe/common/include/fe_input_helper.h b/src/mplfe/common/include/fe_input_helper.h index 663159fa71..fe24ece09d 100644 --- a/src/mplfe/common/include/fe_input_helper.h +++ b/src/mplfe/common/include/fe_input_helper.h @@ -199,7 +199,6 @@ class FEInputMethodHelper { mirFunc->SetClassTyIdx(structType.GetTypeIndex()); } - protected: virtual bool ProcessDeclImpl(MapleAllocator &allocator); virtual void SolveReturnAndArgTypesImpl(MapleAllocator &allocator) = 0; diff --git a/src/mplfe/common/include/fe_options.h b/src/mplfe/common/include/fe_options.h index 5cd34d0bf1..28faf5f0bb 100644 --- a/src/mplfe/common/include/fe_options.h +++ b/src/mplfe/common/include/fe_options.h @@ -75,12 +75,10 @@ class FEOptions { return inputDexFiles; } -#ifdef ENABLE_MPLFE_AST void AddInputASTFile(const std::string &fileName); const std::vector &GetInputASTFiles() const { return inputASTFiles; } -#endif // ~ENABLE_MPLFE_AST void AddInputMpltFileFromSys(const std::string &fileName) { inputMpltFilesFromSys.push_back(fileName); @@ -403,9 +401,7 @@ class FEOptions { std::list inputClassFiles; std::list inputJarFiles; std::vector inputDexFiles; -#ifdef ENABLE_MPLFE_AST std::vector inputASTFiles; -#endif // ~/ENABLE_MPLFE_AST std::list inputMpltFilesFromSys; std::list inputMpltFilesFromApk; std::list inputMpltFiles; diff --git a/src/mplfe/common/include/fe_type_manager.h b/src/mplfe/common/include/fe_type_manager.h index bc649f1099..f8b799ae42 100644 --- a/src/mplfe/common/include/fe_type_manager.h +++ b/src/mplfe/common/include/fe_type_manager.h @@ -128,7 +128,6 @@ class FETypeManager { return GetOrCreateClassOrInterfacePtrType(nameIdx, isInterface, typeFlag, isCreate); } - uint32 GetTypeIDFromMplClassName(const std::string &mplClassName, int32 dexFileHashCode) const; MIRStructType *GetStructTypeFromName(const std::string &name); MIRStructType *GetStructTypeFromName(const GStrIdx &nameIdx); diff --git a/src/mplfe/common/include/fe_utils.h b/src/mplfe/common/include/fe_utils.h index 6efd735952..dd11698537 100644 --- a/src/mplfe/common/include/fe_utils.h +++ b/src/mplfe/common/include/fe_utils.h @@ -41,7 +41,9 @@ class FEUtils { static std::string GetSequentialName0(const std::string &prefix, uint32_t num); static std::string GetSequentialName(const std::string &prefix); static FieldID GetStructFieldID(MIRStructType *base, const std::string &fieldName); + static bool TraverseToNamedField(MIRStructType &structType, GStrIdx nameIdx, FieldID &fieldID); static MIRType *GetStructFieldType(MIRStructType *type, FieldID feildID); + static MIRConst *CreateImplicitConst(MIRType *type); static const std::string kBoolean; static const std::string kByte; @@ -78,14 +80,7 @@ class FEUtils { } static inline void DeleteMempoolPtr(MemPool *memPoolPtr) { -#ifndef USE_OPS - if (memPoolPtr != nullptr) { - delete memPoolPtr; - memPoolPtr = nullptr; - } -#else memPoolCtrler.DeleteMemPool(memPoolPtr); -#endif } static inline GStrIdx &GetBooleanIdx() { diff --git a/src/mplfe/common/include/mplfe_compiler.h b/src/mplfe/common/include/mplfe_compiler.h index 76a86a2cbb..017b2c0a15 100644 --- a/src/mplfe/common/include/mplfe_compiler.h +++ b/src/mplfe/common/include/mplfe_compiler.h @@ -25,9 +25,7 @@ #include "bc_compiler_component.h" #include "ark_annotation_processor.h" #include "dex_reader.h" -#ifdef ENABLE_MPLFE_AST #include "ast_compiler_component.h" -#endif // ~/ENABLE_MPLFE_AST #include "fe_errno.h" #include "mpl_timer.h" #include "mplfe_env.h" diff --git a/src/mplfe/common/include/mplfe_options.h b/src/mplfe/common/include/mplfe_options.h index 9dbff6ae9b..ba97dcc77c 100644 --- a/src/mplfe/common/include/mplfe_options.h +++ b/src/mplfe/common/include/mplfe_options.h @@ -56,9 +56,7 @@ class MPLFEOptions : public maple::MapleDriverOptionBase { bool ProcessInClass(const mapleOption::Option &opt); bool ProcessInJar(const mapleOption::Option &opt); bool ProcessInDex(const mapleOption::Option &opt); -#ifdef ENABLE_MPLFE_AST bool ProcessInAST(const mapleOption::Option &opt); -#endif // ~/ENABLE_MPLFE_AST bool ProcessInputMplt(const mapleOption::Option &opt); bool ProcessInputMpltFromSys(const mapleOption::Option &opt); bool ProcessInputMpltFromApk(const mapleOption::Option &opt); diff --git a/src/mplfe/common/src/fe_file_type.cpp b/src/mplfe/common/src/fe_file_type.cpp index a7236411a0..56589a45ac 100644 --- a/src/mplfe/common/src/fe_file_type.cpp +++ b/src/mplfe/common/src/fe_file_type.cpp @@ -88,11 +88,8 @@ void FEFileType::LoadDefault() { RegisterMagicNumber(kJar, kMagicZip); RegisterExtName(kDex, "dex"); RegisterMagicNumber(kDex, kMagicDex); -#ifdef ENABLE_MPLFE_AST RegisterExtName(kAST, "ast"); RegisterMagicNumber(kAST, kMagicAST); -#endif // ~/ENABLE_MPLFE_AST - } void FEFileType::RegisterExtName(FileType argFileType, const std::string &extName) { diff --git a/src/mplfe/common/src/fe_function.cpp b/src/mplfe/common/src/fe_function.cpp index 49afe0043c..4f50413595 100644 --- a/src/mplfe/common/src/fe_function.cpp +++ b/src/mplfe/common/src/fe_function.cpp @@ -429,11 +429,7 @@ bool FEFunction::UpdateFormal(const std::string &phaseName) { for (const std::unique_ptr &argVar : argVarList) { MIRSymbol *sym = argVar->GenerateMIRSymbol(FEManager::GetMIRBuilder()); sym->SetStorageClass(kScFormal); -#ifndef USE_OPS - mirFunction.AddFormal(sym); -#else mirFunction.AddArgument(sym); -#endif idx++; } return phaseResult.Finish(); diff --git a/src/mplfe/common/src/fe_input_helper.cpp b/src/mplfe/common/src/fe_input_helper.cpp index 14efdc015d..1450f2dbc8 100644 --- a/src/mplfe/common/src/fe_input_helper.cpp +++ b/src/mplfe/common/src/fe_input_helper.cpp @@ -228,11 +228,7 @@ void FEInputStructHelper::ProcessStaticFields() { uint32 i = 0; FieldVector::iterator it; for (it = mirStructType->GetStaticFields().begin(); it != mirStructType->GetStaticFields().end(); ++i, ++it) { -#ifndef USE_OPS - StIdx stIdx = SymbolBuilder::Instance().GetStIdxFromStrIdx(it->first); -#else StIdx stIdx = GlobalTables::GetGsymTable().GetStIdxFromStrIdx(it->first); -#endif const std::string &fieldName = GlobalTables::GetStrTable().GetStringFromStrIdx(it->first); MIRConst *cst = nullptr; MIRType *type = GlobalTables::GetTypeTable().GetTypeFromTyIdx(it->second.first); @@ -252,11 +248,7 @@ void FEInputStructHelper::ProcessStaticFields() { cst = alloc.GetMemPool()->New(expr->GetStIdx(), expr->GetFieldID(), *ptrType); } } -#ifndef USE_OPS - MIRSymbol *fieldVar = SymbolBuilder::Instance().GetSymbolFromStIdx(stIdx.Idx()); -#else MIRSymbol *fieldVar = GlobalTables::GetGsymTable().GetSymbolFromStidx(stIdx.Idx()); -#endif if (fieldVar == nullptr) { fieldVar = FEManager::GetMIRBuilder().GetOrCreateGlobalDecl(fieldName, *type); fieldVar->SetAttrs(it->second.second.ConvertToTypeAttrs()); diff --git a/src/mplfe/common/src/fe_options.cpp b/src/mplfe/common/src/fe_options.cpp index eeb17ce603..c5c17b1832 100644 --- a/src/mplfe/common/src/fe_options.cpp +++ b/src/mplfe/common/src/fe_options.cpp @@ -53,7 +53,6 @@ void FEOptions::AddInputDexFile(const std::string &fileName) { } } -#ifdef ENABLE_MPLFE_AST void FEOptions::AddInputASTFile(const std::string &fileName) { FEFileType::FileType type = FEFileType::GetInstance().GetFileTypeByMagicNumber(fileName); if (type == FEFileType::FileType::kAST) { @@ -62,5 +61,4 @@ void FEOptions::AddInputASTFile(const std::string &fileName) { WARN(kLncWarn, "invalid input AST file %s...skipped", fileName.c_str()); } } -#endif // ~/ENABLE_MPLFE_AST } // namespace maple diff --git a/src/mplfe/common/src/fe_struct_elem_info.cpp b/src/mplfe/common/src/fe_struct_elem_info.cpp index 254b851e81..a9611acb30 100644 --- a/src/mplfe/common/src/fe_struct_elem_info.cpp +++ b/src/mplfe/common/src/fe_struct_elem_info.cpp @@ -364,15 +364,9 @@ void FEStructMethodInfo::PrepareMethod() { for (const std::unique_ptr &argVar : argVarList) { MIRType *mirTy = argVar->GetType()->GenerateMIRTypeAuto(); std::string name = argVar->GetName(*mirTy); -#ifndef USE_OPS - MIRSymbol *sym = SymbolBuilder::Instance().GetOrCreateLocalSymbol(*mirTy, name, *mirFunc); - sym->SetStorageClass(kScFormal); - mirFunc->AddFormal(sym); -#else MIRSymbol *sym = FEManager::GetMIRBuilder().GetOrCreateDeclInFunc(name, *mirTy, *mirFunc); sym->SetStorageClass(kScFormal); mirFunc->AddArgument(sym); -#endif } } isPrepared = true; @@ -394,15 +388,9 @@ bool FEStructMethodInfo::SearchStructMethodJava(MIRStructType &structType, MIRBu if (methodPair.second.second.GetAttr(FUNCATTR_static) != argIsStatic) { continue; } -#ifndef USE_OPS - const MIRFunction *func = methodPair.first; - CHECK_NULL_FATAL(func); - if (func->GetNameStrIdx() == nameIdx) { -#else const MIRSymbol *sym = GlobalTables::GetGsymTable().GetSymbolFromStidx(methodPair.first.Idx(), true); CHECK_NULL_FATAL(sym); if (sym->GetNameStrIdx() == nameIdx) { -#endif isStatic = argIsStatic; if (isStatic) { methodNameIdx = nameIdx; diff --git a/src/mplfe/common/src/fe_type_manager.cpp b/src/mplfe/common/src/fe_type_manager.cpp index 9fc1a309fa..f51cda799c 100644 --- a/src/mplfe/common/src/fe_type_manager.cpp +++ b/src/mplfe/common/src/fe_type_manager.cpp @@ -152,13 +152,8 @@ void FETypeManager::SetMirImportedTypes(FETypeFlag flag) { } void FETypeManager::UpdateNameFuncMapFromTypeTable() { -#ifndef USE_OPS - for (uint32 i = 1; i < SymbolBuilder::Instance().GetSymbolTableSize(); i++) { - MIRSymbol *symbol = SymbolBuilder::Instance().GetSymbolFromStIdx(i); -#else for (uint32 i = 1; i < GlobalTables::GetGsymTable().GetSymbolTableSize(); i++) { MIRSymbol *symbol = GlobalTables::GetGsymTable().GetSymbolFromStidx(i); -#endif CHECK_FATAL(symbol, "Symbol is null"); if (symbol->GetSKind() == kStFunc) { CHECK_FATAL(symbol->GetFunction(), "Function in symbol is null"); @@ -502,20 +497,6 @@ MIRFunction *FETypeManager::CreateFunction(const GStrIdx &nameIdx, const TyIdx & if (mirFunc != nullptr) { return mirFunc; } -#ifndef USE_OPS - MIRSymbol *funcSymbol = SymbolBuilder::Instance().GetSymbolFromStrIdx(nameIdx); - if (funcSymbol == nullptr) { - funcSymbol = SymbolBuilder::Instance().CreateSymbol(TyIdx(), nameIdx, kStFunc, kScText); - SymbolBuilder::Instance().AddToStringSymbolMap(*funcSymbol); - } else { - mirFunc = funcSymbol->GetFunction(); - if (mirFunc != nullptr) { - return mirFunc; - } - funcSymbol->SetStorageClass(kScText); - funcSymbol->SetSKind(kStFunc); - } -#else MIRSymbol *funcSymbol = GlobalTables::GetGsymTable().CreateSymbol(kScopeGlobal); funcSymbol->SetNameStrIdx(nameIdx); bool added = GlobalTables::GetGsymTable().AddToStringSymbolMap(*funcSymbol); @@ -528,15 +509,10 @@ MIRFunction *FETypeManager::CreateFunction(const GStrIdx &nameIdx, const TyIdx & } funcSymbol->SetStorageClass(kScText); funcSymbol->SetSKind(kStFunc); -#endif MemPool *mpModule = module.GetMemPool(); ASSERT(mpModule, "mem pool is nullptr"); mirFunc = mpModule->New(&module, funcSymbol->GetStIdx()); -#ifndef USE_OPS - mirFunc->Init(); -#else mirFunc->AllocSymTab(); -#endif size_t idx = GlobalTables::GetFunctionTable().GetFuncTable().size(); CHECK_FATAL(idx < UINT32_MAX, "PUIdx is out of range"); mirFunc->SetPuidx(static_cast(idx)); @@ -547,14 +523,8 @@ MIRFunction *FETypeManager::CreateFunction(const GStrIdx &nameIdx, const TyIdx & argsAttr.emplace_back(TypeAttrs()); } mirFunc->SetBaseClassFuncNames(nameIdx); -#ifndef USE_OPS - funcSymbol->SetTyIdx(GlobalTables::GetTypeTable().GetOrCreateFunctionType(module, retTypeIdx, - argsTypeIdx, argsAttr, - isVarg)->GetTypeIndex()); -#else funcSymbol->SetTyIdx(GlobalTables::GetTypeTable().GetOrCreateFunctionType(retTypeIdx, argsTypeIdx, argsAttr, isVarg)->GetTypeIndex()); -#endif funcSymbol->SetFunction(mirFunc); MIRFuncType *functype = static_cast(funcSymbol->GetType()); mirFunc->SetMIRFuncType(functype); @@ -750,7 +720,6 @@ void FETypeManager::InitFuncMCCGetOrInsertLiteral() { nameMCCFuncMap[nameIdx] = funcMCCGetOrInsertLiteral; } - MIRFunction *FETypeManager::GetMCCFunction(const std::string &funcName) const { GStrIdx funcNameIdx = GlobalTables::GetStrTable().GetOrCreateStrIdxFromName(funcName); return GetMCCFunction(funcNameIdx); diff --git a/src/mplfe/common/src/fe_utils.cpp b/src/mplfe/common/src/fe_utils.cpp index d938f837c7..99edc2adf3 100644 --- a/src/mplfe/common/src/fe_utils.cpp +++ b/src/mplfe/common/src/fe_utils.cpp @@ -195,6 +195,25 @@ std::string FEUtils::GetSequentialName(const std::string &prefix) { return name; } +bool FEUtils::TraverseToNamedField(MIRStructType &structType, GStrIdx nameIdx, FieldID &fieldID) { + for (uint32 fieldIdx = 0; fieldIdx < structType.GetFieldsSize(); ++fieldIdx) { + ++fieldID; + TyIdx fieldTyIdx = structType.GetFieldsElemt(fieldIdx).second.first; + MIRType *fieldType = GlobalTables::GetTypeTable().GetTypeFromTyIdx(fieldTyIdx); + ASSERT(fieldType != nullptr, "fieldType is null"); + if (structType.GetFieldsElemt(fieldIdx).first == nameIdx) { + return true; + } + if (fieldType->IsStructType()) { + auto *subStructType = static_cast(fieldType); + if (TraverseToNamedField(*subStructType, nameIdx, fieldID)) { + return true; + } + } + } + return false; +} + FieldID FEUtils::GetStructFieldID(MIRStructType *base, const std::string &fieldName) { MIRStructType *type = base; std::vector fieldNames = FEUtils::Split(fieldName, '.'); @@ -202,13 +221,9 @@ FieldID FEUtils::GetStructFieldID(MIRStructType *base, const std::string &fieldN FieldID fieldID = 0; for (const auto &f: fieldNames) { GStrIdx strIdx = GlobalTables::GetStrTable().GetOrCreateStrIdxFromName(f); - uint32 tempFieldID = fieldID; - if (FEManager::GetMIRBuilder().TraverseToNamedFieldWithTypeAndMatchStyle(*type, strIdx, TyIdx(0), tempFieldID, - MIRBuilder::MatchStyle::kMatchAnyField)) { - fieldID = tempFieldID; - FieldID tmpID = tempFieldID; - FieldPair fieldPair = base->TraverseToFieldRef(tmpID); - type = static_cast(GlobalTables::GetTypeTable().GetTypeFromTyIdx(fieldPair.second.first)); + CHECK_FATAL(type->IsStructType(), "Must be struct type!"); + if (TraverseToNamedField(*type, strIdx, fieldID)) { + type = static_cast(base->GetFieldType(fieldID)); } } return fieldID; @@ -221,6 +236,88 @@ MIRType *FEUtils::GetStructFieldType(MIRStructType *type, FieldID fieldID) { return fieldType; } +MIRConst *FEUtils::CreateImplicitConst(MIRType *type) { + switch (type->GetPrimType()) { + case PTY_u8: { + return GlobalTables::GetIntConstTable().GetOrCreateIntConst( + 0, *GlobalTables::GetTypeTable().GetPrimType(PTY_u8)); + } + case PTY_u16: { + return GlobalTables::GetIntConstTable().GetOrCreateIntConst( + 0, *GlobalTables::GetTypeTable().GetPrimType(PTY_u16)); + } + case PTY_u32: { + return GlobalTables::GetIntConstTable().GetOrCreateIntConst( + 0, *GlobalTables::GetTypeTable().GetPrimType(PTY_u32)); + } + case PTY_u64: { + return GlobalTables::GetIntConstTable().GetOrCreateIntConst( + 0, *GlobalTables::GetTypeTable().GetPrimType(PTY_u64)); + } + case PTY_i8: { + return GlobalTables::GetIntConstTable().GetOrCreateIntConst( + 0, *GlobalTables::GetTypeTable().GetPrimType(PTY_i8)); + } + case PTY_i16: { + return GlobalTables::GetIntConstTable().GetOrCreateIntConst( + 0, *GlobalTables::GetTypeTable().GetPrimType(PTY_i16)); + } + case PTY_i32: { + return GlobalTables::GetIntConstTable().GetOrCreateIntConst( + 0, *GlobalTables::GetTypeTable().GetPrimType(PTY_i32)); + } + case PTY_i64: { + return GlobalTables::GetIntConstTable().GetOrCreateIntConst( + 0, *GlobalTables::GetTypeTable().GetPrimType(PTY_i64)); + } + case PTY_f32: { + return FEManager::GetModule().GetMemPool()->New( + 0, *GlobalTables::GetTypeTable().GetPrimType(PTY_f32)); + } + case PTY_f64: { + return FEManager::GetModule().GetMemPool()->New( + 0, *GlobalTables::GetTypeTable().GetPrimType(PTY_f64)); + } + case PTY_ptr: { + return GlobalTables::GetIntConstTable().GetOrCreateIntConst( + 0, *GlobalTables::GetTypeTable().GetPrimType(PTY_i64)); + } + case PTY_agg: { + auto *aggConst = FEManager::GetModule().GetMemPool()->New(FEManager::GetModule(), *type); + if (type->IsStructType()) { + auto structType = static_cast(type); + FieldID fieldID = 0; + for (auto &f:structType->GetFields()) { + fieldID++; + auto fieldType = GlobalTables::GetTypeTable().GetTypeFromTyIdx(f.second.first); + aggConst->AddItem(CreateImplicitConst(fieldType), fieldID); + } + } else if (type->GetKind() == kTypeArray) { + auto arrayType = static_cast(type); + MIRConst *elementConst; + if (arrayType->GetDim() > 1) { + uint32 subSizeArray[arrayType->GetDim()]; + for (int dim = 1; dim < arrayType->GetDim(); ++dim) { + subSizeArray[dim - 1] = arrayType->GetSizeArrayItem(dim); + } + auto subArrayType = GlobalTables::GetTypeTable().GetOrCreateArrayType(*arrayType->GetElemType(), + arrayType->GetDim() - 1, subSizeArray); + elementConst = CreateImplicitConst(subArrayType); + } else { + elementConst = CreateImplicitConst(arrayType->GetElemType()); + } + for (int i = 0; i < arrayType->GetSizeArrayItem(0); ++i) { + aggConst->AddItem(elementConst, 0); + } + } + return aggConst; + } + default: { + CHECK_FATAL(false, "Unsupported Primitive type: %d", type->GetPrimType()); + } + } +} + // ---------- FELinkListNode ---------- FELinkListNode::FELinkListNode() : prev(nullptr), next(nullptr) {} @@ -327,4 +424,4 @@ bool AstLoopUtil::IsLoopLabelsEmpty() const { void AstLoopUtil::PopCurrentLoop(){ loopLabels.pop(); } -} // namespace maple \ No newline at end of file +} // namespace maple diff --git a/src/mplfe/common/src/feir_stmt.cpp b/src/mplfe/common/src/feir_stmt.cpp index e643a34588..a96f6a1e29 100644 --- a/src/mplfe/common/src/feir_stmt.cpp +++ b/src/mplfe/common/src/feir_stmt.cpp @@ -428,12 +428,7 @@ std::list FEIRStmtJavaConstString::GenMIRStmtsImpl(MIRBuilder &mirBui if (literalValPtr == nullptr) { std::string localStrName = kLocalStringPrefix + std::to_string(fileIdx) + "_" + std::to_string(stringID); MIRType *typeString = FETypeManager::kFEIRTypeJavaString->GenerateMIRTypeAuto(kSrcLangJava); -#ifndef USE_OPS - MIRSymbol *symbolLocal = SymbolBuilder::Instance().GetOrCreateLocalSymbol(*typeString, localStrName, - *mirBuilder.GetCurrentFunction()); -#else MIRSymbol *symbolLocal = mirBuilder.GetOrCreateLocalDecl(localStrName.c_str(), *typeString); -#endif if (!FEOptions::GetInstance().IsAOT()) { MapleVector args(mirBuilder.GetCurrentFuncCodeMpAllocator()->Adapter()); args.push_back(mirBuilder.CreateExprAddrof(0, *literalVal)); @@ -741,7 +736,6 @@ std::list FEIRStmtReturn::GenMIRStmtsImpl(MIRBuilder &mirBuilder) con mirStmt = mirBuilder.CreateStmtReturn(nullptr); } else { BaseNode *srcNode = expr->GenMIRNode(mirBuilder); -#ifdef USE_OPS if (mirBuilder.GetCurrentFunction()->IsFirstArgReturn()) { MIRSymbol *firstArgRetSym = mirBuilder.GetCurrentFunction()->GetFormal(0); BaseNode *addrNode = mirBuilder.CreateDread(*firstArgRetSym, PTY_ptr); @@ -751,9 +745,6 @@ std::list FEIRStmtReturn::GenMIRStmtsImpl(MIRBuilder &mirBuilder) con } else { mirStmt = mirBuilder.CreateStmtReturn(srcNode); } -#else - mirStmt = mirBuilder.CreateStmtReturn(srcNode); -#endif } ans.emplace_back(mirStmt); return ans; @@ -822,13 +813,8 @@ FEIRStmtIGoto::FEIRStmtIGoto(UniqueFEIRExpr expr) : FEIRStmt(kStmtIGoto), target std::list FEIRStmtIGoto::GenMIRStmtsImpl(MIRBuilder &mirBuilder) const { std::list stmts; -#ifndef USE_OPS - CHECK_FATAL(false, "Unsupported yet"); - return stmts; -#else stmts.emplace_back(mirBuilder.CreateStmtUnary(OP_igoto, targetExpr->GenMIRNode(mirBuilder))); return stmts; -#endif } // ---------- FEIRStmtCondGotoForC ---------- @@ -1275,12 +1261,7 @@ void FEIRStmtArrayStore::GenMIRStmtsImplForCPart(MIRBuilder &mirBuilder, MIRType MIRType *ptrMIRStructType = typeStruct->GenerateMIRType(false); MIRStructType* mirStructType = static_cast(ptrMIRStructType); // for no init, create the struct symbol -#ifndef USE_OPS - (void)SymbolBuilder::Instance().GetOrCreateLocalSymbol(*mirStructType, arrayName, - *mirBuilder.GetCurrentFunction()); -#else (void)mirBuilder.GetOrCreateLocalDecl(arrayName, *mirStructType); -#endif } *mIRElemType = typeElem->GenerateMIRType(true); @@ -2004,9 +1985,7 @@ std::list FEIRStmtIntrinsicCallAssign::GenMIRStmtsImpl(MIRBuilder &mi type->GenerateMIRType(true)->GetTypeIndex()); } else if (intrinsicId == INTRN_JAVA_POLYMORPHIC_CALL) { return GenMIRStmtsForInvokePolyMorphic(mirBuilder); - } -#ifdef USE_OPS - else if (intrinsicId == INTRN_C_va_start || intrinsicId == INTRN_C_memcpy) { + } else if (intrinsicId == INTRN_C_va_start || intrinsicId == INTRN_C_memcpy) { MapleVector args(mirBuilder.GetCurrentFuncCodeMpAllocator()->Adapter()); if (exprList != nullptr) { for (const auto &expr : *exprList) { @@ -2028,7 +2007,6 @@ std::list FEIRStmtIntrinsicCallAssign::GenMIRStmtsImpl(MIRBuilder &mi } stmtCall = mirBuilder.CreateStmtIntrinsicCall(INTRN_C_memset, std::move(args), TyIdx(0)); } -#endif // other intrinsic call should be implemented ans.emplace_back(stmtCall); return ans; @@ -2252,12 +2230,7 @@ std::unique_ptr FEIRExprSizeOfType::CloneImpl() const { } BaseNode *FEIRExprSizeOfType::GenMIRNodeImpl(MIRBuilder &mirBuilder) const { -#ifndef USE_OPS - CHECK_FATAL(false, "Unsupported in NO OPS"); - return nullptr; -#else return mirBuilder.CreateExprSizeoftype(*(feirType->GenerateMIRTypeAuto())); -#endif } // ---------- FEIRExprDRead ---------- @@ -2366,6 +2339,9 @@ BaseNode *FEIRExprAddrofConstArray::GenMIRNodeImpl(MIRBuilder &mirBuilder) const MIRConst *cst = module.GetMemPool()->New(array[i], *type); val->PushBack(cst); } + // This interface is only for string literal, 0 is added to the end of the string. + MIRConst *cst0 = module.GetMemPool()->New(0, *type); + val->PushBack(cst0); arrayVar->SetKonst(val); BaseNode *nodeAddrof = mirBuilder.CreateExprAddrof(0, *arrayVar); return nodeAddrof; @@ -3183,7 +3159,6 @@ FEIRExprIntrinsicop::FEIRExprIntrinsicop(std::unique_ptr exprType, MIR paramType = std::move(argParamType); } - std::unique_ptr FEIRExprIntrinsicop::CloneImpl() const { if (op == OP_intrinsicop) { return std::make_unique(type->Clone(), intrinsicID, opnds); @@ -3453,12 +3428,7 @@ BaseNode *FEIRExprArrayStoreForC::GenMIRNodeImpl(MIRBuilder &mirBuilder) const { MIRType *ptrMIRStructType = typeNativeStruct->GenerateMIRTypeAuto(); MIRStructType* mirStructType = static_cast(ptrMIRStructType); // for no init, create the struct symbol -#ifndef USE_OPS - (void)SymbolBuilder::Instance().GetOrCreateLocalSymbol(*mirStructType, arrayName, - *mirBuilder.GetCurrentFunction()); -#else (void)mirBuilder.GetOrCreateLocalDecl(arrayName, *mirStructType); -#endif } BaseNode *nodeAddrof = nullptr; if (exprArray->GetKind() == kExprIAddrof) { @@ -3730,14 +3700,8 @@ void FEIRExprAtomic::ProcessAtomicExchange(MIRBuilder &mirBuilder, BlockNode &bl void FEIRExprAtomic::ProcessAtomicCompareExchange(MIRBuilder &mirBuilder, BlockNode &block, BaseNode &lockNode, const MIRSymbol *valueVar) const { -#ifndef USE_OPS - valueVar = SymbolBuilder::Instance().GetOrCreateLocalSymbol(*GlobalTables::GetTypeTable().GetUInt1(), - FEUtils::GetSequentialName("valueVar"), - *mirBuilder.GetCurrentFunction()); -#else valueVar = mirBuilder.GetOrCreateLocalDecl(FEUtils::GetSequentialName("valueVar").c_str(), *GlobalTables::GetTypeTable().GetUInt1()); -#endif StmtNode *retStmt = mirBuilder.CreateStmtDassign(*valueVar, 0, mirBuilder.GetConstUInt1(false)); block.AddStatement(retStmt); BaseNode *expectNode = mirBuilder.CreateExprIread(*refType, *mirType, 0, valExpr1.get()->GenMIRNode(mirBuilder)); diff --git a/src/mplfe/common/src/feir_var.cpp b/src/mplfe/common/src/feir_var.cpp index 9d1b07f198..ce0b5a80ca 100644 --- a/src/mplfe/common/src/feir_var.cpp +++ b/src/mplfe/common/src/feir_var.cpp @@ -136,9 +136,6 @@ MIRSymbol *FEIRVar::GenerateLocalMIRSymbolImpl(MIRBuilder &builder) const { MPLFE_PARALLEL_FORBIDDEN(); MIRType *mirType = type->GenerateMIRTypeAuto(); std::string name = GetName(*mirType); -#ifndef USE_OPS - return SymbolBuilder::Instance().GetOrCreateLocalSymbol(*mirType, name, *builder.GetCurrentFunction()); -#else MIRSymbol *mirSymbol = builder.GetOrCreateLocalDecl(name, *mirType); if (genAttrs.GetAttr(GenericAttrKind::GENATTR_static)) { auto attrs = TypeAttrs(); @@ -148,7 +145,6 @@ MIRSymbol *FEIRVar::GenerateLocalMIRSymbolImpl(MIRBuilder &builder) const { mirSymbol->SetKonst(mirConst); } return mirSymbol; -#endif } MIRSymbol *FEIRVar::GenerateMIRSymbolImpl(MIRBuilder &builder) const { diff --git a/src/mplfe/common/src/feir_var_reg.cpp b/src/mplfe/common/src/feir_var_reg.cpp index 0cbc4a00cb..e4cf2590d0 100644 --- a/src/mplfe/common/src/feir_var_reg.cpp +++ b/src/mplfe/common/src/feir_var_reg.cpp @@ -48,14 +48,7 @@ MIRSymbol *FEIRVarReg::GenerateLocalMIRSymbolImpl(MIRBuilder &builder) const { MPLFE_PARALLEL_FORBIDDEN(); MIRType *mirType = type->GenerateMIRTypeAuto(); std::string name = GetName(*mirType); -#ifndef USE_OPS - MIRSymbol *ret = SymbolBuilder::Instance().GetOrCreateLocalSymbol(*mirType, name, *builder.GetCurrentFunction()); - if (FEOptions::GetInstance().IsAOT()) { - ret->SetVregNo(regNum); - } -#else MIRSymbol *ret = builder.GetOrCreateLocalDecl(name, *mirType); -#endif return ret; } diff --git a/src/mplfe/common/src/feir_var_type_scatter.cpp b/src/mplfe/common/src/feir_var_type_scatter.cpp index e271652028..6c09cffb2d 100644 --- a/src/mplfe/common/src/feir_var_type_scatter.cpp +++ b/src/mplfe/common/src/feir_var_type_scatter.cpp @@ -69,11 +69,7 @@ MIRSymbol *FEIRVarTypeScatter::GenerateLocalMIRSymbolImpl(MIRBuilder &builder) c MPLFE_PARALLEL_FORBIDDEN(); MIRType *mirType = var->GetType()->GenerateMIRTypeAuto(); std::string name = GetName(*mirType); -#ifndef USE_OPS - return SymbolBuilder::Instance().GetOrCreateLocalSymbol(*mirType, name, *builder.GetCurrentFunction()); -#else return builder.GetOrCreateLocalDecl(name, *mirType); -#endif } MIRSymbol *FEIRVarTypeScatter::GenerateMIRSymbolImpl(MIRBuilder &builder) const { diff --git a/src/mplfe/common/src/mplfe_compiler.cpp b/src/mplfe/common/src/mplfe_compiler.cpp index f699faaae1..c55d8ed0b6 100644 --- a/src/mplfe/common/src/mplfe_compiler.cpp +++ b/src/mplfe/common/src/mplfe_compiler.cpp @@ -105,7 +105,6 @@ void MPLFECompiler::CheckInput() { } } -#ifdef ENABLE_MPLFE_AST // check input ast files const std::vector &inputASTNames = FEOptions::GetInstance().GetInputASTFiles(); if (!inputASTNames.empty()) { @@ -114,7 +113,6 @@ void MPLFECompiler::CheckInput() { firstInputName = inputASTNames[0]; } } -#endif // ~/ENABLE_MPLFE_AST CHECK_FATAL(nInput > 0, "Error occurs: no inputs. exit."); } @@ -202,11 +200,7 @@ void MPLFECompiler::ExportMplFile() { if (srcLang == kSrcLangC) { emitStructureType = true; } -#ifndef USE_OPS - module.OutputAsciiMpl("", emitStructureType); -#else module.OutputAsciiMpl("", ".mpl", nullptr, emitStructureType, false); -#endif timer.StopAndDumpTimeMS("Output mpl"); } } @@ -307,13 +301,11 @@ void MPLFECompiler::RegisterCompilerComponent() { std::make_unique>(module); RegisterCompilerComponent(std::move(bcCompilerComp)); } -#ifdef ENABLE_MPLFE_AST if (FEOptions::GetInstance().GetInputASTFiles().size() != 0) { srcLang = kSrcLangC; std::unique_ptr astCompilerComp = std::make_unique(module); RegisterCompilerComponent(std::move(astCompilerComp)); } -#endif // ~/ENABLE_MPLFE_AST module.SetSrcLang(srcLang); FEManager::GetTypeManager().SetSrcLang(srcLang); } diff --git a/src/mplfe/common/src/mplfe_options.cpp b/src/mplfe/common/src/mplfe_options.cpp index 938eebab2a..45dc279186 100644 --- a/src/mplfe/common/src/mplfe_options.cpp +++ b/src/mplfe/common/src/mplfe_options.cpp @@ -32,9 +32,7 @@ enum OptionIndex : uint32 { kInClass, kInJar, kInDex, -#ifdef ENABLE_MPLFE_AST kInAST, -#endif // ~/ENABLE_MPLFE_AST // output control options kOutputPath, kOutputName, @@ -116,12 +114,10 @@ const Descriptor kUsage[] = { kBuildTypeAll, kArgCheckPolicyRequired, " --in-dex file1.dex,file2.dex\n" " : input dex files", "mplfe", {} }, -#ifdef ENABLE_MPLFE_AST { kInAST, 0, "", "in-ast", kBuildTypeAll, kArgCheckPolicyRequired, " --in-ast file1.ast,file2.ast\n" " : input ast files", "mplfe", {} }, -#endif // ~/ENABLE_MPLFE_AST // output control options { kUnknown, 0, "", "", @@ -304,10 +300,8 @@ bool MPLFEOptions::InitFactory() { &MPLFEOptions::ProcessInJar); RegisterFactoryFunction(kInDex, &MPLFEOptions::ProcessInDex); -#ifdef ENABLE_MPLFE_AST RegisterFactoryFunction(kInAST, &MPLFEOptions::ProcessInAST); -#endif // ~/ENABLE_MPLFE_AST // output control options RegisterFactoryFunction(kOutputPath, @@ -467,7 +461,6 @@ bool MPLFEOptions::ProcessInDex(const Option &opt) { return true; } -#ifdef ENABLE_MPLFE_AST bool MPLFEOptions::ProcessInAST(const Option &opt) { std::list listFiles = SplitByComma(opt.Args()); for (const std::string &fileName : listFiles) { @@ -475,7 +468,6 @@ bool MPLFEOptions::ProcessInAST(const Option &opt) { } return true; } -#endif // ~/ENABLE_MPLFE_AST bool MPLFEOptions::ProcessInputMplt(const Option &opt) { std::list listFiles = SplitByComma(opt.Args()); @@ -673,12 +665,10 @@ void MPLFEOptions::ProcessInputFiles(const std::vector &inputs) { FE_INFO_LEVEL(FEOptions::kDumpLevelInfoDetail, "DEX file detected: %s", inputName.c_str()); FEOptions::GetInstance().AddInputDexFile(inputName); break; -#ifdef ENABLE_MPLFE_AST case FEFileType::kAST: FE_INFO_LEVEL(FEOptions::kDumpLevelInfoDetail, "AST file detected: %s", inputName.c_str()); FEOptions::GetInstance().AddInputASTFile(inputName); break; -#endif // ~/ENABLE_MPLFE_AST default: WARN(kLncErr, "unsupported file format (%s)", inputName.c_str()); break; diff --git a/src/mplfe/dex_input/src/dex_pragma.cpp b/src/mplfe/dex_input/src/dex_pragma.cpp index 4cdcceec1c..b73588ba51 100644 --- a/src/mplfe/dex_input/src/dex_pragma.cpp +++ b/src/mplfe/dex_input/src/dex_pragma.cpp @@ -422,11 +422,7 @@ void DexBCMethodAnnotations::SetupFuncAttrWithPragma(MIRFunction &mirFunc, MIRPr mirFunc.SetAttr(attr); // update method attribute in structure type as well for (auto &mit : currStructType->GetMethods()) { -#ifndef USE_OPS - if (mit.first->GetStIdx() == mirFunc.GetStIdx()) { -#else if (mit.first == mirFunc.GetStIdx()) { -#endif mit.second.second.SetAttr(attr); break; } diff --git a/src/mplfe/test/fe_file_type_test.cpp b/src/mplfe/test/fe_file_type_test.cpp index 46a01f56ac..e317748151 100644 --- a/src/mplfe/test/fe_file_type_test.cpp +++ b/src/mplfe/test/fe_file_type_test.cpp @@ -20,6 +20,7 @@ namespace maple { TEST(FEFileType, GetFileTypeByExtName) { EXPECT_EQ(FEFileType::GetInstance().GetFileTypeByExtName("jar"), FEFileType::FileType::kJar); EXPECT_EQ(FEFileType::GetInstance().GetFileTypeByExtName("class"), FEFileType::FileType::kClass); + EXPECT_EQ(FEFileType::GetInstance().GetFileTypeByExtName("dex"), FEFileType::FileType::kDex); EXPECT_EQ(FEFileType::GetInstance().GetFileTypeByExtName(""), FEFileType::FileType::kUnknownType); EXPECT_EQ(FEFileType::GetInstance().GetFileTypeByExtName("txt"), FEFileType::FileType::kUnknownType); } diff --git a/src/mplfe/test/feir_stmt_test.cpp b/src/mplfe/test/feir_stmt_test.cpp index c568edd6b8..3e8116af0b 100644 --- a/src/mplfe/test/feir_stmt_test.cpp +++ b/src/mplfe/test/feir_stmt_test.cpp @@ -26,11 +26,9 @@ #include "feir_builder.h" #include "mplfe_ut_regx.h" #include "fe_utils_java.h" - #define private public #include "dex_op.h" #undef private -#endif namespace maple { class FEIRStmtTest : public FEIRTestBase { -- Gitee