From 4b0d2dc1f39a32258c732726e1658d402941d0e3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bartolom=C3=A9=20S=C3=A1nchez=20Salado?= Date: Mon, 14 Oct 2024 23:10:15 +0200 Subject: [PATCH] ref: move jgezeroi16 function into a class (Bits16) --- src/arch/z80/backend/_16bit.py | 26 +++++++++++++------------- src/arch/z80/backend/main.py | 3 +-- 2 files changed, 14 insertions(+), 15 deletions(-) diff --git a/src/arch/z80/backend/_16bit.py b/src/arch/z80/backend/_16bit.py index 21ab8fe4c..887c72225 100644 --- a/src/arch/z80/backend/_16bit.py +++ b/src/arch/z80/backend/_16bit.py @@ -1102,20 +1102,20 @@ def jgezerou16(cls, ins: Quad) -> list[str]: output.append("jp %s" % str(ins[2])) return output + @classmethod + def jgezeroi16(cls, ins: Quad) -> list[str]: + """Jumps if top of the stack (16bit) is >= 0 to arg(1)""" + value = ins[1] + if is_int(value): + if int(value) >= 0: + return ["jp %s" % str(ins[2])] # Always true + else: + return [] -def _jgezeroi16(ins: Quad) -> list[str]: - """Jumps if top of the stack (16bit) is >= 0 to arg(1)""" - value = ins[1] - if is_int(value): - if int(value) >= 0: - return ["jp %s" % str(ins[2])] # Always true - else: - return [] - - output = Bits16.get_oper(value) - output.append("add hl, hl") # Puts sign into carry - output.append("jp nc, %s" % str(ins[2])) - return output + output = Bits16.get_oper(value) + output.append("add hl, hl") # Puts sign into carry + output.append("jp nc, %s" % str(ins[2])) + return output def _ret16(ins: Quad) -> list[str]: diff --git a/src/arch/z80/backend/main.py b/src/arch/z80/backend/main.py index 62d84d078..ac8d0a8e2 100644 --- a/src/arch/z80/backend/main.py +++ b/src/arch/z80/backend/main.py @@ -29,7 +29,6 @@ from ._16bit import ( Bits16, _fparam16, - _jgezeroi16, _jnzero16, _param16, _ret16, @@ -329,7 +328,7 @@ def _set_quad_table(self): ICInstruction.JNZEROSTR: ICInfo(2, String.jnzerostr), # if str is not NULL and len(str) > 0, jmp LABEL ICInstruction.JGEZEROI8: ICInfo(2, Bits8.jgezeroi8), # if X >= 0 jmp LABEL ICInstruction.JGEZEROU8: ICInfo(2, Bits8.jgezerou8), # if X >= 0 jmp LABEL (ALWAYS TRUE) - ICInstruction.JGEZEROI16: ICInfo(2, _jgezeroi16), # if X >= 0 jmp LABEL + ICInstruction.JGEZEROI16: ICInfo(2, Bits16.jgezeroi16), # if X >= 0 jmp LABEL ICInstruction.JGEZEROU16: ICInfo(2, Bits16.jgezerou16), # if X >= 0 jmp LABEL (ALWAYS TRUE) ICInstruction.JGEZEROI32: ICInfo(2, Bits32.jgezeroi32), # if X >= 0 jmp LABEL (32bit, fixed) ICInstruction.JGEZEROU32: ICInfo(2, Bits32.jgezerou32), # if X >= 0 jmp LABEL (32bit, fixed) (always true)