Fix usage of assembler labels as pointer initializer

This commit is contained in:
drmortalwombat 2024-12-29 10:22:01 +01:00
parent 9e994560a7
commit 87f1ddd27f
3 changed files with 35 additions and 2 deletions

View File

@ -2933,6 +2933,10 @@ bool Declaration::CanAssign(const Declaration* fromType) const
{
return true;
}
else if (mBase->mType == DT_TYPE_FUNCTION && fromType->mType == DT_TYPE_ASSEMBLER)
{
return (mBase->mBase->mType == DT_TYPE_VOID && !mBase->mBase->mParams);
}
}
return false;

View File

@ -2318,6 +2318,23 @@ InterCodeGenerator::ExValue InterCodeGenerator::TranslateExpression(Declaration*
return ExValue(TheVoidPointerTypeDeclaration, ins->mDst.mTemp);
}
case DT_LABEL_REF:
{
if (!dec->mBase->mBase->mLinkerObject)
TranslateAssembler(proc->mModule, dec->mBase->mBase, nullptr);
InterInstruction* ins = new InterInstruction(MapLocation(exp, inlineMapper), IC_CONSTANT);
ins->mDst.mType = IT_POINTER;
ins->mDst.mTemp = proc->AddTemporary(ins->mDst.mType);
ins->mConst.mType = IT_POINTER;
ins->mConst.mVarIndex = dec->mBase->mBase->mVarIndex;
ins->mConst.mLinkerObject = dec->mBase->mBase->mLinkerObject;
ins->mConst.mMemory = IM_PROCEDURE;
ins->mConst.mIntConst = dec->mInteger + dec->mBase->mInteger;
block->Append(ins);
return ExValue(TheVoidPointerTypeDeclaration, ins->mDst.mTemp);
}
case DT_CONST_POINTER:
{
vl = TranslateExpression(procType, proc, block, dec->mValue, destack, gotos, breakBlock, continueBlock, inlineMapper);
@ -5694,6 +5711,19 @@ void InterCodeGenerator::BuildInitializer(InterCodeModule * mod, uint8* dp, int
ref.mRefOffset = 0;
variable->mLinkerObject->AddReference(ref);
}
else if (data->mType == DT_LABEL)
{
if (!data->mBase->mLinkerObject)
TranslateAssembler(mod, data->mBase, nullptr);
LinkerReference ref;
ref.mObject = variable->mLinkerObject;
ref.mOffset = offset;
ref.mFlags = LREF_LOWBYTE | LREF_HIGHBYTE;
ref.mRefObject = data->mBase->mLinkerObject;
ref.mRefOffset = int(data->mInteger);
variable->mLinkerObject->AddReference(ref);
}
else if (data->mType == DT_CONST_FUNCTION)
{
assert(false);

View File

@ -2452,7 +2452,7 @@ Expression* Parser::ParseConstInitExpression(Declaration* dtype, bool inner)
}
else if (dtype->mType == DT_TYPE_POINTER)
{
if (exp->mDecValue->mType == DT_CONST_ADDRESS || exp->mDecValue->mType == DT_CONST_POINTER)
if (exp->mDecValue->mType == DT_CONST_ADDRESS || exp->mDecValue->mType == DT_CONST_POINTER || exp->mDecValue->mType == DT_CONST_ASSEMBLER || exp->mDecValue->mType == DT_LABEL)
;
else if (exp->mDecValue->mType == DT_CONST_FUNCTION)
{
@ -7113,7 +7113,6 @@ Expression* Parser::ParseQualify(Expression* exp)
if (ldec)
{
exp->mDecValue = ldec;
exp->mDecType = TheUnsignedIntTypeDeclaration;
}
else
mErrors->Error(mScanner->mLocation, EERR_OBJECT_NOT_FOUND, "Assembler label not found", mScanner->mTokenIdent);