py/persistentcode: Decouple native code loading from emitters' presence.

This commit lets the interpreter load MPY files containing native code
even if the target platform does not have a native emitter, or if native
code generation is disabled.

Native code loading has been tied to native code generation being
enabled as a discriminant to allow said operation.  This blocks native
code loading on platforms that could benefit from such a thing but they
don't (and probably won't) have a native code generation target written
for them (ie. AArch64 and RISC-V 64).  This also forces a firmware image
to have a full native code compiler present even if it doesn't need to
generate anything, as native modules already have all the code they will
ever need to load.

There is a new configuration setting,
MICROPY_PERSISTENT_CODE_LOAD_NATIVE, that if enabled it will allow
loading native code modules even if code generation
(MICROPY_EMIT_<platform> and MICROPY_EMIT_INLINE_<platform>) is
explicitly turned off.

Signed-off-by: Alessandro Gatti <a.gatti@frob.it>
This commit is contained in:
Alessandro Gatti
2025-12-20 07:13:51 +01:00
parent 6341258207
commit b0f3ecd96c
11 changed files with 41 additions and 36 deletions

View File

@@ -53,7 +53,7 @@ typedef struct _mp_obj_fun_asm_t {
mp_obj_t mp_obj_new_fun_bc(const mp_obj_t *def_args, const byte *code, const mp_module_context_t *cm, struct _mp_raw_code_t *const *raw_code_table);
void mp_obj_fun_bc_attr(mp_obj_t self_in, qstr attr, mp_obj_t *dest);
#if MICROPY_EMIT_NATIVE
#if MICROPY_ENABLE_NATIVE_CODE
static inline mp_obj_t mp_obj_new_fun_native(const mp_obj_t *def_args, const void *fun_data, const mp_module_context_t *mc, struct _mp_raw_code_t *const *child_table) {
mp_obj_fun_bc_t *o = (mp_obj_fun_bc_t *)MP_OBJ_TO_PTR(mp_obj_new_fun_bc(def_args, (const byte *)fun_data, mc, child_table));