8000 tools/mpy-tool.py: Add support for OPT_CACHE_MAP_LOOKUP_IN_BYTECODE. · rch/micropython@98458a4 · GitHub
[go: up one dir, main page]

Skip to content

Commit 98458a4

Browse files
committed
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).
1 parent 343b418 commit 98458a4

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

tools/mpy-tool.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -258,7 +258,10 @@ def freeze(self, parent_name):
258258
# generate bytecode data
259259
print()
260260
print('// frozen bytecode for file %s, scope %s%s' % (self.source_file.str, parent_name, self.simple_name.str))
261-
print('STATIC const byte bytecode_data_%s[%u] = {' % (self.escaped_name, len(self.bytecode)))
261+
print('STATIC ', end='')
262+
if not config.MICROPY_OPT_CACHE_MAP_LOOKUP_IN_BYTECODE:
263+
print('const ', end='')
264+
print('byte bytecode_data_%s[%u] = {' % (self.escaped_name, len(self.bytecode)))
262265
print(' ', end='')
263266
for i in range(self.ip2):
264267
print(' 0x%02x,' % self.bytecode[i], end='')
@@ -463,8 +466,8 @@ def freeze_mpy(base_qstrs, raw_codes):
463466
print('#include "py/emitglue.h"')
464467
print()
465468

466-
print('#if MICROPY_OPT_CACHE_MAP_LOOKUP_IN_BYTECODE')
467-
print('#error "MICROPY_OPT_CACHE_MAP_LOOKUP_IN_BYTECODE not supported with frozen mpy files"')
469+
print('#if MICROPY_OPT_CACHE_MAP_LOOKUP_IN_BYTECODE != %u' % config.MICROPY_OPT_CACHE_MAP_LOOKUP_IN_BYTECODE)
470+
print('#error "incompatible MICROPY_OPT_CACHE_MAP_LOOKUP_IN_BYTECODE"')
468471
print('#endif')
469472
print()
470473

0 commit comments

Comments
 (0)
0