summaryrefslogtreecommitdiff
path: root/tools/mpy-tool.py
AgeCommit message (Collapse)Author
2020-08-21tools/mpy-tool.py: Fix offset of line number info.Martin Milata
Signed-off-by: Martin Milata <martin@martinmilata.cz>
2020-04-18all: Fix implicit conversion from double to float.stijn
These are found when building with -Wfloat-conversion.
2020-02-28all: Reformat C and Python source code with tools/codeformat.py.Damien George
This is run with uncrustify 0.70.1, and black 19.10b0.
2019-12-12tools/mpy-tool.py: Raise exception if trying to freeze relocatable mpy.Damien George
2019-12-12tools/mpy-tool.py: Add ability to merge multiple .mpy files into one.Damien George
Usage: mpy-tool.py -o merged.mpy --merge mod1.mpy mod2.mpy The constituent .mpy files are executed sequentially when the merged file is imported, and they all use the same global namespace.
2019-12-12py/nativeglue: Add new header file with native function table typedef.Damien George
2019-11-28tools/mpy-tool.py: Support qstr linking when freezing Xtensa native mpy.Damien George
2019-11-04tools/mpy-tool.py: Use "@progbits #" attribute for native xtensa code.Damien George
2019-10-15py/persistentcode: Make .mpy more compact with qstr directly in prelude.Damien George
Instead of encoding 4 zero bytes as placeholders for the simple_name and source_file qstrs, and storing the qstrs after the bytecode, store the qstrs at the location of these 4 bytes. This saves 4 bytes per bytecode function stored in a .mpy file (for example lcd160cr.mpy drops by 232 bytes, 4x 58 functions). And resulting code size is slightly reduced on ports that use this feature.
2019-10-05py: Add new Xtensa-Windowed arch for native emitter.Damien George
Enabled via the configuration MICROPY_EMIT_XTENSAWIN.
2019-10-01py: Rework and compress second part of bytecode prelude.Damien George
This patch compresses the second part of the bytecode prelude which contains the source file name, function name, source-line-number mapping and cell closure information. This part of the prelude now begins with a single varible length unsigned integer which encodes 2 numbers, being the byte-size of the following 2 sections in the header: the "source info section" and the "closure section". After decoding this variable unsigned integer it's possible to skip over one or both of these sections very easily. This scheme saves about 2 bytes for most functions compared to the original format: one in the case that there are no closure cells, and one because padding was eliminated.
2019-10-01py: Compress first part of bytecode prelude.Damien George
The start of the bytecode prelude contains 6 numbers telling the amount of stack needed for the Python values and exceptions, and the signature of the function. Prior to this patch these numbers were all encoded one after the other (2x variable unsigned integers, then 4x bytes), but using so many bytes is unnecessary. An entropy analysis of around 150,000 bytecode functions from the CPython standard library showed that the optimal Shannon coding would need about 7.1 bits on average to encode these 6 numbers, compared to the existing 48 bits. This patch attempts to get close to this optimal value by packing the 6 numbers into a single, varible-length unsigned integer via bit-wise interleaving. The interleaving scheme is chosen to minimise the average number of bytes needed, and at the same time keep the scheme simple enough so it can be implemented without too much overhead in code size or speed. The scheme requires about 10.5 bits on average to store the 6 numbers. As a result most functions which originally took 6 bytes to encode these 6 numbers now need only 1 byte (in 80% of cases).
2019-09-26py/persistentcode: Bump .mpy version to 5.Damien George
The bytecode opcodes have changed (there are more, and they have been reordered).
2019-09-26py: Rename MP_QSTR_NULL to MP_QSTRnull to avoid intern collisions.Josh Lloyd
Fixes #5140.
2019-09-26py/bc: Replace big opcode format table with simple macro.Damien George
2019-09-26py/bc0: Order opcodes into groups based on their size and format.Damien George
2019-09-06tools/mpy-tool.py: Fix freezing of non-bytecode funcs with settrace.Damien George
Only bytecode functions can be profiled at this stage. Native functions (eg inline assembler) may not even have a valid prelude. Fixes issue #5075.
2019-09-02py/bc: Fix size calculation of UNWIND_JUMP opcode in mp_opcode_format.Damien George
Prior to this patch mp_opcode_format would calculate the incorrect size of the MP_BC_UNWIND_JUMP opcode, missing the additional byte. But, because opcodes below 0x10 are unused and treated as bytes in the .mpy load/save and freezing code, this bug did not show any symptoms, since nested unwind jumps would rarely (if ever) reach a depth of 16 (so the extra byte of this opcode would be between 0x01 and 0x0f and be correctly loaded/saved/frozen simply as an undefined opcode). This patch fixes this bug by correctly accounting for the additional byte. .
2019-08-30tools/mpy-tool.py: Add initial support for frozen with settrace.Damien George
2019-08-20tools/mpy-tool.py: Force native func alignment to halfword/word on ARM.Jim Mussared
This is necessary for ARMV6 and V7. Without this change, calling a frozen native/viper function that is misaligned will crash.
2019-06-28py: Define EMIT_MACHINE_CODE as EMIT_NATIVE || EMIT_INLINE_ASM.Jun Wu
The combination MICROPY_EMIT_NATIVE || MICROPY_EMIT_INLINE_ASM is used in many places, so define a new macro for it.
2019-06-11tools/mpy-tool.py: Fix linking of qstr objects in native ARM Thumb code.Damien George
Previously, when linking qstr objects in native code for ARM Thumb, the index into the machine code was being incremented by 4, not 8. It should be 8 to account for the size of the two machine instructions movw and movt. This patch makes sure the index into the machine code is incremented by the correct amount for all variations of qstr linking. See issue #4829.
2019-06-04tools/mpy-tool.py: Fix linking qstrs in native code, and multiple files.Damien George
Fixes errors in the tool when 1) linking qstrs in native ARM-M code; 2) freezing multiple files some of which use native code and some which don't. Fixes issue #4829.
2019-04-08tools/mpy-tool.py: Fix init of QStrWindow, and remove unused variable.Damien George
The qstr window size is not log-2 encoded, it's just the actual number (but in mpy-tool.py this didn't lead to an error because the size is just used to truncate the window so it doesn't grow arbitrarily large in memory). Addresses issue #4635.
2019-04-08tools/mpy-tool.py: Adjust use of super() to make it work with Python 2.Damien George
Fixes the regression introduced in ea3c80a514c5dc4cc3a8349815eceec4fa1ac57f
2019-03-08py/persistentcode: Bump .mpy version to 4.Damien George
2019-03-08tools/mpy-tool.py: Add support for freezing native code.Damien George
This adds support to freeze .mpy files that contain native code blocks.
2019-03-08py/emitglue: Remove union in mp_raw_code_t to combine bytecode & native.Damien George
2019-03-05py/persistentcode: Define static qstr set to reduce size of mpy files.Damien George
When encoded in the mpy file, if qstr <= QSTR_LAST_STATIC then store two bytes: 0, static_qstr_id. Otherwise encode the qstr as usual (either with string data or a reference into the qstr window). Reduces mpy file size by about 5%.
2019-03-05py/persistentcode: Pack qstrs directly in bytecode to reduce mpy size.Damien George
Instead of emitting two bytes in the bytecode for where the linked qstr should be written to, it is now replaced by the actual qstr data, or a reference into the qstr window. Reduces mpy file size by about 10%.
2019-03-05py/persistentcode: Add a qstr window to save mpy files more efficiently.Damien George
This is an implementation of a sliding qstr window used to reduce the number of qstrs stored in a .mpy file. The window size is configured to 32 entries which takes a fixed 64 bytes (16-bits each) on the C stack when loading/saving a .mpy file. It allows to remember the most recent 32 qstrs so they don't need to be stored again in the .mpy file. The qstr window uses a simple least-recently-used mechanism to discard the least recently used qstr when the window overflows (similar to dictionary compression). This scheme only needs a single pass to save/load the .mpy file. Reduces mpy file size by about 25% with a window size of 32.
2019-03-05py: Replace POP_BLOCK and POP_EXCEPT opcodes with POP_EXCEPT_JUMP.Damien George
POP_BLOCK and POP_EXCEPT are now the same, and are always followed by a JUMP. So this optimisation reduces code size, and RAM usage of bytecode by two bytes for each try-except handler.
2018-12-15tools/mpy-tool.py: Fix build error when no qstrs present in frozen mpy.Dave Hylands
If you happen to only have a really simple frozen file that doesn't contain any new qstrs then the generated frozen_mpy.c file contains an empty enumeration which causes a C compile time error.
2018-12-13tools/mpy-tool.py: Fix calc of opcode size for opcodes with map caching.Damien George
Following an equivalent fix to py/bc.c. The reason the incorrect values for the opcode constants were not previously causing a bug is because they were never being used: these opcodes always have qstr arguments so the part of the code that was comparing them would never be reached. Thanks to @malinah for finding the problem and providing the initial patch.
2018-08-01tools/mpy-tool: Set sane initial dynamic qstr pool size with frozen modsRich Barlow
The first dynamic qstr pool is double the size of the 'alloc' field of the last const qstr pool. The built in const qstr pool (mp_qstr_const_pool) has a hardcoded alloc size of 10, meaning that the first dynamic pool is allocated space for 20 entries. The alloc size must be less than or equal to the actual number of qstrs in the pool (the 'len' field) to ensure that the first dynamically created qstr triggers the creation of a new pool. When modules are frozen a second const pool is created (generally mp_qstr_frozen_const_pool) and linked to the built in pool. However, this second const pool had its 'alloc' field set to the number of qstrs in the pool. When freezing a large quantity of modules this can result in thousands of qstrs being in the pool. This means that the first dynamically created qstr results in a massive allocation. This commit sets the alloc size of the frozen qstr pool to 10 or less (if the number of qstrs in the pool is less than 10). The result of this is that the allocation behaviour when a dynamic qstr is created is identical with an without frozen code. Note that there is the potential for a slight memory inefficiency if the frozen modules have less than 10 qstrs, as the first few dynamic allocations will have quite a large overhead, but the geometric growth soon deals with this.
2018-07-09tools/mpy-tool.py: Put frozen bignum digit data in ROM, not in RAM.Damien George
2018-07-09tools/mpy-tool.py: Support freezing of floats in obj representation D.Damien George
2017-11-15tools/mpy-tool.py: Implement freezing of Ellipsis const object.Damien George
2017-10-10py/bc: Update opcode_format_table to match the bytecode.Damien George
2017-10-05py/persistentcode: Bump .mpy version number to version 3.Damien George
The binary and unary ops have changed bytecode encoding.
2017-08-16tools/mpy-tool.py: Fix missing argument in dump() functionstijn
This makes the -d commandline argument usable again. Pass empty string as parent name as listing starts from the root.
2017-08-12tools/mpy-tool.py: Don't generate const_table if it's empty.Damien George
2017-05-16tools/mpy-tool.py: Fix regression with freezing floats in obj repr C.Damien George
Regression was introduced by ec534609f665cb791b8fc1eae1a44e514c297659
2017-05-13tools/mpy-tool.py: Use MP_ROM_xxx macros to support nanbox builds.Damien George
2017-05-01tools/mpy-tool: Make work if run from another directory.Paul Sokolovsky
By making sure we don't add relative paths to sys.path.
2017-04-22py: Add LOAD_SUPER_METHOD bytecode to allow heap-free super meth calls.Damien George
This patch allows the following code to run without allocating on the heap: super().foo(...) Before this patch such a call would allocate a super object on the heap and then load the foo method and call it right away. The super object is only needed to perform the lookup of the method and not needed after that. This patch makes an optimisation to allocate the super object on the C stack and discard it right after use. Changes in code size due to this patch are: bare-arm: +128 minimal: +232 unix x64: +416 unix nanbox: +364 stmhal: +184 esp8266: +340 cc3200: +128
2017-02-17py/persistentcode: Bump .mpy version due to change in bytecode.Damien George
2017-01-05tools/mpy-tool.py: Add support for OPT_CACHE_MAP_LOOKUP_IN_BYTECODE.Damien George
With caching of map lookups in the bytecode, frozen bytecode can still work but must be stored in RAM, not ROM. This patch allows mpy-tool.py to generate code that works with this optimisation, but it's not recommended to use it on embedded targets (because of lack of RAM).
2016-09-23py: Update opcode format table because 3 opcodes were removed, 1 added.Damien George
LIST_APPEND, MAP_ADD and SET_ADD have been removed, and STORE_COMP has been added in adaf0d865cd6c81fb352751566460506392ed55f.
2016-09-03tools/mpy-tool.py: Support freezing of complex numbers.Damien George