From e08c7b3642a18d76bfbb16b94224fb17390fe3af Mon Sep 17 00:00:00 2001 From: nickysn Date: Wed, 29 Apr 2020 21:38:41 +0000 Subject: [PATCH] + z80: added condition checking in taicpu.Matches git-svn-id: trunk@45178 - --- compiler/z80/aasmcpu.pas | 61 ++++++++++++++++++++++++++++++++++++++++ compiler/z80/cpubase.pas | 3 ++ 2 files changed, 64 insertions(+) diff --git a/compiler/z80/aasmcpu.pas b/compiler/z80/aasmcpu.pas index 3a5fb99692..bd8f008d68 100644 --- a/compiler/z80/aasmcpu.pas +++ b/compiler/z80/aasmcpu.pas @@ -269,6 +269,67 @@ implementation begin result:=false; + { Check the opcode } + if p^.opcode<>opcode then + exit; + + { The opcode doesn't support conditions, but we have a condition? + That's an invalid instruction, don't match it against anything. } + if (condition<>C_NONE) and not (opcode in cond_instructions) then + exit; + + { if our opcode supports a condition, but our operation doesn't have + one, and we're matching it with an instruction entry 'p' that has a + condition, then it doesn't match } + if (opcode in cond_instructions) and (condition=C_None) and + (p^.ops>0) and (p^.optypes[0] in [OT_COND..OT_COND_NZ]) then + exit; + + { instruction has a condition? } + if (opcode in cond_instructions) and (condition<>C_None) then + begin + { Check the operand count } + if p^.ops<>(ops+1) then + exit; + + { Check the condition } + case p^.optypes[0] of + OT_COND: + { any condition accepted }; + OT_COND_C: + if condition<>C_C then + exit; + OT_COND_NC: + if condition<>C_NC then + exit; + OT_COND_Z: + if condition<>C_Z then + exit; + OT_COND_NZ: + if condition<>C_NZ then + exit; + else + { no condition in 'p'? Then it's not a match! } + exit; + end; + { Check the operands } + for i:=1 to p^.ops-1 do + if not OperandsMatch(oper[i-1]^,p^.optypes[i]) then + exit; + end + else + { no condition } + begin + { Check the operand count } + if p^.ops<>ops then + exit; + + { Check the operands } + for i:=0 to p^.ops-1 do + if not OperandsMatch(oper[i]^,p^.optypes[i]) then + exit; + end; + { Check the opcode and operands } if (p^.opcode<>opcode) or (p^.ops<>ops) then exit; diff --git a/compiler/z80/cpubase.pas b/compiler/z80/cpubase.pas index 61381d6897..60f00153dd 100644 --- a/compiler/z80/cpubase.pas +++ b/compiler/z80/cpubase.pas @@ -62,6 +62,9 @@ unit cpubase; jmp_instructions = [A_JP,A_JR,A_DJNZ]; call_jmp_instructions = [A_CALL]+jmp_instructions; + { instructions that can have a condition } + cond_instructions = [A_CALL,A_JP,A_RET]; + {***************************************************************************** Registers *****************************************************************************}