From 84a8bf22e865fe5b3fe7292423ef13af8f786d26 Mon Sep 17 00:00:00 2001 From: drmortalwombat <90205530+drmortalwombat@users.noreply.github.com> Date: Sun, 29 Sep 2024 17:24:42 +0200 Subject: [PATCH] Constant folding of pointer type cast --- oscar64/Declaration.cpp | 7 +++++++ oscar64/Parser.cpp | 2 ++ 2 files changed, 9 insertions(+) diff --git a/oscar64/Declaration.cpp b/oscar64/Declaration.cpp index 866d429..cbae647 100644 --- a/oscar64/Declaration.cpp +++ b/oscar64/Declaration.cpp @@ -732,6 +732,13 @@ Expression* Expression::ConstantFold(Errors * errors, LinkerSection * dataSectio ex->mDecType = mDecType; return ex; } + else if (mLeft->mDecValue->mType == DT_CONST_POINTER) + { + Expression* ex = new Expression(mLocation, EX_CONSTANT); + ex->mDecValue = mLeft->mDecValue; + ex->mDecType = mDecType; + return ex; + } } else if (mDecType->mType == DT_TYPE_INTEGER) { diff --git a/oscar64/Parser.cpp b/oscar64/Parser.cpp index 359c325..c201d50 100644 --- a/oscar64/Parser.cpp +++ b/oscar64/Parser.cpp @@ -1510,6 +1510,8 @@ Declaration * Parser::CopyConstantInitializer(int offset, Declaration* dtype, Ex exp = CoerceExpression(exp, dtype); + exp = exp->ConstantFold(mErrors, mDataSection); + Declaration* dec = exp->mDecValue; if (exp->mType == EX_CONSTANT)