diff options
Diffstat (limited to 'py')
| -rw-r--r-- | py/bc.h | 1 | ||||
| -rw-r--r-- | py/persistentcode.c | 15 | ||||
| -rw-r--r-- | py/persistentcode.h | 6 | 
3 files changed, 19 insertions, 3 deletions
| @@ -220,6 +220,7 @@ typedef struct _mp_compiled_module_t {      bool has_native;      size_t n_qstr;      size_t n_obj; +    size_t arch_flags;      #endif  } mp_compiled_module_t; diff --git a/py/persistentcode.c b/py/persistentcode.c index 6ec0717f9..7d71cfd98 100644 --- a/py/persistentcode.c +++ b/py/persistentcode.c @@ -471,7 +471,7 @@ void mp_raw_code_load(mp_reader_t *reader, mp_compiled_module_t *cm) {          || header[3] > MP_SMALL_INT_BITS) {          mp_raise_ValueError(MP_ERROR_TEXT("incompatible .mpy file"));      } -    if (MPY_FEATURE_DECODE_ARCH(header[2]) != MP_NATIVE_ARCH_NONE) { +    if (arch != MP_NATIVE_ARCH_NONE) {          if (!MPY_FEATURE_ARCH_TEST(arch)) {              if (MPY_FEATURE_ARCH_TEST(MP_NATIVE_ARCH_NONE)) {                  // On supported ports this can be resolved by enabling feature, eg @@ -483,6 +483,12 @@ void mp_raw_code_load(mp_reader_t *reader, mp_compiled_module_t *cm) {          }      } +    size_t arch_flags = 0; +    if (MPY_FEATURE_ARCH_FLAGS_TEST(header[2])) { +        (void)arch_flags; +        mp_raise_ValueError(MP_ERROR_TEXT("incompatible .mpy file")); +    } +      size_t n_qstr = read_uint(reader);      size_t n_obj = read_uint(reader);      mp_module_context_alloc_tables(cm->context, n_qstr, n_obj); @@ -504,6 +510,7 @@ void mp_raw_code_load(mp_reader_t *reader, mp_compiled_module_t *cm) {      cm->has_native = MPY_FEATURE_DECODE_ARCH(header[2]) != MP_NATIVE_ARCH_NONE;      cm->n_qstr = n_qstr;      cm->n_obj = n_obj; +    cm->arch_flags = arch_flags;      #endif      // Deregister exception handler and close the reader. @@ -672,7 +679,7 @@ void mp_raw_code_save(mp_compiled_module_t *cm, mp_print_t *print) {      byte header[4] = {          'M',          MPY_VERSION, -        cm->has_native ? MPY_FEATURE_ENCODE_SUB_VERSION(MPY_SUB_VERSION) | MPY_FEATURE_ENCODE_ARCH(MPY_FEATURE_ARCH_DYNAMIC) : 0, +        (cm->arch_flags != 0 ? MPY_FEATURE_ARCH_FLAGS : 0) | (cm->has_native ? MPY_FEATURE_ENCODE_SUB_VERSION(MPY_SUB_VERSION) | MPY_FEATURE_ENCODE_ARCH(MPY_FEATURE_ARCH_DYNAMIC) : 0),          #if MICROPY_DYNAMIC_COMPILER          mp_dynamic_compiler.small_int_bits,          #else @@ -681,6 +688,10 @@ void mp_raw_code_save(mp_compiled_module_t *cm, mp_print_t *print) {      };      mp_print_bytes(print, header, sizeof(header)); +    if (cm->arch_flags) { +        mp_print_uint(print, cm->arch_flags); +    } +      // Number of entries in constant table.      mp_print_uint(print, cm->n_qstr);      mp_print_uint(print, cm->n_obj); diff --git a/py/persistentcode.h b/py/persistentcode.h index a45d5fd18..8fd7068e3 100644 --- a/py/persistentcode.h +++ b/py/persistentcode.h @@ -45,7 +45,7 @@  // Macros to encode/decode native architecture to/from the feature byte  #define MPY_FEATURE_ENCODE_ARCH(arch) ((arch) << 2) -#define MPY_FEATURE_DECODE_ARCH(feat) ((feat) >> 2) +#define MPY_FEATURE_DECODE_ARCH(feat) (((feat) >> 2) & 0x2F)  // Define the host architecture  #if MICROPY_EMIT_X86 @@ -85,6 +85,10 @@  #define MPY_FILE_HEADER_INT (MPY_VERSION \      | (MPY_FEATURE_ENCODE_SUB_VERSION(MPY_SUB_VERSION) | MPY_FEATURE_ENCODE_ARCH(MPY_FEATURE_ARCH)) << 8) +// Architecture-specific flags are present in the .mpy file +#define MPY_FEATURE_ARCH_FLAGS (0x40) +#define MPY_FEATURE_ARCH_FLAGS_TEST(x) (((x) & MPY_FEATURE_ARCH_FLAGS) == MPY_FEATURE_ARCH_FLAGS) +  enum {      MP_NATIVE_ARCH_NONE = 0,      MP_NATIVE_ARCH_X86, | 
