py/emitndebug: Add native debug emitter.

This emitter prints out pseudo-machine instructions, instead of the usual
output of the native emitter.  It can be enabled on any port via
`MICROPY_EMIT_NATIVE_DEBUG` (make sure other native emitters are disabled)
but the easiest way to use it is with mpy-cross:

    $ mpy-cross -march=debug file.py

Signed-off-by: Damien George <damien@micropython.org>
This commit is contained in:
Damien George
2024-03-07 11:38:27 +11:00
parent e2ae03e979
commit 9dbc787ce8
11 changed files with 315 additions and 4 deletions

View File

@@ -59,7 +59,7 @@
#endif
// wrapper around everything in this file
#if N_X64 || N_X86 || N_THUMB || N_ARM || N_XTENSA || N_XTENSAWIN || N_RV32
#if N_X64 || N_X86 || N_THUMB || N_ARM || N_XTENSA || N_XTENSAWIN || N_RV32 || N_DEBUG
// C stack layout for native functions:
// 0: nlr_buf_t [optional]
@@ -348,6 +348,8 @@ static void emit_native_mov_reg_state_addr(emit_t *emit, int reg_dest, int local
static void emit_native_mov_reg_qstr(emit_t *emit, int arg_reg, qstr qst) {
#if MICROPY_PERSISTENT_CODE_SAVE
ASM_LOAD16_REG_REG_OFFSET(emit->as, arg_reg, REG_QSTR_TABLE, mp_emit_common_use_qstr(emit->emit_common, qst));
#elif defined(ASM_MOV_REG_QSTR)
ASM_MOV_REG_QSTR(emit->as, arg_reg, qst);
#else
ASM_MOV_REG_IMM(emit->as, arg_reg, qst);
#endif
@@ -2604,6 +2606,8 @@ static void emit_native_binary_op(emit_t *emit, mp_binary_op_t op) {
default:
break;
}
#elif N_DEBUG
asm_debug_setcc_reg_reg_reg(emit->as, op_idx, REG_RET, REG_ARG_2, reg_rhs);
#else
#error not implemented
#endif