py/persistentcode: Fix compilation with load and save both enabled.
With both MICROPY_PERSISTENT_CODE_SAVE and MICROPY_PERSISTENT_CODE_LOAD enabled the code fails to compile, due to undeclared 'n_obj'. If MICROPY_EMIT_NATIVE is disabled there are more errors due to the use of undefined fields in mp_raw_code_t. This patch fixes such compilation by avoiding undefined fields. MICROPY_EMIT_NATIVE was changed to MICROPY_EMIT_MACHINE_CODE in this file to match the mp_raw_code_t definition.
This commit is contained in:
parent
b152bbddd1
commit
d165a401dc
|
@ -157,7 +157,7 @@ typedef struct _bytecode_prelude_t {
|
||||||
uint code_info_size;
|
uint code_info_size;
|
||||||
} bytecode_prelude_t;
|
} bytecode_prelude_t;
|
||||||
|
|
||||||
#if MICROPY_PERSISTENT_CODE_SAVE || MICROPY_EMIT_NATIVE
|
#if MICROPY_PERSISTENT_CODE_SAVE || MICROPY_EMIT_MACHINE_CODE
|
||||||
|
|
||||||
// ip will point to start of opcodes
|
// ip will point to start of opcodes
|
||||||
// ip2 will point to simple_name, source_file qstrs
|
// ip2 will point to simple_name, source_file qstrs
|
||||||
|
@ -183,7 +183,7 @@ STATIC void extract_prelude(const byte **ip, const byte **ip2, bytecode_prelude_
|
||||||
|
|
||||||
#include "py/parsenum.h"
|
#include "py/parsenum.h"
|
||||||
|
|
||||||
#if MICROPY_EMIT_NATIVE
|
#if MICROPY_EMIT_MACHINE_CODE
|
||||||
|
|
||||||
#if MICROPY_EMIT_THUMB
|
#if MICROPY_EMIT_THUMB
|
||||||
STATIC void asm_thumb_rewrite_mov(uint8_t *pc, uint16_t val) {
|
STATIC void asm_thumb_rewrite_mov(uint8_t *pc, uint16_t val) {
|
||||||
|
@ -327,7 +327,7 @@ STATIC mp_raw_code_t *load_raw_code(mp_reader_t *reader, qstr_window_t *qw) {
|
||||||
int kind = (kind_len & 3) + MP_CODE_BYTECODE;
|
int kind = (kind_len & 3) + MP_CODE_BYTECODE;
|
||||||
size_t fun_data_len = kind_len >> 2;
|
size_t fun_data_len = kind_len >> 2;
|
||||||
|
|
||||||
#if !MICROPY_EMIT_NATIVE
|
#if !MICROPY_EMIT_MACHINE_CODE
|
||||||
if (kind != MP_CODE_BYTECODE) {
|
if (kind != MP_CODE_BYTECODE) {
|
||||||
mp_raise_ValueError("incompatible .mpy file");
|
mp_raise_ValueError("incompatible .mpy file");
|
||||||
}
|
}
|
||||||
|
@ -336,7 +336,7 @@ STATIC mp_raw_code_t *load_raw_code(mp_reader_t *reader, qstr_window_t *qw) {
|
||||||
uint8_t *fun_data = NULL;
|
uint8_t *fun_data = NULL;
|
||||||
byte *ip2;
|
byte *ip2;
|
||||||
bytecode_prelude_t prelude = {0};
|
bytecode_prelude_t prelude = {0};
|
||||||
#if MICROPY_EMIT_NATIVE
|
#if MICROPY_EMIT_MACHINE_CODE
|
||||||
size_t prelude_offset;
|
size_t prelude_offset;
|
||||||
mp_uint_t type_sig = 0;
|
mp_uint_t type_sig = 0;
|
||||||
size_t n_qstr_link = 0;
|
size_t n_qstr_link = 0;
|
||||||
|
@ -353,7 +353,7 @@ STATIC mp_raw_code_t *load_raw_code(mp_reader_t *reader, qstr_window_t *qw) {
|
||||||
// Load bytecode
|
// Load bytecode
|
||||||
load_bytecode(reader, qw, ip, fun_data + fun_data_len);
|
load_bytecode(reader, qw, ip, fun_data + fun_data_len);
|
||||||
|
|
||||||
#if MICROPY_EMIT_NATIVE
|
#if MICROPY_EMIT_MACHINE_CODE
|
||||||
} else {
|
} else {
|
||||||
// Allocate memory for native data and load it
|
// Allocate memory for native data and load it
|
||||||
size_t fun_alloc;
|
size_t fun_alloc;
|
||||||
|
@ -404,13 +404,16 @@ STATIC mp_raw_code_t *load_raw_code(mp_reader_t *reader, qstr_window_t *qw) {
|
||||||
ip2[2] = source_file; ip2[3] = source_file >> 8;
|
ip2[2] = source_file; ip2[3] = source_file >> 8;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
size_t n_obj = 0;
|
||||||
|
size_t n_raw_code = 0;
|
||||||
mp_uint_t *const_table = NULL;
|
mp_uint_t *const_table = NULL;
|
||||||
|
|
||||||
if (kind != MP_CODE_NATIVE_ASM) {
|
if (kind != MP_CODE_NATIVE_ASM) {
|
||||||
// Load constant table for bytecode, native and viper
|
// Load constant table for bytecode, native and viper
|
||||||
|
|
||||||
// Number of entries in constant table
|
// Number of entries in constant table
|
||||||
size_t n_obj = read_uint(reader, NULL);
|
n_obj = read_uint(reader, NULL);
|
||||||
size_t n_raw_code = read_uint(reader, NULL);
|
n_raw_code = read_uint(reader, NULL);
|
||||||
|
|
||||||
// Allocate constant table
|
// Allocate constant table
|
||||||
size_t n_alloc = prelude.n_pos_args + prelude.n_kwonly_args + n_obj + n_raw_code;
|
size_t n_alloc = prelude.n_pos_args + prelude.n_kwonly_args + n_obj + n_raw_code;
|
||||||
|
@ -426,7 +429,7 @@ STATIC mp_raw_code_t *load_raw_code(mp_reader_t *reader, qstr_window_t *qw) {
|
||||||
*ct++ = (mp_uint_t)MP_OBJ_NEW_QSTR(load_qstr(reader, qw));
|
*ct++ = (mp_uint_t)MP_OBJ_NEW_QSTR(load_qstr(reader, qw));
|
||||||
}
|
}
|
||||||
|
|
||||||
#if MICROPY_EMIT_NATIVE
|
#if MICROPY_EMIT_MACHINE_CODE
|
||||||
if (kind != MP_CODE_BYTECODE) {
|
if (kind != MP_CODE_BYTECODE) {
|
||||||
// Populate mp_fun_table entry
|
// Populate mp_fun_table entry
|
||||||
*ct++ = (mp_uint_t)(uintptr_t)mp_fun_table;
|
*ct++ = (mp_uint_t)(uintptr_t)mp_fun_table;
|
||||||
|
@ -455,7 +458,7 @@ STATIC mp_raw_code_t *load_raw_code(mp_reader_t *reader, qstr_window_t *qw) {
|
||||||
#endif
|
#endif
|
||||||
prelude.scope_flags);
|
prelude.scope_flags);
|
||||||
|
|
||||||
#if MICROPY_EMIT_NATIVE
|
#if MICROPY_EMIT_MACHINE_CODE
|
||||||
} else {
|
} else {
|
||||||
#if defined(MP_PLAT_COMMIT_EXEC)
|
#if defined(MP_PLAT_COMMIT_EXEC)
|
||||||
fun_data = MP_PLAT_COMMIT_EXEC(fun_data, fun_data_len);
|
fun_data = MP_PLAT_COMMIT_EXEC(fun_data, fun_data_len);
|
||||||
|
@ -626,6 +629,7 @@ STATIC void save_raw_code(mp_print_t *print, mp_raw_code_t *rc, qstr_window_t *q
|
||||||
|
|
||||||
// Save bytecode
|
// Save bytecode
|
||||||
save_bytecode(print, qstr_window, ip, ip_top);
|
save_bytecode(print, qstr_window, ip, ip_top);
|
||||||
|
#if MICROPY_EMIT_MACHINE_CODE
|
||||||
} else {
|
} else {
|
||||||
// Save native code
|
// Save native code
|
||||||
mp_print_bytes(print, rc->fun_data, rc->fun_data_len);
|
mp_print_bytes(print, rc->fun_data, rc->fun_data_len);
|
||||||
|
@ -654,6 +658,7 @@ STATIC void save_raw_code(mp_print_t *print, mp_raw_code_t *rc, qstr_window_t *q
|
||||||
mp_print_uint(print, rc->type_sig);
|
mp_print_uint(print, rc->type_sig);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
if (rc->kind == MP_CODE_BYTECODE || rc->kind == MP_CODE_NATIVE_PY) {
|
if (rc->kind == MP_CODE_BYTECODE || rc->kind == MP_CODE_NATIVE_PY) {
|
||||||
|
|
Loading…
Reference in New Issue