diff --git a/src/mapleall/maple_be/src/be/lower.cpp b/src/mapleall/maple_be/src/be/lower.cpp index d3e70932fb66a8921c829031880e71db69793aa8..bbde064389a2fcc8903a0f120f430bf1db21a4b8 100644 --- a/src/mapleall/maple_be/src/be/lower.cpp +++ b/src/mapleall/maple_be/src/be/lower.cpp @@ -2667,7 +2667,7 @@ BaseNode *CGLowerer::LowerExpr(BaseNode &parent, BaseNode &expr, BlockNode &blkN bool isCvtU1Expr = (expr.GetOpCode() == OP_cvt && expr.GetPrimType() == PTY_u1 && static_cast(expr).FromType() != PTY_u1); if (expr.GetPrimType() == PTY_u1) { - expr.SetPrimType(PTY_u8); + expr.SetPrimType(PTY_i32); } if (expr.GetOpCode() == OP_intrinsicopwithtype) { return LowerIntrinsicopwithtype(parent, static_cast(expr), blkNode); diff --git a/src/mapleall/maple_me/include/lmbc_lower.h b/src/mapleall/maple_me/include/lmbc_lower.h index 385ac8cd4e033af0dd5b4c8852762b5bb8f5bbbf..0641d0b4ccc8985d96680f0933c7712839ac165a 100644 --- a/src/mapleall/maple_me/include/lmbc_lower.h +++ b/src/mapleall/maple_me/include/lmbc_lower.h @@ -42,6 +42,7 @@ class LMBCLowerer { void LowerReturn(NaryStmtNode *retNode, BlockNode *newblk); void LowerCall(NaryStmtNode *stmt, BlockNode *newblk); BlockNode *LowerBlock(BlockNode *); + void FixPrototype4FirstArgReturn(IcallNode *icall); void LowerFunction(); MIRModule *mirModule; diff --git a/src/mapleall/maple_me/src/lmbc_lower.cpp b/src/mapleall/maple_me/src/lmbc_lower.cpp index bab9b20c21f6afd72408f4d654012852af945c01..39c4a9d1c2b7cd2857213503ee9af4b3788278c5 100644 --- a/src/mapleall/maple_me/src/lmbc_lower.cpp +++ b/src/mapleall/maple_me/src/lmbc_lower.cpp @@ -230,9 +230,13 @@ void LMBCLowerer::LowerDassign(DassignNode *dsnode, BlockNode *newblk) { } BaseNode *rhs = LowerExpr(dsnode->Opnd(0)); if (rhs->GetPrimType() != PTY_agg || rhs->GetOpCode() == OP_regread) { + PrimType ptypUsed = symty->GetPrimType(); + if (ptypUsed == PTY_agg) { + ptypUsed = rhs->GetPrimType(); + } if (!symbol->LMBCAllocateOffSpecialReg()) { BaseNode *base = mirBuilder->CreateExprDreadoff(OP_addrofoff, LOWERED_PTR_TYPE, *symbol, 0); - IassignoffNode *iassignoff = mirBuilder->CreateStmtIassignoff(symty->GetPrimType(), + IassignoffNode *iassignoff = mirBuilder->CreateStmtIassignoff(ptypUsed, offset, base, rhs); newblk->AddStatement(iassignoff); return; @@ -240,7 +244,7 @@ void LMBCLowerer::LowerDassign(DassignNode *dsnode, BlockNode *newblk) { PregIdx spcreg = GetSpecialRegFromSt(symbol); if (spcreg == -kSregFp) { IassignFPoffNode *iassignoff = mirBuilder->CreateStmtIassignFPoff(OP_iassignfpoff, - symty->GetPrimType(), + ptypUsed, memlayout->sym_alloc_table[symbol->GetStIndex()].offset + offset, rhs); newblk->AddStatement(iassignoff); } else { @@ -248,7 +252,7 @@ void LMBCLowerer::LowerDassign(DassignNode *dsnode, BlockNode *newblk) { SymbolAlloc &symalloc = symbol->IsLocal() ? memlayout->sym_alloc_table[symbol->GetStIndex()] : globmemlayout->sym_alloc_table[symbol->GetStIndex()]; - IassignoffNode *iassignoff = mirBuilder->CreateStmtIassignoff(symty->GetPrimType(), + IassignoffNode *iassignoff = mirBuilder->CreateStmtIassignoff(ptypUsed, symalloc.offset + offset, rrn, rhs); @@ -424,6 +428,31 @@ void LMBCLowerer::LowerCall(NaryStmtNode *stmt, BlockNode *newblk) { newblk->AddStatement(stmt); } +void LMBCLowerer::FixPrototype4FirstArgReturn(IcallNode *icall) { + MIRFuncType *ftype = static_cast(GlobalTables::GetTypeTable().GetTypeFromTyIdx(icall->GetRetTyIdx())); + if (!ftype->FirstArgReturn()) { + return; + } + MIRType *retType = GlobalTables::GetTypeTable().GetTypeFromTyIdx(ftype->GetRetTyIdx()); + if (retType->GetPrimType() == PTY_void) { + return; + } + // insert return type as fake first parameter + size_t oldSize = ftype->GetParamTypeList().size(); + ftype->GetParamTypeList().push_back(TyIdx(0)); + ftype->GetParamAttrsList().push_back(TypeAttrs()); + for (size_t i = oldSize; i > 0; i--) { + ftype->GetParamTypeList()[i] = ftype->GetParamTypeList()[i-1]; + ftype->GetParamAttrsList()[i] = ftype->GetParamAttrsList()[i-1]; + } + MIRType *newType = GlobalTables::GetTypeTable().GetOrCreatePointerType(ftype->GetRetTyIdx(), GetExactPtrPrimType(), ftype->GetRetAttrs()); + ftype->GetParamTypeList()[0] = newType->GetTypeIndex(); + ftype->GetParamAttrsList()[0] = TypeAttrs(); + // change return type to void + ftype->SetRetTyIdx(GlobalTables::GetTypeTable().GetVoid()->GetTypeIndex()); + ftype->SetRetAttrs(TypeAttrs()); +} + BlockNode *LMBCLowerer::LowerBlock(BlockNode *block) { BlockNode *newblk = mirModule->CurFuncCodeMemPool()->New(); if (!block->GetFirst()) { @@ -460,9 +489,11 @@ BlockNode *LMBCLowerer::LowerBlock(BlockNode *block) { } break; } + case OP_icallproto: + FixPrototype4FirstArgReturn(static_cast(stmt)); + // fall thru case OP_asm: - case OP_call: - case OP_icallproto: { + case OP_call: { LowerCall(static_cast(stmt), newblk); break; }