From 5b4e5b545d7b419ba9b0e439e84db9754fbe9467 Mon Sep 17 00:00:00 2001 From: drmortalwombat <90205530+drmortalwombat@users.noreply.github.com> Date: Sun, 20 Aug 2023 19:06:24 +0200 Subject: [PATCH] Add or/and/shift to inline assembler --- oscar64/Assembler.cpp | 2 +- oscar64/Parser.cpp | 49 ++++++++++++++++++++++++++++++++++++++++++- oscar64/Parser.h | 3 +++ 3 files changed, 52 insertions(+), 2 deletions(-) diff --git a/oscar64/Assembler.cpp b/oscar64/Assembler.cpp index f103ab6..2b9fc21 100644 --- a/oscar64/Assembler.cpp +++ b/oscar64/Assembler.cpp @@ -333,7 +333,7 @@ void InitAssembler(void) int AsmInsSize(AsmInsType type, AsmInsMode mode) { - if (type < ASMIT_INV) + if (type < ASMIT_INV && mode >= ASMIM_IMPLIED && mode < NUM_ASM_INS_MODES) return AsmInsModeSize[mode]; else return 1; diff --git a/oscar64/Parser.cpp b/oscar64/Parser.cpp index 1318abb..5d4f30d 100644 --- a/oscar64/Parser.cpp +++ b/oscar64/Parser.cpp @@ -8045,6 +8045,53 @@ Expression* Parser::ParseAssemblerAddOperand(Declaration* pcasm, int pcoffset) return exp; } +Expression* Parser::ParseAssemblerShiftOperand(Declaration* pcasm, int pcoffset) +{ + Expression* exp = ParseAssemblerAddOperand(pcasm, pcoffset); + while (mScanner->mToken == TK_LEFT_SHIFT || mScanner->mToken == TK_RIGHT_SHIFT) + { + Expression* nexp = new Expression(mScanner->mLocation, EX_BINARY); + nexp->mToken = mScanner->mToken; + nexp->mLeft = exp; + mScanner->NextToken(); + nexp->mRight = ParseAssemblerAddOperand(pcasm, pcoffset); + exp = nexp->ConstantFold(mErrors); + } + return exp; +} + + +Expression* Parser::ParseAssemblerAndOperand(Declaration* pcasm, int pcoffset) +{ + Expression* exp = ParseAssemblerShiftOperand(pcasm, pcoffset); + while (mScanner->mToken == TK_BINARY_AND) + { + Expression* nexp = new Expression(mScanner->mLocation, EX_BINARY); + nexp->mToken = mScanner->mToken; + nexp->mLeft = exp; + mScanner->NextToken(); + nexp->mRight = ParseAssemblerShiftOperand(pcasm, pcoffset); + exp = nexp->ConstantFold(mErrors); + } + return exp; +} + +Expression* Parser::ParseAssemblerOrOperand(Declaration* pcasm, int pcoffset) +{ + Expression* exp = ParseAssemblerAndOperand(pcasm, pcoffset); + while (mScanner->mToken == TK_BINARY_OR) + { + Expression* nexp = new Expression(mScanner->mLocation, EX_BINARY); + nexp->mToken = mScanner->mToken; + nexp->mLeft = exp; + mScanner->NextToken(); + nexp->mRight = ParseAssemblerAndOperand(pcasm, pcoffset); + exp = nexp->ConstantFold(mErrors); + } + return exp; +} + + Expression* Parser::ParseAssemblerOperand(Declaration* pcasm, int pcoffset) { if (mScanner->mToken == TK_LESS_THAN) @@ -8188,7 +8235,7 @@ Expression* Parser::ParseAssemblerOperand(Declaration* pcasm, int pcoffset) return exp; } else - return ParseAssemblerAddOperand(pcasm, pcoffset); + return ParseAssemblerOrOperand(pcasm, pcoffset); } void Parser::AddAssemblerRegister(const Ident* ident, int value) diff --git a/oscar64/Parser.h b/oscar64/Parser.h index 7915cc6..bf3faad 100644 --- a/oscar64/Parser.h +++ b/oscar64/Parser.h @@ -74,6 +74,9 @@ protected: Expression* ParseAssemblerBaseOperand(Declaration* pcasm, int pcoffset); Expression* ParseAssemblerMulOperand(Declaration* pcasm, int pcoffset); Expression* ParseAssemblerAddOperand(Declaration* pcasm, int pcoffset); + Expression* ParseAssemblerShiftOperand(Declaration* pcasm, int pcoffset); + Expression* ParseAssemblerAndOperand(Declaration* pcasm, int pcoffset); + Expression* ParseAssemblerOrOperand(Declaration* pcasm, int pcoffset); Expression* ParseAssemblerOperand(Declaration * pcasm, int pcoffset); Expression* CheckOperatorOverload(Expression* exp);