summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJim Mussared <jim.mussared@gmail.com>2022-11-16 14:53:03 +1100
committerJim Mussared <jim.mussared@gmail.com>2022-11-17 22:37:45 +1100
commitf31a358eb222aac98f797bd51302d5b5b2711fb6 (patch)
treeedade027f8d8618e980f48d91ec6046a997da936
parent5ef3aec33c457d535ae1cce8ff617d0c1cf52a90 (diff)
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 <jim.mussared@gmail.com>
-rw-r--r--mpy-cross/main.c26
1 files changed, 15 insertions, 11 deletions
diff --git a/mpy-cross/main.c b/mpy-cross/main.c
index 4975c8ddb..55aefb65c 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);
}