summaryrefslogtreecommitdiffstatshomepage
path: root/tools
diff options
context:
space:
mode:
authorDamien George <damien@micropython.org>2024-03-19 10:04:29 +1100
committerDamien George <damien@micropython.org>2024-03-19 10:08:05 +1100
commitbf18ddd98930787c22b561884e0b3807b47d412b (patch)
treed0b6807f02792af20332d1cf32d84eef64529397 /tools
parent7dff38fdc190d7b731fad8319d2ae8aa13fde18a (diff)
downloadmicropython-bf18ddd98930787c22b561884e0b3807b47d412b.tar.gz
micropython-bf18ddd98930787c22b561884e0b3807b47d412b.zip
tools/mpy-tool.py: Fix merging of more than 128 mpy files.
The argument to MP_BC_MAKE_FUNCTION (raw code index) was being encoded as a byte instead of a variable unsigned int. That meant that if there were more than 128 merged mpy files the encoding would be invalid. Fix that by using `mp_encode_uint(idx)` to encode the raw code index. And also use `Opcode` constants for the opcode values to make it easier to understand the code. Signed-off-by: Damien George <damien@micropython.org>
Diffstat (limited to 'tools')
-rwxr-xr-xtools/mpy-tool.py11
1 files changed, 7 insertions, 4 deletions
diff --git a/tools/mpy-tool.py b/tools/mpy-tool.py
index 35c06a3028..06ccd6a1da 100755
--- a/tools/mpy-tool.py
+++ b/tools/mpy-tool.py
@@ -1730,10 +1730,13 @@ def merge_mpy(compiled_modules, output_file):
bytecode.append(0b00000010) # prelude size (n_info=1, n_cell=0)
bytecode.extend(b"\x00") # simple_name: qstr index 0 (will use source filename)
for idx in range(len(compiled_modules)):
- bytecode.append(0x32) # MP_BC_MAKE_FUNCTION
- bytecode.append(idx) # index raw code
- bytecode.extend(b"\x34\x00\x59") # MP_BC_CALL_FUNCTION, 0 args, MP_BC_POP_TOP
- bytecode.extend(b"\x51\x63") # MP_BC_LOAD_NONE, MP_BC_RETURN_VALUE
+ bytecode.append(Opcode.MP_BC_MAKE_FUNCTION)
+ bytecode.extend(mp_encode_uint(idx)) # index of raw code
+ bytecode.append(Opcode.MP_BC_CALL_FUNCTION)
+ bytecode.append(0) # 0 arguments
+ bytecode.append(Opcode.MP_BC_POP_TOP)
+ bytecode.append(Opcode.MP_BC_LOAD_CONST_NONE)
+ bytecode.append(Opcode.MP_BC_RETURN_VALUE)
merged_mpy.extend(mp_encode_uint(len(bytecode) << 3 | 1 << 2)) # length, has_children
merged_mpy.extend(bytecode)