Skip to content

Commit f506bf3

Browse files
committed
py/bc: Remove unused mp_opcode_format function.
This was made redundant by f2040bf, which also did not update this function for the change to qstr-opcode encoding, so it does not work correctly anyway. Signed-off-by: Damien George <damien@micropython.org>
1 parent b37b578 commit f506bf3

3 files changed

Lines changed: 0 additions & 62 deletions

File tree

py/bc.c

Lines changed: 0 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -337,35 +337,3 @@ void mp_setup_code_state_native(mp_code_state_native_t *code_state, size_t n_arg
337337
mp_setup_code_state_helper((mp_code_state_t *)code_state, n_args, n_kw, args);
338338
}
339339
#endif
340-
341-
#if MICROPY_PERSISTENT_CODE_LOAD || MICROPY_PERSISTENT_CODE_SAVE
342-
343-
// The following table encodes the number of bytes that a specific opcode
344-
// takes up. Some opcodes have an extra byte, defined by MP_BC_MASK_EXTRA_BYTE.
345-
uint mp_opcode_format(const byte *ip, size_t *opcode_size, bool count_var_uint) {
346-
uint f = MP_BC_FORMAT(*ip);
347-
const byte *ip_start = ip;
348-
if (f == MP_BC_FORMAT_QSTR) {
349-
ip += 3;
350-
} else {
351-
int extra_byte = (*ip & MP_BC_MASK_EXTRA_BYTE) == 0;
352-
ip += 1;
353-
if (f == MP_BC_FORMAT_VAR_UINT) {
354-
if (count_var_uint) {
355-
while ((*ip++ & 0x80) != 0) {
356-
}
357-
}
358-
} else if (f == MP_BC_FORMAT_OFFSET) {
359-
if ((*ip & 0x80) == 0) {
360-
ip += 1;
361-
} else {
362-
ip += 2;
363-
}
364-
}
365-
ip += extra_byte;
366-
}
367-
*opcode_size = ip - ip_start;
368-
return f;
369-
}
370-
371-
#endif // MICROPY_PERSISTENT_CODE_LOAD || MICROPY_PERSISTENT_CODE_SAVE

py/bc.h

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -292,12 +292,6 @@ const byte *mp_bytecode_print_str(const mp_print_t *print, const byte *ip_start,
292292
#define MP_TAGPTR_TAG1(x) ((uintptr_t)(x) & 2)
293293
#define MP_TAGPTR_MAKE(ptr, tag) ((void *)((uintptr_t)(ptr) | (tag)))
294294

295-
#if MICROPY_PERSISTENT_CODE_LOAD || MICROPY_PERSISTENT_CODE_SAVE
296-
297-
uint mp_opcode_format(const byte *ip, size_t *opcode_size, bool count_var_uint);
298-
299-
#endif
300-
301295
static inline void mp_module_context_alloc_tables(mp_module_context_t *context, size_t n_qstr, size_t n_obj) {
302296
#if MICROPY_EMIT_BYTECODE_USES_QSTR_TABLE
303297
size_t nq = (n_qstr * sizeof(qstr_short_t) + sizeof(mp_uint_t) - 1) / sizeof(mp_uint_t);

tools/mpy-tool.py

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -326,30 +326,6 @@ def mp_small_int_fits(i):
326326
return -0x2000 <= i <= 0x1FFF
327327

328328

329-
# this function mirrors that in py/bc.c
330-
def mp_opcode_format(bytecode, ip, count_var_uint):
331-
opcode = bytecode[ip]
332-
ip_start = ip
333-
f = (0x000003A4 >> (2 * ((opcode) >> 4))) & 3
334-
if f == MP_BC_FORMAT_QSTR:
335-
ip += 3
336-
else:
337-
extra_byte = (opcode & MP_BC_MASK_EXTRA_BYTE) == 0
338-
ip += 1
339-
if f == MP_BC_FORMAT_VAR_UINT:
340-
if count_var_uint:
341-
while bytecode[ip] & 0x80 != 0:
342-
ip += 1
343-
ip += 1
344-
elif f == MP_BC_FORMAT_OFFSET:
345-
if bytecode[ip] & 0x80 == 0:
346-
ip += 1
347-
else:
348-
ip += 2
349-
ip += extra_byte
350-
return f, ip - ip_start
351-
352-
353329
def mp_opcode_decode(bytecode, ip):
354330
opcode = bytecode[ip]
355331
ip_start = ip

0 commit comments

Comments
 (0)