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>
This commit is contained in:
Jim Mussared 2022-11-16 14:53:03 +11:00
parent 5ef3aec33c
commit f31a358eb2
1 changed files with 15 additions and 11 deletions

View File

@ -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);
}