From 87f1ddd27f4dc45782658aecd67808ab704e1c8a Mon Sep 17 00:00:00 2001 From: drmortalwombat <90205530+drmortalwombat@users.noreply.github.com> Date: Sun, 29 Dec 2024 10:22:01 +0100 Subject: [PATCH] Fix usage of assembler labels as pointer initializer --- oscar64/Declaration.cpp | 4 ++++ oscar64/InterCodeGenerator.cpp | 30 ++++++++++++++++++++++++++++++ oscar64/Parser.cpp | 3 +-- 3 files changed, 35 insertions(+), 2 deletions(-) diff --git a/oscar64/Declaration.cpp b/oscar64/Declaration.cpp index bbbec84..418bc77 100644 --- a/oscar64/Declaration.cpp +++ b/oscar64/Declaration.cpp @@ -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; diff --git a/oscar64/InterCodeGenerator.cpp b/oscar64/InterCodeGenerator.cpp index c1e75aa..8700a7e 100644 --- a/oscar64/InterCodeGenerator.cpp +++ b/oscar64/InterCodeGenerator.cpp @@ -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); diff --git a/oscar64/Parser.cpp b/oscar64/Parser.cpp index 5e02f27..280b864 100644 --- a/oscar64/Parser.cpp +++ b/oscar64/Parser.cpp @@ -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);