Skip to content
Snippets Groups Projects
Commit 98458a46 authored by Damien George's avatar Damien George
Browse files

tools/mpy-tool.py: Add support for OPT_CACHE_MAP_LOOKUP_IN_BYTECODE.

With caching of map lookups in the bytecode, frozen bytecode can still
work but must be stored in RAM, not ROM.  This patch allows mpy-tool.py to
generate code that works with this optimisation, but it's not recommended
to use it on embedded targets (because of lack of RAM).
parent 343b4189
Branches
No related tags found
No related merge requests found
...@@ -258,7 +258,10 @@ class RawCode: ...@@ -258,7 +258,10 @@ class RawCode:
# generate bytecode data # generate bytecode data
print() print()
print('// frozen bytecode for file %s, scope %s%s' % (self.source_file.str, parent_name, self.simple_name.str)) print('// frozen bytecode for file %s, scope %s%s' % (self.source_file.str, parent_name, self.simple_name.str))
print('STATIC const byte bytecode_data_%s[%u] = {' % (self.escaped_name, len(self.bytecode))) print('STATIC ', end='')
if not config.MICROPY_OPT_CACHE_MAP_LOOKUP_IN_BYTECODE:
print('const ', end='')
print('byte bytecode_data_%s[%u] = {' % (self.escaped_name, len(self.bytecode)))
print(' ', end='') print(' ', end='')
for i in range(self.ip2): for i in range(self.ip2):
print(' 0x%02x,' % self.bytecode[i], end='') print(' 0x%02x,' % self.bytecode[i], end='')
...@@ -463,8 +466,8 @@ def freeze_mpy(base_qstrs, raw_codes): ...@@ -463,8 +466,8 @@ def freeze_mpy(base_qstrs, raw_codes):
print('#include "py/emitglue.h"') print('#include "py/emitglue.h"')
print() print()
print('#if MICROPY_OPT_CACHE_MAP_LOOKUP_IN_BYTECODE') print('#if MICROPY_OPT_CACHE_MAP_LOOKUP_IN_BYTECODE != %u' % config.MICROPY_OPT_CACHE_MAP_LOOKUP_IN_BYTECODE)
print('#error "MICROPY_OPT_CACHE_MAP_LOOKUP_IN_BYTECODE not supported with frozen mpy files"') print('#error "incompatible MICROPY_OPT_CACHE_MAP_LOOKUP_IN_BYTECODE"')
print('#endif') print('#endif')
print() print()
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment