summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--mpy-cross/main.c33
1 files changed, 33 insertions, 0 deletions
diff --git a/mpy-cross/main.c b/mpy-cross/main.c
index 63a74d084..9dcad3c5d 100644
--- a/mpy-cross/main.c
+++ b/mpy-cross/main.c
@@ -40,6 +40,12 @@
#include "ports/windows/fmode.h"
#endif
+#if MICROPY_EMIT_NATIVE && MICROPY_EMIT_RV32
+#include "py/asmrv32.h"
+
+static asm_rv32_backend_options_t rv32_options = { 0 };
+#endif
+
// Command line options, with their defaults
static uint emit_opt = MP_EMIT_OPT_NONE;
mp_uint_t mp_verbose_flag = 0;
@@ -132,6 +138,8 @@ static int usage(char **argv) {
"-march=<arch> : set architecture for native emitter;\n"
" x86, x64, armv6, armv6m, armv7m, armv7em, armv7emsp,\n"
" armv7emdp, xtensa, xtensawin, rv32imc, rv64imc, host, debug\n"
+ "-march-flags=<flags> : set architecture-specific flags (OUTPUT FILE MAY NOT WORK ON ALL TARGETS!)\n"
+ " supported flags for rv32imc: zba\n"
"\n"
"Implementation specific options:\n", argv[0]
);
@@ -237,11 +245,13 @@ MP_NOINLINE int main_(int argc, char **argv) {
// 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;
+ mp_dynamic_compiler.backend_options = NULL;
const char *input_file = NULL;
const char *output_file = NULL;
const char *source_file = NULL;
bool option_parsing_active = true;
+ const char *arch_flags = NULL;
// parse main options
for (int a = 1; a < argc; a++) {
@@ -343,6 +353,8 @@ MP_NOINLINE int main_(int argc, char **argv) {
} else {
return usage(argv);
}
+ } else if (strncmp(argv[a], "-march-flags=", sizeof("-march-flags=") - 1) == 0) {
+ arch_flags = argv[a] + sizeof("-march-flags=") - 1;
} else if (strcmp(argv[a], "--") == 0) {
option_parsing_active = false;
} else {
@@ -357,6 +369,27 @@ MP_NOINLINE int main_(int argc, char **argv) {
}
}
+ if (arch_flags && mp_dynamic_compiler.native_arch != MP_NATIVE_ARCH_NONE) {
+ bool processed = false;
+ #if MICROPY_EMIT_NATIVE && MICROPY_EMIT_RV32
+ if (mp_dynamic_compiler.native_arch == MP_NATIVE_ARCH_RV32IMC) {
+ mp_dynamic_compiler.backend_options = (void *)&rv32_options;
+ if (strncmp(arch_flags, "zba", sizeof("zba") - 1) == 0) {
+ rv32_options.allowed_extensions |= RV32_EXT_ZBA;
+ processed = true;
+ }
+ }
+ #endif
+ if (!processed) {
+ mp_printf(&mp_stderr_print, "unrecognised arch flags\n");
+ exit(1);
+ }
+ mp_printf(&mp_stderr_print,
+ "WARNING: Using architecture-specific flags may create a MPY file whose code won't run on all targets!\n"
+ " Currently there are no checks in the module file loader for whether the chosen flags used to\n"
+ " build the MPY file are compatible with the running target.\n\n");
+ }
+
#if MICROPY_EMIT_NATIVE
if ((MP_STATE_VM(default_emit_opt) == MP_EMIT_OPT_NATIVE_PYTHON
|| MP_STATE_VM(default_emit_opt) == MP_EMIT_OPT_VIPER)