Skip to content

Commit 8bcc4de

Browse files
committed
ref: move jnzero16 function into a class (Bits16)
1 parent 2d8ea7a commit 8bcc4de

2 files changed

Lines changed: 17 additions & 20 deletions

File tree

src/arch/z80/backend/_16bit.py

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1141,18 +1141,18 @@ def fparam16(cls, ins: Quad) -> list[str]:
11411141
"""
11421142
return Bits16.get_oper(ins[1])
11431143

1144+
@classmethod
1145+
def jnzero16(cls, ins: Quad) -> list[str]:
1146+
"""Jumps if top of the stack (16bit) is != 0 to arg(1)"""
1147+
value = ins[1]
1148+
if is_int(value):
1149+
if int(value) != 0:
1150+
return ["jp %s" % str(ins[2])] # Always true
1151+
else:
1152+
return []
11441153

1145-
def _jnzero16(ins: Quad) -> list[str]:
1146-
"""Jumps if top of the stack (16bit) is != 0 to arg(1)"""
1147-
value = ins[1]
1148-
if is_int(value):
1149-
if int(value) != 0:
1150-
return ["jp %s" % str(ins[2])] # Always true
1151-
else:
1152-
return []
1153-
1154-
output = Bits16.get_oper(value)
1155-
output.append("ld a, h")
1156-
output.append("or l")
1157-
output.append("jp nz, %s" % str(ins[2]))
1158-
return output
1154+
output = Bits16.get_oper(value)
1155+
output.append("ld a, h")
1156+
output.append("or l")
1157+
output.append("jp nz, %s" % str(ins[2]))
1158+
return output

src/arch/z80/backend/main.py

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,7 @@
2626
# 16 bit comparison functions
2727
# 16bit parameters and function call instrs
2828
# 16 bit arithmetic functions
29-
from ._16bit import (
30-
Bits16,
31-
_jnzero16,
32-
)
29+
from ._16bit import Bits16
3330

3431
# 32 bit bitwise operations
3532
# 32 bit shift operations
@@ -316,8 +313,8 @@ def _set_quad_table(self):
316313
ICInstruction.JZEROSTR: ICInfo(2, String.jzerostr), # if str is NULL or len(str) == 0, jmp LABEL
317314
ICInstruction.JNZEROI8: ICInfo(2, Bits8.jnzero8), # if X != 0 jmp LABEL
318315
ICInstruction.JNZEROU8: ICInfo(2, Bits8.jnzero8), # if X != 0 jmp LABEL
319-
ICInstruction.JNZEROI16: ICInfo(2, _jnzero16), # if X != 0 jmp LABEL
320-
ICInstruction.JNZEROU16: ICInfo(2, _jnzero16), # if X != 0 jmp LABEL
316+
ICInstruction.JNZEROI16: ICInfo(2, Bits16.jnzero16), # if X != 0 jmp LABEL
317+
ICInstruction.JNZEROU16: ICInfo(2, Bits16.jnzero16), # if X != 0 jmp LABEL
321318
ICInstruction.JNZEROI32: ICInfo(2, Bits32.jnzero32), # if X != 0 jmp LABEL (32bit, fixed)
322319
ICInstruction.JNZEROU32: ICInfo(2, Bits32.jnzero32), # if X != 0 jmp LABEL (32bit, fixed)
323320
ICInstruction.JNZEROF16: ICInfo(2, Fixed16.jnzerof16), # if X != 0 jmp LABEL (32bit, fixed)

0 commit comments

Comments
 (0)