Skip to content

Commit 33bc700

Browse files
authored
Merge pull request #563 from boriel/refact/type_quads_in_backend
refact: type QUADS dict table
2 parents 0a87262 + a5564cb commit 33bc700

14 files changed

Lines changed: 763 additions & 738 deletions

File tree

Lines changed: 45 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,16 @@
55
# Copyleft (k) 2008, by Jose M. Rodriguez-Rosa
66
# (a.k.a. Boriel, http://www.boriel.com)
77
#
8-
# This module contains 8 bit boolean, arithmetic and
8+
# This module contains 16 bit boolean, arithmetic and
99
# comparison intermediate-code translations
1010
# --------------------------------------------------------------
11+
12+
from typing import List
13+
1114
from src.arch.z80.backend.runtime import Labels as RuntimeLabel
1215

13-
from src.arch.z80.backend.common import is_int, log2, is_2n, _int_ops, tmp_label, runtime_call
14-
from src.arch.z80.backend.__8bit import _8bit_oper
16+
from src.arch.z80.backend.common import is_int, log2, is_2n, _int_ops, tmp_label, runtime_call, Quad
17+
from src.arch.z80.backend._8bit import _8bit_oper
1518

1619

1720
# -----------------------------------------------------
@@ -122,7 +125,7 @@ def _16bit_oper(op1, op2=None, reversed=False):
122125
# -----------------------------------------------------
123126

124127

125-
def _add16(ins):
128+
def _add16(ins: Quad) -> List[str]:
126129
"""Pops last 2 bytes from the stack and adds them.
127130
Then push the result onto the stack.
128131
@@ -171,7 +174,7 @@ def _add16(ins):
171174
return output
172175

173176

174-
def _sub16(ins):
177+
def _sub16(ins: Quad) -> List[str]:
175178
"""Pops last 2 words from the stack and subtract them.
176179
Then push the result onto the stack. Top of the stack is
177180
subtracted Top -1
@@ -224,7 +227,7 @@ def _sub16(ins):
224227
return output
225228

226229

227-
def _mul16(ins):
230+
def _mul16(ins: Quad) -> List[str]:
228231
"""Multiplies tow last 16bit values on top of the stack and
229232
and returns the value on top of the stack
230233
@@ -275,7 +278,7 @@ def _mul16(ins):
275278
return output
276279

277280

278-
def _divu16(ins):
281+
def _divu16(ins: Quad) -> List[str]:
279282
"""Divides 2 16bit unsigned integers. The result is pushed onto the stack.
280283
281284
Optimizations:
@@ -331,7 +334,7 @@ def _divu16(ins):
331334
return output
332335

333336

334-
def _divi16(ins):
337+
def _divi16(ins: Quad) -> List[str]:
335338
"""Divides 2 16bit signed integers. The result is pushed onto the stack.
336339
337340
Optimizations:
@@ -388,7 +391,7 @@ def _divi16(ins):
388391
return output
389392

390393

391-
def _modu16(ins):
394+
def _modu16(ins: Quad) -> List[str]:
392395
"""Reminder of div. 2 16bit unsigned integers. The result is pushed onto the stack.
393396
394397
Optimizations:
@@ -433,7 +436,7 @@ def _modu16(ins):
433436
return output
434437

435438

436-
def _modi16(ins):
439+
def _modi16(ins: Quad) -> List[str]:
437440
"""Reminder of div 2 16bit signed integers. The result is pushed onto the stack.
438441
439442
Optimizations:
@@ -478,7 +481,7 @@ def _modi16(ins):
478481
return output
479482

480483

481-
def _ltu16(ins):
484+
def _ltu16(ins: Quad) -> List[str]:
482485
"""Compares & pops top 2 operands out of the stack, and checks
483486
if the 1st operand < 2nd operand (top of the stack).
484487
Pushes 0 if False, 1 if True.
@@ -493,7 +496,7 @@ def _ltu16(ins):
493496
return output
494497

495498

496-
def _lti16(ins):
499+
def _lti16(ins: Quad) -> List[str]:
497500
"""Compares & pops top 2 operands out of the stack, and checks
498501
if the 1st operand < 2nd operand (top of the stack).
499502
Pushes 0 if False, 1 if True.
@@ -506,7 +509,7 @@ def _lti16(ins):
506509
return output
507510

508511

509-
def _gtu16(ins):
512+
def _gtu16(ins: Quad) -> List[str]:
510513
"""Compares & pops top 2 operands out of the stack, and checks
511514
if the 1st operand > 2nd operand (top of the stack).
512515
Pushes 0 if False, 1 if True.
@@ -521,7 +524,7 @@ def _gtu16(ins):
521524
return output
522525

523526

524-
def _gti16(ins):
527+
def _gti16(ins: Quad) -> List[str]:
525528
"""Compares & pops top 2 operands out of the stack, and checks
526529
if the 1st operand > 2nd operand (top of the stack).
527530
Pushes 0 if False, 1 if True.
@@ -534,7 +537,7 @@ def _gti16(ins):
534537
return output
535538

536539

537-
def _leu16(ins):
540+
def _leu16(ins: Quad) -> List[str]:
538541
"""Compares & pops top 2 operands out of the stack, and checks
539542
if the 1st operand <= 2nd operand (top of the stack).
540543
Pushes 0 if False, 1 if True.
@@ -550,7 +553,7 @@ def _leu16(ins):
550553
return output
551554

552555

553-
def _lei16(ins):
556+
def _lei16(ins: Quad) -> List[str]:
554557
"""Compares & pops top 2 operands out of the stack, and checks
555558
if the 1st operand <= 2nd operand (top of the stack).
556559
Pushes 0 if False, 1 if True.
@@ -563,7 +566,7 @@ def _lei16(ins):
563566
return output
564567

565568

566-
def _geu16(ins):
569+
def _geu16(ins: Quad) -> List[str]:
567570
"""Compares & pops top 2 operands out of the stack, and checks
568571
if the 1st operand >= 2nd operand (top of the stack).
569572
Pushes 0 if False, 1 if True.
@@ -579,7 +582,7 @@ def _geu16(ins):
579582
return output
580583

581584

582-
def _gei16(ins):
585+
def _gei16(ins: Quad) -> List[str]:
583586
"""Compares & pops top 2 operands out of the stack, and checks
584587
if the 1st operand >= 2nd operand (top of the stack).
585588
Pushes 0 if False, 1 if True.
@@ -592,7 +595,7 @@ def _gei16(ins):
592595
return output
593596

594597

595-
def _eq16(ins):
598+
def _eq16(ins: Quad) -> List[str]:
596599
"""Compares & pops top 2 operands out of the stack, and checks
597600
if the 1st operand == 2nd operand (top of the stack).
598601
Pushes 0 if False, 1 if True.
@@ -606,7 +609,7 @@ def _eq16(ins):
606609
return output
607610

608611

609-
def _ne16(ins):
612+
def _ne16(ins: Quad) -> List[str]:
610613
"""Compares & pops top 2 operands out of the stack, and checks
611614
if the 1st operand != 2nd operand (top of the stack).
612615
Pushes 0 if False, 1 if True.
@@ -623,7 +626,7 @@ def _ne16(ins):
623626
return output
624627

625628

626-
def _or16(ins):
629+
def _or16(ins: Quad) -> List[str]:
627630
"""Compares & pops top 2 operands out of the stack, and checks
628631
if the 1st operand OR (logical) 2nd operand (top of the stack),
629632
pushes 0 if False, 1 if True.
@@ -661,7 +664,7 @@ def _or16(ins):
661664
return output
662665

663666

664-
def _bor16(ins):
667+
def _bor16(ins: Quad) -> List[str]:
665668
"""Pops top 2 operands out of the stack, and performs
666669
1st operand OR (bitwise) 2nd operand (top of the stack),
667670
pushes result (16 bit in HL).
@@ -694,7 +697,7 @@ def _bor16(ins):
694697
return output
695698

696699

697-
def _xor16(ins):
700+
def _xor16(ins: Quad) -> List[str]:
698701
"""Compares & pops top 2 operands out of the stack, and checks
699702
if the 1st operand XOR (logical) 2nd operand (top of the stack),
700703
pushes 0 if False, 1 if True.
@@ -732,7 +735,7 @@ def _xor16(ins):
732735
return output
733736

734737

735-
def _bxor16(ins):
738+
def _bxor16(ins: Quad) -> List[str]:
736739
"""Pops top 2 operands out of the stack, and performs
737740
1st operand XOR (bitwise) 2nd operand (top of the stack),
738741
pushes result (16 bit in HL).
@@ -765,7 +768,7 @@ def _bxor16(ins):
765768
return output
766769

767770

768-
def _and16(ins):
771+
def _and16(ins: Quad) -> List[str]:
769772
"""Compares & pops top 2 operands out of the stack, and checks
770773
if the 1st operand AND (logical) 2nd operand (top of the stack),
771774
pushes 0 if False, 1 if True.
@@ -800,7 +803,7 @@ def _and16(ins):
800803
return output
801804

802805

803-
def _band16(ins):
806+
def _band16(ins: Quad) -> List[str]:
804807
"""Pops top 2 operands out of the stack, and performs
805808
1st operand AND (bitwise) 2nd operand (top of the stack),
806809
pushes result (16 bit in HL).
@@ -832,7 +835,7 @@ def _band16(ins):
832835
return output
833836

834837

835-
def _not16(ins):
838+
def _not16(ins: Quad) -> List[str]:
836839
"""Negates top (Logical NOT) of the stack (16 bits in HL)"""
837840
output = _16bit_oper(ins.quad[2])
838841
output.append("ld a, h")
@@ -843,31 +846,31 @@ def _not16(ins):
843846
return output
844847

845848

846-
def _bnot16(ins):
849+
def _bnot16(ins: Quad) -> List[str]:
847850
"""Negates top (Bitwise NOT) of the stack (16 bits in HL)"""
848851
output = _16bit_oper(ins.quad[2])
849852
output.append(runtime_call(RuntimeLabel.BNOT16))
850853
output.append("push hl")
851854
return output
852855

853856

854-
def _neg16(ins):
857+
def _neg16(ins: Quad) -> List[str]:
855858
"""Negates top of the stack (16 bits in HL)"""
856859
output = _16bit_oper(ins.quad[2])
857860
output.append(runtime_call(RuntimeLabel.NEGHL))
858861
output.append("push hl")
859862
return output
860863

861864

862-
def _abs16(ins):
865+
def _abs16(ins: Quad) -> List[str]:
863866
"""Absolute value of top of the stack (16 bits in HL)"""
864867
output = _16bit_oper(ins.quad[2])
865868
output.append(runtime_call(RuntimeLabel.ABS16))
866869
output.append("push hl")
867870
return output
868871

869872

870-
def _shru16(ins):
873+
def _shru16(ins: Quad) -> List[str]:
871874
"""Logical right shift 16bit unsigned integer.
872875
The result is pushed onto the stack.
873876
@@ -911,7 +914,7 @@ def _shru16(ins):
911914
return output
912915

913916

914-
def _shri16(ins):
917+
def _shri16(ins: Quad) -> List[str]:
915918
"""Arithmetical right shift 16bit signed integer.
916919
The result is pushed onto the stack.
917920
@@ -955,7 +958,7 @@ def _shri16(ins):
955958
return output
956959

957960

958-
def _shl16(ins):
961+
def _shl16(ins: Quad) -> List[str]:
959962
"""Logical/aritmetical left shift 16bit (un)signed integer.
960963
The result is pushed onto the stack.
961964
@@ -997,7 +1000,7 @@ def _shl16(ins):
9971000
return output
9981001

9991002

1000-
def _load16(ins):
1003+
def _load16(ins: Quad) -> List[str]:
10011004
"""Loads a 16 bit value from a memory address
10021005
If 2nd arg. start with '*', it is always treated as
10031006
an indirect value.
@@ -1007,7 +1010,7 @@ def _load16(ins):
10071010
return output
10081011

10091012

1010-
def _store16(ins):
1013+
def _store16(ins: Quad) -> List[str]:
10111014
"""Stores 2nd operand content into address of 1st operand.
10121015
store16 a, x => *(&a) = x
10131016
Use '*' for indirect store on 1st operand.
@@ -1069,7 +1072,7 @@ def _store16(ins):
10691072
return output
10701073

10711074

1072-
def _jzero16(ins):
1075+
def _jzero16(ins: Quad) -> List[str]:
10731076
"""Jumps if top of the stack (16bit) is 0 to arg(1)"""
10741077
value = ins.quad[1]
10751078
if is_int(value):
@@ -1085,7 +1088,7 @@ def _jzero16(ins):
10851088
return output
10861089

10871090

1088-
def _jgezerou16(ins):
1091+
def _jgezerou16(ins: Quad) -> List[str]:
10891092
"""Jumps if top of the stack (16bit) is >= 0 to arg(1)
10901093
Always TRUE for unsigned
10911094
"""
@@ -1098,7 +1101,7 @@ def _jgezerou16(ins):
10981101
return output
10991102

11001103

1101-
def _jgezeroi16(ins):
1104+
def _jgezeroi16(ins: Quad) -> List[str]:
11021105
"""Jumps if top of the stack (16bit) is >= 0 to arg(1)"""
11031106
value = ins.quad[1]
11041107
if is_int(value):
@@ -1113,22 +1116,22 @@ def _jgezeroi16(ins):
11131116
return output
11141117

11151118

1116-
def _ret16(ins):
1119+
def _ret16(ins: Quad) -> List[str]:
11171120
"""Returns from a procedure / function a 16bits value"""
11181121
output = _16bit_oper(ins.quad[1])
11191122
output.append("#pragma opt require hl")
11201123
output.append("jp %s" % str(ins.quad[2]))
11211124
return output
11221125

11231126

1124-
def _param16(ins):
1127+
def _param16(ins: Quad) -> List[str]:
11251128
"""Pushes 16bit param into the stack"""
11261129
output = _16bit_oper(ins.quad[1])
11271130
output.append("push hl")
11281131
return output
11291132

11301133

1131-
def _fparam16(ins):
1134+
def _fparam16(ins: Quad) -> List[str]:
11321135
"""Passes a word as a __FASTCALL__ parameter.
11331136
This is done by popping out of the stack for a
11341137
value, or by loading it from memory (indirect)
@@ -1137,7 +1140,7 @@ def _fparam16(ins):
11371140
return _16bit_oper(ins.quad[1])
11381141

11391142

1140-
def _jnzero16(ins):
1143+
def _jnzero16(ins: Quad) -> List[str]:
11411144
"""Jumps if top of the stack (16bit) is != 0 to arg(1)"""
11421145
value = ins.quad[1]
11431146
if is_int(value):

0 commit comments

Comments
 (0)