diff --git a/Makefile b/Makefile index ba140ce914dd9b4bdb1f30a3a99f5c3cb2986c6b..eb4864a7be47c0d83243b73cf9b4ac3e5c570800 100644 --- a/Makefile +++ b/Makefile @@ -64,6 +64,22 @@ GN_OPTIONS := \ TARGET="$(TARGET)" \ X86=1 +GN_OPTIONS_MPLJS := \ + GN_INSTALL_PREFIX="$(MAPLE_ROOT)" \ + GN_BUILD_TYPE="$(BUILD_TYPE_OP)" \ + USE_CLANG=$(USE_CLANG_OP) \ + HOST_ARCH=$(HOST_ARCH_OP) \ + JAVA=0 \ + USE_ZRT=$(USE_ZRT) \ + DEFERRAL_RC="$(DEFERRAL_RC)" \ + STRICT_NAIVE_RC="$(STRICT_NAIVE_RC)" \ + RC_TESTING="$(RC_TESTING)" \ + USE_MALLOC="$(USE_MALLOC)" \ + COV_CHECK=$(COV_CHECK) \ + PLATFORM_SDK_VERSION=27 \ + TARGET="vm" \ + X86=1 + .PHONY: default default: mapleall @@ -79,6 +95,11 @@ js2mpl: mplbe: $(call build_gn, ${GN_OPTIONS}, mplbe) +.PHONY: mplbe_js +mplbe_js: + $(call build_gn, ${GN_OPTIONS_MPLJS}, mplbe) + mv ${OUTPUT_BIN_DIR}/mplbe ${OUTPUT_BIN_DIR}/mplbe_js + .PHONY: install install: mapleall $(shell mkdir -p ${MAPLE_ROOT}/bin; \ @@ -86,6 +107,14 @@ install: mapleall mkdir -p ${MAPLE_EXECUTE_BIN}; \ cp -p ${OUTPUT_BIN_DIR}/* ${MAPLE_EXECUTE_BIN}) +.PHONY: setup +setup: + (cd tools; ./setup_tools.sh) + +.PHONY: resetup +resetup: + (cd tools; rm -rf dwsrf gn ninja open64_prebuilt; ./setup_tools.sh) + .PHONY: clean clean: @rm -rf out/bin/${MAPLE_BUILD_TYPE} out/${MAPLE_BUILD_TYPE} diff --git a/README.md b/README.md index d05b41f0959624d718141441959460cb9231c028..4a16412b4e0f9638b98e9d8aab6c7a78c9924f0a 100644 --- a/README.md +++ b/README.md @@ -44,8 +44,7 @@ The directory structure as follows: ### Set up tools 1. `cd $MAPLE_ROOT` -2. `cd tools` -3. `./setup_tools.sh` +2. `make setup` ### Build compiler 1. `cd $MAPLE_ROOT` diff --git a/build/config/BUILDCONFIG.gn b/build/config/BUILDCONFIG.gn index a53f63197833169acda79c04a91a8c39e039db66..564fb418b37b3644573ab2708f3aaec48e1c5558 100644 --- a/build/config/BUILDCONFIG.gn +++ b/build/config/BUILDCONFIG.gn @@ -45,6 +45,7 @@ if (IS_JS2MPL_EXISTS == "1") { JAVA = 0 TARGET = "vm" JAVA_OP = 0 + USE_CLANG = 0 } DYNAMICLANG = true RC_V2 = true diff --git a/mapleall/maple_be/include/be/switch_lowerer.h b/mapleall/maple_be/include/be/switch_lowerer.h index b4fb4655695bf1bae37b62a93d6e62c1130e8047..75cb7fe64c49bc8c923585ce00475b1f89923760 100644 --- a/mapleall/maple_be/include/be/switch_lowerer.h +++ b/mapleall/maple_be/include/be/switch_lowerer.h @@ -62,10 +62,13 @@ class SwitchLowerer { void FindClusters(MapleVector &); void InitSwitchItems(MapleVector &clusters); RangegotoNode *BuildRangegotoNode(int32 startIdx, int32 endIdx); - CompareNode *BuildCmpNode(Opcode opcode, uint32 idx); + BaseNode *BuildCmpNode(Opcode opcode, uint32 idx); GotoNode *BuildGotoNode(int32 idx); CondGotoNode *BuildCondGotoNode(int32 idx, Opcode opcode, BaseNode *cond); BlockNode *BuildCodeForSwitchItems(int32 start, int32 end, bool lowbndchecked, bool highbndchecked); +#ifdef DYNAMICLANG + BaseNode* BuildSwitchCmpNode(Opcode opcode, uint32 idx); +#endif }; } // namespace maplebe diff --git a/mapleall/maple_be/include/cg/ark/ark_mir_emit.h b/mapleall/maple_be/include/cg/ark/ark_mir_emit.h index 4cf4445356f803f8f0d08c352c022e6a5c443b54..d5d6948c2839c6e57eb13107d546b2d3ff68c39d 100644 --- a/mapleall/maple_be/include/cg/ark/ark_mir_emit.h +++ b/mapleall/maple_be/include/cg/ark/ark_mir_emit.h @@ -219,7 +219,8 @@ enum RE_FuncAttr { FuncAttrWeak = 1 << 0, FuncAttrFinalize = 1 << 1, FuncAttrStatic = 1 << 2, - FuncAttrConstructor = 1 << 3 + FuncAttrConstructor = 1 << 3, + FuncAttrJSStrict = 1 << 4 }; class RE_Func { @@ -275,6 +276,9 @@ class RE_Func { void SetConstructorAttr() { funcAttrs |= FuncAttrConstructor; } + void SetJSStrictAttr() { + funcAttrs |= FuncAttrJSStrict; + } void AddFormalPreg(int pregno) { formalPregs[pregno] = 1+numFormalArgs++; } diff --git a/mapleall/maple_be/include/cg/asm_info.h b/mapleall/maple_be/include/cg/asm_info.h index 6727bb3471cede4b6186977f9ce4ee5302be723a..759dae68c27c25ac2b1fa8d4e7a85fae69920b94 100644 --- a/mapleall/maple_be/include/cg/asm_info.h +++ b/mapleall/maple_be/include/cg/asm_info.h @@ -45,6 +45,7 @@ class Asminfo { MapleString asm_cmnt; MapleString asm_atobt; MapleString asm_file; + MapleString asm_option; MapleString asm_section; MapleString asm_rodata; MapleString asm_global; @@ -89,6 +90,11 @@ class Asminfo { asm_file.setMemPool(mp); asm_file = "\t.file\t"; +#if TARGRISCV64 + asm_option.setMemPool(mp); + asm_option = "\t.option\t"; +#endif + asm_section.setMemPool(mp); asm_section = "\t.section\t"; diff --git a/mapleall/maple_be/include/cg/emit.h b/mapleall/maple_be/include/cg/emit.h index d2c402bc5bcb0971fa72af3b88fae300ef123daf..bc84edb7771e27250a6dd44c9d87475d57928eb4 100644 --- a/mapleall/maple_be/include/cg/emit.h +++ b/mapleall/maple_be/include/cg/emit.h @@ -123,6 +123,7 @@ class Emitter { void EmitAsmLabel(Asmlabel al); void EmitAsmLabel(const MIRSymbol *st, Asmlabel al); void EmitFileInfo(const std::string &fileName); + void EmitCompilationInfo(); void EmitBlockMarker(const char *markerName); // a symbol start/end a block void EmitBlockMarkerWithAddr(const char *markerName, const std::string &addrName); void EmitNullConstant(uint32 size); diff --git a/mapleall/maple_be/include/cg/riscv64/riscv64_md.def b/mapleall/maple_be/include/cg/riscv64/riscv64_md.def index ec0a63aac23c0c7386b7cddf1b545e993f33a49c..354ce908f5326bb9d00b5098bdc761fc1ceb61e8 100644 --- a/mapleall/maple_be/include/cg/riscv64/riscv64_md.def +++ b/mapleall/maple_be/include/cg/riscv64/riscv64_md.def @@ -66,6 +66,8 @@ DEFINE_MOP(MOP_vdupf64, {MOPD_Reg128FD,MOPD_Reg64FS,MOPD_Undef,MOPD_Undef,MOPD_U DEFINE_MOP(MOP_adrp, {MOPD_Reg64ID,MOPD_Literal,MOPD_Undef,MOPD_Undef,MOPD_Undef},ISLOADADDR,kLtShift,"lui","0,1", 1, 1) // MOP_laddr // riscv64 load label address DEFINE_MOP(MOP_laddr, {MOPD_Reg64ID,MOPD_Literal,MOPD_Undef,MOPD_Undef,MOPD_Undef},ISLOADADDR,kLtShift,"la","0,1", 1, 1) +// MOP_lladdr // riscv64 load local label address +DEFINE_MOP(MOP_lladdr, {MOPD_Reg64ID,MOPD_Literal,MOPD_Undef,MOPD_Undef,MOPD_Undef},ISLOADADDR,kLtShift,"lla","0,1", 1, 1) // MOP_xadr (Java) DEFINE_MOP(MOP_xadri64, {MOPD_Reg64ID,MOPD_Imm64,MOPD_Undef,MOPD_Undef,MOPD_Undef},ISLOADADDR,kLtShift,"err","0,1", 1, 1) // MOP_adrpl12 // riscv64 add label address low diff --git a/mapleall/maple_be/include/cg/riscv64/riscv64_mem_layout.h b/mapleall/maple_be/include/cg/riscv64/riscv64_mem_layout.h index 2c48b081a87ea013ef38c9ac2a4a8fa1bda78980..a27dd60ddef98459f5f395d52a514ac882f5edb8 100644 --- a/mapleall/maple_be/include/cg/riscv64/riscv64_mem_layout.h +++ b/mapleall/maple_be/include/cg/riscv64/riscv64_mem_layout.h @@ -123,6 +123,8 @@ class Riscv64SymbolAlloc : public SymbolAlloc { | including those used for | | parameter passing | ||----------------------------| + | StackChkguard if enabled | + |----------------------------| | empty space. should have | | at least 16-byte alignment | ||----------------------------| diff --git a/mapleall/maple_be/include/cg/riscv64/riscv64_operand.h b/mapleall/maple_be/include/cg/riscv64/riscv64_operand.h index 6aca64aa1fdb5e51bdf2edd672241a00580d255f..3b396560be0daebba612f4b5efa6d25ec9145651 100644 --- a/mapleall/maple_be/include/cg/riscv64/riscv64_operand.h +++ b/mapleall/maple_be/include/cg/riscv64/riscv64_operand.h @@ -415,27 +415,19 @@ class StImmOperand : public Operand // representing for global variables addres } /* virtual */ void Emit(Emitter &emitter, OpndProp *opndprop) override { - bool isLower12 = static_cast(opndprop)->IsLiteralLow12(); - if (isLower12) { - emitter.Emit("%lo("); - } if (CGOptions::doPIC && (st_->GetStorageClass() == kScGlobal || st_->GetStorageClass() == kScExtern)) { - emitter.Emit(":got:" + GetName()); + emitter.Emit(GetName()); } else { - if (isLower12 == false) { - emitter.Emit("%hi("); - } // check for sKind since it might be created by cg. (i.eg. LB_*) if (st_->storageClass == kScPstatic && st_->sKind != kStConst && st_->IsLocal()) { emitter.Emit(GetName() + to_string(CG::curPuIdx)); } else { emitter.Emit(GetName()); } + if (offset_ != 0) { + emitter.Emit("+" + to_string(offset_)); + } } - if (offset_ != 0) { - emitter.Emit("+" + to_string(offset_)); - } - emitter.Emit(")"); } /* virtual */ void dump() override { @@ -489,7 +481,12 @@ class FuncNameOperand : public Operand { } /* virtual */ void Emit(Emitter &emitter, OpndProp *opndprop) override { - emitter.Emit(GetName()); + auto func = symbol_->GetFunction(); + if (CGOptions::doPIC && func && !(func->IsLocal())) { + emitter.Emit(GetName() + "@plt"); + } else { + emitter.Emit(GetName()); + } } virtual bool Less(Operand *right) const override { diff --git a/mapleall/maple_be/src/be/switch_lowerer.cpp b/mapleall/maple_be/src/be/switch_lowerer.cpp index 23b3992b1c6a003063ed0684365ce858d79635df..0833042b7b708df3dd6aa8bef269ef89777f0c02 100644 --- a/mapleall/maple_be/src/be/switch_lowerer.cpp +++ b/mapleall/maple_be/src/be/switch_lowerer.cpp @@ -126,7 +126,26 @@ RangegotoNode *SwitchLowerer::BuildRangegotoNode(int32 startIdx, int32 endIdx) { return node; } -CompareNode *SwitchLowerer::BuildCmpNode(Opcode opcode, uint32 idx) { +#ifdef DYNAMICLANG +BaseNode *SwitchLowerer::BuildSwitchCmpNode(Opcode opcode, uint32 idx) { + // CompareNode *binaryExpr = mirModule.CurFuncCodeMemPool()->New(opcode); + if (mirModule.IsJavaModule() || mirModule.IsCModule()) { // DYNAMICLANG on is conflicting with Java or C/C++ + return BuildCmpNode(opcode, idx); + } + MIRBuilder *mirBuilder = mirModule.mirBuilder; + ConstvalNode *op0 = mirBuilder->CreateIntConst((int64)opcode, PTY_u32); + BaseNode *op1 = stmt->switchOpnd; + ConstvalNode *op2 = mirBuilder->CreateIntConst(stmt->switchTable.at(idx).first, PTY_i32); + MapleVector opVec(mirModule.CurFuncCodeMemPoolAllocator()->Adapter()); + opVec.push_back(op0); + opVec.push_back(op1); + opVec.push_back(op2); + IntrinsicopNode *cmpExpr = mirBuilder->CreateExprIntrinsicop(INTRN_JSOP_SWITCH_CMP, GlobalTables::GetTypeTable().GetUInt1(), opVec, false); + return cmpExpr; +} +#endif + +BaseNode *SwitchLowerer::BuildCmpNode(Opcode opcode, uint32 idx) { CompareNode *binaryExpr = mirModule.CurFuncCodeMemPool()->New(opcode); binaryExpr->primType = PTY_u32; binaryExpr->opndType = stmt->switchOpnd->primType; @@ -172,17 +191,26 @@ BlockNode *SwitchLowerer::BuildCodeForSwitchItems(int32 start, int32 end, bool l CondGotoNode *cgoto = nullptr; RangegotoNode *rangegoto = nullptr; IfStmtNode *ifstmt = nullptr; - CompareNode *cmpnode = nullptr; + BaseNode *cmpnode = nullptr; MIRLower mirlowerer(mirModule, lowerer->GetCurrentFunc()); // if low side starts with a dense item, handle it first while (start <= end && switch_items[start].second != 0) { if (!lowbndchecked) { - cgoto = BuildCondGotoNode(-1, OP_brtrue, BuildCmpNode(OP_lt, switch_items[start].first)); + cgoto = BuildCondGotoNode(-1, OP_brtrue, +#ifdef DYNAMICLANG + BuildSwitchCmpNode(OP_lt, switch_items[start].first)); +#else + BuildCmpNode(OP_lt, switch_items[start].first)); +#endif localBlk->AddStatement(cgoto); lowbndchecked = true; } rangegoto = BuildRangegotoNode(switch_items[start].first, switch_items[start].second); +#ifdef DYNAMICLANG + cmpnode = BuildSwitchCmpNode(OP_le, switch_items[start].second); +#else cmpnode = BuildCmpNode(OP_le, switch_items[start].second); +#endif ifstmt = static_cast(mirModule.mirBuilder->CreateStmtIf(cmpnode)); ifstmt->thenPart->AddStatement(rangegoto); localBlk->AppendStatementsFromBlock(mirlowerer.LowerIfStmt(ifstmt, false)); @@ -195,12 +223,21 @@ BlockNode *SwitchLowerer::BuildCodeForSwitchItems(int32 start, int32 end, bool l // if high side starts with a dense item, handle it also while (start <= end && switch_items[end].second != 0) { if (!highbndchecked) { - cgoto = BuildCondGotoNode(-1, OP_brtrue, BuildCmpNode(OP_gt, switch_items[end].second)); + cgoto = BuildCondGotoNode(-1, OP_brtrue, +#ifdef DYNAMICLANG + BuildSwitchCmpNode(OP_gt, switch_items[end].second)); +#else + BuildCmpNode(OP_gt, switch_items[end].second)); +#endif localBlk->AddStatement(cgoto); highbndchecked = true; } rangegoto = BuildRangegotoNode(switch_items[end].first, switch_items[end].second); +#ifdef DYNAMICLANG + cmpnode = BuildSwitchCmpNode(OP_ge, switch_items[end].first); +#else cmpnode = BuildCmpNode(OP_ge, switch_items[end].first); +#endif ifstmt = static_cast(mirModule.mirBuilder->CreateStmtIf(cmpnode)); ifstmt->thenPart->AddStatement(rangegoto); localBlk->AppendStatementsFromBlock(mirlowerer.LowerIfStmt(ifstmt, false)); @@ -230,7 +267,12 @@ BlockNode *SwitchLowerer::BuildCodeForSwitchItems(int32 start, int32 end, bool l if (start == end && lowbndchecked && highbndchecked) { cgoto = (CondGotoNode *)BuildGotoNode(switch_items[start].first); // can omit the condition } else { - cgoto = BuildCondGotoNode(switch_items[start].first, OP_brtrue, BuildCmpNode(OP_eq, switch_items[start].first)); + cgoto = BuildCondGotoNode(switch_items[start].first, OP_brtrue, +#ifdef DYNAMICLANG + BuildSwitchCmpNode(OP_eq, switch_items[start].first)); +#else + BuildCmpNode(OP_eq, switch_items[start].first)); +#endif } localBlk->AddStatement(cgoto); if (lowbndchecked && start < end) { @@ -267,7 +309,11 @@ BlockNode *SwitchLowerer::BuildCodeForSwitchItems(int32 start, int32 end, bool l ASSERT(mid >= start, "switch lowering mid must be > start"); ASSERT(mid <= end, "switch lowering mid must be <= end"); // generate test for binary search +#ifdef DYNAMICLANG + cmpnode = BuildSwitchCmpNode(OP_ge, switch_items[mid].first); +#else cmpnode = BuildCmpNode(OP_ge, switch_items[mid].first); +#endif BaseNode *expnode = static_cast(mirModule.mirBuilder->CreateExprUnary(OP_lnot, GlobalTables::GetTypeTable().GetUInt1(), cmpnode)); ifstmt = static_cast(mirModule.mirBuilder->CreateStmtIf(expnode)); diff --git a/mapleall/maple_be/src/cg/aarch64/aarch64_abi.cpp b/mapleall/maple_be/src/cg/aarch64/aarch64_abi.cpp index fc5fb1a14c4d26bfeade5ce42051836aba885983..738ce0895a337d165735b9654701d2430b089845 100644 --- a/mapleall/maple_be/src/cg/aarch64/aarch64_abi.cpp +++ b/mapleall/maple_be/src/cg/aarch64/aarch64_abi.cpp @@ -219,6 +219,14 @@ int32 ParmLocator::LocateNextParm(MIRType *ty, PLocInfo &ploc, bool isFirst) { InitPlocInfo(ploc); if (isFirst) { MIRFunction *func = _be.mirModule.CurFunction(); + + // Check if the front-end moved the return address to an implicit first + // paramter. If it is, this must be in register x8. + if (func->IsFirstArgReturn()) { + ploc.reg0 = R8; + return SIZEOFPTR; + } + auto funcIt = _be.funcReturnType.find(func); if (funcIt != _be.funcReturnType.end()) { TyIdx retidx = funcIt->second; diff --git a/mapleall/maple_be/src/cg/aarch64/aarch64_cg_func.cpp b/mapleall/maple_be/src/cg/aarch64/aarch64_cg_func.cpp index 27cad3ef2083cd05d948033645da834ce4966741..7c08bd33550305d7d9039ea2c312595f3b82a455 100644 --- a/mapleall/maple_be/src/cg/aarch64/aarch64_cg_func.cpp +++ b/mapleall/maple_be/src/cg/aarch64/aarch64_cg_func.cpp @@ -3809,7 +3809,8 @@ void AArch64CGFunc::SelectParmList(StmtNode * narynode, AArch64ListOperand * src expregopnd = static_cast(opnd); } - if (pnum == 0 && retSize > 16) { + // If the first parameter is actually the return address, put it in x8. + if (pnum == 0 && (retSize > 16 || (callfunc && callfunc->IsFirstArgReturn()))) { parmlocator.InitPlocInfo(ploc); ploc.reg0 = R8; } else { diff --git a/mapleall/maple_be/src/cg/aarch64/aarch64_load_store.cpp b/mapleall/maple_be/src/cg/aarch64/aarch64_load_store.cpp index 497215a8cd2ad5aaa532cfb5215e2a3a79122221..c93d2f755e7878d15fd50347d74ff9aa36faf822 100644 --- a/mapleall/maple_be/src/cg/aarch64/aarch64_load_store.cpp +++ b/mapleall/maple_be/src/cg/aarch64/aarch64_load_store.cpp @@ -2131,7 +2131,7 @@ Operand *AArch64CGFunc::SelectIread(BaseNode *parent, IreadNode *expr) { if (regty == kRegTyFloat) { destType = expr->primType; bitsize = GetPrimTypeBitSize(destType); - } else if (expr->fieldID == 0 && destType == PTY_agg) { // entire struct + } else if (destType == PTY_agg) { // entire struct switch (bitsize) { case 8: destType = PTY_u8; diff --git a/mapleall/maple_be/src/cg/ark/ark_mir_emit.cpp b/mapleall/maple_be/src/cg/ark/ark_mir_emit.cpp index 6384687547e33f55e148c02595b1586acb05475d..4a212a8715fb6bc4132ea812f75f43a1d37f3542 100644 --- a/mapleall/maple_be/src/cg/ark/ark_mir_emit.cpp +++ b/mapleall/maple_be/src/cg/ark/ark_mir_emit.cpp @@ -1159,6 +1159,8 @@ void MirGenerator::EmitAsmFuncInfo(MIRFunction *func) { if (func->IsStatic()) curFunc.SetStaticAttr(); if (func->IsConstructor()) curFunc.SetConstructorAttr(); if (GlobalTables::GetStrTable().GetStringFromStrIdx(func->GetBaseFuncNameStridx()) == "finalize") curFunc.SetFinalizeAttr(); + } else { + if (func->GetAttr(FUNCATTR_strict)) curFunc.SetJSStrictAttr(); } curFunc.evalStackDepth = MaxEvalStack(func); // insert interpreter shim and signature @@ -1169,7 +1171,7 @@ void MirGenerator::EmitAsmFuncInfo(MIRFunction *func) { int formalsBlkBitVectBytes = BlkSize2BitvectorSize(func->upFormalSize); int localsBlkBitVectBytes = BlkSize2BitvectorSize(func->frameSize); - os << "\t" << ".word " << func->upFormalSize << ", " << func->frameSize << ", " << curFunc.evalStackDepth << ", " << 0 << "\t// upFormalSize, frameSize, evalStackDepth\n"; + os << "\t" << ".word " << func->upFormalSize << ", " << func->frameSize << ", " << curFunc.evalStackDepth << ", " << curFunc.funcAttrs << "\t// upFormalSize, frameSize, evalStackDepth, funcAttrs\n"; os << "\t" << ".word " << formalsBlkBitVectBytes << ", " << localsBlkBitVectBytes << "\t\t// formalWords bit vector byte count, localWords bit vector byte count\n"; if (formalsBlkBitVectBytes) { EmitBytesCommentOffset(func->formalWordsTypeTagged, formalsBlkBitVectBytes, "// formalWordsTypeTagged", 0); diff --git a/mapleall/maple_be/src/cg/cg_driver.cpp b/mapleall/maple_be/src/cg/cg_driver.cpp index 4cff699a0f992a16ba696a444ad533b6f41c795a..c4060aab88c52f0c8337a05388000e5ac230fc42 100644 --- a/mapleall/maple_be/src/cg/cg_driver.cpp +++ b/mapleall/maple_be/src/cg/cg_driver.cpp @@ -193,6 +193,7 @@ int main(int argc, char **argv) { if (!cgoption.SuppressFileInfo()) { thecg.emitter_->EmitFileInfo(fileName); } + thecg.emitter_->EmitCompilationInfo(); #if TARGARK MirGenerator *mirGen = new MirGenerator(*themodule, thecg.emitter_->out, *g->becommon); diff --git a/mapleall/maple_be/src/cg/emit.cpp b/mapleall/maple_be/src/cg/emit.cpp index c9e63089c92cf8cd1b4546133a48b53cc4e62aab..92c8c4dda9a5766791c0ad97df86b427478d4709 100644 --- a/mapleall/maple_be/src/cg/emit.cpp +++ b/mapleall/maple_be/src/cg/emit.cpp @@ -173,6 +173,17 @@ void Emitter::EmitFileInfo(const std::string &fileName) { #endif /* TARGARM */ } +void Emitter::EmitCompilationInfo() { +#if TARGRISCV64 + // gnu as risc-v dependent directives + if (CGOptions::doPIC) { + Emit(asminfo_->asm_option); + Emit("pic"); + Emit("\n"); + } +#endif +} + void Emitter::EmitAsmLabel(Asmlabel al) { switch (al) { case kAsmData: { diff --git a/mapleall/maple_be/src/cg/emit_dbg.cpp b/mapleall/maple_be/src/cg/emit_dbg.cpp index 98cce27892d71f033b01ed11cb1ce2f21957aab2..e661b9be1911b1b6c3f8d0a3f5fa044e9b8a7676 100644 --- a/mapleall/maple_be/src/cg/emit_dbg.cpp +++ b/mapleall/maple_be/src/cg/emit_dbg.cpp @@ -234,6 +234,7 @@ void Emitter::EmitDIFormSpecification(unsigned int dwform) { void Emitter::EmitDIAttrValue(DBGDie *die, DBGDieAttr *attr, dw_at attrName, dw_tag tagName, DebugInfo *di) { MapleVector &attrvec = die->attrvec_; +#if 0 switch (attr->dwattr_) { case DW_AT_decl_file: EmitHexUnsigned(1); // file num, 1 for debugging .mpl @@ -241,6 +242,7 @@ void Emitter::EmitDIAttrValue(DBGDie *die, DBGDieAttr *attr, dw_at attrName, dw_ default: break; } +#endif switch (attr->dwform_) { case DW_FORM_string: { @@ -493,11 +495,13 @@ void Emitter::EmitDIDebugInfoSection(DebugInfo *mirdi) { string sfile, spath; if (diae->tag_ == DW_TAG_compile_unit && sfile.empty()) { // get full source path from fileMap[2] - string srcPath = emitter->fileMap[2]; - size_t t = srcPath.rfind("/"); - CG_ASSERT(t != string::npos, ""); - sfile = srcPath.substr(t+1); - spath = srcPath.substr(0, t-1); + if (emitter->fileMap.size() > 2) { // have src file map + string srcPath = emitter->fileMap[2]; + size_t t = srcPath.rfind("/"); + CG_ASSERT(t != string::npos, ""); + sfile = srcPath.substr(t+1); + spath = srcPath.substr(0, t-1); + } } for (int i = 0; i < diae->attrpairs_.size(); i += 2) { @@ -686,11 +690,18 @@ void Emitter::SetupDBGInfo(DebugInfo *mirdi) { MIRStructType *sty = static_cast(mty); CHECK_FATAL(sty != nullptr, "pointer cast failed"); CHECK_FATAL(sty->tyIdx.GetIdx() < g->becommon->struct_fieldcount_table.size(), ""); - int32_t myEnd = g->becommon->struct_fieldcount_table[sty->tyIdx.GetIdx()]; - int32_t myBegin = myEnd - sty->fields.size() + 1; - for (int i = myBegin; i <= myEnd; i++) { - int offset = g->becommon->GetFieldOffset(sty, i).first; - GStrIdx fldName = sty->fields[i - myBegin].first; + int embeddedIDs = 0; + MIRStructType *prevSubstruct = nullptr; + for (int i = 0; i < sty->fields.size(); i++) { + TyIdx fieldtyidx = sty->fields[i].second.first; + MIRType *fieldty = GlobalTables::GetTypeTable().GetTypeFromTyIdx(fieldtyidx); + if (prevSubstruct) { + embeddedIDs += g->becommon->struct_fieldcount_table[prevSubstruct->tyIdx.GetIdx()]; + } + prevSubstruct = fieldty->EmbeddedStructType(); + FieldID fieldID = i + embeddedIDs + 1; + int offset = g->becommon->GetFieldOffset(sty, fieldID).first; + GStrIdx fldName = sty->fields[i].first; DBGDie *cdie = LFindChildDieWithName(die, DW_TAG_member, fldName); CHECK_FATAL(cdie != nullptr, "cdie is null in Emitter::SetupDBGInfo"); DBGDieAttr *mloc = LFindDieAttr(cdie, DW_AT_data_member_location); diff --git a/mapleall/maple_be/src/cg/riscv64/riscv64_cg_func.cpp b/mapleall/maple_be/src/cg/riscv64/riscv64_cg_func.cpp index c0cc29b3ee1e6319dcba492278660a7d83294a47..d48ecd6f744f0759250751b83c47d58c0935fb97 100644 --- a/mapleall/maple_be/src/cg/riscv64/riscv64_cg_func.cpp +++ b/mapleall/maple_be/src/cg/riscv64/riscv64_cg_func.cpp @@ -295,7 +295,7 @@ void Riscv64CGFunc::AppendInstructionPushSingle(Riscv64reg_t reg, RegType rty, i uint32 datasize = SIZEOFPTR * BITS_PER_BYTE; if (IsImmediateOffsetOutOfRange(static_cast(o1), datasize)) { - o1 = SplitOffsetWithAddInstruction(static_cast(o1), datasize, R9); + o1 = SplitOffsetWithAddInstruction(static_cast(o1), datasize, R5); } Insn *pushInsn = cg->BuildInstruction(mop, o0, o1); @@ -449,7 +449,7 @@ void Riscv64CGFunc::AppendInstructionAllocateCallFrame(Riscv64reg_t reg0, Riscv6 allocInsn = cg->BuildInstruction(mop, o1, o2); AppendInstructionTo(allocInsn, this); } else { - Riscv64RegOperand *oo = GetOrCreatePhysicalRegisterOperand(R9, SIZEOFPTR * BITS_PER_BYTE, kRegTyInt); + Riscv64RegOperand *oo = GetOrCreatePhysicalRegisterOperand(R5, SIZEOFPTR * BITS_PER_BYTE, kRegTyInt); Riscv64ImmOperand *io = CreateImmOperand(argsToStkpassSize, 64, true); SelectCopyImm(oo, io, PTY_i64); @@ -569,7 +569,7 @@ void Riscv64CGFunc::AppendInstructionAllocateCallFrameDebug(Riscv64reg_t reg0, R CreateCfiRegOperand(RRA, 64), CreateCfiImmOperand(-cfiOffset + 8, 64))); } } else { - Riscv64RegOperand *oo = GetOrCreatePhysicalRegisterOperand(R9, SIZEOFPTR * BITS_PER_BYTE, kRegTyInt); + Riscv64RegOperand *oo = GetOrCreatePhysicalRegisterOperand(R5, SIZEOFPTR * BITS_PER_BYTE, kRegTyInt); Riscv64ImmOperand *io = CreateImmOperand(argsToStkpassSize, 64, true); SelectCopyImm(oo, io, PTY_i64); @@ -822,7 +822,7 @@ void Riscv64CGFunc::AppendInstructionDeallocateCallFrame(Riscv64reg_t reg0, Risc popInsn = cg->BuildInstruction(mop, o1, o2); AppendInstructionTo(popInsn, this); } else { - Riscv64RegOperand *oo = GetOrCreatePhysicalRegisterOperand(R9, SIZEOFPTR * BITS_PER_BYTE, kRegTyInt); + Riscv64RegOperand *oo = GetOrCreatePhysicalRegisterOperand(R5, SIZEOFPTR * BITS_PER_BYTE, kRegTyInt); Riscv64ImmOperand *io = CreateImmOperand(argsToStkpassSize, 64, true); SelectCopyImm(oo, io, PTY_i64); @@ -939,7 +939,7 @@ void Riscv64CGFunc::AppendInstructionDeallocateCallFrameDebug(Riscv64reg_t reg0, AppendInstructionTo(popInsn, this); curbb->AppendInsn(cg->BuildInstruction(cfi::OP_CFI_restore, CreateCfiRegOperand(RRA, 64))); } else { - Riscv64RegOperand *oo = GetOrCreatePhysicalRegisterOperand(R9, SIZEOFPTR * BITS_PER_BYTE, kRegTyInt); + Riscv64RegOperand *oo = GetOrCreatePhysicalRegisterOperand(R5, SIZEOFPTR * BITS_PER_BYTE, kRegTyInt); Riscv64ImmOperand *io = CreateImmOperand(argsToStkpassSize, 64, true); SelectCopyImm(oo, io, PTY_i64); @@ -1177,13 +1177,11 @@ void Riscv64CGFunc::Genstackguard(BB *bb) { MIRSymbol *stkguardsym = GlobalTables::GetGsymTable().GetSymbolFromStrIdx(GlobalTables::GetStrTable().GetStrIdxFromName("__stack_chk_guard")); StImmOperand *stopnd = CreateStImmOperand(stkguardsym, 0, 0); Riscv64RegOperand *staddropnd = - static_cast(GetOrCreatePhysicalRegisterOperand(R9, SIZEOFPTR * 8, kRegTyInt)); + static_cast(GetOrCreatePhysicalRegisterOperand(R5, SIZEOFPTR * 8, kRegTyInt)); SelectAddrof(staddropnd, stopnd); - Riscv64MemOperand *guardmemopn = - memPool->New(SIZEOFPTR * 8, staddropnd, - static_cast(nullptr), GetOrCreateOfstOpnd(0, 32), stkguardsym); MOperator mop = PickLdInsn(64, PTY_u64); - Insn *ins = cg->BuildInstruction(mop, staddropnd, guardmemopn); + Insn *ins = cg->BuildInstruction(mop, staddropnd, + memPool->New(R5, 0, SIZEOFPTR * BITS_PER_BYTE)); ins->do_not_remove = true; curbb->AppendInsn(ins); @@ -1201,7 +1199,10 @@ void Riscv64CGFunc::Genstackguard(BB *bb) { int32 stksize = static_cast(memlayout)->RealStackFrameSize() - static_cast(memlayout)->SizeOfArgsToStackpass() - varea; - downstk = memPool->New(RFP, stksize - 8, SIZEOFPTR * BITS_PER_BYTE); + // Note that the total size of stack frame alread count in a slot for stackguard + // Use a lot right below callee-saved registers in stack frame and FP and RA are saved on top of frame + downstk = memPool->New(RFP, stksize - (SizeOfCalleeSaved() - 2 * kIntregBytelen) - kIntregBytelen, + SIZEOFPTR * BITS_PER_BYTE); } else { downstk = memPool->New(RSP, static_cast(memlayout)->RealStackFrameSize() - 8 - varea, SIZEOFPTR * BITS_PER_BYTE); @@ -1993,7 +1994,7 @@ void Riscv64CGFunc::InitialSpillSlot(BB * bb) { uint32 datasize = SIZEOFPTR * BITS_PER_BYTE; Operand* memopnd = CreateStkTopOpnd(offset + i, datasize); if (IsImmediateOffsetOutOfRange(static_cast(memopnd), datasize)) { - memopnd = SplitOffsetWithAddInstruction(static_cast(memopnd), datasize, R9); + memopnd = SplitOffsetWithAddInstruction(static_cast(memopnd), datasize, R5); } Insn* pushInsn = cg->BuildInstruction( MOP_xstr, GetZeroOpnd(64), memopnd); @@ -2440,13 +2441,11 @@ void Riscv64CGFunc::GenerateEpilog(BB * bb) { MIRSymbol *stkguardsym = GlobalTables::GetGsymTable().GetSymbolFromStrIdx(GlobalTables::GetStrTable().GetStrIdxFromName("__stack_chk_guard")); StImmOperand *stopnd = CreateStImmOperand(stkguardsym, 0, 0); Riscv64RegOperand *staddropnd = - static_cast(GetOrCreatePhysicalRegisterOperand(R9, SIZEOFPTR * 8, kRegTyInt)); + static_cast(GetOrCreatePhysicalRegisterOperand(R5, SIZEOFPTR * 8, kRegTyInt)); SelectAddrof(staddropnd, stopnd); - Riscv64MemOperand *guardmemopn = - memPool->New(SIZEOFPTR * 8, staddropnd, - static_cast(nullptr), GetOrCreateOfstOpnd(0, 32), stkguardsym); MOperator mop = PickLdInsn(64, PTY_u64); - Insn *ins = cg->BuildInstruction(mop, staddropnd, guardmemopn); + Insn *ins = cg->BuildInstruction(mop, staddropnd, + memPool->New(R5, 0, SIZEOFPTR * BITS_PER_BYTE)); ins->do_not_remove = true; curbb->AppendInsn(ins); @@ -2460,22 +2459,22 @@ void Riscv64CGFunc::GenerateEpilog(BB * bb) { } Riscv64RegOperand *checkopn = - static_cast(GetOrCreatePhysicalRegisterOperand(R12, SIZEOFPTR * 8, kRegTyInt)); + static_cast(GetOrCreatePhysicalRegisterOperand(R6, SIZEOFPTR * 8, kRegTyInt)); Riscv64MemOperand *downstk = nullptr; if (cg->UseFP() || HasVLAOrAlloca()) { int32 stksize = static_cast(memlayout)->RealStackFrameSize() - static_cast(memlayout)->SizeOfArgsToStackpass() - varea; - downstk = memPool->New(RFP, stksize - 8, SIZEOFPTR * BITS_PER_BYTE); + downstk = memPool->New(RFP, stksize - (SizeOfCalleeSaved() - 2 * kIntregBytelen) - kIntregBytelen, + SIZEOFPTR * BITS_PER_BYTE); } else { downstk = memPool->New(RSP, static_cast(memlayout)->RealStackFrameSize() - 8 - varea, SIZEOFPTR * BITS_PER_BYTE); } if (IsImmediateOffsetOutOfRange(static_cast(downstk), 64)) { - downstk = SplitOffsetWithAddInstruction(static_cast(downstk), 64, R12); + downstk = SplitOffsetWithAddInstruction(static_cast(downstk), 64, R6); } - mop = PickLdInsn(SIZEOFPTR * BITS_PER_BYTE, PTY_u64); ins = cg->BuildInstruction(mop, checkopn, downstk); ins->do_not_remove = true; @@ -3411,8 +3410,7 @@ RegOperand *Riscv64CGFunc::CreateCallStructParamMemcpy(MIRSymbol *sym, RegOperan } StImmOperand *stopnd = CreateStImmOperand(sym, 0, 0); Riscv64RegOperand *staddropnd = static_cast(CreateRegisterOperandOfType(PTY_u64)); - curbb->AppendInsn(cg->BuildInstruction(MOP_adrp, staddropnd, stopnd)); - curbb->AppendInsn(cg->BuildInstruction(MOP_adrpl12, staddropnd, staddropnd, stopnd)); + curbb->AppendInsn(cg->BuildInstruction(MOP_laddr, staddropnd, stopnd)); opndvec.push_back(staddropnd); // param 1 } else { CHECK_FATAL(0,"Unsupported sym for struct param"); @@ -4339,7 +4337,7 @@ MemOperand *Riscv64CGFunc::GetOrCreateArgMemOpnd(MIRSymbol * symbol, int32 offse return it->second; } - RegOperand *tempreg = GetOrCreatePhysicalRegisterOperand(R9, SIZEOFPTR * 8, kRegTyInt); + RegOperand *tempreg = GetOrCreatePhysicalRegisterOperand(R5, SIZEOFPTR * 8, kRegTyInt); Riscv64RegOperand *baseOpnd = static_cast(GetBaseReg(symloc)); int32 stoffset = GetBaseOffset(symloc); @@ -5274,7 +5272,7 @@ void Riscv64CGFunc::InsertYieldpoint() { // Converting x31 to x9 for alternate calling convention used in special functions. for (auto &p : callnativemap) { Insn *in = p.first; - Riscv64RegOperand *funcreg = GetOrCreatePhysicalRegisterOperand(R9, 64, kRegTyInt); + Riscv64RegOperand *funcreg = GetOrCreatePhysicalRegisterOperand(R5, 64, kRegTyInt); in->SetOperand(0, funcreg); } // do not insert yieldpoint in function that not saved X30 into stack, diff --git a/mapleall/maple_be/src/cg/riscv64/riscv64_insn_slct.cpp b/mapleall/maple_be/src/cg/riscv64/riscv64_insn_slct.cpp index 3c05f9d8b8aec56f74b34f737ee0b05dc33d1a61..5bd5edc6dd9d4cb98630f90b6cd95fc8a8c7a1b9 100644 --- a/mapleall/maple_be/src/cg/riscv64/riscv64_insn_slct.cpp +++ b/mapleall/maple_be/src/cg/riscv64/riscv64_insn_slct.cpp @@ -2442,8 +2442,7 @@ void Riscv64CGFunc::SelectRangegoto(RangegotoNode *rangegotonode, Operand *opnd0 StImmOperand *switchTable = CreateStImmOperand(lblst, 0, 0); // load the address of the switch table - curbb->AppendInsn(cg->BuildInstruction(MOP_adrp, baseopnd, switchTable)); - curbb->AppendInsn(cg->BuildInstruction(MOP_adrpl12, baseopnd, baseopnd, switchTable)); + curbb->AppendInsn(cg->BuildInstruction(MOP_laddr, baseopnd, switchTable)); // Compute the address of the load RegOperand *sllDst = CreateVirtualRegisterOperand(New_V_Reg(kRegTyInt, 8)); diff --git a/mapleall/maple_be/src/cg/riscv64/riscv64_load_store.cpp b/mapleall/maple_be/src/cg/riscv64/riscv64_load_store.cpp index 4a161f3e43a7d23e85df4f3ea0fa511b611b802a..223cc4232199768398da35bb2ab6c03b195e68ba 100644 --- a/mapleall/maple_be/src/cg/riscv64/riscv64_load_store.cpp +++ b/mapleall/maple_be/src/cg/riscv64/riscv64_load_store.cpp @@ -1907,14 +1907,22 @@ void Riscv64CGFunc::SelectAddrof(Operand *result, StImmOperand *stimm) { insn->AddComment(comm); } } else { - curbb->AppendInsn(cg->BuildInstruction(MOP_adrp, result, stimm)); if (CGOptions::doPIC && (symbol->GetStorageClass() == kScGlobal || symbol->GetStorageClass() == kScExtern)) { - // ldr x0, [x0, #:got_lo12:Ljava_2Flang_2FSystem_3B_7Cout] - Riscv64MemOperand *mo = GetOrCreateMemOpnd(SIZEOFPTR * BITS_PER_BYTE, - static_cast(result), nullptr, stimm, nullptr); - curbb->AppendInsn(cg->BuildInstruction(MOP_xldr, result, mo)); + curbb->AppendInsn(cg->BuildInstruction(MOP_laddr, result, stimm)); + int64 offsetVal = stimm->GetOffset(); + if (offsetVal != 0) { + if (llabs(offsetVal) < 1<<12) { + curbb->AppendInsn(cg->BuildInstruction(MOP_xaddrri12, result, result, + CreateImmOperand(offsetVal, 8, true))); + } else { + Riscv64RegOperand *offsetReg = static_cast(CreateRegisterOperandOfType(PTY_u64)); + curbb->AppendInsn(cg->BuildInstruction(MOP_xmovri64, offsetReg, + CreateImmOperand(offsetVal, 8, true))); + curbb->AppendInsn(cg->BuildInstruction(MOP_xaddrrr, result, result, offsetReg)); + } + } } else { - curbb->AppendInsn(cg->BuildInstruction(MOP_adrpl12, result, result, stimm)); + curbb->AppendInsn(cg->BuildInstruction(MOP_lladdr, result, stimm)); } } } @@ -2081,7 +2089,7 @@ Operand *Riscv64CGFunc::SelectIread(BaseNode *parent, IreadNode *expr) { if (regty == kRegTyFloat) { destType = expr->primType; bitsize = GetPrimTypeBitSize(destType); - } else if (expr->fieldID == 0 && destType == PTY_agg) { // entire struct + } else if (destType == PTY_agg) { // entire struct switch (bitsize) { case 8: destType = PTY_u8; diff --git a/mapleall/maple_driver/src/driver_runner.cpp b/mapleall/maple_driver/src/driver_runner.cpp index 5b9e6408dfc30c859a7873bd53b72552f9ea49ac..4cf3261ccf2fb71b49c82bebf5a334d1cb2d58a3 100644 --- a/mapleall/maple_driver/src/driver_runner.cpp +++ b/mapleall/maple_driver/src/driver_runner.cpp @@ -318,6 +318,8 @@ void DriverRunner::ProcessMpl2mplAndMeAndMplCgPhases(const std::string &interimO thecg.emitter_->EmitFileInfo(actualInput); } + thecg.emitter_->EmitCompilationInfo(); + #if TARGARK MirGenerator *mirGen = new MirGenerator(*theModule, thecg.emitter_->out, *g->becommon); mirGen->OutputMIR(cgOptions->genMirMpl); diff --git a/mapleall/maple_ir/include/all_attributes.def b/mapleall/maple_ir/include/all_attributes.def index 100ff8e83afa728669defc276f0bf81e0d25ec33..1f1edacd738f9d9bfb9fab03b87e59b026267b86 100644 --- a/mapleall/maple_ir/include/all_attributes.def +++ b/mapleall/maple_ir/include/all_attributes.def @@ -78,3 +78,6 @@ ATTR(localrefvar) ATTR(rcunownedthis) #endif +#ifdef FUNC_ATTR + ATTR(firstarg_return) +#endif diff --git a/mapleall/maple_ir/include/debug_info.h b/mapleall/maple_ir/include/debug_info.h index 428f28a57a59780a7fd62f42c475c9b410541803..2a674a149166c2a1cab1151a2d4753733ca571de 100644 --- a/mapleall/maple_ir/include/debug_info.h +++ b/mapleall/maple_ir/include/debug_info.h @@ -392,11 +392,13 @@ class DebugInfo { DBGDieAttr *CreateAttr(dw_at attr, dw_form form, uint64 val); DBGDie *CreateVarDie(MIRSymbol *sym, uint32 lnum); - DBGDie *CreateFormalParaDie(MIRFunction *func, MIRType *type, GStrIdx nameidx, uint32 lnum); + DBGDie *CreateFormalParaDie(MIRFunction *func, MIRType *type, MIRSymbol *sym); DBGDie *CreateFieldDie(maple::FieldPair pair, uint32 lnum); + DBGDie *CreateBitfieldDie(MIRBitfieldType *type, GStrIdx idx); DBGDie *CreateStructTypeDie(GStrIdx strIdx, const MIRStructType *type, bool update = false); DBGDie *CreateClassTypeDie(GStrIdx strIdx, const MIRClassType *type); DBGDie *CreateInterfaceTypeDie(GStrIdx strIdx, const MIRInterfaceType *type); + DBGDie *CreatePointedFuncTypeDie(MIRFuncType *func); DBGDie *GetOrCreateLabelDie(LabelIdx labid); DBGDie *GetOrCreateTypeAttrDie(MIRSymbol *sym); diff --git a/mapleall/maple_ir/include/js2mpl/jsintrinsic.def b/mapleall/maple_ir/include/js2mpl/jsintrinsic.def index 1c42c3d4ea6ceec35048de41802e96e71061be46..16a8b078ada6ee95d5ed74a31905952a0b933cb0 100644 --- a/mapleall/maple_ir/include/js2mpl/jsintrinsic.def +++ b/mapleall/maple_ir/include/js2mpl/jsintrinsic.def @@ -55,7 +55,7 @@ DEF_MIR_INTRINSIC(JSSTR_LENGTH,\ DEF_MIR_INTRINSIC(JS_BOOLEAN,\ __js_ToBoolean, INTRNISJS | INTRNISJSUNARY | INTRNISPURE | INTRNNOSIDEEFFECT, kArgTyU1, kArgTyDynany, kArgTyDynany, kArgTyUndef, kArgTyUndef, kArgTyUndef, kArgTyUndef) DEF_MIR_INTRINSIC(JS_NUMBER,\ - __js_ToNumber, INTRNISJS | INTRNISJSUNARY | INTRNISPURE | INTRNNOSIDEEFFECT, kArgTyI32, kArgTyDynany, kArgTyDynany, kArgTyUndef, kArgTyUndef, kArgTyUndef, kArgTyUndef) + __js_ToNumber, INTRNISJS | INTRNISJSUNARY | INTRNISPURE | INTRNNOSIDEEFFECT, kArgTyDynany, kArgTyDynany, kArgTyDynany, kArgTyUndef, kArgTyUndef, kArgTyUndef, kArgTyUndef) DEF_MIR_INTRINSIC(JS_INT32,\ __js_ToInt32, INTRNISJS | INTRNISJSUNARY | INTRNISPURE | INTRNNOSIDEEFFECT, kArgTyI32, kArgTyDynany, kArgTyDynany, kArgTyUndef, kArgTyUndef, kArgTyUndef, kArgTyUndef) DEF_MIR_INTRINSIC(JS_PRINT,\ @@ -107,7 +107,7 @@ DEF_MIR_INTRINSIC(JS_NEW_ARR_ELEMS,\ DEF_MIR_INTRINSIC(JS_NEW_ARR_LENGTH,\ __js_new_arr_length, INTRNISJS | INTRNNOSIDEEFFECT, kArgTySimpleobj, kArgTyDynany, kArgTyUndef, kArgTyUndef, kArgTyUndef, kArgTyUndef, kArgTyUndef) DEF_MIR_INTRINSIC(JSOP_LENGTH,\ - __jsop_length, INTRNISJS | INTRNLOADMEM | INTRNNOSIDEEFFECT | INTRNISPURE, kArgTyI32, kArgTyDynany, kArgTyUndef, kArgTyUndef, kArgTyUndef, kArgTyUndef, kArgTyUndef) + __jsop_length, INTRNISJS | INTRNLOADMEM | INTRNNOSIDEEFFECT | INTRNISPURE, kArgTyDynany, kArgTyDynany, kArgTyUndef, kArgTyUndef, kArgTyUndef, kArgTyUndef, kArgTyUndef) DEF_MIR_INTRINSIC(JSOP_NEW_ITERATOR,\ __jsop_valueto_iterator, INTRNISJS, kArgTyPtr, kArgTyDynany, kArgTyU32, kArgTyUndef, kArgTyUndef, kArgTyUndef, kArgTyUndef) DEF_MIR_INTRINSIC(JSOP_NEXT_ITERATOR,\ @@ -116,4 +116,3 @@ DEF_MIR_INTRINSIC(JSOP_MORE_ITERATOR,\ __jsop_more_iterator, INTRNISJS, kArgTyU32, kArgTyPtr, kArgTyUndef, kArgTyUndef, kArgTyUndef, kArgTyUndef, kArgTyUndef) DEF_MIR_INTRINSIC(JS_ADDSYSEVENTLISTENER,\ __js_add_sysevent_listener, INTRNISJS, kArgTyU32, kArgTyDynany, kArgTyUndef, kArgTyUndef, kArgTyUndef, kArgTyUndef, kArgTyUndef) - diff --git a/mapleall/maple_ir/include/js2mpl/jsintrinsic_eng.def b/mapleall/maple_ir/include/js2mpl/jsintrinsic_eng.def index aed902742f6e4a95a41b964a1639ca996df91948..98c9b9a2c618595160cec02b6adfe180c389b5c0 100644 --- a/mapleall/maple_ir/include/js2mpl/jsintrinsic_eng.def +++ b/mapleall/maple_ir/include/js2mpl/jsintrinsic_eng.def @@ -32,3 +32,19 @@ DEF_MIR_INTRINSIC(JS_GET_URIERROR_OBJECT,\ __jsobj_get_or_create_uriError, INTRNISJS | INTRNISPURE, kArgTySimpleobj, kArgTyUndef, kArgTyUndef, kArgTyUndef, kArgTyUndef, kArgTyUndef, kArgTyUndef) DEF_MIR_INTRINSIC(JSOP_ASSERTVALUE, __jsop_assert_value, INTRNISJS, kArgTyDynany, kArgTyUndef, kArgTyUndef, kArgTyUndef, kArgTyUndef, kArgTyUndef, kArgTyUndef) +DEF_MIR_INTRINSIC(JS_ISNAN,\ + NULL, INTRNISJS | INTRNISPURE | INTRNNOSIDEEFFECT, kArgTyDynany, kArgTyDynany, kArgTyDynany, kArgTyUndef, kArgTyUndef, kArgTyUndef, kArgTyUndef) +DEF_MIR_INTRINSIC(JS_DATE,\ + NULL, INTRNISJS | INTRNISPURE | INTRNNOSIDEEFFECT, kArgTyDynany, kArgTyDynany, kArgTyDynany, kArgTyUndef, kArgTyUndef, kArgTyUndef, kArgTyUndef) +DEF_MIR_INTRINSIC(JS_REGEXP,\ + NULL, INTRNISJS | INTRNISPURE | INTRNNOSIDEEFFECT, kArgTyDynany, kArgTyDynany, kArgTyDynany, kArgTyUndef, kArgTyUndef, kArgTyUndef, kArgTyUndef) +DEF_MIR_INTRINSIC(JS_DELNAME,\ + NULL, INTRNISJS | INTRNISPURE | INTRNNOSIDEEFFECT, kArgTyDynany, kArgTyDynany, kArgTyDynany, kArgTyUndef, kArgTyUndef, kArgTyUndef, kArgTyUndef) +DEF_MIR_INTRINSIC(JSOP_GET_THIS_PROP_BY_NAME,\ + NULL, INTRNISJS | INTRNLOADMEM | INTRNNOSIDEEFFECT, kArgTyDynany, kArgTyDynany, kArgTySimplestr, kArgTyUndef, kArgTyUndef, kArgTyUndef, kArgTyUndef) +DEF_MIR_INTRINSIC(JSOP_SET_THIS_PROP_BY_NAME,\ + NULL, INTRNISJS, kArgTyVoid, kArgTyDynany, kArgTySimplestr, kArgTyDynany, kArgTyUndef, kArgTyUndef, kArgTyUndef) +DEF_MIR_INTRINSIC(JSOP_INIT_THIS_PROP_BY_NAME,\ + NULL, INTRNISJS, kArgTyVoid, kArgTyDynany, kArgTySimplestr, kArgTyDynany, kArgTyUndef, kArgTyUndef, kArgTyUndef) +DEF_MIR_INTRINSIC(JSOP_SWITCH_CMP,\ + NULL, INTRNISJS, kArgTyU1, kArgTyDynany, kArgTyDynany, kArgTyDynany, kArgTyUndef, kArgTyUndef, kArgTyUndef) diff --git a/mapleall/maple_ir/include/mir_builder.h b/mapleall/maple_ir/include/mir_builder.h index 66ccf6279ff83d4cd36803afdb584786532df83a..36b0f5ec6d828a4f695388688b99106e7157d8dc 100644 --- a/mapleall/maple_ir/include/mir_builder.h +++ b/mapleall/maple_ir/include/mir_builder.h @@ -147,6 +147,13 @@ class MIRBuilder { } public: + virtual MIRSymbol *GetOrCreateLocalDecl(const string &name, MIRType *type, MIRFunction *func); + virtual MIRSymbol *GetOrCreateLocalDecl(const char *name, MIRType *type, MIRFunction *func); + MIRSymbol *GetLocalDecl(const string &name, MIRFunction *func); + MIRSymbol *GetLocalDecl(const char *name, MIRFunction *func); + MIRSymbol *CreateLocalDecl(const string &name, MIRType *type, MIRFunction *func); + MIRSymbol *CreateLocalDecl(const char *name, MIRType *type, MIRFunction *func); + virtual MIRSymbol *GetOrCreateLocalDecl(const string &name, MIRType *type); virtual MIRSymbol *GetOrCreateLocalDecl(const char *name, MIRType *type); MIRSymbol *GetLocalDecl(const string &name); diff --git a/mapleall/maple_ir/include/mir_function.h b/mapleall/maple_ir/include/mir_function.h index db21a203abcb3be30841f9da653b6fab20daf639..ef2df97532cc2f42623d3bfe36ea162eff778876 100644 --- a/mapleall/maple_ir/include/mir_function.h +++ b/mapleall/maple_ir/include/mir_function.h @@ -382,6 +382,10 @@ class MIRFunction : public mir_func_t { return funcAttrs.GetAttr(FUNCATTR_pure); } + bool IsFirstArgReturn() const { + return funcAttrs.GetAttr(FUNCATTR_firstarg_return); + } + void SetVarargs() { funcAttrs.SetAttr(FUNCATTR_varargs); } @@ -406,6 +410,10 @@ class MIRFunction : public mir_func_t { funcAttrs.SetAttr(FUNCATTR_pure); } + void SetFirstArgReturn() { + funcAttrs.SetAttr(FUNCATTR_firstarg_return); + } + void UnsetNoDefEffect() { funcAttrs.SetAttr(FUNCATTR_nodefeffect, true); } diff --git a/mapleall/maple_ir/include/mir_nodes.h b/mapleall/maple_ir/include/mir_nodes.h index 239d43646c4dcc3f86ee4a7a9d68250a77f9be22..c8b8e9fbd5a5799a3fce1bf8355a2e041240d5a2 100644 --- a/mapleall/maple_ir/include/mir_nodes.h +++ b/mapleall/maple_ir/include/mir_nodes.h @@ -1403,6 +1403,11 @@ class IassignNode : public StmtNode { numOpnds = 2; } + IassignNode(TyIdx t, FieldID f, BaseNode* a, BaseNode *r) : + StmtNode(OP_iassign), tyIdx(t), fieldID(f), addrExpr(a), rhs(r) { + numOpnds = 2; + } + ~IassignNode() = default; BaseNode *Opnd(size_t i) const { @@ -1594,7 +1599,7 @@ class CatchNode : public StmtNode { } }; -using CasePair = std::pair; +using CasePair = std::pair; using CaseVector = MapleVector; class SwitchNode : public StmtNode { diff --git a/mapleall/maple_ir/include/mir_parser.h b/mapleall/maple_ir/include/mir_parser.h index 75fba4048deb562e6e118fb44d5f4bf4da9bac01..5155b6417221ae68652e1f66a35818983405121a 100644 --- a/mapleall/maple_ir/include/mir_parser.h +++ b/mapleall/maple_ir/include/mir_parser.h @@ -159,7 +159,7 @@ class MIRParser { bool ParseLocStmt(StmtNode *&stmt); bool ParseAlias(StmtNode *&stmt); uint8 *ParseWordsInfo(uint32 size); - bool ParseSwitchCase(int32 &constVal, LabelIdx &lblidx); + bool ParseSwitchCase(int64 &constVal, LabelIdx &lblidx); bool ParseExprOneOperand(BaseNode *&expr); bool ParseExprTwoOperand(BaseNode *&opnd0, BaseNode *&opnd1); bool ParseExprNaryOperand(MapleVector &opndvec); diff --git a/mapleall/maple_ir/include/mir_symbol.h b/mapleall/maple_ir/include/mir_symbol.h index 465e5e27d4914073aeee9925f47e3bbf718191aa..702b1b9c5077fa11643a373f72e3d32c1c9f0316 100644 --- a/mapleall/maple_ir/include/mir_symbol.h +++ b/mapleall/maple_ir/include/mir_symbol.h @@ -102,7 +102,7 @@ class MIRSymbol { istmpunused(0), stIdx(0, 0), nameStrIdx(0), - value({ nullptr }) {} + value({ nullptr }) { UpdateStaticMembers(); } MIRSymbol(uint32 idx, uint8 scp) : tyIdx(0), @@ -120,10 +120,12 @@ class MIRSymbol { istmpunused(0), stIdx(scp, idx), nameStrIdx(0), - value({ nullptr }) {} + value({ nullptr }) { UpdateStaticMembers(); } ~MIRSymbol() {} + void UpdateStaticMembers(); + void SetTyIdx(TyIdx tyIdx) { this->tyIdx = tyIdx; } diff --git a/mapleall/maple_ir/include/mir_type.h b/mapleall/maple_ir/include/mir_type.h index 5202beb301858b754fa1e457a49a60d475d721a1..35e9617f3a05792f3bbb3e3fc2598cd4a713f688 100644 --- a/mapleall/maple_ir/include/mir_type.h +++ b/mapleall/maple_ir/include/mir_type.h @@ -328,6 +328,11 @@ class FieldAttrs { return !(*this == tA); } + void Clear() { + attrFlag = 0; + attrAlign = 0; + } + void DumpAttributes() const; TypeAttrs ConvertToTypeAttrs(); }; diff --git a/mapleall/maple_ir/src/bin_func_import.cpp b/mapleall/maple_ir/src/bin_func_import.cpp index 9aadcc41179683d0bdace668d2e21f3ed9885c86..e88c23848a03b2c17b945b1a72dbd210f9f9e290 100644 --- a/mapleall/maple_ir/src/bin_func_import.cpp +++ b/mapleall/maple_ir/src/bin_func_import.cpp @@ -708,7 +708,7 @@ BlockNode *BinaryMplImport::ImportBlockNode(MIRFunction *func) { s->defaultLabel = ReadNum(); uint32 size = ReadNum(); for (uint32 i = 0; i < size; i++) { - int32 casetag = ReadNum(); + int64 casetag = ReadNum(); LabelIdx lidx(ReadNum()); CasePair cpair = std::make_pair(casetag, lidx); s->switchTable.push_back(cpair); diff --git a/mapleall/maple_ir/src/debug_info.cpp b/mapleall/maple_ir/src/debug_info.cpp index e19645c0845c0fb1659e2ba3a6697e50acc1dfe9..3fe9b53645ca60895fd82ad7e4efc969710ba48a 100644 --- a/mapleall/maple_ir/src/debug_info.cpp +++ b/mapleall/maple_ir/src/debug_info.cpp @@ -391,19 +391,20 @@ LabelIdx DebugInfo::GetLabelIdx(GStrIdx strIdx) { return labidx; } -DBGDie *DebugInfo::CreateFormalParaDie(MIRFunction *func, MIRType *type, GStrIdx nameidx, uint32 lnum) { +DBGDie *DebugInfo::CreateFormalParaDie(MIRFunction *func, MIRType *type, MIRSymbol *sym) { DBGDie *die = mod_->memPool->New(mod_, DW_TAG_formal_parameter); (void)GetOrCreateTypeDie(type); die->AddAttr(DW_AT_type, DW_FORM_ref4, type->tyIdx.GetIdx()); /* var Name */ - if (nameidx.GetIdx()) { - die->AddAttr(DW_AT_name, DW_FORM_strp, nameidx.GetIdx()); - die->AddAttr(DW_AT_decl_file, DW_FORM_data4, mplsrcidx_.GetIdx()); - die->AddAttr(DW_AT_decl_line, DW_FORM_data4, lnum); + if (sym) { + die->AddAttr(DW_AT_name, DW_FORM_strp, sym->nameStrIdx.GetIdx()); + die->AddAttr(DW_AT_decl_file, DW_FORM_data4, sym->srcPosition.Filenum()); + die->AddAttr(DW_AT_decl_line, DW_FORM_data4, sym->srcPosition.Linenum()); + die->AddAttr(DW_AT_decl_column, DW_FORM_data4, sym->srcPosition.Column()); die->AddSimpLocAttr(DW_AT_location, DW_FORM_exprloc, kDbgDefaultVal); - SetLocalDie(func, nameidx, die); + SetLocalDie(func, sym->nameStrIdx, die); } return die; } @@ -461,8 +462,9 @@ DBGDie *DebugInfo::CreateVarDie(MIRSymbol *sym, uint32 lnum) { /* var Name */ die->AddAttr(DW_AT_name, DW_FORM_strp, sym->nameStrIdx.GetIdx()); - die->AddAttr(DW_AT_decl_file, DW_FORM_data4, mplsrcidx_.GetIdx()); - die->AddAttr(DW_AT_decl_line, DW_FORM_data4, lnum); + die->AddAttr(DW_AT_decl_file, DW_FORM_data4, sym->srcPosition.Filenum()); + die->AddAttr(DW_AT_decl_line, DW_FORM_data4, sym->srcPosition.Linenum()); + die->AddAttr(DW_AT_decl_column, DW_FORM_data4, sym->srcPosition.Column()); if (isLocal) { die->AddSimpLocAttr(DW_AT_location, DW_FORM_exprloc, kDbgDefaultVal); @@ -502,9 +504,12 @@ DBGDie *DebugInfo::GetOrCreateFuncDeclDie(MIRFunction *func, uint32 lnum) { die->AddAttr(DW_AT_external, DW_FORM_flag_present, 1); // Function Name + MIRSymbol *sym = GlobalTables::GetGsymTable().GetSymbolFromStIdx(func->stIdx.Idx()); + die->AddAttr(DW_AT_name, DW_FORM_strp, funcnameidx); - die->AddAttr(DW_AT_decl_file, DW_FORM_data4, mplsrcidx_.GetIdx()); - die->AddAttr(DW_AT_decl_line, DW_FORM_data4, lnum); + die->AddAttr(DW_AT_decl_file, DW_FORM_data4, sym->srcPosition.Filenum()); + die->AddAttr(DW_AT_decl_line, DW_FORM_data4, sym->srcPosition.Linenum()); + die->AddAttr(DW_AT_decl_column, DW_FORM_data4, sym->srcPosition.Column()); // Attributes for DW_AT_accessibility uint32 access = 0; @@ -524,10 +529,9 @@ DBGDie *DebugInfo::GetOrCreateFuncDeclDie(MIRFunction *func, uint32 lnum) { PushParentDie(die); // formal parameter - GStrIdx strIdx(0); for (uint32 i = 0; i < func->formalDefVec.size(); i++) { MIRType *type = GlobalTables::GetTypeTable().GetTypeFromTyIdx(func->formalDefVec[i].formalTyIdx); - DBGDie *param = CreateFormalParaDie(func, type, strIdx, lnum); + DBGDie *param = CreateFormalParaDie(func, type, nullptr); die->AddSubVec(param); } @@ -567,7 +571,7 @@ DBGDie *DebugInfo::GetOrCreateFuncDefDie(MIRFunction *func, uint32 lnum) { // formal parameter for (uint32 i = 0; i < func->formalDefVec.size(); i++) { MIRType *type = GlobalTables::GetTypeTable().GetTypeFromTyIdx(func->formalDefVec[i].formalTyIdx); - DBGDie *pdie = CreateFormalParaDie(func, type, func->formalDefVec[i].formalStrIdx, lnum); + DBGDie *pdie = CreateFormalParaDie(func, type, func->formalDefVec[i].formalSym); die->AddSubVec(pdie); } @@ -603,6 +607,28 @@ DBGDie *DebugInfo::GetOrCreatePrimTypeDie(PrimType pty) { return die; } +DBGDie *DebugInfo::CreatePointedFuncTypeDie(MIRFuncType *func) { + DBGDie *die = mod_->memPool->New(mod_, DW_TAG_subroutine_type); + + die->AddAttr(DW_AT_prototyped, DW_FORM_data4, (int)(func->paramTypeList.size()>0)); + MIRType *rtype = GlobalTables::GetTypeTable().GetTypeFromTyIdx(func->retTyIdx); + (void)GetOrCreateTypeDie(rtype); + die->AddAttr(DW_AT_type, DW_FORM_ref4, func->retTyIdx.GetIdx()); + + cu_->AddSubVec(die); + + for (uint32 i = 0; i < func->paramTypeList.size(); i++) { + DBGDie *paramdie = mod_->memPool->New(mod_, DW_TAG_formal_parameter); + MIRType *ptype = GlobalTables::GetTypeTable().GetTypeFromTyIdx(func->paramTypeList[i]); + (void)GetOrCreateTypeDie(ptype); + paramdie->AddAttr(DW_AT_type, DW_FORM_ref4, func->paramTypeList[i].GetIdx()); + die->AddSubVec(paramdie); + } + + tyidx_dieid_map_[func->tyIdx.GetIdx()] = die->id; + return die; +} + DBGDie *DebugInfo::GetOrCreateTypeDie(MIRType *type) { if (!type) { return nullptr; @@ -632,6 +658,11 @@ DBGDie *DebugInfo::GetOrCreateTypeDie(MIRType *type) { die = GetOrCreatePointTypeDie(ptype); break; } + case kTypeFunction: { + MIRFuncType *ftype = static_cast(type); + die = CreatePointedFuncTypeDie(ftype); + break; + } case kTypeArray: case kTypeFArray: case kTypeJArray: { @@ -668,9 +699,15 @@ DBGDie *DebugInfo::GetOrCreatePointTypeDie(const MIRPtrType *ptrtype) { MIRType *type = ptrtype->GetPointedType(); // for <* void> - if (type && type->primType == PTY_void) { + if (type && + (type->primType == PTY_void || type->typeKind == kTypeFunction)) { DBGDie *die = mod_->memPool->New(mod_, DW_TAG_pointer_type); die->AddAttr(DW_AT_byte_size, DW_FORM_data4, 8); + if (type->typeKind == kTypeFunction) { + DBGDie *pdie = GetOrCreateTypeDie(type); + die->AddAttr(DW_AT_type, DW_FORM_ref4, type->tyIdx.GetIdx()); + tyidx_dieid_map_[type->tyIdx.GetIdx()] = pdie->id; + } tyidx_dieid_map_[ptrtype->tyIdx.GetIdx()] = die->id; cu_->AddSubVec(die); return die; @@ -763,6 +800,26 @@ DBGDie *DebugInfo::CreateFieldDie(maple::FieldPair pair, uint32 lnum) { return die; } +DBGDie *DebugInfo::CreateBitfieldDie(MIRBitfieldType *type, GStrIdx sidx) { + DBGDie *die = mod_->memPool->New(mod_, DW_TAG_member); + + die->AddAttr(DW_AT_name, DW_FORM_strp, sidx.GetIdx()); + die->AddAttr(DW_AT_decl_file, DW_FORM_data4, mplsrcidx_.GetIdx()); + die->AddAttr(DW_AT_decl_line, DW_FORM_data4, 0); + + MIRType *ty = GlobalTables::GetTypeTable().typeTable[type->primType]; + (void)GetOrCreateTypeDie(ty); + die->AddAttr(DW_AT_type, DW_FORM_ref4, ty->tyIdx.GetIdx()); + + die->AddAttr(DW_AT_byte_size, DW_FORM_data4, GetPrimTypeSize(type->primType)); + die->AddAttr(DW_AT_bit_size, DW_FORM_data4, type->fieldSize); + die->AddAttr(DW_AT_bit_offset, DW_FORM_data4, GetPrimTypeSize(type->primType)*8-type->fieldSize); + + die->AddAttr(DW_AT_data_member_location, DW_FORM_data4, 0); + + return die; +} + DBGDie *DebugInfo::GetOrCreateStructTypeDie(const MIRType *type) { ASSERT(type, "null struture type"); GStrIdx strIdx = type->nameStrIdx; @@ -835,9 +892,15 @@ DBGDie *DebugInfo::CreateStructTypeDie(GStrIdx strIdx, const MIRStructType *stru // fields for (int64 i = 0; i < structtype->fields.size(); i++) { + MIRType *ety = structtype->GetElemType(i); FieldPair fp = structtype->fields[i]; - DBGDie *fdie = CreateFieldDie(fp, 0); - die->AddSubVec(fdie); + if (MIRBitfieldType *bfty = dynamic_cast(ety)) { + DBGDie *bfdie = CreateBitfieldDie(bfty, fp.first); + die->AddSubVec(bfdie); + } else { + DBGDie *fdie = CreateFieldDie(fp, 0); + die->AddSubVec(fdie); + } } // parentFields diff --git a/mapleall/maple_ir/src/mir_builder.cpp b/mapleall/maple_ir/src/mir_builder.cpp index 06b380e6e81d722a47bd60d95e4fcb311bf278ee..3ad86e7dda44405aae1e1115c5525308233b9325 100644 --- a/mapleall/maple_ir/src/mir_builder.cpp +++ b/mapleall/maple_ir/src/mir_builder.cpp @@ -335,6 +335,40 @@ MIRSymbol *MIRBuilder::CreateSymbol(TyIdx tyIdx, GStrIdx strIdx, MIRSymKind sKin return st; } +MIRSymbol *MIRBuilder::GetLocalDecl(const string &name, MIRFunction *func) { + return GetSymbol(TyIdx(0), GetStringIndex(name), kStVar, kScAuto, kScopeLocal, func); +} + +MIRSymbol *MIRBuilder::GetLocalDecl(const char *name, MIRFunction *func) { + return GetSymbol(TyIdx(0), GetStringIndex(name), kStVar, kScAuto, kScopeLocal, func); +} + +MIRSymbol *MIRBuilder::CreateLocalDecl(const string &name, MIRType *type, MIRFunction *func) { + return MIRSymbolBuilder::Instance().CreateLocalDecl(*func->symTab, + GetOrCreateStringIndex(name), *type); +} + +MIRSymbol *MIRBuilder::CreateLocalDecl(const char *name, MIRType *type, MIRFunction *func) { + return MIRSymbolBuilder::Instance().CreateLocalDecl(*func->symTab, + GetOrCreateStringIndex(name), *type); +} + +MIRSymbol *MIRBuilder::GetOrCreateLocalDecl(const string &name, MIRType *type, MIRFunction *func) { + MIRSymbol *st = GetLocalDecl(name, func); + if (!st) { + st = CreateLocalDecl(name, type, func); + } + return st; +} + +MIRSymbol *MIRBuilder::GetOrCreateLocalDecl(const char *name, MIRType *type, MIRFunction *func) { + MIRSymbol *st = GetLocalDecl(name, func); + if (!st) { + st = CreateLocalDecl(name, type, func); + } + return st; +} + MIRSymbol *MIRBuilder::GetLocalDecl(const string &name) { return GetSymbol(TyIdx(0), GetStringIndex(name), kStVar, kScAuto, kScopeLocal, GetCurrentFunction()); } diff --git a/mapleall/maple_ir/src/mir_function.cpp b/mapleall/maple_ir/src/mir_function.cpp index d965fffac63c9aba3552305153d3232c639e01bc..9708a412ce1ff908f43f63e9b581affb1f17d580 100644 --- a/mapleall/maple_ir/src/mir_function.cpp +++ b/mapleall/maple_ir/src/mir_function.cpp @@ -189,8 +189,11 @@ void MIRFunction::SetBaseClassFuncNames(GStrIdx strIdx) { baseClassStrIdx = GlobalTables::GetStrTable().GetOrCreateStrIdxFromName(classname); std::string funcnameWithtype = name.substr(pos + width, name.length() - pos - width); baseFuncWithTypeStrIdx = GlobalTables::GetStrTable().GetOrCreateStrIdxFromName(funcnameWithtype); - size_t posEnd = name.find(NameMangler::kRightBracketStr) + (std::string(NameMangler::kRightBracketStr)).length(); - funcnameWithtype = name.substr(pos + width, posEnd - pos - width); + size_t index = name.find(NameMangler::kRightBracketStr); + if (index != std::string::npos) { + size_t posEnd = index + (std::string(NameMangler::kRightBracketStr)).length(); + funcnameWithtype = name.substr(pos + width, posEnd - pos - width); + } baseFuncSigStridx = GlobalTables::GetStrTable().GetOrCreateStrIdxFromName(funcnameWithtype); size_t pos1 = name.find(delimiter, pos + width); while (pos1 != std::string::npos && (name[pos1 - 1] == '_' && name[pos1 - 2] != '_')) { diff --git a/mapleall/maple_ir/src/mir_nodes.cpp b/mapleall/maple_ir/src/mir_nodes.cpp index 5df4f5ff12ff7414fecdba1ea1532661f6620029..b9a5472cc6562514855451833417e7612f1297ec 100644 --- a/mapleall/maple_ir/src/mir_nodes.cpp +++ b/mapleall/maple_ir/src/mir_nodes.cpp @@ -1496,51 +1496,11 @@ static inline MIRTypeKind GetPointedTypeKind(TyIdx tyIdx) { return pointedType->GetKind(); } -static bool GetFieldType(const MIRStructType *structType, FieldID targetFid, TyIdx &tid) { - if (structType == nullptr) { - return false; - } - // For Java module class, find targetFid in inheritance chain firstly - if (theModule->IsJavaModule()) { - if (structType->GetKind() == kTypeClass || structType->GetKind() == kTypeClassIncomplete) { - const MIRClassType *classType = static_cast(structType); - std::stack inheritChain; - TyIdx parentTyIdx = classType->parentTyIdx; - while (parentTyIdx.GetIdx() > 0) { - MIRStructType *parentType = - static_cast(GlobalTables::GetTypeTable().GetTypeFromTyIdx(parentTyIdx)); - inheritChain.push(parentType); - parentTyIdx = static_cast(parentType)->parentTyIdx; - } - targetFid -= inheritChain.size(); - while (!inheritChain.empty()) { - MIRClassType *curClassType = static_cast(inheritChain.top()); - if (0 < static_cast(targetFid) && static_cast(targetFid) <= curClassType->fields.size()) { - tid = curClassType->fields.at(targetFid - 1).second.first; - return true; - } else { - targetFid -= curClassType->fields.size(); - } - inheritChain.pop(); - } - if (0 < static_cast(targetFid) && static_cast(targetFid) <= classType->fields.size()) { - tid = classType->fields.at(targetFid - 1).second.first; - return true; - } - } - } - return false; -} - -static MIRTypeKind GetFieldTypeKind(const MIRStructType *structType, FieldID fieldID) { +static MIRTypeKind GetFieldTypeKind(MIRStructType *structType, FieldID fieldID) { TyIdx fieldTyIdx; if (fieldID > 0) { - bool isValid = GetFieldType(structType, fieldID, fieldTyIdx); - // when mpl does not have complete class info - if (!isValid) { - LogInfo::MapleLogger() << "\n#Error:field not found, must have complete class info\n"; - return kTypeInvalid; - } + MIRType *mirType = structType->GetFieldType(fieldID); + fieldTyIdx = mirType->GetTypeIndex(); } else { ASSERT(static_cast(-fieldID) < structType->parentFields.size() + 1, "array index out of range"); fieldTyIdx = structType->parentFields.at(-fieldID - 1).second.first; diff --git a/mapleall/maple_ir/src/mir_parser_stmt.cpp b/mapleall/maple_ir/src/mir_parser_stmt.cpp index d4e8dbafb8ec35051ca1296c75a552fe8c8980ae..61d14f02255641fce8d8040544bb17361d9c2584 100644 --- a/mapleall/maple_ir/src/mir_parser_stmt.cpp +++ b/mapleall/maple_ir/src/mir_parser_stmt.cpp @@ -637,7 +637,7 @@ bool MIRParser::ParseStmtBr(StmtNode *&stmt) { return true; } -bool MIRParser::ParseSwitchCase(int32 &constVal, LabelIdx &lblidx) { +bool MIRParser::ParseSwitchCase(int64 &constVal, LabelIdx &lblidx) { // syntax : goto if (lexer.GetTokenKind() != TK_intconst) { Error("expect intconst in switch but get "); @@ -677,7 +677,11 @@ bool MIRParser::ParseStmtSwitch(StmtNode *&stmt) { Error("expect expression parsing switch but get "); return false; } - if (!IsPrimitiveInteger(opnd0->primType)) { + if (!IsPrimitiveInteger(opnd0->primType) +#ifdef DYNAMICLANG + && opnd0->primType != PTY_dynany +#endif + ) { Error("expect expression return integer but get "); return false; } @@ -707,7 +711,7 @@ bool MIRParser::ParseStmtSwitch(StmtNode *&stmt) { MapleVector &switchTable = switchnode->switchTable; std::set casesSet; while (tk != TK_rbrace) { - int32 constVal = 0; + int64 constVal = 0; LabelIdx lbl = 0; if (!ParseSwitchCase(constVal, lbl)) { Error("parse switch case failed "); @@ -738,7 +742,11 @@ bool MIRParser::ParseStmtRangegoto(StmtNode *&stmt) { Error("expect expression parsing rangegoto but get "); return false; } - if (!IsPrimitiveInteger(opnd0->primType)) { + if (!IsPrimitiveInteger(opnd0->primType) +#ifdef DYNAMICLANG + && opnd0->primType != PTY_dynany +#endif + ) { Error("expect expression return integer but get "); return false; } @@ -770,7 +778,7 @@ bool MIRParser::ParseStmtRangegoto(StmtNode *&stmt) { int32 minidx = MAXUINT16; int32 maxidx = 0; while (tk != TK_rbrace) { - int32 constVal = 0; + int64 constVal = 0; LabelIdx lbl = 0; if (!ParseSwitchCase(constVal, lbl)) { Error("parse switch case failed "); diff --git a/mapleall/maple_ir/src/mir_symbol.cpp b/mapleall/maple_ir/src/mir_symbol.cpp index 8408a00a0c33beea7d353fa8bbac5222c6c91dcc..bbba1d95d9dd76d4b7dcae95af6afdbd81d845b2 100644 --- a/mapleall/maple_ir/src/mir_symbol.cpp +++ b/mapleall/maple_ir/src/mir_symbol.cpp @@ -232,11 +232,25 @@ bool MIRSymbol::IsGctibSym() { // Some symbols are ignored by reference counting as they represent objects not managed by us. These include // string-based exact comparison for "current_vptr", "vtabptr", "itabptr", "funcptr", "env_ptr", "retvar_stubfunc". -GStrIdx MIRSymbol::reflectClassNameIdx = GlobalTables::GetStrTable().GetOrCreateStrIdxFromName(NameMangler::kJavaLangClassStr); -GStrIdx MIRSymbol::reflectMethodNameIdx = - GlobalTables::GetStrTable().GetOrCreateStrIdxFromName(NameMangler::kJavaLangReflectMethod); -GStrIdx MIRSymbol::reflectFieldNameIdx = - GlobalTables::GetStrTable().GetOrCreateStrIdxFromName(NameMangler::kJavaLangReflectField); +GStrIdx MIRSymbol::reflectClassNameIdx = GStrIdx(0); +GStrIdx MIRSymbol::reflectMethodNameIdx = GStrIdx(0); +GStrIdx MIRSymbol::reflectFieldNameIdx = GStrIdx(0); + +void MIRSymbol::UpdateStaticMembers() { + if (MIRSymbol::reflectClassNameIdx == GStrIdx(0)) { + MIRSymbol::reflectClassNameIdx = + GlobalTables::GetStrTable().GetOrCreateStrIdxFromName(NameMangler::kJavaLangClassStr); + } + if (MIRSymbol::reflectMethodNameIdx == GStrIdx(0)) { + MIRSymbol::reflectMethodNameIdx = + GlobalTables::GetStrTable().GetOrCreateStrIdxFromName(NameMangler::kJavaLangReflectMethod); + } + if (MIRSymbol::reflectFieldNameIdx == GStrIdx(0)) { + MIRSymbol::reflectFieldNameIdx = + GlobalTables::GetStrTable().GetOrCreateStrIdxFromName(NameMangler::kJavaLangReflectField); + } + return; +} bool MIRSymbol::IgnoreRC() { // is RC needed if (isDeleted || GetAttr(ATTR_rcunowned)) { @@ -268,7 +282,7 @@ bool MIRSymbol::IgnoreRC() { // is RC needed MIRPtrType *ptype = static_cast(type); GStrIdx strIdx = GlobalTables::GetTypeTable().GetTypeFromTyIdx(ptype->pointedTyIdx)->nameStrIdx; // LogInfo::MapleLogger() << globaltable.GetStringFromStrIdx(strIdx) << std::endl; - if (strIdx == reflectClassNameIdx || strIdx == reflectMethodNameIdx || strIdx == reflectFieldNameIdx) { + if (strIdx == MIRSymbol::reflectClassNameIdx || strIdx == MIRSymbol::reflectMethodNameIdx || strIdx == MIRSymbol::reflectFieldNameIdx) { return true; } diff --git a/mapleall/maple_ir/src/mir_type.cpp b/mapleall/maple_ir/src/mir_type.cpp index fb2cab4d6baf20b48367738ea15f566892a9a530..324dabcb9d972b55579766719ab1b2fe25c19fea 100644 --- a/mapleall/maple_ir/src/mir_type.cpp +++ b/mapleall/maple_ir/src/mir_type.cpp @@ -1377,7 +1377,7 @@ MIRType *MIRStructType::GetFieldType(FieldID fieldID) { if (fieldID == 0) { return this; } - FieldPair fldpair = TraverseToField(fieldID); + FieldPair fldpair = TraverseToFieldRef(fieldID); return GlobalTables::GetTypeTable().GetTypeFromTyIdx(fldpair.second.first); }