summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--mpy-cross/main.c9
-rw-r--r--py/emitnative.c4
-rw-r--r--py/mpstate.h1
3 files changed, 14 insertions, 0 deletions
diff --git a/mpy-cross/main.c b/mpy-cross/main.c
index afd24ca9f..be43598c5 100644
--- a/mpy-cross/main.c
+++ b/mpy-cross/main.c
@@ -209,12 +209,16 @@ MP_NOINLINE int main_(int argc, char **argv) {
mp_dynamic_compiler.py_builtins_str_unicode = 1;
#if defined(__i386__)
mp_dynamic_compiler.native_arch = MP_NATIVE_ARCH_X86;
+ mp_dynamic_compiler.nlr_buf_num_regs = MICROPY_NLR_NUM_REGS_X86;
#elif defined(__x86_64__)
mp_dynamic_compiler.native_arch = MP_NATIVE_ARCH_X64;
+ mp_dynamic_compiler.nlr_buf_num_regs = MAX(MICROPY_NLR_NUM_REGS_X64, MICROPY_NLR_NUM_REGS_X64_WIN);
#elif defined(__arm__) && !defined(__thumb2__)
mp_dynamic_compiler.native_arch = MP_NATIVE_ARCH_ARMV6;
+ mp_dynamic_compiler.nlr_buf_num_regs = MICROPY_NLR_NUM_REGS_ARM_THUMB_FP;
#else
mp_dynamic_compiler.native_arch = MP_NATIVE_ARCH_NONE;
+ mp_dynamic_compiler.nlr_buf_num_regs = 0;
#endif
const char *input_file = NULL;
@@ -271,14 +275,19 @@ MP_NOINLINE int main_(int argc, char **argv) {
const char *arch = argv[a] + sizeof("-march=") - 1;
if (strcmp(arch, "x86") == 0) {
mp_dynamic_compiler.native_arch = MP_NATIVE_ARCH_X86;
+ mp_dynamic_compiler.nlr_buf_num_regs = MICROPY_NLR_NUM_REGS_X86;
} else if (strcmp(arch, "x64") == 0) {
mp_dynamic_compiler.native_arch = MP_NATIVE_ARCH_X64;
+ mp_dynamic_compiler.nlr_buf_num_regs = MAX(MICROPY_NLR_NUM_REGS_X64, MICROPY_NLR_NUM_REGS_X64_WIN);
} else if (strcmp(arch, "armv6") == 0) {
mp_dynamic_compiler.native_arch = MP_NATIVE_ARCH_ARMV6;
+ mp_dynamic_compiler.nlr_buf_num_regs = MICROPY_NLR_NUM_REGS_ARM_THUMB_FP;
} else if (strcmp(arch, "armv7m") == 0) {
mp_dynamic_compiler.native_arch = MP_NATIVE_ARCH_ARMV7M;
+ mp_dynamic_compiler.nlr_buf_num_regs = MICROPY_NLR_NUM_REGS_ARM_THUMB_FP;
} else if (strcmp(arch, "xtensa") == 0) {
mp_dynamic_compiler.native_arch = MP_NATIVE_ARCH_XTENSA;
+ mp_dynamic_compiler.nlr_buf_num_regs = MICROPY_NLR_NUM_REGS_XTENSA;
} else {
return usage(argv);
}
diff --git a/py/emitnative.c b/py/emitnative.c
index c701e132a..760c7fb0c 100644
--- a/py/emitnative.c
+++ b/py/emitnative.c
@@ -81,7 +81,11 @@
// (L0-L2 may be in regs instead)
// Native emitter needs to know the following sizes and offsets of C structs (on the target):
+#if MICROPY_DYNAMIC_COMPILER
+#define SIZEOF_NLR_BUF (2 + mp_dynamic_compiler.nlr_buf_num_regs + 1) // the +1 is conservative in case MICROPY_ENABLE_PYSTACK enabled
+#else
#define SIZEOF_NLR_BUF (sizeof(nlr_buf_t) / sizeof(uintptr_t))
+#endif
#define SIZEOF_CODE_STATE (sizeof(mp_code_state_t) / sizeof(uintptr_t))
#define OFFSETOF_CODE_STATE_STATE (offsetof(mp_code_state_t, state) / sizeof(uintptr_t))
#define OFFSETOF_CODE_STATE_FUN_BC (offsetof(mp_code_state_t, fun_bc) / sizeof(uintptr_t))
diff --git a/py/mpstate.h b/py/mpstate.h
index aba32084d..0f9c56d2c 100644
--- a/py/mpstate.h
+++ b/py/mpstate.h
@@ -47,6 +47,7 @@ typedef struct mp_dynamic_compiler_t {
bool opt_cache_map_lookup_in_bytecode;
bool py_builtins_str_unicode;
uint8_t native_arch;
+ uint8_t nlr_buf_num_regs;
} mp_dynamic_compiler_t;
extern mp_dynamic_compiler_t mp_dynamic_compiler;
#endif