Commit b6a32895 authored by Damien George's avatar Damien George

tools/mpy-tool.py: Don't generate const_table if it's empty.

parent bfc2092d
...@@ -331,27 +331,29 @@ class RawCode: ...@@ -331,27 +331,29 @@ class RawCode:
# TODO # TODO
raise FreezeError(self, 'freezing of object %r is not implemented' % (obj,)) raise FreezeError(self, 'freezing of object %r is not implemented' % (obj,))
# generate constant table # generate constant table, if it has any entries
print('STATIC const mp_rom_obj_t const_table_data_%s[%u] = {' const_table_len = len(self.qstrs) + len(self.objs) + len(self.raw_codes)
% (self.escaped_name, len(self.qstrs) + len(self.objs) + len(self.raw_codes))) if const_table_len:
for qst in self.qstrs: print('STATIC const mp_rom_obj_t const_table_data_%s[%u] = {'
print(' MP_ROM_QSTR(%s),' % global_qstrs[qst].qstr_id) % (self.escaped_name, const_table_len))
for i in range(len(self.objs)): for qst in self.qstrs:
if type(self.objs[i]) is float: print(' MP_ROM_QSTR(%s),' % global_qstrs[qst].qstr_id)
print('#if MICROPY_OBJ_REPR == MICROPY_OBJ_REPR_A || MICROPY_OBJ_REPR == MICROPY_OBJ_REPR_B') for i in range(len(self.objs)):
print(' MP_ROM_PTR(&const_obj_%s_%u),' % (self.escaped_name, i)) if type(self.objs[i]) is float:
print('#elif MICROPY_OBJ_REPR == MICROPY_OBJ_REPR_C') print('#if MICROPY_OBJ_REPR == MICROPY_OBJ_REPR_A || MICROPY_OBJ_REPR == MICROPY_OBJ_REPR_B')
n = struct.unpack('<I', struct.pack('<f', self.objs[i]))[0] print(' MP_ROM_PTR(&const_obj_%s_%u),' % (self.escaped_name, i))
n = ((n & ~0x3) | 2) + 0x80800000 print('#elif MICROPY_OBJ_REPR == MICROPY_OBJ_REPR_C')
print(' (mp_rom_obj_t)(0x%08x),' % (n,)) n = struct.unpack('<I', struct.pack('<f', self.objs[i]))[0]
print('#else') n = ((n & ~0x3) | 2) + 0x80800000
print('#error "MICROPY_OBJ_REPR_D not supported with floats in frozen mpy files"') print(' (mp_rom_obj_t)(0x%08x),' % (n,))
print('#endif') print('#else')
else: print('#error "MICROPY_OBJ_REPR_D not supported with floats in frozen mpy files"')
print(' MP_ROM_PTR(&const_obj_%s_%u),' % (self.escaped_name, i)) print('#endif')
for rc in self.raw_codes: else:
print(' MP_ROM_PTR(&raw_code_%s),' % rc.escaped_name) print(' MP_ROM_PTR(&const_obj_%s_%u),' % (self.escaped_name, i))
print('};') for rc in self.raw_codes:
print(' MP_ROM_PTR(&raw_code_%s),' % rc.escaped_name)
print('};')
# generate module # generate module
if self.simple_name.str != '<module>': if self.simple_name.str != '<module>':
...@@ -362,7 +364,10 @@ class RawCode: ...@@ -362,7 +364,10 @@ class RawCode:
print(' .n_pos_args = %u,' % self.prelude[3]) print(' .n_pos_args = %u,' % self.prelude[3])
print(' .data.u_byte = {') print(' .data.u_byte = {')
print(' .bytecode = bytecode_data_%s,' % self.escaped_name) print(' .bytecode = bytecode_data_%s,' % self.escaped_name)
print(' .const_table = (mp_uint_t*)const_table_data_%s,' % self.escaped_name) if const_table_len:
print(' .const_table = (mp_uint_t*)const_table_data_%s,' % self.escaped_name)
else:
print(' .const_table = NULL,')
print(' #if MICROPY_PERSISTENT_CODE_SAVE') print(' #if MICROPY_PERSISTENT_CODE_SAVE')
print(' .bc_len = %u,' % len(self.bytecode)) print(' .bc_len = %u,' % len(self.bytecode))
print(' .n_obj = %u,' % len(self.objs)) print(' .n_obj = %u,' % len(self.objs))
......
Markdown is supported
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