Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion arch/zx48k/backend/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@
OPT32 = True

# Label RegExp
RE_LABEL = re.compile('^[ \t]*[a-zA-Z_][_a-zA-Z\d]*:')
RE_LABEL = re.compile(r'^[ \t]*[a-zA-Z_][_a-zA-Z\d]*:')

# (ix +/- ...) regexp
RE_IX_IDX = re.compile(r'^\([ \t]*ix[ \t]*[-+][ \t]*.+\)$')
Expand Down
10 changes: 5 additions & 5 deletions arch/zx48k/optimizer.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,14 +44,14 @@
'bc', 'de', 'hl', 'sp', 'ix', 'iy', 'ixh', 'ixl', 'iyh', 'iyl',
'af', "af'", 'i', 'r'}

RE_NUMBER = re.compile('^([-+]?[0-9]+|$[A-Fa-f0-9]+|[0-9][A-Fa-f0-9]*[Hh]|%[01]+|[01]+[bB])$')
RE_NUMBER = re.compile(r'^([-+]?[0-9]+|$[A-Fa-f0-9]+|[0-9][A-Fa-f0-9]*[Hh]|%[01]+|[01]+[bB])$')
RE_INDIR = re.compile(r'\([ \t]*[Ii][XxYy][ \t]*[-+][ \t]*[0-9]+[ \t]*\)')
RE_IXIND = re.compile(r'[iI][xXyY]([-+][0-9]+)?')
RE_LABEL = re.compile(r'^[ \t]*[_a-zA-Z][a-zA-Z\d]*:')
RE_INDIR16 = re.compile('r[ \t]*\([ \t]*([dD][eE])|([hH][lL])[ \t]*\)[ \t]*')
RE_OUTC = re.compile('[ \t]*\([ \t]*[cC]\)')
RE_ID = re.compile('[.a-zA-Z_][.a-zA-Z_0-9]*')
RE_PRAGMA = re.compile('^#[ \t]?pragma[ \t]opt[ \t]')
RE_INDIR16 = re.compile(r'[ \t]*\([ \t]*([dD][eE])|([hH][lL])[ \t]*\)[ \t]*')
RE_OUTC = re.compile(r'[ \t]*\([ \t]*[cC]\)')
RE_ID = re.compile(r'[.a-zA-Z_][.a-zA-Z_0-9]*')
RE_PRAGMA = re.compile(r'^#[ \t]?pragma[ \t]opt[ \t]')

# Enabled Optimizations (this is useful for debugging)
OPT00 = True
Expand Down
16 changes: 8 additions & 8 deletions arch/zx48k/translator.py
Original file line number Diff line number Diff line change
Expand Up @@ -285,6 +285,9 @@ def traverse_const(node):
if node.token == 'CONST':
return Translator.traverse_const(node.expr)

if node.token == 'ARRAYACCESS':
return '({} + {})'.format(node.entry.mangled, node.offset)

raise InvalidCONSTexpr(node)

@staticmethod
Expand Down Expand Up @@ -457,6 +460,11 @@ def visit_ARGLIST(self, node):
for i in range(len(node) - 1, -1, -1): # visit in reverse order
yield node[i]

if isinstance(node.parent, symbols.ARRAYACCESS) and OPTIONS.arrayCheck.value:
upper = node.parent.entry.bounds[i].upper
lower = node.parent.entry.bounds[i].lower
self.emit('paramu16', upper - lower)

def visit_ARGUMENT(self, node):
if not node.byref:
suffix = self.TSUFFIX(node.type_)
Expand Down Expand Up @@ -496,11 +504,6 @@ def visit_ARRAYLOAD(self, node):
if node.offset is None:
yield node.args

if OPTIONS.arrayCheck.value:
upper = node.entry.bounds[0].upper
lower = node.entry.bounds[0].lower
self.emit('paramu16', upper - lower)

if scope == SCOPE.global_:
self.emit('aload' + self.TSUFFIX(node.type_), node.entry.t, node.entry.mangled)
elif scope == SCOPE.parameter:
Expand Down Expand Up @@ -644,9 +647,6 @@ def visit_LETARRAYSUBSTR(self, node):
def visit_ARRAYACCESS(self, node):
yield node.arglist

if OPTIONS.arrayCheck.value:
self.emit('param' + self.TSUFFIX(gl.BOUND_TYPE), len(node.entry.bounds))

def visit_STRSLICE(self, node):
yield node.string
if node.string.token == 'STRING' or \
Expand Down
10 changes: 1 addition & 9 deletions library-asm/array.asm
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,10 @@ __ARRAY:

ld hl, 0 ; BC = Offset "accumulator"

LOOP:
#ifdef __CHECK_ARRAY_BOUNDARY__
pop de
#endif

LOOP:
pop bc ; Get next index (Ai) from the stack

#ifdef __CHECK_ARRAY_BOUNDARY__
Expand Down Expand Up @@ -74,15 +73,8 @@ LOOP:
exx
pop de ; DE = Max bound Number (i-th dimension)

#ifdef __CHECK_ARRAY_BOUNDARY__
push de
#endif
;call __MUL16_FAST ; HL *= DE
call __FNMUL
#ifdef __CHECK_ARRAY_BOUNDARY__
pop de
dec de
#endif
jp LOOP

ARRAY_END:
Expand Down
11 changes: 4 additions & 7 deletions tests/functional/46.asm
Original file line number Diff line number Diff line change
Expand Up @@ -140,12 +140,11 @@ __ARRAY:

ld hl, 0 ; BC = Offset "accumulator"

#line 48 "/src/zxb/trunk/library-asm/array.asm"

LOOP:
#line 49 "/src/zxb/trunk/library-asm/array.asm"
pop bc ; Get next index (Ai) from the stack

#line 60 "/src/zxb/trunk/library-asm/array.asm"
#line 59 "/src/zxb/trunk/library-asm/array.asm"

add hl, bc ; Adds current index

Expand All @@ -163,10 +162,8 @@ LOOP:
exx
pop de ; DE = Max bound Number (i-th dimension)

#line 80 "/src/zxb/trunk/library-asm/array.asm"
;call __MUL16_FAST ; HL *= DE
call __FNMUL
#line 86 "/src/zxb/trunk/library-asm/array.asm"
jp LOOP

ARRAY_END:
Expand All @@ -177,7 +174,7 @@ ARRAY_END:
push de
exx

#line 100 "/src/zxb/trunk/library-asm/array.asm"
#line 92 "/src/zxb/trunk/library-asm/array.asm"
LOCAL ARRAY_SIZE_LOOP

ex de, hl
Expand Down Expand Up @@ -208,7 +205,7 @@ ARRAY_SIZE_LOOP:

;add hl, de
;__ARRAY_FIN:
#line 131 "/src/zxb/trunk/library-asm/array.asm"
#line 123 "/src/zxb/trunk/library-asm/array.asm"

pop de
add hl, de ; Adds element start
Expand Down
11 changes: 4 additions & 7 deletions tests/functional/47.asm
Original file line number Diff line number Diff line change
Expand Up @@ -167,12 +167,11 @@ __ARRAY:

ld hl, 0 ; BC = Offset "accumulator"

#line 48 "/src/zxb/trunk/library-asm/array.asm"

LOOP:
#line 49 "/src/zxb/trunk/library-asm/array.asm"
pop bc ; Get next index (Ai) from the stack

#line 60 "/src/zxb/trunk/library-asm/array.asm"
#line 59 "/src/zxb/trunk/library-asm/array.asm"

add hl, bc ; Adds current index

Expand All @@ -190,10 +189,8 @@ LOOP:
exx
pop de ; DE = Max bound Number (i-th dimension)

#line 80 "/src/zxb/trunk/library-asm/array.asm"
;call __MUL16_FAST ; HL *= DE
call __FNMUL
#line 86 "/src/zxb/trunk/library-asm/array.asm"
jp LOOP

ARRAY_END:
Expand All @@ -204,7 +201,7 @@ ARRAY_END:
push de
exx

#line 100 "/src/zxb/trunk/library-asm/array.asm"
#line 92 "/src/zxb/trunk/library-asm/array.asm"
LOCAL ARRAY_SIZE_LOOP

ex de, hl
Expand Down Expand Up @@ -235,7 +232,7 @@ ARRAY_SIZE_LOOP:

;add hl, de
;__ARRAY_FIN:
#line 131 "/src/zxb/trunk/library-asm/array.asm"
#line 123 "/src/zxb/trunk/library-asm/array.asm"

pop de
add hl, de ; Adds element start
Expand Down
11 changes: 4 additions & 7 deletions tests/functional/55.asm
Original file line number Diff line number Diff line change
Expand Up @@ -135,12 +135,11 @@ __ARRAY:

ld hl, 0 ; BC = Offset "accumulator"

#line 48 "/src/zxb/trunk/library-asm/array.asm"

LOOP:
#line 49 "/src/zxb/trunk/library-asm/array.asm"
pop bc ; Get next index (Ai) from the stack

#line 60 "/src/zxb/trunk/library-asm/array.asm"
#line 59 "/src/zxb/trunk/library-asm/array.asm"

add hl, bc ; Adds current index

Expand All @@ -158,10 +157,8 @@ LOOP:
exx
pop de ; DE = Max bound Number (i-th dimension)

#line 80 "/src/zxb/trunk/library-asm/array.asm"
;call __MUL16_FAST ; HL *= DE
call __FNMUL
#line 86 "/src/zxb/trunk/library-asm/array.asm"
jp LOOP

ARRAY_END:
Expand All @@ -172,7 +169,7 @@ ARRAY_END:
push de
exx

#line 100 "/src/zxb/trunk/library-asm/array.asm"
#line 92 "/src/zxb/trunk/library-asm/array.asm"
LOCAL ARRAY_SIZE_LOOP

ex de, hl
Expand Down Expand Up @@ -203,7 +200,7 @@ ARRAY_SIZE_LOOP:

;add hl, de
;__ARRAY_FIN:
#line 131 "/src/zxb/trunk/library-asm/array.asm"
#line 123 "/src/zxb/trunk/library-asm/array.asm"

pop de
add hl, de ; Adds element start
Expand Down
11 changes: 4 additions & 7 deletions tests/functional/aloadstr1.asm
Original file line number Diff line number Diff line change
Expand Up @@ -138,12 +138,11 @@ __ARRAY:

ld hl, 0 ; BC = Offset "accumulator"

#line 48 "/src/zxb/trunk/library-asm/array.asm"

LOOP:
#line 49 "/src/zxb/trunk/library-asm/array.asm"
pop bc ; Get next index (Ai) from the stack

#line 60 "/src/zxb/trunk/library-asm/array.asm"
#line 59 "/src/zxb/trunk/library-asm/array.asm"

add hl, bc ; Adds current index

Expand All @@ -161,10 +160,8 @@ LOOP:
exx
pop de ; DE = Max bound Number (i-th dimension)

#line 80 "/src/zxb/trunk/library-asm/array.asm"
;call __MUL16_FAST ; HL *= DE
call __FNMUL
#line 86 "/src/zxb/trunk/library-asm/array.asm"
jp LOOP

ARRAY_END:
Expand All @@ -175,7 +172,7 @@ ARRAY_END:
push de
exx

#line 100 "/src/zxb/trunk/library-asm/array.asm"
#line 92 "/src/zxb/trunk/library-asm/array.asm"
LOCAL ARRAY_SIZE_LOOP

ex de, hl
Expand Down Expand Up @@ -206,7 +203,7 @@ ARRAY_SIZE_LOOP:

;add hl, de
;__ARRAY_FIN:
#line 131 "/src/zxb/trunk/library-asm/array.asm"
#line 123 "/src/zxb/trunk/library-asm/array.asm"

pop de
add hl, de ; Adds element start
Expand Down
11 changes: 4 additions & 7 deletions tests/functional/array03.asm
Original file line number Diff line number Diff line change
Expand Up @@ -133,12 +133,11 @@ __ARRAY:

ld hl, 0 ; BC = Offset "accumulator"

#line 48 "/src/zxb/trunk/library-asm/array.asm"

LOOP:
#line 49 "/src/zxb/trunk/library-asm/array.asm"
pop bc ; Get next index (Ai) from the stack

#line 60 "/src/zxb/trunk/library-asm/array.asm"
#line 59 "/src/zxb/trunk/library-asm/array.asm"

add hl, bc ; Adds current index

Expand All @@ -156,10 +155,8 @@ LOOP:
exx
pop de ; DE = Max bound Number (i-th dimension)

#line 80 "/src/zxb/trunk/library-asm/array.asm"
;call __MUL16_FAST ; HL *= DE
call __FNMUL
#line 86 "/src/zxb/trunk/library-asm/array.asm"
jp LOOP

ARRAY_END:
Expand All @@ -170,7 +167,7 @@ ARRAY_END:
push de
exx

#line 100 "/src/zxb/trunk/library-asm/array.asm"
#line 92 "/src/zxb/trunk/library-asm/array.asm"
LOCAL ARRAY_SIZE_LOOP

ex de, hl
Expand Down Expand Up @@ -201,7 +198,7 @@ ARRAY_SIZE_LOOP:

;add hl, de
;__ARRAY_FIN:
#line 131 "/src/zxb/trunk/library-asm/array.asm"
#line 123 "/src/zxb/trunk/library-asm/array.asm"

pop de
add hl, de ; Adds element start
Expand Down
11 changes: 4 additions & 7 deletions tests/functional/array06.asm
Original file line number Diff line number Diff line change
Expand Up @@ -133,12 +133,11 @@ __ARRAY:

ld hl, 0 ; BC = Offset "accumulator"

#line 48 "/src/zxb/trunk/library-asm/array.asm"

LOOP:
#line 49 "/src/zxb/trunk/library-asm/array.asm"
pop bc ; Get next index (Ai) from the stack

#line 60 "/src/zxb/trunk/library-asm/array.asm"
#line 59 "/src/zxb/trunk/library-asm/array.asm"

add hl, bc ; Adds current index

Expand All @@ -156,10 +155,8 @@ LOOP:
exx
pop de ; DE = Max bound Number (i-th dimension)

#line 80 "/src/zxb/trunk/library-asm/array.asm"
;call __MUL16_FAST ; HL *= DE
call __FNMUL
#line 86 "/src/zxb/trunk/library-asm/array.asm"
jp LOOP

ARRAY_END:
Expand All @@ -170,7 +167,7 @@ ARRAY_END:
push de
exx

#line 100 "/src/zxb/trunk/library-asm/array.asm"
#line 92 "/src/zxb/trunk/library-asm/array.asm"
LOCAL ARRAY_SIZE_LOOP

ex de, hl
Expand Down Expand Up @@ -201,7 +198,7 @@ ARRAY_SIZE_LOOP:

;add hl, de
;__ARRAY_FIN:
#line 131 "/src/zxb/trunk/library-asm/array.asm"
#line 123 "/src/zxb/trunk/library-asm/array.asm"

pop de
add hl, de ; Adds element start
Expand Down
Loading