Skip to content

Commit 742692b

Browse files
committed
refact: ends up earlier when using parse-only
1 parent addefb1 commit 742692b

1 file changed

Lines changed: 12 additions & 3 deletions

File tree

src/zxbc/zxbc.py

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
import re
55
import sys
6+
from argparse import Namespace
67
from io import StringIO
78

89
import src.api.optimize
@@ -61,7 +62,12 @@ def output(memory, ofile=None):
6162
ofile.write("%s\n" % m)
6263

6364

64-
def main(args=None, emitter=None):
65+
def save_config(options: Namespace) -> None:
66+
if not gl.has_errors and options.save_config:
67+
src.api.config.save_config_into_file(options.save_config, src.api.config.ConfigSections.ZXBC)
68+
69+
70+
def main(args=None, emitter=None) -> int:
6571
"""Entry point when executed from command line.
6672
zxbc can be used as python module. If so, bear in mind this function
6773
won't be executed unless explicitly called.
@@ -124,6 +130,10 @@ def main(args=None, emitter=None):
124130
debug.__DEBUG__("exiting due to errors.")
125131
return 1 # Exit with errors
126132

133+
if options.parse_only:
134+
save_config(options)
135+
return gl.has_errors
136+
127137
# Emits data lines
128138
translator.emit_data_blocks()
129139
# Emits default constant strings
@@ -216,8 +226,7 @@ def main(args=None, emitter=None):
216226
with open_file(OPTIONS.memory_map, "wt", "utf-8") as f:
217227
f.write(asmparse.MEMORY.memory_map)
218228

219-
if not gl.has_errors and options.save_config:
220-
src.api.config.save_config_into_file(options.save_config, src.api.config.ConfigSections.ZXBC)
229+
save_config(options)
221230

222231
return gl.has_errors # Exit success
223232

0 commit comments

Comments
 (0)