py: Add qstr cfg capability; generate QSTR_NULL and QSTR_ from script.
This commit is contained in:
@@ -40,12 +40,25 @@ def compute_hash(qstr):
|
||||
|
||||
def do_work(infiles):
|
||||
# read the qstrs in from the input files
|
||||
qcfgs = {}
|
||||
qstrs = {}
|
||||
for infile in infiles:
|
||||
with open(infile, 'rt') as f:
|
||||
for line in f:
|
||||
line = line.strip()
|
||||
|
||||
# is this a config line?
|
||||
match = re.match(r'^QCFG\((.+), (.+)\)', line)
|
||||
if match:
|
||||
value = match.group(2)
|
||||
if value[0] == '(' and value[-1] == ')':
|
||||
# strip parenthesis from config value
|
||||
value = value[1:-1]
|
||||
qcfgs[match.group(1)] = value
|
||||
continue
|
||||
|
||||
# is this a QSTR line?
|
||||
match = re.match(r'^Q\((.+)\)$', line.strip())
|
||||
match = re.match(r'^Q\((.*)\)$', line)
|
||||
if not match:
|
||||
continue
|
||||
|
||||
@@ -63,11 +76,13 @@ def do_work(infiles):
|
||||
# process the qstrs, printing out 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" "")')
|
||||
for order, ident, qstr in sorted(qstrs.values(), key=lambda x: x[0]):
|
||||
qhash = compute_hash(qstr)
|
||||
qlen = len(qstr)
|
||||
qdata = qstr.replace('"', '\\"')
|
||||
print('Q(%s, (const byte*)"\\x%02x\\x%02x\\x%02x\\x%02x" "%s")' % (ident, qhash & 0xff, (qhash >> 8) & 0xff, qlen & 0xff, (qlen >> 8) & 0xff, qdata))
|
||||
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))
|
||||
|
||||
return True
|
||||
|
||||
|
||||
Reference in New Issue
Block a user