diff --git a/Makefile.in b/Makefile.in index d4035a8104d9807a3557c314fb2654c5c0f3c2ba..0902fbd1540ecc1bbcf4887df41e44c3f94f50d2 100644 --- a/Makefile.in +++ b/Makefile.in @@ -4,16 +4,17 @@ AR = ar rcs FLAVOR = gnu LD = clang++ -CXXFLAGS = -O0 -g3 -Wall -std=c++11 -DDEBUG -LFLAGS=-std=c++11 +CXXFLAGS = -O0 -g3 -Wall -std=c++17 -DDEBUG +LFLAGS=-std=c++17 MKDIR_P = mkdir -p -MAPLELIBPATH:=$(MAPLEALL_ROOT)/out/aarch64-clang-debug/lib/64 -MAPLELIBS := -L $(MAPLELIBPATH) -lmplir -loption_parser -lmpl2mpl -lmplutil -lmempool -lHWSecureC +MAPLELIBPATH:=$(MAPLE_ROOT)/OpenArkCompiler/output/aarch64-clang-debug/lib/64 +MAPLELIBPATH1:=$(MAPLE_ROOT)/OpenArkCompiler/output/aarch64-clang-debug/ar +MAPLELIBS := -L $(MAPLELIBPATH) -L $(MAPLELIBPATH1) -lmplir -loption_parser -lmpl2mpl -lmplutil -lmempool -lHWSecureC -ldriver_option MAPLEALL_INC = -I $(MAPLEALL_SRC)/maple_ir/include \ - -I $(MAPLEALL_SRC)/mpl2mpl/include \ -I $(MAPLEALL_SRC)/mempool/include \ -I $(MAPLEALL_SRC)/maple_util/include \ - -I $(MAPLEALL_ROOT)/huawei_secure_c/include + -I $(MAPLEALL_SRC)/maple_driver/include \ + -I $(MAPLEALL_ROOT)/third_party/bounds_checking_function/include diff --git a/envsetup.sh b/envsetup.sh index 37781d55f8333f18a26672843a5bee36a40e206b..1895cbccb164fd281ea3a071a2fc425bec9b3281 100755 --- a/envsetup.sh +++ b/envsetup.sh @@ -34,10 +34,10 @@ unset MAPLEFE_ROOT export MAPLEFE_ROOT=${curdir} unset MAPLEALL_ROOT -export MAPLEALL_ROOT=${MAPLE_ROOT}/mapleall +export MAPLEALL_ROOT=${MAPLE_ROOT}/OpenArkCompiler unset MAPLEALL_SRC -export MAPLEALL_SRC=${MAPLEALL_ROOT}/mapleall +export MAPLEALL_SRC=${MAPLEALL_ROOT}/src/mapleall unset BUILDDIR export BUILDDIR=${MAPLEFE_ROOT}/output diff --git a/java/include/ast2mpl_java.h b/java/include/ast2mpl_java.h index 4fd2dbea11ce2cd7b0d43b9828123a8aeb617924..cec63ef9035608a2e8ab8eddf821b02b6d0fc2ae 100644 --- a/java/include/ast2mpl_java.h +++ b/java/include/ast2mpl_java.h @@ -29,9 +29,9 @@ private: public: A2MJava(const char *filename) : A2M(filename) { } - const char *Type2Label(const MIRType *type); + const char *Type2Label(const maple::MIRType *type); - MIRType *MapPrimType(PrimTypeNode *ptnode); + maple::MIRType *MapPrimType(PrimTypeNode *ptnode); }; } diff --git a/java/src/ast2mpl_java.cpp b/java/src/ast2mpl_java.cpp index 0de6a83acc983dfb39688c8cfc280d0b62ce07be..ca77eaaa32c95629b3a6b89eb088e175ee9c78f3 100644 --- a/java/src/ast2mpl_java.cpp +++ b/java/src/ast2mpl_java.cpp @@ -17,38 +17,38 @@ namespace maplefe { -MIRType *A2MJava::MapPrimType(PrimTypeNode *ptnode) { - PrimType prim; +maple::MIRType *A2MJava::MapPrimType(PrimTypeNode *ptnode) { + maple::PrimType prim; switch (ptnode->GetPrimType()) { - case TY_Boolean: prim = PTY_u1; break; - case TY_Byte: prim = PTY_u8; break; - case TY_Short: prim = PTY_i16; break; - case TY_Int: prim = PTY_i32; break; - case TY_Long: prim = PTY_i64; break; - case TY_Char: prim = PTY_u16; break; - case TY_Float: prim = PTY_f32; break; - case TY_Double: prim = PTY_f64; break; - case TY_Void: prim = PTY_void; break; - case TY_Null: prim = PTY_void; break; + case TY_Boolean: prim = maple::PTY_u1; break; + case TY_Byte: prim = maple::PTY_u8; break; + case TY_Short: prim = maple::PTY_i16; break; + case TY_Int: prim = maple::PTY_i32; break; + case TY_Long: prim = maple::PTY_i64; break; + case TY_Char: prim = maple::PTY_u16; break; + case TY_Float: prim = maple::PTY_f32; break; + case TY_Double: prim = maple::PTY_f64; break; + case TY_Void: prim = maple::PTY_void; break; + case TY_Null: prim = maple::PTY_void; break; default: MASSERT("Unsupported PrimType"); break; } - TyIdx tid(prim); - return GlobalTables::GetTypeTable().GetTypeFromTyIdx(tid); + maple::TyIdx tid(prim); + return maple::GlobalTables::GetTypeTable().GetTypeFromTyIdx(tid); } -const char *A2MJava::Type2Label(const MIRType *type) { - PrimType pty = type->GetPrimType(); +const char *A2MJava::Type2Label(const maple::MIRType *type) { + maple::PrimType pty = type->GetPrimType(); switch (pty) { - case PTY_u1: return "Z"; - case PTY_u8: return "B"; - case PTY_i16: return "S"; - case PTY_u16: return "C"; - case PTY_i32: return "I"; - case PTY_i64: return "J"; - case PTY_f32: return "F"; - case PTY_f64: return "D"; - case PTY_void: return "V"; + case maple::PTY_u1: return "Z"; + case maple::PTY_u8: return "B"; + case maple::PTY_i16: return "S"; + case maple::PTY_u16: return "C"; + case maple::PTY_i32: return "I"; + case maple::PTY_i64: return "J"; + case maple::PTY_f32: return "F"; + case maple::PTY_f64: return "D"; + case maple::PTY_void: return "V"; default: return "L"; } } diff --git a/scripts/build_mapleall.sh b/scripts/build_mapleall.sh index bbddc6f4658c42136398cfacfd5b5d75f4d28b45..a37d1634def7e2988d4bc89a29ee234cfb97e03e 100755 --- a/scripts/build_mapleall.sh +++ b/scripts/build_mapleall.sh @@ -15,12 +15,11 @@ if [ ! -d $MAPLEALL_ROOT ]; then cd $MAPLE_ROOT - git clone https://gitee.com/openarkcompiler-incubator/mapleall.git + git clone https://gitee.com/openarkcompiler/OpenArkCompiler.git fi cd $MAPLEALL_ROOT git pull -source envsetup.sh arm debug +source build/envsetup.sh arm debug make setup make -make install diff --git a/shared/include/ast2mpl.h b/shared/include/ast2mpl.h index dd06dca23b9cc5f6ed43b3fffcdbec962d00e062..837c7ee30229625f1a58893e3f424b26a858f48a 100644 --- a/shared/include/ast2mpl.h +++ b/shared/include/ast2mpl.h @@ -63,24 +63,24 @@ public: void Init(); bool IsStmt(TreeNode *tnode); - void UpdateFuncName(MIRFunction *func); + void UpdateFuncName(maple::MIRFunction *func); - virtual const char *Type2Label(const MIRType *type); - void Type2Name(std::string &str, const MIRType *type); + virtual const char *Type2Label(const maple::MIRType *type); + void Type2Name(std::string &str, const maple::MIRType *type); BlockNode *GetSuperBlock(BlockNode *block); - MIRSymbol *GetSymbol(TreeNode *tnode, BlockNode *block); - MIRSymbol *CreateSymbol(TreeNode *tnode, BlockNode *block); - MIRSymbol *CreateTempVar(const char *prefix, MIRType *type); - MIRFunction *GetFunc(BlockNode *block); - MIRFunction *SearchFunc(const char *name, const MapleVector &args); - MIRClassType *GetClass(BlockNode *block); + maple::MIRSymbol *GetSymbol(TreeNode *tnode, BlockNode *block); + maple::MIRSymbol *CreateSymbol(TreeNode *tnode, BlockNode *block); + maple::MIRSymbol *CreateTempVar(const char *prefix, maple::MIRType *type); + maple::MIRFunction *GetFunc(BlockNode *block); + maple::MIRFunction *SearchFunc(const char *name, const maple::MapleVector &args); + maple::MIRClassType *GetClass(BlockNode *block); void UpdateUniqName(std::string &str); - virtual MIRType *MapPrimType(PrimTypeNode *tnode)=0; + virtual maple::MIRType *MapPrimType(PrimTypeNode *tnode)=0; - MIRType *MapType(TreeNode *tnode); - void MapAttr(GenericAttrs &attr, const IdentifierNode *inode); + maple::MIRType *MapType(TreeNode *tnode); + void MapAttr(maple::GenericAttrs &attr, const IdentifierNode *inode); maple::Opcode MapUnaOpcode(OprId); maple::Opcode MapBinOpcode(OprId); diff --git a/shared/include/macros.h b/shared/include/macros.h index 83481e58016209e945d95b77640d1e2e1ad336b4..5532cbd2790179e5ab220707df0621224e28a648 100644 --- a/shared/include/macros.h +++ b/shared/include/macros.h @@ -35,10 +35,10 @@ namespace maplefe { std::cout << "(" << __FILE__ << ":" << __LINE__ << ") " << std::endl;\ } while (0) -// SET_INFO_PAIR(module->fileInfo, "filename", strIdx, module_->fileInfoIsString, true); -#define SET_INFO_PAIR(A, B, C, D, E) \ - A.push_back(MIRInfoPair(GlobalTables::GetStrTable().GetOrCreateStrIdxFromName(B), C)); \ - D.push_back(E) +// SET_INFO_PAIR(module, "filename", strIdx, true); +#define SET_INFO_PAIR(A, B, C, D) \ + A->PushFileInfoPair(maple::MIRInfoPair(maple::GlobalTables::GetStrTable().GetOrCreateStrIdxFromName(B), C)); \ + A->PushFileInfoIsString(D) } #endif /* __MACROS_H__ */ diff --git a/shared/include/maplefe_mir_builder.h b/shared/include/maplefe_mir_builder.h index 4c353f8ebcffddcdab7a022eac861e1cec5ab789..d4fa730156948804ba3add28fa1162b3ec61b3cf 100644 --- a/shared/include/maplefe_mir_builder.h +++ b/shared/include/maplefe_mir_builder.h @@ -23,36 +23,36 @@ namespace maplefe { class FieldData { private: - GStrIdx strIdx; - TyIdx tyIdx; - FieldAttrs attr; + maple::GStrIdx strIdx; + maple::TyIdx tyIdx; + maple::FieldAttrs attr; public: FieldData() : strIdx(0), tyIdx(0), attr() {} - FieldData(GStrIdx idx) : strIdx(idx), tyIdx(0), attr() {} + FieldData(maple::GStrIdx idx) : strIdx(idx), tyIdx(0), attr() {} ~FieldData() {} - void SetStrIdx(GStrIdx s) { + void SetStrIdx(maple::GStrIdx s) { strIdx.SetIdx(s.GetIdx()); } - void SetTyIdx(TyIdx t) { + void SetTyIdx(maple::TyIdx t) { tyIdx.SetIdx(t.GetIdx()); } - void SetFieldAttrs(FieldAttrs a) { + void SetFieldAttrs(maple::FieldAttrs a) { attr = a; } - GStrIdx GetStrIdx() { + maple::GStrIdx GetStrIdx() { return strIdx; } - TyIdx GetTyIdx() { + maple::TyIdx GetTyIdx() { return tyIdx; } - FieldAttrs GetFieldAttrs() { + maple::FieldAttrs GetFieldAttrs() { return attr; } @@ -62,20 +62,21 @@ class FieldData { attr.Clear(); } - void ResetStrIdx(GStrIdx s) { + void ResetStrIdx(maple::GStrIdx s) { strIdx.SetIdx(s.GetIdx()); tyIdx.SetIdx(0); attr.Clear(); } }; -class FEMIRBuilder : public MIRBuilder { +class FEMIRBuilder : public maple::MIRBuilder { private: public: - FEMIRBuilder(MIRModule *mod) : MIRBuilder(mod) {} + FEMIRBuilder(maple::MIRModule *mod) : maple::MIRBuilder(mod) {} - bool TraverseToNamedField(MIRStructType *structType, uint32 &fieldID, FieldData *fieldData); + bool TraverseToNamedField(maple::MIRStructType *structType, unsigned &fieldID, FieldData *fieldData); + maple::BaseNode *CreateExprDread(const maple::MIRSymbol *symbol, maple::FieldID fieldID = maple::FieldID(0)); }; } diff --git a/shared/src/ast2mpl.cpp b/shared/src/ast2mpl.cpp index e2e812709220493930093e3db55cfd27246bdaf1..f980347848ae9f737588bf3a6dc768ea8ca57a01 100644 --- a/shared/src/ast2mpl.cpp +++ b/shared/src/ast2mpl.cpp @@ -16,7 +16,6 @@ #include "ast2mpl.h" #include "mir_function.h" #include "maplefe_mir_builder.h" -#include "constant_fold.h" namespace maplefe { @@ -24,6 +23,7 @@ static unsigned mVarUniqNum; A2M::A2M(const char *filename) : mFileName(filename) { mMirModule = new maple::MIRModule(mFileName); + maple::theMIRModule = mMirModule; mMirBuilder = new FEMIRBuilder(mMirModule); mFieldData = new FieldData(); mVarUniqNum = 1; @@ -39,25 +39,25 @@ A2M::~A2M() { void A2M::Init() { // create mDefaultType - MIRType *type = GlobalTables::GetTypeTable().GetOrCreateClassType("DEFAULT_TYPE", mMirModule); - type->typeKind = maple::MIRTypeKind::kTypeClass; - mDefaultType = GlobalTables::GetTypeTable().GetOrCreatePointerType(type); + maple::MIRType *type = maple::GlobalTables::GetTypeTable().GetOrCreateClassType("DEFAULT_TYPE", *mMirModule); + type->SetMIRTypeKind(maple::kTypeClass); + mDefaultType = maple::GlobalTables::GetTypeTable().GetOrCreatePointerType(*type); // setup flavor and srclang - mMirModule->flavor = maple::kFeProduced; - mMirModule->srcLang = maple::kSrcLangJava; + mMirModule->SetFlavor(maple::kFeProduced); + mMirModule->SetSrcLang(maple::kSrcLangJava); // setup INFO_filename - GStrIdx idx = GlobalTables::GetStrTable().GetOrCreateStrIdxFromName(mFileName); - SET_INFO_PAIR(mMirModule->fileInfo, "INFO_filename", idx.GetIdx(), mMirModule->fileInfoIsString, true); + maple::GStrIdx idx = maple::GlobalTables::GetStrTable().GetOrCreateStrIdxFromName(mFileName); + SET_INFO_PAIR(mMirModule, "INFO_filename", idx.GetIdx(), true); // add to java src file list std::string str(mFileName); size_t pos = str.rfind('/'); if (pos != std::string::npos) { - idx = GlobalTables::GetStrTable().GetOrCreateStrIdxFromName(str.substr(pos+1)); + idx = maple::GlobalTables::GetStrTable().GetOrCreateStrIdxFromName(str.substr(pos+1)); } - mMirModule->srcFileInfo.push_back(MIRInfoPair(idx, 2)); + mMirModule->PushbackFileInfo(maple::MIRInfoPair(idx, 2)); } // starting point of AST to MPL process @@ -77,12 +77,12 @@ void A2M::ProcessAST(bool trace_a2m) { } } -MIRType *A2M::MapType(TreeNode *type) { +maple::MIRType *A2M::MapType(TreeNode *type) { if (!type) { - return GlobalTables::GetTypeTable().GetVoid(); + return maple::GlobalTables::GetTypeTable().GetVoid(); } - MIRType *mir_type = mDefaultType; + maple::MIRType *mir_type = mDefaultType; const char *name = type->GetName(); if (mNodeTypeMap.find(name) != mNodeTypeMap.end()) { @@ -114,89 +114,89 @@ MIRType *A2M::MapType(TreeNode *type) { } maple::Opcode A2M::MapUnaOpcode(OprId ast_op) { - maple::Opcode op = maple::kOpUndef; + maple::Opcode op = maple::OP_undef; switch (ast_op) { - case OPR_Add: op = OP_add; break; - case OPR_Sub: op = OP_neg; break; - case OPR_Inc: op = OP_incref; break; - case OPR_Dec: op = OP_decref; break; - case OPR_Bcomp: op = OP_bnot; break; - case OPR_Not: op = OP_lnot; break; + case OPR_Add: op = maple::OP_add; break; + case OPR_Sub: op = maple::OP_neg; break; + case OPR_Inc: op = maple::OP_incref; break; + case OPR_Dec: op = maple::OP_decref; break; + case OPR_Bcomp: op = maple::OP_bnot; break; + case OPR_Not: op = maple::OP_lnot; break; default: break; } return op; } maple::Opcode A2M::MapBinOpcode(OprId ast_op) { - maple::Opcode op = maple::kOpUndef; + maple::Opcode op = maple::OP_undef; switch (ast_op) { - case OPR_Add: op = OP_add; break; - case OPR_Sub: op = OP_sub; break; - case OPR_Mul: op = OP_mul; break; - case OPR_Div: op = OP_div; break; - case OPR_Mod: op = OP_rem; break; - case OPR_Band: op = OP_band; break; - case OPR_Bor: op = OP_bior; break; - case OPR_Bxor: op = OP_bxor; break; - case OPR_Shl: op = OP_shl; break; - case OPR_Shr: op = OP_ashr; break; - case OPR_Zext: op = OP_zext; break; - case OPR_Land: op = OP_land; break; - case OPR_Lor: op = OP_lior; break; + case OPR_Add: op = maple::OP_add; break; + case OPR_Sub: op = maple::OP_sub; break; + case OPR_Mul: op = maple::OP_mul; break; + case OPR_Div: op = maple::OP_div; break; + case OPR_Mod: op = maple::OP_rem; break; + case OPR_Band: op = maple::OP_band; break; + case OPR_Bor: op = maple::OP_bior; break; + case OPR_Bxor: op = maple::OP_bxor; break; + case OPR_Shl: op = maple::OP_shl; break; + case OPR_Shr: op = maple::OP_ashr; break; + case OPR_Zext: op = maple::OP_zext; break; + case OPR_Land: op = maple::OP_land; break; + case OPR_Lor: op = maple::OP_lior; break; default: break; } return op; } maple::Opcode A2M::MapBinCmpOpcode(OprId ast_op) { - maple::Opcode op = maple::kOpUndef; + maple::Opcode op = maple::OP_undef; switch (ast_op) { - case OPR_EQ: op = OP_eq; break; - case OPR_NE: op = OP_ne; break; - case OPR_GT: op = OP_gt; break; - case OPR_LT: op = OP_lt; break; - case OPR_GE: op = OP_ge; break; - case OPR_LE: op = OP_le; break; + case OPR_EQ: op = maple::OP_eq; break; + case OPR_NE: op = maple::OP_ne; break; + case OPR_GT: op = maple::OP_gt; break; + case OPR_LT: op = maple::OP_lt; break; + case OPR_GE: op = maple::OP_ge; break; + case OPR_LE: op = maple::OP_le; break; default: break; } return op; } maple::Opcode A2M::MapBinComboOpcode(OprId ast_op) { - maple::Opcode op = maple::kOpUndef; + maple::Opcode op = maple::OP_undef; switch (ast_op) { - case OPR_AddAssign: op = OP_add; break; - case OPR_SubAssign: op = OP_sub; break; - case OPR_MulAssign: op = OP_mul; break; - case OPR_DivAssign: op = OP_div; break; - case OPR_ModAssign: op = OP_rem; break; - case OPR_ShlAssign: op = OP_shl; break; - case OPR_ShrAssign: op = OP_ashr; break; - case OPR_BandAssign: op = OP_band; break; - case OPR_BorAssign: op = OP_bior; break; - case OPR_BxorAssign: op = OP_bxor; break; - case OPR_ZextAssign: op = OP_zext; break; + case OPR_AddAssign: op = maple::OP_add; break; + case OPR_SubAssign: op = maple::OP_sub; break; + case OPR_MulAssign: op = maple::OP_mul; break; + case OPR_DivAssign: op = maple::OP_div; break; + case OPR_ModAssign: op = maple::OP_rem; break; + case OPR_ShlAssign: op = maple::OP_shl; break; + case OPR_ShrAssign: op = maple::OP_ashr; break; + case OPR_BandAssign: op = maple::OP_band; break; + case OPR_BorAssign: op = maple::OP_bior; break; + case OPR_BxorAssign: op = maple::OP_bxor; break; + case OPR_ZextAssign: op = maple::OP_zext; break; default: break; } return op; } -const char *A2M::Type2Label(const MIRType *type) { - PrimType pty = type->GetPrimType(); +const char *A2M::Type2Label(const maple::MIRType *type) { + maple::PrimType pty = type->GetPrimType(); switch (pty) { - case PTY_u1: return "Z"; - case PTY_i8: return "C"; - case PTY_u8: return "UC"; - case PTY_i16: return "S"; - case PTY_u16: return "US"; - case PTY_i32: return "I"; - case PTY_u32: return "UI"; - case PTY_i64: return "J"; - case PTY_u64: return "UJ"; - case PTY_f32: return "F"; - case PTY_f64: return "D"; - case PTY_void: return "V"; + case maple::PTY_u1: return "Z"; + case maple::PTY_i8: return "C"; + case maple::PTY_u8: return "UC"; + case maple::PTY_i16: return "S"; + case maple::PTY_u16: return "US"; + case maple::PTY_i32: return "I"; + case maple::PTY_u32: return "UI"; + case maple::PTY_i64: return "J"; + case maple::PTY_u64: return "UJ"; + case maple::PTY_f32: return "F"; + case maple::PTY_f64: return "D"; + case maple::PTY_void: return "V"; default: return "L"; } } @@ -225,7 +225,7 @@ bool A2M::IsStmt(TreeNode *tnode) { case NK_BinOperator: { BinOperatorNode *bon = static_cast(tnode); maple::Opcode op = MapBinComboOpcode(bon->mOprId); - if (bon->mOprId != OPR_Assign && op == kOpUndef) { + if (bon->mOprId != OPR_Assign && op == maple::OP_undef) { status = false; } break; @@ -251,13 +251,13 @@ bool A2M::IsStmt(TreeNode *tnode) { #define RARG "_29" // ")" #endif -void A2M::Type2Name(std::string &str, const MIRType *type) { - PrimType pty = type->GetPrimType(); +void A2M::Type2Name(std::string &str, const maple::MIRType *type) { + maple::PrimType pty = type->GetPrimType(); const char *n = Type2Label(type); str.append(n); if (n[0] == 'L') { - while (type->GetPrimType() == PTY_ptr || type->GetPrimType() == PTY_ref) { - const MIRPtrType *ptype = static_cast(type); + while (type->GetPrimType() == maple::PTY_ptr || type->GetPrimType() == maple::PTY_ref) { + const maple::MIRPtrType *ptype = static_cast(type); type = ptype->GetPointedType(); } str.append(type->GetName()); @@ -274,37 +274,38 @@ void A2M::UpdateUniqName(std::string &str) { } // update to use mangled name: className|funcName|(argTypes)retType -void A2M::UpdateFuncName(MIRFunction *func) { +void A2M::UpdateFuncName(maple::MIRFunction *func) { std::string str; - TyIdx tyIdx = func->GetClassTyIdx(); - MIRType *type; + maple::TyIdx tyIdx = func->GetClassTyIdx(); + maple::MIRType *type; if (tyIdx.GetIdx() != 0) { - type = GlobalTables::GetTypeTable().GetTypeFromTyIdx(tyIdx); + type = maple::GlobalTables::GetTypeTable().GetTypeFromTyIdx(tyIdx); str.append(type->GetName()); str.append(SEP); } str.append(func->GetName()); str.append(SEP); str.append(LARG); - GStrIdx stridx = GlobalTables::GetStrTable().GetOrCreateStrIdxFromName("this"); - for (auto def: func->formalDefVec) { + maple::GStrIdx stridx = maple::GlobalTables::GetStrTable().GetOrCreateStrIdxFromName("this"); + for (size_t i = 0; i < func->GetFormalCount(); i++) { + maple::FormalDef def = func->GetFormalDefAt(i); // exclude type of extra "this" in the function name if (stridx == def.formalStrIdx) continue; - MIRType *type = GlobalTables::GetTypeTable().GetTypeFromTyIdx(def.formalTyIdx); + maple::MIRType *type = maple::GlobalTables::GetTypeTable().GetTypeFromTyIdx(def.formalTyIdx); Type2Name(str, type); } str.append(RARG); type = func->GetReturnType(); Type2Name(str, type); - MIRSymbol *funcst = GlobalTables::GetGsymTable().GetSymbolFromStIdx(func->stIdx.Idx()); + maple::MIRSymbol *funcst = maple::GlobalTables::GetGsymTable().GetSymbolFromStidx(func->GetStIdx().Idx()); // remove old entry in strIdxToStIdxMap - GlobalTables::GetGsymTable().RemoveFromStringSymbolMap(funcst); + maple::GlobalTables::GetGsymTable().RemoveFromStringSymbolMap(*funcst); AST2MPLMSG("UpdateFuncName()", str); - stridx = GlobalTables::GetStrTable().GetOrCreateStrIdxFromName(str); - funcst->SetNameStridx(stridx); + stridx = maple::GlobalTables::GetStrTable().GetOrCreateStrIdxFromName(str); + funcst->SetNameStrIdx(stridx); // add new entry in strIdxToStIdxMap - GlobalTables::GetGsymTable().AddToStringSymbolMap(funcst); + maple::GlobalTables::GetGsymTable().AddToStringSymbolMap(*funcst); } BlockNode *A2M::GetSuperBlock(BlockNode *block) { @@ -315,9 +316,9 @@ BlockNode *A2M::GetSuperBlock(BlockNode *block) { return (BlockNode*)blk; } -MIRSymbol *A2M::GetSymbol(TreeNode *tnode, BlockNode *block) { +maple::MIRSymbol *A2M::GetSymbol(TreeNode *tnode, BlockNode *block) { const char *name = tnode->GetName(); - MIRSymbol *symbol = nullptr; + maple::MIRSymbol *symbol = nullptr; // global symbol if (!block) { @@ -338,21 +339,20 @@ MIRSymbol *A2M::GetSymbol(TreeNode *tnode, BlockNode *block) { } while (blk); // check parameters - MIRFunction *func = GetFunc(blk); + maple::MIRFunction *func = GetFunc(blk); if (!func) { NOTYETIMPL("Block parent hirachy"); return symbol; } - GStrIdx stridx = GlobalTables::GetStrTable().GetOrCreateStrIdxFromName(name); - for (auto it: func->formalDefVec) { - if (it.formalStrIdx == stridx) { - return it.formalSym; - } + maple::GStrIdx stridx = maple::GlobalTables::GetStrTable().GetOrCreateStrIdxFromName(name); + if (func->IsAFormalName(stridx)) { + maple::FormalDef def = func->GetFormalFromName(stridx); + return def.formalSym; } return symbol; } -MIRSymbol *A2M::CreateTempVar(const char *prefix, MIRType *type) { +maple::MIRSymbol *A2M::CreateTempVar(const char *prefix, maple::MIRType *type) { if (!type) { return nullptr; } @@ -361,13 +361,13 @@ MIRSymbol *A2M::CreateTempVar(const char *prefix, MIRType *type) { str.append(std::to_string(mVarUniqNum)); mVarUniqNum++; maple::MIRFunction *func = mMirModule->CurFunction(); - MIRSymbol *var = mMirBuilder->CreateLocalDecl(str, type, func); + maple::MIRSymbol *var = mMirBuilder->CreateLocalDecl(str, *type); return var; } -MIRSymbol *A2M::CreateSymbol(TreeNode *tnode, BlockNode *block) { +maple::MIRSymbol *A2M::CreateSymbol(TreeNode *tnode, BlockNode *block) { const char *name = tnode->GetName(); - MIRType *mir_type; + maple::MIRType *mir_type; if (tnode->IsIdentifier()) { IdentifierNode *inode = static_cast(tnode); @@ -378,21 +378,22 @@ MIRSymbol *A2M::CreateSymbol(TreeNode *tnode, BlockNode *block) { } // always use pointer type for classes, with PTY_ref - if (mir_type->typeKind == kTypeClass || mir_type->typeKind == kTypeClassIncomplete || - mir_type->typeKind == kTypeInterface || mir_type->typeKind == kTypeInterfaceIncomplete) { - mir_type = GlobalTables::GetTypeTable().GetOrCreatePointerType(mir_type, PTY_ref); + maple::MIRTypeKind kind = mir_type->GetKind(); + if (kind == maple::kTypeClass || kind == maple::kTypeClassIncomplete || + kind == maple::kTypeInterface || kind == maple::kTypeInterfaceIncomplete) { + mir_type = maple::GlobalTables::GetTypeTable().GetOrCreatePointerType(*mir_type, maple::PTY_ref); } - MIRSymbol *symbol = nullptr; + maple::MIRSymbol *symbol = nullptr; if (block) { maple::MIRFunction *func = GetFunc(block); - symbol = mMirBuilder->GetLocalDecl(name, func); + symbol = mMirBuilder->GetLocalDecl(name); std::string str(name); // symbol with same name already exist, use a uniq new name if (symbol) { UpdateUniqName(str); } - symbol = mMirBuilder->CreateLocalDecl(str, mir_type, func); + symbol = mMirBuilder->CreateLocalDecl(str, *mir_type); } else { symbol = mMirBuilder->GetGlobalDecl(name); std::string str(name); @@ -400,7 +401,7 @@ MIRSymbol *A2M::CreateSymbol(TreeNode *tnode, BlockNode *block) { if (symbol) { UpdateUniqName(str); } - symbol = mMirBuilder->CreateGlobalDecl(str, mir_type, kScGlobal); + symbol = mMirBuilder->CreateGlobalDecl(str, *mir_type, maple::kScGlobal); } std::pair P(name, block); @@ -409,30 +410,30 @@ MIRSymbol *A2M::CreateSymbol(TreeNode *tnode, BlockNode *block) { return symbol; } -MIRFunction *A2M::GetFunc(BlockNode *block) { - MIRFunction *func = nullptr; +maple::MIRFunction *A2M::GetFunc(BlockNode *block) { + maple::MIRFunction *func = nullptr; // func = mBlockFuncMap[block]; func = mMirModule->CurFunction(); return func; } -MIRClassType *A2M::GetClass(BlockNode *block) { - TyIdx tyidx = GetFunc(block)->classTyIdx; - return (MIRClassType*)GlobalTables::GetTypeTable().GetTypeFromTyIdx(tyidx); +maple::MIRClassType *A2M::GetClass(BlockNode *block) { + maple::TyIdx tyidx = GetFunc(block)->GetClassTyIdx(); + return (maple::MIRClassType*)maple::GlobalTables::GetTypeTable().GetTypeFromTyIdx(tyidx); } -MIRFunction *A2M::SearchFunc(const char *name, const MapleVector &args) { +maple::MIRFunction *A2M::SearchFunc(const char *name, const maple::MapleVector &args) { if (mNameFuncMap.find(name) == mNameFuncMap.end()) { return nullptr; } for (auto it: mNameFuncMap[name]) { - if (it->formalDefVec.size() != args.size()) { + if (it->GetFormalCount() != args.size()) { continue; } bool matched = true; - for (int i = 0; i < it->formalDefVec.size(); i++) { + for (int i = 0; i < it->GetFormalCount(); i++) { // TODO: allow compatible types - MIRType *type = GlobalTables::GetTypeTable().GetTypeFromTyIdx(it->formalDefVec[i].formalTyIdx); + maple::MIRType *type = maple::GlobalTables::GetTypeTable().GetTypeFromTyIdx(it->GetFormalDefAt(i).formalTyIdx); if (type->GetPrimType() != args[i]->GetPrimType()) { matched = false; break; @@ -446,7 +447,7 @@ MIRFunction *A2M::SearchFunc(const char *name, const MapleVector &ar return nullptr; } -void A2M::MapAttr(GenericAttrs &attr, const IdentifierNode *inode) { +void A2M::MapAttr(maple::GenericAttrs &attr, const IdentifierNode *inode) { // SmallVector mAttrs unsigned anum = inode->GetAttrsNum(); for (int i = 0; i < anum; i++) { diff --git a/shared/src/maplefe_mir_builder.cpp b/shared/src/maplefe_mir_builder.cpp index 2814ec6d57992ee3939d79f21c35ccea7744d08d..adae368a639ea461a274e7ba7d5df2e55b5fcbc3 100644 --- a/shared/src/maplefe_mir_builder.cpp +++ b/shared/src/maplefe_mir_builder.cpp @@ -17,37 +17,39 @@ namespace maplefe { -bool FEMIRBuilder::TraverseToNamedField(MIRStructType *structType, uint32 &fieldID, FieldData *fieldData) { +bool FEMIRBuilder::TraverseToNamedField(maple::MIRStructType *structType, unsigned &fieldID, FieldData *fieldData) { if (!structType) { return false; } - for (uint32 fieldidx = 0; fieldidx < structType->fields.size(); fieldidx++) { + for (unsigned fieldidx = 0; fieldidx < structType->GetFieldsSize(); fieldidx++) { fieldID++; - if (structType->fields[fieldidx].first == fieldData->GetStrIdx()) { - fieldData->SetTyIdx(structType->fields[fieldidx].second.first); - fieldData->SetFieldAttrs(structType->fields[fieldidx].second.second); + const maple::FieldPair fp = structType->GetFieldsElemt(fieldidx); + if (structType->GetFieldsElemt(fieldidx).first == fieldData->GetStrIdx()) { + fieldData->SetTyIdx(fp.second.first); + fieldData->SetFieldAttrs(fp.second.second); // for pointer type, check their pointed type - MIRType *type = GlobalTables::GetTypeTable().GetTypeFromTyIdx(fieldData->GetTyIdx()); - MIRType *typeit = GlobalTables::GetTypeTable().GetTypeFromTyIdx(structType->fields[fieldidx].second.first); - if (IsOfSameType(type, typeit)) { + maple::MIRType *type = maple::GlobalTables::GetTypeTable().GetTypeFromTyIdx(fieldData->GetTyIdx()); + maple::MIRType *typeit = maple::GlobalTables::GetTypeTable().GetTypeFromTyIdx(fp.second.first); + if (type->IsOfSameType(*typeit)) { return true; } } - MIRType *fieldtype = GlobalTables::GetTypeTable().GetTypeFromTyIdx(structType->fields[fieldidx].second.first); - if (fieldtype->typeKind == kTypeStruct || fieldtype->typeKind == kTypeStructIncomplete) { - MIRStructType *substructtype = static_cast(fieldtype); + maple::MIRType *fieldtype = maple::GlobalTables::GetTypeTable().GetTypeFromTyIdx(fp.second.first); + maple::MIRTypeKind kind = fieldtype->GetKind(); + if (kind == maple::kTypeStruct || kind == maple::kTypeStructIncomplete) { + maple::MIRStructType *substructtype = static_cast(fieldtype); if (TraverseToNamedField(substructtype, fieldID, fieldData)) { return true; } - } else if (fieldtype->typeKind == kTypeClass || fieldtype->typeKind == kTypeClassIncomplete) { - MIRClassType *subclasstype = static_cast(fieldtype); + } else if (kind == maple::kTypeClass || kind == maple::kTypeClassIncomplete) { + maple::MIRClassType *subclasstype = static_cast(fieldtype); if (TraverseToNamedField(subclasstype, fieldID, fieldData)) { return true; } - } else if (fieldtype->typeKind == kTypeInterface || fieldtype->typeKind == kTypeInterfaceIncomplete) { - MIRInterfaceType *subinterfacetype = static_cast(fieldtype); + } else if (kind == maple::kTypeInterface || kind == maple::kTypeInterfaceIncomplete) { + maple::MIRInterfaceType *subinterfacetype = static_cast(fieldtype); if (TraverseToNamedField(subinterfacetype, fieldID, fieldData)) { return true; } @@ -56,4 +58,9 @@ bool FEMIRBuilder::TraverseToNamedField(MIRStructType *structType, uint32 &field return false; } +maple::BaseNode *FEMIRBuilder::CreateExprDread(const maple::MIRSymbol *symbol, maple::FieldID fieldID) { + maple::BaseNode *nd = new maple::AddrofNode(maple::OP_dread, maple::kPtyInvalid, symbol->GetStIdx(), fieldID); + return nd; +} + } diff --git a/shared/src/mpl_processor.cpp b/shared/src/mpl_processor.cpp index ce71c2c632d655f9a751f8fdbd3e5ad15151d4d3..62e2e29d0f242febba626ffefd240c4fceb98544 100644 --- a/shared/src/mpl_processor.cpp +++ b/shared/src/mpl_processor.cpp @@ -82,44 +82,43 @@ maple::BaseNode *A2M::ProcessIdentifier(StmtExprKind skind, TreeNode *tnode, Blo if (skind == SK_Stmt) { AST2MPLMSG("ProcessIdentifier() is a decl", name); - MIRSymbol *symbol = CreateSymbol(node, block); + maple::MIRSymbol *symbol = CreateSymbol(node, block); return nullptr; } // check local var - MIRSymbol *symbol = GetSymbol(node, block); + maple::MIRSymbol *symbol = GetSymbol(node, block); if (symbol) { AST2MPLMSG("ProcessIdentifier() found local symbol", name); return mMirBuilder->CreateExprDread(symbol); } - GStrIdx stridx = GlobalTables::GetStrTable().GetOrCreateStrIdxFromName(name); - MIRFunction *func = GetFunc(block); + maple::GStrIdx stridx = maple::GlobalTables::GetStrTable().GetOrCreateStrIdxFromName(name); + maple::MIRFunction *func = GetFunc(block); // check parameters - for (auto it: func->formalDefVec) { - if (it.formalStrIdx == stridx) { - AST2MPLMSG("ProcessIdentifier() found parameter", name); - return mMirBuilder->CreateExprDread(it.formalSym); - } + if (func->IsAFormalName(stridx)) { + maple::FormalDef def = func->GetFormalFromName(stridx); + AST2MPLMSG("ProcessIdentifier() found parameter", name); + return mMirBuilder->CreateExprDread(def.formalSym); } // check class fields - TyIdx tyidx = func->formalDefVec[0].formalTyIdx; - MIRType *ctype = GlobalTables::GetTypeTable().GetTypeFromTyIdx(tyidx); - if (ctype->GetPrimType() == PTY_ptr || ctype->GetPrimType() == PTY_ref) { - MIRPtrType *ptype = static_cast(ctype); + maple::TyIdx tyidx = func->GetFormalDefAt(0).formalTyIdx; + maple::MIRType *ctype = maple::GlobalTables::GetTypeTable().GetTypeFromTyIdx(tyidx); + if (ctype->GetPrimType() == maple::PTY_ptr || ctype->GetPrimType() == maple::PTY_ref) { + maple::MIRPtrType *ptype = static_cast(ctype); ctype = ptype->GetPointedType(); } mFieldData->ResetStrIdx(stridx); - uint32 fid = 0; - bool status = mMirBuilder->TraverseToNamedField((MIRStructType*)ctype, fid, mFieldData); + maple::uint32 fid = 0; + bool status = mMirBuilder->TraverseToNamedField((maple::MIRStructType*)ctype, fid, mFieldData); if (status) { - MIRSymbol *sym = func->formalDefVec[0].formalSym; // this + maple::MIRSymbol *sym = func->GetFormal(0); // this maple::BaseNode *bn = mMirBuilder->CreateExprDread(sym); - maple::MIRType *ftype = GlobalTables::GetTypeTable().GetTypeFromTyIdx(mFieldData->GetTyIdx()); + maple::MIRType *ftype = maple::GlobalTables::GetTypeTable().GetTypeFromTyIdx(mFieldData->GetTyIdx()); AST2MPLMSG("ProcessIdentifier() found match field", name); - return mMirBuilder->CreateExprIread(ftype, sym->GetType(), FieldID(fid), bn); + return new maple::IreadNode(maple::OP_iread, ftype->GetPrimType(), mFieldData->GetTyIdx(), maple::FieldID(fid), bn); } // check global var @@ -130,7 +129,7 @@ maple::BaseNode *A2M::ProcessIdentifier(StmtExprKind skind, TreeNode *tnode, Blo } AST2MPLMSG("ProcessIdentifier() unknown identifier", name); - symbol = mMirBuilder->GetOrCreateLocalDecl(name, mDefaultType, func); + symbol = mMirBuilder->GetOrCreateLocalDecl(name, *mDefaultType); return mMirBuilder->CreateExprDread(symbol); } @@ -147,17 +146,17 @@ maple::BaseNode *A2M::ProcessField(StmtExprKind skind, TreeNode *tnode, BlockNod TreeNode *upper = node->GetUpper(); TreeNode *field = node->GetField(); - MIRType *ctype = nullptr; - TyIdx cptyidx(0); + maple::MIRType *ctype = nullptr; + maple::TyIdx cptyidx(0); maple::BaseNode *dr = nullptr; if (upper->IsLiteral()) { LiteralNode *lt = static_cast(upper); if (lt->GetData().mType == LT_ThisLiteral) { - MIRFunction *func = GetFunc(block); - MIRSymbol *sym = func->formalDefVec[0].formalSym; // this + maple::MIRFunction *func = GetFunc(block); + maple::MIRSymbol *sym = func->GetFormal(0); // this cptyidx = sym->GetTyIdx(); ctype = GetClass(block); - dr = new DreadNode(OP_dread, PTY_ptr, sym->GetStIdx(), 0); + dr = new maple::DreadNode(maple::OP_dread, maple::PTY_ptr, sym->GetStIdx(), 0); } else { NOTYETIMPL("ProcessField() not this literal"); } @@ -171,13 +170,13 @@ maple::BaseNode *A2M::ProcessField(StmtExprKind skind, TreeNode *tnode, BlockNod } const char *fname = field->GetName(); - GStrIdx stridx = GlobalTables::GetStrTable().GetOrCreateStrIdxFromName(fname); + maple::GStrIdx stridx = maple::GlobalTables::GetStrTable().GetOrCreateStrIdxFromName(fname); mFieldData->ResetStrIdx(stridx); - uint32 fid = 0; - bool status = mMirBuilder->TraverseToNamedField((MIRStructType*)ctype, fid, mFieldData); + maple::uint32 fid = 0; + bool status = mMirBuilder->TraverseToNamedField((maple::MIRStructType*)ctype, fid, mFieldData); if (status) { - maple::MIRType *ftype = GlobalTables::GetTypeTable().GetTypeFromTyIdx(mFieldData->GetTyIdx()); - bn = new IreadNode(OP_iread, ftype->GetPrimType(), cptyidx, fid, dr); + maple::MIRType *ftype = maple::GlobalTables::GetTypeTable().GetTypeFromTyIdx(mFieldData->GetTyIdx()); + bn = new maple::IreadNode(maple::OP_iread, ftype->GetPrimType(), cptyidx, fid, dr); } return bn; } @@ -193,8 +192,8 @@ maple::BaseNode *A2M::ProcessFieldDecl(StmtExprKind skind, TreeNode *tnode, Bloc TreeNode *parent = tnode->GetParent(); MASSERT((parent->IsClass() || parent->IsInterface()) && "Not class or interface"); - MIRType *ptype = mNodeTypeMap[parent->GetName()]; - MIRStructType *stype = static_cast(ptype); + maple::MIRType *ptype = mNodeTypeMap[parent->GetName()]; + maple::MIRStructType *stype = static_cast(ptype); MASSERT(stype && "struct type not valid"); IdentifierNode *inode = static_cast(tnode); @@ -202,20 +201,20 @@ maple::BaseNode *A2M::ProcessFieldDecl(StmtExprKind skind, TreeNode *tnode, Bloc TreeNode *type = inode->GetType(); // PrimTypeNode or UserTypeNode TreeNode *init = inode->GetInit(); // Init value - GenericAttrs genAttrs; + maple::GenericAttrs genAttrs; MapAttr(genAttrs, inode); - GStrIdx stridx = GlobalTables::GetStrTable().GetOrCreateStrIdxFromName(name); - MIRType *mir_type = MapType(type); + maple::GStrIdx stridx = maple::GlobalTables::GetStrTable().GetOrCreateStrIdxFromName(name); + maple::MIRType *mir_type = MapType(type); // always use pointer type for classes, with PTY_ref - if (mir_type->typeKind == kTypeClass || mir_type->typeKind == kTypeClassIncomplete || - mir_type->typeKind == kTypeInterface || mir_type->typeKind == kTypeInterfaceIncomplete) { - mir_type = GlobalTables::GetTypeTable().GetOrCreatePointerType(mir_type, PTY_ref); + if (mir_type->GetKind() == maple::kTypeClass || mir_type->GetKind() == maple::kTypeClassIncomplete || + mir_type->GetKind() == maple::kTypeInterface || mir_type->GetKind() == maple::kTypeInterfaceIncomplete) { + mir_type = maple::GlobalTables::GetTypeTable().GetOrCreatePointerType(*mir_type, maple::PTY_ref); } if (mir_type) { - TyidxFieldAttrPair P0(mir_type->GetTypeIndex(), genAttrs.ConvertToFieldAttrs()); - FieldPair P1(stridx, P0); - stype->fields.push_back(P1); + maple::TyIdxFieldAttrPair P0(mir_type->GetTypeIndex(), genAttrs.ConvertToFieldAttrs()); + maple::FieldPair P1(stridx, P0); + stype->GetFields().push_back(P1); } return bn; @@ -274,12 +273,12 @@ maple::BaseNode *A2M::ProcessVarList(StmtExprKind skind, TreeNode *tnode, BlockN TreeNode *n = node->VarAtIndex(i); IdentifierNode *inode = static_cast(n); AST2MPLMSG("ProcessVarList() decl", inode->GetName()); - MIRSymbol *symbol = CreateSymbol(inode, block); + maple::MIRSymbol *symbol = CreateSymbol(inode, block); TreeNode *init = inode->GetInit(); // Init value if (init) { maple::BaseNode *bn = ProcessNode(SK_Expr, init, block); - MIRType *mir_type = MapType(inode->GetType()); - bn = new DassignNode(mir_type->GetPrimType(), bn, symbol->stIdx, 0); + maple::MIRType *mir_type = MapType(inode->GetType()); + bn = new maple::DassignNode(mir_type->GetPrimType(), bn, symbol->GetStIdx(), 0); if (bn) { maple::BlockNode *blk = mBlockNodeMap[block]; blk->AddStatement((maple::StmtNode*)bn); @@ -301,13 +300,15 @@ maple::BaseNode *A2M::ProcessLiteral(StmtExprKind skind, TreeNode *tnode, BlockN maple::BaseNode *bn = nullptr; switch (data.mType) { case LT_IntegerLiteral: { - MIRIntConst *cst = new MIRIntConst(data.mData.mInt, GlobalTables::GetTypeTable().GetInt32()); - bn = new maple::ConstvalNode(PTY_i32, cst); + maple::MIRType *typeI32 = maple::GlobalTables::GetTypeTable().GetInt32(); + maple::MIRIntConst *cst = new maple::MIRIntConst(data.mData.mInt, *typeI32); + bn = new maple::ConstvalNode(maple::PTY_i32, cst); break; } case LT_BooleanLiteral: { int val = (data.mData.mBool == true) ? 1 : 0; - bn = new maple::ConstvalNode(PTY_u1, new MIRIntConst(val, GlobalTables::GetTypeTable().GetUInt1())); + maple::MIRType *typeU1 = maple::GlobalTables::GetTypeTable().GetUInt1(); + bn = new maple::ConstvalNode(maple::PTY_u1, new maple::MIRIntConst(val, *typeU1)); break; } case LT_FPLiteral: @@ -336,10 +337,10 @@ maple::BaseNode *A2M::ProcessUnaOperator(StmtExprKind skind, TreeNode *tnode, Bl return mpl_node; } - maple::Opcode op = maple::kOpUndef; + maple::Opcode op = maple::OP_undef; op = MapUnaOpcode(ast_op); - if (op != kOpUndef) { + if (op != maple::OP_undef) { mpl_node = ProcessUnaOperatorMpl(skind, op, bn, block); } @@ -360,17 +361,17 @@ maple::BaseNode *A2M::ProcessBinOperator(StmtExprKind skind, TreeNode *tnode, Bl return mpl_node; } - maple::Opcode op = maple::kOpUndef; + maple::Opcode op = maple::OP_undef; op = MapBinOpcode(ast_op); - if (op != kOpUndef) { - mpl_node = new BinaryNode(op, lhs->GetPrimType(), lhs, rhs); + if (op != maple::OP_undef) { + mpl_node = new maple::BinaryNode(op, lhs->GetPrimType(), lhs, rhs); return mpl_node; } op = MapBinCmpOpcode(ast_op); - if (op != kOpUndef) { - mpl_node = new CompareNode(op, PTY_u1, lhs->GetPrimType(), lhs, rhs); + if (op != maple::OP_undef) { + mpl_node = new maple::CompareNode(op, maple::PTY_u1, lhs->GetPrimType(), lhs, rhs); return mpl_node; } @@ -380,7 +381,7 @@ maple::BaseNode *A2M::ProcessBinOperator(StmtExprKind skind, TreeNode *tnode, Bl } op = MapBinComboOpcode(ast_op); - if (op != kOpUndef) { + if (op != maple::OP_undef) { mpl_node = ProcessBinOperatorMplComboAssign(SK_Stmt, op, lhs, rhs, block); return mpl_node; } @@ -410,7 +411,7 @@ maple::BaseNode *A2M::ProcessBlockDecl(StmtExprKind skind, TreeNode *tnode, Bloc maple::BlockNode *blk = mBlockNodeMap[block]; for (int i = 0; i < ast_block->GetChildrenNum(); i++) { TreeNode *child = ast_block->GetChildAtIndex(i); - BaseNode *stmt = ProcessNodeDecl(skind, child, block); + maple::BaseNode *stmt = ProcessNodeDecl(skind, child, block); } return nullptr; } @@ -420,10 +421,10 @@ maple::BaseNode *A2M::ProcessBlock(StmtExprKind skind, TreeNode *tnode, BlockNod maple::BlockNode *blk = mBlockNodeMap[block]; for (int i = 0; i < ast_block->GetChildrenNum(); i++) { TreeNode *child = ast_block->GetChildAtIndex(i); - BaseNode *stmt = ProcessNode(skind, child, block); + maple::BaseNode *stmt = ProcessNode(skind, child, block); if (stmt) { - blk->AddStatement((StmtNode*)stmt); - if (mTraceA2m) stmt->Dump(mMirModule, 0); + blk->AddStatement((maple::StmtNode*)stmt); + if (mTraceA2m) stmt->Dump(0); } } return nullptr; @@ -449,19 +450,19 @@ maple::BaseNode *A2M::ProcessFuncDecl(StmtExprKind skind, TreeNode *tnode, Block AST2MPLMSG("\n================== function ==================", name); TreeNode *parent = tnode->GetParent(); - MIRStructType *stype = nullptr; + maple::MIRStructType *stype = nullptr; if (parent->IsClass() || parent->IsInterface()) { - MIRType *ptype = mNodeTypeMap[parent->GetName()]; - stype = static_cast(ptype); + maple::MIRType *ptype = mNodeTypeMap[parent->GetName()]; + stype = static_cast(ptype); MASSERT(stype && "struct type not valid"); } - MIRType *rettype = MapType(ast_rettype); - MIRFunction *func = mMirBuilder->GetOrCreateFunction(name, rettype->GetTypeIndex()); + maple::MIRType *rettype = MapType(ast_rettype); + maple::MIRFunction *func = mMirBuilder->GetOrCreateFunction(name, rettype->GetTypeIndex()); // init function fields - func->body = func->codeMemPool->New(); - func->symTab = func->dataMemPool->New(&func->dataMPAllocator); + func->SetBody(func->GetCodeMemPool()->New()); + func->AllocSymTab(); mMirModule->AddFunction(func); mMirModule->SetCurFunction(func); @@ -472,18 +473,17 @@ maple::BaseNode *A2M::ProcessFuncDecl(StmtExprKind skind, TreeNode *tnode, Block } // process function arguments for function type and formal parameters - std::vector funcvectype; - std::vector funcvecattr; + std::vector funcvectype; + std::vector funcvecattr; // insert this as first parameter if (stype) { - GStrIdx stridx = GlobalTables::GetStrTable().GetOrCreateStrIdxFromName("this"); - TypeAttrs attr = TypeAttrs(); - MIRType *sptype = GlobalTables::GetTypeTable().GetOrCreatePointerType(stype, PTY_ref); - MIRSymbol *sym = mMirBuilder->GetOrCreateLocalDecl("this", sptype, func); - sym->SetStorageClass(kScFormal); - FormalDef formalDef(stridx, sym, sptype->GetTypeIndex(), attr); - func->formalDefVec.push_back(formalDef); + maple::GStrIdx stridx = maple::GlobalTables::GetStrTable().GetOrCreateStrIdxFromName("this"); + maple::TypeAttrs attr = maple::TypeAttrs(); + maple::MIRType *sptype = maple::GlobalTables::GetTypeTable().GetOrCreatePointerType(*stype, maple::PTY_ref); + maple::MIRSymbol *sym = mMirBuilder->GetOrCreateLocalDecl("this", *sptype); + sym->SetStorageClass(maple::kScFormal); + func->AddArgument(sym); funcvectype.push_back(sptype->GetTypeIndex()); funcvecattr.push_back(attr); } @@ -491,7 +491,7 @@ maple::BaseNode *A2M::ProcessFuncDecl(StmtExprKind skind, TreeNode *tnode, Block // process remaining parameters for (int i = 0; i < ast_func->GetParamsNum(); i++) { TreeNode *param = ast_func->GetParam(i); - MIRType *type = mDefaultType; + maple::MIRType *type = mDefaultType; if (param->IsIdentifier()) { IdentifierNode *inode = static_cast(param); type = MapType(inode->GetType()); @@ -500,12 +500,11 @@ maple::BaseNode *A2M::ProcessFuncDecl(StmtExprKind skind, TreeNode *tnode, Block continue; } - GStrIdx stridx = GlobalTables::GetStrTable().GetOrCreateStrIdxFromName(param->GetName()); - TypeAttrs attr = TypeAttrs(); - MIRSymbol *sym = mMirBuilder->GetOrCreateLocalDecl(param->GetName(), type, func); - sym->SetStorageClass(kScFormal); - FormalDef formalDef(stridx, sym, type->GetTypeIndex(), attr); - func->formalDefVec.push_back(formalDef); + maple::GStrIdx stridx = maple::GlobalTables::GetStrTable().GetOrCreateStrIdxFromName(param->GetName()); + maple::TypeAttrs attr = maple::TypeAttrs(); + maple::MIRSymbol *sym = mMirBuilder->GetOrCreateLocalDecl(param->GetName(), *type); + sym->SetStorageClass(maple::kScFormal); + func->AddArgument(sym); funcvectype.push_back(type->GetTypeIndex()); funcvecattr.push_back(attr); } @@ -516,27 +515,27 @@ maple::BaseNode *A2M::ProcessFuncDecl(StmtExprKind skind, TreeNode *tnode, Block mNameFuncMap[name].push_back(func); // create function type - MIRFuncType *functype = (MIRFuncType*)GlobalTables::GetTypeTable().GetOrCreateFunctionType(mMirModule, rettype->GetTypeIndex(), funcvectype, funcvecattr, /*isvarg*/ false, true); - func->funcType = functype; + maple::MIRFuncType *functype = (maple::MIRFuncType*)maple::GlobalTables::GetTypeTable().GetOrCreateFunctionType(*mMirModule, rettype->GetTypeIndex(), funcvectype, funcvecattr, /*isvarg*/ false, false); + func->SetMIRFuncType(functype); // update function symbol's type - MIRSymbol *funcst = GlobalTables::GetGsymTable().GetSymbolFromStIdx(func->stIdx.Idx()); + maple::MIRSymbol *funcst = maple::GlobalTables::GetGsymTable().GetSymbolFromStidx(func->GetStIdx().Idx()); funcst->SetTyIdx(functype->GetTypeIndex()); // add method with updated funcname to parent stype if (stype) { - StIdx stIdx = func->stIdx; - FuncAttrs funcattrs(func->GetAttrs()); - TyidxFuncAttrPair P0(funcst->tyIdx, funcattrs); - MethodPair P1(stIdx, P0); - stype->methods.push_back(P1); + maple::StIdx stIdx = func->GetStIdx(); + maple::FuncAttrs funcattrs(func->GetFuncAttrs()); + maple::TyidxFuncAttrPair P0(func->GetMIRFuncType()->GetTypeIndex(), funcattrs); + maple::MethodPair P1(stIdx, P0); + stype->GetMethods().push_back(P1); } if (ast_func->GetBody()) { BlockNode *ast_block = static_cast(ast_func->GetBody()); for (int i = 0; i < ast_block->GetChildrenNum(); i++) { TreeNode *child = ast_block->GetChildAtIndex(i); - BaseNode *stmt = ProcessNodeDecl(skind, child, block); + maple::BaseNode *stmt = ProcessNodeDecl(skind, child, block); } } @@ -547,7 +546,7 @@ maple::BaseNode *A2M::ProcessFuncDecl(StmtExprKind skind, TreeNode *tnode, Block maple::BaseNode *A2M::ProcessFuncSetup(StmtExprKind skind, TreeNode *tnode, BlockNode *block) { FunctionNode *ast_func = static_cast(tnode); - MIRFunction *func = mFuncMap[ast_func]; + maple::MIRFunction *func = mFuncMap[ast_func]; MASSERT(func && "func should have been declared"); const std::string name = func->GetName(); @@ -556,15 +555,15 @@ maple::BaseNode *A2M::ProcessFuncSetup(StmtExprKind skind, TreeNode *tnode, Bloc mMirModule->SetCurFunction(func); // init function fields - func->pregTab = func->dataMemPool->New(&func->dataMPAllocator); - func->typeNameTab = func->dataMemPool->New(&func->dataMPAllocator); - func->labelTab = func->dataMemPool->New(&func->dataMPAllocator); + func->AllocPregTab(); + func->AllocTypeNameTab(); + func->AllocLabelTab(); // set up function body BlockNode *ast_body = ast_func->GetBody(); if (ast_body) { // update mBlockNodeMap - mBlockNodeMap[ast_body] = func->body; + mBlockNodeMap[ast_body] = func->GetBody(); mBlockFuncMap[ast_body] = func; ProcessNode(skind, ast_body, ast_body); } @@ -576,7 +575,7 @@ maple::BaseNode *A2M::ProcessFuncSetup(StmtExprKind skind, TreeNode *tnode, Bloc maple::BaseNode *A2M::ProcessClassDecl(StmtExprKind skind, TreeNode *tnode, BlockNode *block) { ClassNode *classnode = static_cast(tnode); const char *name = classnode->GetName(); - MIRType *type = GlobalTables::GetTypeTable().GetOrCreateClassType(name, mMirModule); + maple::MIRType *type = maple::GlobalTables::GetTypeTable().GetOrCreateClassType(name, *mMirModule); mNodeTypeMap[name] = type; AST2MPLMSG("\n================== class =====================", name); @@ -601,14 +600,14 @@ maple::BaseNode *A2M::ProcessClassDecl(StmtExprKind skind, TreeNode *tnode, Bloc } // set kind to kTypeClass from kTypeClassIncomplete - type->typeKind = maple::MIRTypeKind::kTypeClass; + type->SetMIRTypeKind(maple::kTypeClass); return nullptr; } maple::BaseNode *A2M::ProcessClass(StmtExprKind skind, TreeNode *tnode, BlockNode *block) { ClassNode *classnode = static_cast(tnode); const char *name = classnode->GetName(); - MIRType *type = GlobalTables::GetTypeTable().GetOrCreateClassType(name, mMirModule); + maple::MIRType *type = maple::GlobalTables::GetTypeTable().GetOrCreateClassType(name, *mMirModule); mNodeTypeMap[name] = type; AST2MPLMSG("\n================== class =====================", name); @@ -629,7 +628,7 @@ maple::BaseNode *A2M::ProcessClass(StmtExprKind skind, TreeNode *tnode, BlockNod } // set kind to kTypeClass from kTypeClassIncomplete - type->typeKind = maple::MIRTypeKind::kTypeClass; + type->SetMIRTypeKind(maple::kTypeClass); return nullptr; } @@ -665,8 +664,8 @@ maple::BaseNode *A2M::ProcessException(StmtExprKind skind, TreeNode *tnode, Bloc maple::BaseNode *A2M::ProcessReturn(StmtExprKind skind, TreeNode *tnode, BlockNode *block) { ReturnNode *node = static_cast(tnode); - BaseNode *val = ProcessNode(SK_Expr, node->GetResult(), block); - NaryStmtNode *stmt = mMirBuilder->CreateStmtReturn(val); + maple::BaseNode *val = ProcessNode(SK_Expr, node->GetResult(), block); + maple::NaryStmtNode *stmt = mMirBuilder->CreateStmtReturn(val); return stmt; } @@ -675,7 +674,8 @@ maple::BaseNode *A2M::ProcessCondBranch(StmtExprKind skind, TreeNode *tnode, Blo maple::BaseNode *cond = ProcessNode(SK_Expr, node->GetCond(), block); if (!cond) { NOTYETIMPL("ProcessCondBranch() condition"); - cond = new maple::ConstvalNode(PTY_u1, new MIRIntConst(1, GlobalTables::GetTypeTable().GetUInt1())); + maple::MIRType *typeU1 = maple::GlobalTables::GetTypeTable().GetUInt1(); + cond = new maple::ConstvalNode(maple::PTY_u1, new maple::MIRIntConst(1, *typeU1)); } maple::BlockNode *thenBlock = nullptr; maple::BlockNode *elseBlock = nullptr; @@ -694,9 +694,9 @@ maple::BaseNode *A2M::ProcessCondBranch(StmtExprKind skind, TreeNode *tnode, Blo ProcessBlock(skind, blk, blk); } maple::IfStmtNode *ifnode = new maple::IfStmtNode(); - ifnode->uOpnd = cond; - ifnode->thenPart = thenBlock; - ifnode->elsePart = elseBlock; + ifnode->SetOpnd(cond, 0); + ifnode->SetThenPart(thenBlock); + ifnode->SetElsePart(elseBlock); return ifnode; } @@ -710,7 +710,8 @@ maple::BaseNode *A2M::ProcessLoopCondBody(StmtExprKind skind, TreeNode *cond, Tr maple::BaseNode *mircond = ProcessNode(SK_Expr, cond, block); if (!mircond) { NOTYETIMPL("ProcessLoopCondBody() condition"); - mircond = new maple::ConstvalNode(PTY_u1, new MIRIntConst(1, GlobalTables::GetTypeTable().GetUInt1())); + maple::MIRType *typeU1 = maple::GlobalTables::GetTypeTable().GetUInt1(); + mircond = new maple::ConstvalNode(maple::PTY_u1, new maple::MIRIntConst(1, *typeU1)); } MASSERT(body && body->IsBlock() && "body is nullptr or not a block"); @@ -719,10 +720,10 @@ maple::BaseNode *A2M::ProcessLoopCondBody(StmtExprKind skind, TreeNode *cond, Tr mBlockNodeMap[blk] = mbody; ProcessBlock(skind, blk, blk); - WhileStmtNode *wsn = new WhileStmtNode(OP_while); - wsn->uOpnd = mircond; - wsn->body = mbody; - mBlockNodeMap[block] ->AddStatement(wsn); + maple::WhileStmtNode *wsn = new maple::WhileStmtNode(maple::OP_while); + wsn->SetOpnd(mircond, 0); + wsn->SetBody(mbody); + mBlockNodeMap[block]->AddStatement(wsn); return nullptr; } @@ -736,7 +737,7 @@ maple::BaseNode *A2M::ProcessForLoop(StmtExprKind skind, TreeNode *tnode, BlockN bn = ProcessNode(SK_Stmt, node->InitAtIndex(i), block); if (bn) { mblock->AddStatement((maple::StmtNode*)bn); - if (mTraceA2m) bn->Dump(mMirModule, 0); + if (mTraceA2m) bn->Dump(0); } } @@ -751,7 +752,7 @@ maple::BaseNode *A2M::ProcessForLoop(StmtExprKind skind, TreeNode *tnode, BlockN bn = ProcessNode(SK_Stmt, node->UpdateAtIndex(i), (maplefe::BlockNode*)astbody); if (bn) { mbody->AddStatement((maple::StmtNode*)bn); - if (mTraceA2m) bn->Dump(mMirModule, 0); + if (mTraceA2m) bn->Dump(0); } } @@ -783,11 +784,11 @@ maple::BaseNode *A2M::ProcessDelete(StmtExprKind skind, TreeNode *tnode, BlockNo maple::BaseNode *A2M::ProcessCall(StmtExprKind skind, TreeNode *tnode, BlockNode *block) { NOTYETIMPL("ProcessCall()"); CallNode *node = static_cast(tnode); - MapleVector args(mMirModule->CurFuncCodeMemPoolAllocator()->Adapter()); - MIRFunction *func = GetFunc(block); + maple::MapleVector args(mMirModule->CurFuncCodeMemPoolAllocator()->Adapter()); + maple::MIRFunction *func = GetFunc(block); // pass this - MIRSymbol *sym = func->formalDefVec[0].formalSym; + maple::MIRSymbol *sym = func->GetFormal(0); args.push_back(mMirBuilder->CreateExprDread(sym)); // pass arg for (int i = 0; i < node->GetArgsNum(); i++) { @@ -809,18 +810,18 @@ maple::BaseNode *A2M::ProcessCall(StmtExprKind skind, TreeNode *tnode, BlockNode NOTYETIMPL("ProcessCall() method not found"); return nullptr; } - PUIdx puIdx = func->puIdx; + maple::PUIdx puIdx = func->GetPuidx(); - MIRType *returnType = func->GetReturnType(); - MIRSymbol *rv = nullptr; - Opcode callop = OP_call; - if (returnType->GetPrimType() != PTY_void) { + maple::MIRType *returnType = func->GetReturnType(); + maple::MIRSymbol *rv = nullptr; + maple::Opcode callop = maple::OP_call; + if (returnType->GetPrimType() != maple::PTY_void) { NOTYETIMPL("ProcessCall() OP_callassigned"); // rv = CreateTempVar("retvar", returnType); - // callop = OP_callassigned; + // callop = maple::OP_callassigned; } - StmtNode *stmt = mMirBuilder->CreateStmtCallAssigned(puIdx, args, rv, callop); + maple::StmtNode *stmt = mMirBuilder->CreateStmtCallAssigned(puIdx, args, rv, callop); maple::BlockNode *blk = mBlockNodeMap[block]; blk->AddStatement(stmt); @@ -852,13 +853,13 @@ maple::BaseNode *A2M::ProcessSwitch(StmtExprKind skind, TreeNode *tnode, BlockNo maple::BaseNode *A2M::ProcessPass(StmtExprKind skind, TreeNode *tnode, BlockNode *block) { PassNode *node = static_cast(tnode); maple::BlockNode *blk = mBlockNodeMap[block]; - BaseNode *stmt = nullptr; + maple::BaseNode *stmt = nullptr; for (int i = 0; i < node->GetChildrenNum(); i++) { TreeNode *child = node->GetChild(i); stmt = ProcessNode(skind, child, block); if (stmt && IsStmt(child)) { blk->AddStatement((maple::StmtNode*)stmt); - if (mTraceA2m) stmt->Dump(mMirModule, 0); + if (mTraceA2m) stmt->Dump(0); } } return nullptr; @@ -869,17 +870,17 @@ maple::BaseNode *A2M::ProcessUnaOperatorMpl(StmtExprKind skind, maple::BaseNode *bn, BlockNode *block) { maple::BaseNode *node = nullptr; - if (op == OP_incref || op == OP_decref) { - MIRType *typeI32 = GlobalTables::GetTypeTable().GetInt32(); - MIRIntConst *cst = new MIRIntConst(1, typeI32); - BaseNode *one = new maple::ConstvalNode(PTY_i32, cst); - if (op == OP_incref) { - node = new BinaryNode(OP_add, bn->GetPrimType(), bn, one); - } else if (op == OP_decref) { - node = new BinaryNode(OP_sub, bn->GetPrimType(), bn, one); + if (op == maple::OP_incref || op == maple::OP_decref) { + maple::MIRType *typeI32 = maple::GlobalTables::GetTypeTable().GetInt32(); + maple::MIRIntConst *cst = new maple::MIRIntConst(1, *typeI32); + maple::BaseNode *one = new maple::ConstvalNode(maple::PTY_i32, cst); + if (op == maple::OP_incref) { + node = new maple::BinaryNode(maple::OP_add, bn->GetPrimType(), bn, one); + } else if (op == maple::OP_decref) { + node = new maple::BinaryNode(maple::OP_sub, bn->GetPrimType(), bn, one); } } else { - node = new UnaryNode(op, bn->GetPrimType(), bn); + node = new maple::UnaryNode(op, bn->GetPrimType(), bn); } if (skind == SK_Expr) { @@ -887,16 +888,16 @@ maple::BaseNode *A2M::ProcessUnaOperatorMpl(StmtExprKind skind, } if (skind == SK_Stmt) { - if (op == OP_incref || op == OP_decref) { + if (op == maple::OP_incref || op == maple::OP_decref) { switch (bn->op) { - case OP_iread: { - IreadNode *ir = static_cast(bn); - node = new IassignNode(ir->tyIdx, ir->fieldID, ir->uOpnd, node); + case maple::OP_iread: { + maple::IreadNode *ir = static_cast(bn); + node = new maple::IassignNode(ir->GetTyIdx(), ir->GetFieldID(), ir->Opnd(0), node); break; } - case OP_dread: { - DreadNode *dr = static_cast(bn); - node = new DassignNode(dr->GetPrimType(), node, dr->stIdx, dr->fieldID); + case maple::OP_dread: { + maple::DreadNode *dr = static_cast(bn); + node = new maple::DassignNode(dr->GetPrimType(), node, dr->GetStIdx(), dr->GetFieldID()); break; } default: @@ -918,16 +919,16 @@ maple::BaseNode *A2M::ProcessBinOperatorMplAssign(StmtExprKind skind, return nullptr; } - BaseNode *node = nullptr; + maple::BaseNode *node = nullptr; switch (lhs->op) { - case OP_iread: { - IreadNode *ir = static_cast(lhs); - node = new IassignNode(ir->tyIdx, ir->fieldID, ir->uOpnd, rhs); + case maple::OP_iread: { + maple::IreadNode *ir = static_cast(lhs); + node = new maple::IassignNode(ir->GetTyIdx(), ir->GetFieldID(), ir->Opnd(0), rhs); break; } - case OP_dread: { - DreadNode *dr = static_cast(lhs); - node = new DassignNode(dr->GetPrimType(), rhs, dr->stIdx, dr->fieldID); + case maple::OP_dread: { + maple::DreadNode *dr = static_cast(lhs); + node = new maple::DassignNode(dr->GetPrimType(), rhs, dr->GetStIdx(), dr->GetFieldID()); break; } default: @@ -943,7 +944,7 @@ maple::BaseNode *A2M::ProcessBinOperatorMplComboAssign(StmtExprKind skind, maple::BaseNode *lhs, maple::BaseNode *rhs, BlockNode *block) { - maple::BaseNode *result = new BinaryNode(op, lhs->GetPrimType(), lhs, rhs); + maple::BaseNode *result = new maple::BinaryNode(op, lhs->GetPrimType(), lhs, rhs); maple::BaseNode *assign = ProcessBinOperatorMplAssign(SK_Stmt, lhs, result, block); return assign; }