py/modsys: Add architecture flags to MicroPython metadata.

This commit adds the currently supported architecture flags value as the
upper part of "sys.implementation._mpy".

This had the side effect of perturbing quite a bit of testing
infrastructure and invalidating documentation related to MPY files.  To
make the test suite run successfully and keep the documentation in sync
the following changes have been made:

* The target info feature check file now isolates eventual architecture
  flags and adds them as a separate field
* The test runner now picks up the new architecture flags field, reports
  it to STDOUT if needed and stores it for future uses
* Relevant test files for MPY files import code had to be updated to
  mask out the architecture flags bits in order to perform correctly
* MPY file format documentation was updated to show how to mask off and
  properly display the architecture flags information.

This works out of the box if the flag bits can fit in a smallint value
once merged with the MPY file header value.

Signed-off-by: Alessandro Gatti <a.gatti@frob.it>
This commit is contained in:
Alessandro Gatti
2025-09-24 22:26:39 +02:00
parent 3e2b41f8f6
commit 430837996b
7 changed files with 27 additions and 12 deletions

View File

@@ -58,12 +58,14 @@ If importing an .mpy file fails then try the following:
sys_mpy = sys.implementation._mpy
arch = [None, 'x86', 'x64',
'armv6', 'armv6m', 'armv7m', 'armv7em', 'armv7emsp', 'armv7emdp',
'xtensa', 'xtensawin', 'rv32imc', 'rv64imc'][sys_mpy >> 10]
'xtensa', 'xtensawin', 'rv32imc', 'rv64imc'][(sys_mpy >> 10) & 0x0F]
print('mpy version:', sys_mpy & 0xff)
print('mpy sub-version:', sys_mpy >> 8 & 3)
print('mpy flags:', end='')
if arch:
print(' -march=' + arch, end='')
if (sys_mpy >> 16) != 0:
print(' -march-flags=' + (sys_mpy >> 16), end='')
print()
* Check the validity of the .mpy file by inspecting the first two bytes of