From f31a358eb222aac98f797bd51302d5b5b2711fb6 Mon Sep 17 00:00:00 2001 From: Jim Mussared Date: Wed, 16 Nov 2022 14:53:03 +1100 Subject: [PATCH] mpy-cross/main: Don't set a default native architecture. If `-march` isn't set then it means the user hasn't thought about it, or in the case of freezing, MPY_CROSS_FLAGS isn't set. It's almost certainly going to lead to problems, as there's no reason why the host architecture is likely to be the right choice. Compiling regular Python code is unaffected, but if `@native`/`@viper` is used, the compiler will raise `SyntaxError: invalid arch`. For situations where you explicitly want to use the host architecture (e.g. for running tests on the unix port), added -march=host that keeps the old behavior. This work was funded through GitHub Sponsors. Signed-off-by: Jim Mussared --- mpy-cross/main.c | 26 +++++++++++++++----------- 1 file changed, 15 insertions(+), 11 deletions(-) diff --git a/mpy-cross/main.c b/mpy-cross/main.c index 4975c8ddb2..55aefb65c1 100644 --- a/mpy-cross/main.c +++ b/mpy-cross/main.c @@ -203,19 +203,9 @@ MP_NOINLINE int main_(int argc, char **argv) { // set default compiler configuration mp_dynamic_compiler.small_int_bits = 31; - #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 + // don't support native emitter unless -march is specified mp_dynamic_compiler.native_arch = MP_NATIVE_ARCH_NONE; mp_dynamic_compiler.nlr_buf_num_regs = 0; - #endif const char *input_file = NULL; const char *output_file = NULL; @@ -292,6 +282,20 @@ MP_NOINLINE int main_(int argc, char **argv) { } else if (strcmp(arch, "xtensawin") == 0) { mp_dynamic_compiler.native_arch = MP_NATIVE_ARCH_XTENSAWIN; mp_dynamic_compiler.nlr_buf_num_regs = MICROPY_NLR_NUM_REGS_XTENSAWIN; + } else if (strcmp(arch, "host") == 0) { + #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_printf(&mp_stderr_print, "unable to determine host architecture for -march=host\n"); + exit(1); + #endif } else { return usage(argv); }