Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

py: Fix compilation of persistentcode with uncommon configs #4753

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 2 additions & 2 deletions py/asmbase.c
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
#include "py/misc.h"
#include "py/asmbase.h"

#if MICROPY_EMIT_NATIVE || MICROPY_EMIT_INLINE_ASM
#if MICROPY_EMIT_ANY_ASM

void mp_asm_base_init(mp_asm_base_t *as, size_t max_num_labels) {
as->max_num_labels = max_num_labels;
Expand Down Expand Up @@ -99,4 +99,4 @@ void mp_asm_base_data(mp_asm_base_t* as, unsigned int bytesize, uintptr_t val) {
}
}

#endif // MICROPY_EMIT_NATIVE || MICROPY_EMIT_INLINE_ASM
#endif // MICROPY_EMIT_ANY_ASM
2 changes: 1 addition & 1 deletion py/emitglue.c
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ void mp_emit_glue_assign_bytecode(mp_raw_code_t *rc, const byte *code,
#endif
}

#if MICROPY_EMIT_NATIVE || MICROPY_EMIT_INLINE_ASM
#if MICROPY_EMIT_ANY_ASM
void mp_emit_glue_assign_native(mp_raw_code_t *rc, mp_raw_code_kind_t kind, void *fun_data, mp_uint_t fun_len, const mp_uint_t *const_table,
#if MICROPY_PERSISTENT_CODE_SAVE
uint16_t prelude_offset,
Expand Down
4 changes: 2 additions & 2 deletions py/emitglue.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,13 +63,13 @@ typedef struct _mp_raw_code_t {
size_t fun_data_len;
uint16_t n_obj;
uint16_t n_raw_code;
#if MICROPY_EMIT_NATIVE || MICROPY_EMIT_INLINE_ASM
#if MICROPY_EMIT_ANY_ASM
uint16_t prelude_offset;
uint16_t n_qstr;
mp_qstr_link_entry_t *qstr_link;
#endif
#endif
#if MICROPY_EMIT_NATIVE || MICROPY_EMIT_INLINE_ASM
#if MICROPY_EMIT_ANY_ASM
mp_uint_t type_sig; // for viper, compressed as 2-bit types; ret is MSB, then arg0, arg1, etc
#endif
} mp_raw_code_t;
Expand Down
3 changes: 3 additions & 0 deletions py/mpconfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -329,6 +329,9 @@
// Convenience definition for whether any inline assembler emitter is enabled
#define MICROPY_EMIT_INLINE_ASM (MICROPY_EMIT_INLINE_THUMB || MICROPY_EMIT_INLINE_XTENSA)

// Convenience definition for whether any native or inline assembler emitter is enabled
#define MICROPY_EMIT_ANY_ASM (MICROPY_EMIT_NATIVE || MICROPY_EMIT_INLINE_ASM)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, it's probably a good idea to make this define. But, I'm just thinking if there's a better name for it, because "any asm" could be mistaken for meaning "any inline asm" (which is already what MICROPY_EMIT_INLINE_ASM is for).

Maybe MICROPY_EMIT_MACHINE_CODE?


/*****************************************************************************/
/* Compiler configuration */

Expand Down
2 changes: 1 addition & 1 deletion py/nativeglue.c
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ mp_uint_t mp_native_from_obj(mp_obj_t obj, mp_uint_t type) {

#endif

#if MICROPY_EMIT_NATIVE || MICROPY_EMIT_INLINE_ASM
#if MICROPY_EMIT_ANY_ASM

// convert a native value to a MicroPython object based on type
mp_obj_t mp_native_to_obj(mp_uint_t val, mp_uint_t type) {
Expand Down
23 changes: 14 additions & 9 deletions py/persistentcode.c
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ typedef struct _bytecode_prelude_t {
uint code_info_size;
} bytecode_prelude_t;

#if MICROPY_PERSISTENT_CODE_SAVE || MICROPY_EMIT_NATIVE
#if MICROPY_PERSISTENT_CODE_SAVE || MICROPY_EMIT_ANY_ASM

// ip will point to start of opcodes
// ip2 will point to simple_name, source_file qstrs
Expand All @@ -186,7 +186,7 @@ STATIC void extract_prelude(const byte **ip, const byte **ip2, bytecode_prelude_

#include "py/parsenum.h"

#if MICROPY_EMIT_NATIVE
#if MICROPY_EMIT_ANY_ASM

#if MICROPY_EMIT_THUMB
STATIC void asm_thumb_rewrite_mov(uint8_t *pc, uint16_t val) {
Expand Down Expand Up @@ -330,7 +330,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;
size_t fun_data_len = kind_len >> 2;

#if !MICROPY_EMIT_NATIVE
#if !MICROPY_EMIT_ANY_ASM
if (kind != MP_CODE_BYTECODE) {
mp_raise_ValueError("incompatible .mpy file");
}
Expand All @@ -339,7 +339,7 @@ STATIC mp_raw_code_t *load_raw_code(mp_reader_t *reader, qstr_window_t *qw) {
uint8_t *fun_data = NULL;
byte *ip2;
bytecode_prelude_t prelude = {0};
#if MICROPY_EMIT_NATIVE
#if MICROPY_EMIT_ANY_ASM
size_t prelude_offset;
mp_uint_t type_sig = 0;
size_t n_qstr_link = 0;
Expand All @@ -356,7 +356,7 @@ STATIC mp_raw_code_t *load_raw_code(mp_reader_t *reader, qstr_window_t *qw) {
// Load bytecode
load_bytecode(reader, qw, ip, fun_data + fun_data_len);

#if MICROPY_EMIT_NATIVE
#if MICROPY_EMIT_ANY_ASM
} else {
// Allocate memory for native data and load it
size_t fun_alloc;
Expand Down Expand Up @@ -407,13 +407,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;
}

size_t n_obj = 0;
size_t n_raw_code = 0;
quark-zju marked this conversation as resolved.
Show resolved Hide resolved
mp_uint_t *const_table = NULL;

if (kind != MP_CODE_NATIVE_ASM) {
// Load constant table for bytecode, native and viper

// Number of entries in constant table
size_t n_obj = read_uint(reader, NULL);
size_t n_raw_code = read_uint(reader, NULL);
n_obj = read_uint(reader, NULL);
n_raw_code = read_uint(reader, NULL);

// Allocate constant table
size_t n_alloc = prelude.n_pos_args + prelude.n_kwonly_args + n_obj + n_raw_code;
Expand All @@ -429,7 +432,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));
}

#if MICROPY_EMIT_NATIVE
#if MICROPY_EMIT_ANY_ASM
if (kind != MP_CODE_BYTECODE) {
// Populate mp_fun_table entry
*ct++ = (mp_uint_t)(uintptr_t)mp_fun_table;
Expand Down Expand Up @@ -458,7 +461,7 @@ STATIC mp_raw_code_t *load_raw_code(mp_reader_t *reader, qstr_window_t *qw) {
#endif
prelude.scope_flags);

#if MICROPY_EMIT_NATIVE
#if MICROPY_EMIT_ANY_ASM
} else {
#if defined(MP_PLAT_COMMIT_EXEC)
fun_data = MP_PLAT_COMMIT_EXEC(fun_data, fun_data_len);
Expand Down Expand Up @@ -629,6 +632,7 @@ STATIC void save_raw_code(mp_print_t *print, mp_raw_code_t *rc, qstr_window_t *q

// Save bytecode
save_bytecode(print, qstr_window, ip, ip_top);
#if MICROPY_EMIT_ANY_ASM
} else {
// Save native code
quark-zju marked this conversation as resolved.
Show resolved Hide resolved
mp_print_bytes(print, rc->fun_data, rc->fun_data_len);
Expand Down Expand Up @@ -657,6 +661,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);
}
}
#endif
}

if (rc->kind == MP_CODE_BYTECODE || rc->kind == MP_CODE_NATIVE_PY) {
Expand Down
4 changes: 2 additions & 2 deletions tools/mpy-tool.py
Original file line number Diff line number Diff line change
Expand Up @@ -410,13 +410,13 @@ def freeze_module(self, qstr_links=(), type_sig=0):
print(' .fun_data_len = %u,' % len(self.bytecode))
print(' .n_obj = %u,' % len(self.objs))
print(' .n_raw_code = %u,' % len(self.raw_codes))
print(' #if MICROPY_EMIT_NATIVE || MICROPY_EMIT_INLINE_ASM')
print(' #if MICROPY_EMIT_ANY_ASM')
print(' .prelude_offset = %u,' % self.prelude_offset)
print(' .n_qstr = %u,' % len(qstr_links))
print(' .qstr_link = NULL,') # TODO
print(' #endif')
print(' #endif')
print(' #if MICROPY_EMIT_NATIVE || MICROPY_EMIT_INLINE_ASM')
print(' #if MICROPY_EMIT_ANY_ASM')
print(' .type_sig = %u,' % type_sig)
print(' #endif')
print('};')
Expand Down