diff options
Diffstat (limited to 'py/makeqstrdata.py')
-rw-r--r-- | py/makeqstrdata.py | 17 |
1 files changed, 14 insertions, 3 deletions
diff --git a/py/makeqstrdata.py b/py/makeqstrdata.py index c8e998ed11..48fd9e09d4 100644 --- a/py/makeqstrdata.py +++ b/py/makeqstrdata.py @@ -73,16 +73,27 @@ def do_work(infiles): # add the qstr to the list, with order number to retain original order in file qstrs[ident] = (len(qstrs), ident, qstr) - # process the qstrs, printing out the generated C header file + # get config variables + cfg_bytes_len = int(qcfgs['BYTES_IN_LEN']) + cfg_max_len = 1 << (8 * cfg_bytes_len) + + # print out the starte of the generated C header file print('// This file was automatically generated by makeqstrdata.py') print('') + # add NULL qstr with no hash or data - print('QDEF(MP_QSTR_NULL, (const byte*)"\\x00\\x00\\x00\\x00" "")') + print('QDEF(MP_QSTR_NULL, (const byte*)"\\x00\\x00%s" "")' % ('\\x00' * cfg_bytes_len)) + + # go through each qstr and print it out for order, ident, qstr in sorted(qstrs.values(), key=lambda x: x[0]): qhash = compute_hash(qstr) qlen = len(qstr) qdata = qstr.replace('"', '\\"') - print('QDEF(MP_QSTR_%s, (const byte*)"\\x%02x\\x%02x\\x%02x\\x%02x" "%s")' % (ident, qhash & 0xff, (qhash >> 8) & 0xff, qlen & 0xff, (qlen >> 8) & 0xff, qdata)) + if qlen >= cfg_max_len: + print('qstr is too long:', qstr) + assert False + qlen_str = ('\\x%02x' * cfg_bytes_len) % tuple(qlen.to_bytes(cfg_bytes_len, 'little')) + print('QDEF(MP_QSTR_%s, (const byte*)"\\x%02x\\x%02x%s" "%s")' % (ident, qhash & 0xff, (qhash >> 8) & 0xff, qlen_str, qdata)) return True |