summaryrefslogtreecommitdiff
path: root/py/makeqstrdata.py
diff options
context:
space:
mode:
authorDamien George <damien.p.george@gmail.com>2015-01-11 17:52:45 +0000
committerDamien George <damien.p.george@gmail.com>2015-01-11 22:06:53 +0000
commit6942f80a8feb521ff4dc2b457fa5cb3d039bee54 (patch)
tree586870b58e8930480f8ec63263ecec551b15477e /py/makeqstrdata.py
parente233a55a296a981bce5fe3a7c20049bea46e3a16 (diff)
py: Add qstr cfg capability; generate QSTR_NULL and QSTR_ from script.
Diffstat (limited to 'py/makeqstrdata.py')
-rw-r--r--py/makeqstrdata.py19
1 files changed, 17 insertions, 2 deletions
diff --git a/py/makeqstrdata.py b/py/makeqstrdata.py
index f5ce2778a..c8e998ed1 100644
--- a/py/makeqstrdata.py
+++ b/py/makeqstrdata.py
@@ -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