Commit b4790afd authored by Damien George's avatar Damien George
Browse files

tools/mpy-tool.py: Store qstr config values in global config object.

Makes it easier to access them without passing around another dict of the
config values.
parent 58f38613
...@@ -444,10 +444,7 @@ def dump_mpy(raw_codes): ...@@ -444,10 +444,7 @@ def dump_mpy(raw_codes):
for rc in raw_codes: for rc in raw_codes:
rc.dump() rc.dump()
def freeze_mpy(qcfgs, base_qstrs, raw_codes): def freeze_mpy(base_qstrs, raw_codes):
cfg_bytes_len = int(qcfgs['BYTES_IN_LEN'])
cfg_bytes_hash = int(qcfgs['BYTES_IN_HASH'])
# add to qstrs # add to qstrs
new = {} new = {}
for q in global_qstrs: for q in global_qstrs:
...@@ -505,7 +502,8 @@ def freeze_mpy(qcfgs, base_qstrs, raw_codes): ...@@ -505,7 +502,8 @@ def freeze_mpy(qcfgs, base_qstrs, raw_codes):
print(' %u, // used entries' % len(new)) print(' %u, // used entries' % len(new))
print(' {') print(' {')
for _, _, qstr in new: for _, _, qstr in new:
print(' %s,' % qstrutil.make_bytes(cfg_bytes_len, cfg_bytes_hash, qstr)) print(' %s,'
% qstrutil.make_bytes(config.MICROPY_QSTR_BYTES_IN_LEN, config.MICROPY_QSTR_BYTES_IN_HASH, qstr))
print(' },') print(' },')
print('};') print('};')
...@@ -549,10 +547,15 @@ def main(): ...@@ -549,10 +547,15 @@ def main():
}[args.mlongint_impl] }[args.mlongint_impl]
config.MPZ_DIG_SIZE = args.mmpz_dig_size config.MPZ_DIG_SIZE = args.mmpz_dig_size
# set config values for qstrs, and get the existing base set of qstrs
if args.qstr_header: if args.qstr_header:
qcfgs, base_qstrs = qstrutil.parse_input_headers([args.qstr_header]) qcfgs, base_qstrs = qstrutil.parse_input_headers([args.qstr_header])
config.MICROPY_QSTR_BYTES_IN_LEN = int(qcfgs['BYTES_IN_LEN'])
config.MICROPY_QSTR_BYTES_IN_HASH = int(qcfgs['BYTES_IN_HASH'])
else: else:
qcfgs, base_qstrs = {'BYTES_IN_LEN':1, 'BYTES_IN_HASH':1}, {} config.MICROPY_QSTR_BYTES_IN_LEN = 1
config.MICROPY_QSTR_BYTES_IN_HASH = 1
base_qstrs = {}
raw_codes = [read_mpy(file) for file in args.files] raw_codes = [read_mpy(file) for file in args.files]
...@@ -560,7 +563,7 @@ def main(): ...@@ -560,7 +563,7 @@ def main():
dump_mpy(raw_codes) dump_mpy(raw_codes)
elif args.freeze: elif args.freeze:
try: try:
freeze_mpy(qcfgs, base_qstrs, raw_codes) freeze_mpy(base_qstrs, raw_codes)
except FreezeError as er: except FreezeError as er:
print(er, file=sys.stderr) print(er, file=sys.stderr)
sys.exit(1) sys.exit(1)
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment