py/persistentcode: Make ARM Thumb archs support multiple sub-archs.

This commit is contained in:
Damien George 2019-11-30 23:00:56 +11:00
parent 42c1aed2bb
commit 9ac949cdbd
2 changed files with 27 additions and 10 deletions

View File

@ -526,9 +526,11 @@ mp_raw_code_t *mp_raw_code_load(mp_reader_t *reader) {
|| read_uint(reader, NULL) > QSTR_WINDOW_SIZE) {
mp_raise_ValueError("incompatible .mpy file");
}
if (MPY_FEATURE_DECODE_ARCH(header[2]) != MP_NATIVE_ARCH_NONE
&& MPY_FEATURE_DECODE_ARCH(header[2]) != MPY_FEATURE_ARCH) {
mp_raise_ValueError("incompatible .mpy arch");
if (MPY_FEATURE_DECODE_ARCH(header[2]) != MP_NATIVE_ARCH_NONE) {
byte arch = MPY_FEATURE_DECODE_ARCH(header[2]);
if (!MPY_FEATURE_ARCH_TEST(arch)) {
mp_raise_ValueError("incompatible .mpy arch");
}
}
qstr_window_t qw;
qw.idx = 0;

View File

@ -55,19 +55,34 @@
// Define the host architecture
#if MICROPY_EMIT_X86
#define MPY_FEATURE_ARCH (MP_NATIVE_ARCH_X86)
#define MPY_FEATURE_ARCH (MP_NATIVE_ARCH_X86)
#elif MICROPY_EMIT_X64
#define MPY_FEATURE_ARCH (MP_NATIVE_ARCH_X64)
#define MPY_FEATURE_ARCH (MP_NATIVE_ARCH_X64)
#elif MICROPY_EMIT_THUMB
#define MPY_FEATURE_ARCH (MP_NATIVE_ARCH_ARMV7M)
#if defined(__thumb2__)
#if defined(__ARM_FP) && (__ARM_FP & 8) == 8
#define MPY_FEATURE_ARCH (MP_NATIVE_ARCH_ARMV7EMDP)
#elif defined(__ARM_FP) && (__ARM_FP & 4) == 4
#define MPY_FEATURE_ARCH (MP_NATIVE_ARCH_ARMV7EMSP)
#else
#define MPY_FEATURE_ARCH (MP_NATIVE_ARCH_ARMV7EM)
#endif
#else
#define MPY_FEATURE_ARCH (MP_NATIVE_ARCH_ARMV7M)
#endif
#define MPY_FEATURE_ARCH_TEST(x) (MP_NATIVE_ARCH_ARMV6M <= (x) && (x) <= MPY_FEATURE_ARCH)
#elif MICROPY_EMIT_ARM
#define MPY_FEATURE_ARCH (MP_NATIVE_ARCH_ARMV6)
#define MPY_FEATURE_ARCH (MP_NATIVE_ARCH_ARMV6)
#elif MICROPY_EMIT_XTENSA
#define MPY_FEATURE_ARCH (MP_NATIVE_ARCH_XTENSA)
#define MPY_FEATURE_ARCH (MP_NATIVE_ARCH_XTENSA)
#elif MICROPY_EMIT_XTENSAWIN
#define MPY_FEATURE_ARCH (MP_NATIVE_ARCH_XTENSAWIN)
#define MPY_FEATURE_ARCH (MP_NATIVE_ARCH_XTENSAWIN)
#else
#define MPY_FEATURE_ARCH (MP_NATIVE_ARCH_NONE)
#define MPY_FEATURE_ARCH (MP_NATIVE_ARCH_NONE)
#endif
#ifndef MPY_FEATURE_ARCH_TEST
#define MPY_FEATURE_ARCH_TEST(x) ((x) == MPY_FEATURE_ARCH)
#endif
// 16-bit little-endian integer with the second and third bytes of supported .mpy files