mirror of
https://github.com/micropython/micropython.git
synced 2026-01-06 20:20:14 +01:00
mpy-cross/main: Add support for RV32 Zba opcodes.
This commit adds a new command line switch to inform the RV32 emitter to use Zba opcodes in its output. A new implementation-specific option was introduced, called "-march-flags", that will contain a list of additional architecture-specific flags to pass to the chosen native emitter implementation. At the moment only the RV32 emitter can make use of this command line facility: if the architecture flags string equals to "zba" (case-sensitive), then the native emitter will emit Zba opcodes if it has a chance to do so. At the moment there is no check on whether additional architecture flags using to build a MPY file are compatible with the target the output code is run on, so use this with caution. Signed-off-by: Alessandro Gatti <a.gatti@frob.it>
This commit is contained in:
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user