Skip to content

Commit e578cc1

Browse files
committed
Move zxbasm into its own folder
This will unclutter the root directory
1 parent 09e6b30 commit e578cc1

12 files changed

Lines changed: 171 additions & 153 deletions

File tree

arch/zx48k/optimizer/memcell.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
from .. import backend
77
from .asm import Asm
88
from api.utils import flatten_list
9-
import asmlex
9+
from zxbasm import asmlex
1010

1111

1212
class MemCell(object):

parsetab/tabs.dbm.bak

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
'zxbppparse', (0, 68810)
2-
'asmparse', (69120, 250081)
3-
'zxnext_asmparse', (319488, 280962)
4-
'zxbparser', (600576, 707013)
2+
'asmparse', (69120, 250690)
3+
'zxnext_asmparse', (320000, 281648)
4+
'zxbparser', (602112, 707013)

parsetab/tabs.dbm.dat

1.5 KB
Binary file not shown.

parsetab/tabs.dbm.dir

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
'zxbppparse', (0, 68810)
2-
'asmparse', (69120, 250081)
3-
'zxnext_asmparse', (319488, 280962)
4-
'zxbparser', (600576, 707013)
2+
'asmparse', (69120, 250690)
3+
'zxnext_asmparse', (320000, 281648)
4+
'zxbparser', (602112, 707013)

zxb.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
import zxblex
2020
import zxbparser
2121
import zxbpp
22-
import asmparse
22+
from zxbasm import asmparse
2323
import arch.zx48k.backend as backend
2424

2525
from api import global_ as gl

zxbasm.py

Lines changed: 2 additions & 134 deletions
Original file line numberDiff line numberDiff line change
@@ -12,139 +12,7 @@
1212
# ----------------------------------------------------------------------
1313

1414
import sys
15-
import os
16-
import argparse
17-
18-
import asmparse
19-
import zxbpp
20-
21-
import api.config
22-
from api.config import OPTIONS
23-
from api import global_
24-
25-
# Release version
26-
VERSION = '1.13.1'
27-
28-
29-
def main(args=None):
30-
# Initializes asm parser state
31-
api.config.init()
32-
asmparse.init()
33-
zxbpp.init()
34-
35-
# Create option parser
36-
o_parser = argparse.ArgumentParser(prog='zxbasm')
37-
o_parser.add_argument('PROGRAM', type=str, help='ASM program file')
38-
o_parser.add_argument("-d", "--debug", action="count", default=OPTIONS.Debug.value,
39-
help="Enable verbosity/debugging output")
40-
41-
o_parser.add_argument("-O", "--optimize", type=int, dest="optimization_level",
42-
help="Sets optimization level. 0 = None", default=OPTIONS.optimization.value)
43-
44-
o_parser.add_argument("-o", "--output", type=str, dest="output_file",
45-
help="Sets output file. Default is input filename with .bin extension", default=None)
46-
47-
o_parser.add_argument("-T", "--tzx", action="store_true", dest="tzx", default=False,
48-
help="Sets output format to tzx (default is .bin)")
49-
50-
o_parser.add_argument("-t", "--tap", action="store_true", dest="tap", default=False,
51-
help="Sets output format to tzx (default is .bin)")
52-
53-
o_parser.add_argument("-B", "--BASIC", action="store_true", dest="basic", default=False,
54-
help="Creates a BASIC loader which load the rest of the CODE. Requires -T ot -t")
55-
56-
o_parser.add_argument("-a", "--autorun", action="store_true", default=False,
57-
help="Sets the program to auto run once loaded (implies --BASIC)")
58-
59-
o_parser.add_argument("-e", "--errmsg", type=str, dest="stderr", default=OPTIONS.StdErrFileName.value,
60-
help="Error messages file (standard error console by default")
61-
62-
o_parser.add_argument("-M", "--mmap", type=str, dest="memory_map", default=None,
63-
help="Generate label memory map")
64-
65-
o_parser.add_argument("-b", "--bracket", action="store_true", default=False,
66-
help="Allows brackets only for memory access and indirections")
67-
68-
o_parser.add_argument('-N', "--zxnext", action="store_true", default=False,
69-
help="Enable ZX Next extra ASM opcodes!")
70-
71-
o_parser.add_argument("--version", action="version", version="%(prog)s " + VERSION)
72-
73-
options = o_parser.parse_args(args)
74-
75-
if not os.path.exists(options.PROGRAM):
76-
o_parser.error("No such file or directory: '%s'" % options.PROGRAM)
77-
sys.exit(2)
78-
79-
OPTIONS.Debug.value = int(options.debug)
80-
OPTIONS.inputFileName.value = options.PROGRAM
81-
OPTIONS.outputFileName.value = options.output_file
82-
OPTIONS.optimization.value = options.optimization_level
83-
OPTIONS.use_loader.value = options.autorun or options.basic
84-
OPTIONS.autorun.value = options.autorun
85-
OPTIONS.StdErrFileName.value = options.stderr
86-
OPTIONS.memory_map.value = options.memory_map
87-
OPTIONS.bracket.value = options.bracket
88-
OPTIONS.zxnext.value = options.zxnext
89-
90-
if options.tzx:
91-
OPTIONS.output_file_type.value = 'tzx'
92-
elif options.tap:
93-
OPTIONS.output_file_type.value = 'tap'
94-
95-
if not OPTIONS.outputFileName.value:
96-
OPTIONS.outputFileName.value = os.path.splitext(
97-
os.path.basename(OPTIONS.inputFileName.value))[0] + os.path.extsep + OPTIONS.output_file_type.value
98-
99-
if OPTIONS.StdErrFileName.value:
100-
OPTIONS.stderr.value = open(OPTIONS.StdErrFileName.value, 'wt')
101-
102-
if int(options.tzx) + int(options.tap) > 1:
103-
o_parser.error("Options --tap, --tzx and --asm are mutually exclusive")
104-
return 3
105-
106-
if OPTIONS.use_loader.value and not options.tzx and not options.tap:
107-
o_parser.error('Option --BASIC and --autorun requires --tzx or tap format')
108-
return 4
109-
110-
# Configure the preprocessor to use the asm-preprocessor-lexer
111-
zxbpp.setMode('asm')
112-
113-
# Now filter them against the preprocessor
114-
zxbpp.main([OPTIONS.inputFileName.value])
115-
116-
# Now output the result
117-
asm_output = zxbpp.OUTPUT
118-
asmparse.assemble(asm_output)
119-
if global_.has_errors:
120-
return 1
121-
122-
if not asmparse.MEMORY.memory_bytes: # empty seq.
123-
asmparse.warning(0, "Nothing to assemble. Exiting...")
124-
return 0
125-
126-
current_org = max(asmparse.MEMORY.memory_bytes.keys() or [0]) + 1
127-
128-
for label, line in asmparse.INITS:
129-
expr_label = asmparse.Expr.makenode(asmparse.Container(asmparse.MEMORY.get_label(label, line), line))
130-
asmparse.MEMORY.add_instruction(asmparse.Asm(0, 'CALL NN', expr_label))
131-
132-
if len(asmparse.INITS) > 0:
133-
if asmparse.AUTORUN_ADDR is not None:
134-
asmparse.MEMORY.add_instruction(asmparse.Asm(0, 'JP NN', asmparse.AUTORUN_ADDR))
135-
else:
136-
asmparse.MEMORY.add_instruction(
137-
asmparse.Asm(0, 'JP NN', min(asmparse.MEMORY.orgs.keys()))) # To the beginning of binary
138-
139-
asmparse.AUTORUN_ADDR = current_org
140-
141-
if OPTIONS.memory_map.value:
142-
with open(OPTIONS.memory_map.value, 'wt') as f:
143-
f.write(asmparse.MEMORY.memory_map)
144-
145-
asmparse.generate_binary(OPTIONS.outputFileName.value, OPTIONS.output_file_type.value)
146-
return global_.has_errors
147-
15+
import zxbasm
14816

14917
if __name__ == '__main__':
150-
sys.exit(main())
18+
sys.exit(zxbasm.main())

zxbasm/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
from .zxbasm import main # noqa

asm.py renamed to zxbasm/asm.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ def num2bytes(x, bytes):
3838

3939

4040
class InvalidMnemonicError(Error):
41-
""" Exception raised when an invalid Mnemonic has been emmitted.
41+
""" Exception raised when an invalid Mnemonic has been emitted.
4242
"""
4343

4444
def __init__(self, mnemo):
@@ -47,7 +47,7 @@ def __init__(self, mnemo):
4747

4848

4949
class InvalidArgError(Error):
50-
""" Exception raised when an invalid argument has been emmitted.
50+
""" Exception raised when an invalid argument has been emitted.
5151
"""
5252

5353
def __init__(self, arg):
@@ -56,7 +56,7 @@ def __init__(self, arg):
5656

5757

5858
class InternalMismatchSizeError(Error):
59-
""" Exception raised when an invalid instruction length has been emmitted.
59+
""" Exception raised when an invalid instruction length has been emitted.
6060
"""
6161

6262
def __init__(self, current_size, asm):
@@ -71,8 +71,8 @@ def __init__(self, current_size, asm):
7171

7272

7373
class AsmInstruction(Opcode):
74-
""" Derivates from Opcode. This one checks the nmenomic
75-
is valid. """
74+
""" Derives from Opcode. This one checks for opcode validity.
75+
"""
7676

7777
def __init__(self, asm, arg=None):
7878
""" Parses the given asm instruction and validates
File renamed without changes.

asmparse.py renamed to zxbasm/asmparse.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,11 @@
1313

1414
import os
1515
import re
16-
import asmlex
16+
from zxbasm import asmlex
1717
import ply.yacc as yacc
1818

19-
from asmlex import tokens # noqa
20-
from asm import AsmInstruction, Error
19+
from zxbasm.asmlex import tokens # noqa
20+
from zxbasm.asm import AsmInstruction, Error
2121
from ast_ import Ast
2222
from api.debug import __DEBUG__
2323
from api.config import OPTIONS
@@ -1551,7 +1551,7 @@ def main(argv):
15511551
lambda: yacc.yacc(start="start", debug=OPTIONS.Debug.value > 2))
15521552

15531553
# needed for ply
1554-
from zxnext import * # noqa
1554+
from .zxnext import * # noqa
15551555

15561556
# ZXNEXT extended OPcodes parser
15571557
zxnext_parser = api.utils.get_or_create('zxnext_asmparse',

0 commit comments

Comments
 (0)