2014-01-24 04:05:30 -05:00
|
|
|
ifneq ($(MKENV_INCLUDED),1)
|
|
|
|
# We assume that mkenv is in the same directory as this file.
|
|
|
|
THIS_MAKEFILE = $(lastword $(MAKEFILE_LIST))
|
|
|
|
include $(dir $(THIS_MAKEFILE))mkenv.mk
|
|
|
|
endif
|
|
|
|
|
2022-09-13 19:57:47 -04:00
|
|
|
HELP_BUILD_ERROR ?= "See \033[1;31mhttps://github.com/micropython/micropython/wiki/Build-Troubleshooting\033[0m"
|
|
|
|
HELP_MPY_LIB_SUBMODULE ?= "\033[1;31mError: micropython-lib submodule is not initialized.\033[0m Run 'make submodules'"
|
|
|
|
|
py: Implement "common word" compression scheme for error messages.
The idea here is that there's a moderate amount of ROM used up by exception
text. Obviously we try to keep the messages short, and the code can enable
terse errors, but it still adds up. Listed below is the total string data
size for various ports:
bare-arm 2860
minimal 2876
stm32 8926 (PYBV11)
cc3200 3751
esp32 5721
This commit implements compression of these strings. It takes advantage of
the fact that these strings are all 7-bit ascii and extracts the top 128
frequently used words from the messages and stores them packed (dropping
their null-terminator), then uses (0x80 | index) inside strings to refer to
these common words. Spaces are automatically added around words, saving
more bytes. This happens transparently in the build process, mirroring the
steps that are used to generate the QSTR data. The MP_COMPRESSED_ROM_TEXT
macro wraps any literal string that should compressed, and it's
automatically decompressed in mp_decompress_rom_string.
There are many schemes that could be used for the compression, and some are
included in py/makecompresseddata.py for reference (space, Huffman, ngram,
common word). Results showed that the common-word compression gets better
results. This is before counting the increased cost of the Huffman
decoder. This might be slightly counter-intuitive, but this data is
extremely repetitive at a word-level, and the byte-level entropy coder
can't quite exploit that as efficiently. Ideally one would combine both
approaches, but for now the common-word approach is the one that is used.
For additional comparison, the size of the raw data compressed with gzip
and zlib is calculated, as a sort of proxy for a lower entropy bound. With
this scheme we come within 15% on stm32, and 30% on bare-arm (i.e. we use
x% more bytes than the data compressed with gzip -- not counting the code
overhead of a decoder, and how this would be hypothetically implemented).
The feature is disabled by default and can be enabled by setting
MICROPY_ROM_TEXT_COMPRESSION at the Makefile-level.
2019-09-26 08:19:29 -04:00
|
|
|
# Extra deps that need to happen before object compilation.
|
|
|
|
OBJ_EXTRA_ORDER_DEPS =
|
|
|
|
|
2022-07-01 13:29:08 -04:00
|
|
|
# Generate header files.
|
|
|
|
OBJ_EXTRA_ORDER_DEPS += $(HEADER_BUILD)/moduledefs.h $(HEADER_BUILD)/root_pointers.h
|
2022-05-31 03:10:14 -04:00
|
|
|
|
py: Implement "common word" compression scheme for error messages.
The idea here is that there's a moderate amount of ROM used up by exception
text. Obviously we try to keep the messages short, and the code can enable
terse errors, but it still adds up. Listed below is the total string data
size for various ports:
bare-arm 2860
minimal 2876
stm32 8926 (PYBV11)
cc3200 3751
esp32 5721
This commit implements compression of these strings. It takes advantage of
the fact that these strings are all 7-bit ascii and extracts the top 128
frequently used words from the messages and stores them packed (dropping
their null-terminator), then uses (0x80 | index) inside strings to refer to
these common words. Spaces are automatically added around words, saving
more bytes. This happens transparently in the build process, mirroring the
steps that are used to generate the QSTR data. The MP_COMPRESSED_ROM_TEXT
macro wraps any literal string that should compressed, and it's
automatically decompressed in mp_decompress_rom_string.
There are many schemes that could be used for the compression, and some are
included in py/makecompresseddata.py for reference (space, Huffman, ngram,
common word). Results showed that the common-word compression gets better
results. This is before counting the increased cost of the Huffman
decoder. This might be slightly counter-intuitive, but this data is
extremely repetitive at a word-level, and the byte-level entropy coder
can't quite exploit that as efficiently. Ideally one would combine both
approaches, but for now the common-word approach is the one that is used.
For additional comparison, the size of the raw data compressed with gzip
and zlib is calculated, as a sort of proxy for a lower entropy bound. With
this scheme we come within 15% on stm32, and 30% on bare-arm (i.e. we use
x% more bytes than the data compressed with gzip -- not counting the code
overhead of a decoder, and how this would be hypothetically implemented).
The feature is disabled by default and can be enabled by setting
MICROPY_ROM_TEXT_COMPRESSION at the Makefile-level.
2019-09-26 08:19:29 -04:00
|
|
|
ifeq ($(MICROPY_ROM_TEXT_COMPRESSION),1)
|
|
|
|
# If compression is enabled, trigger the build of compressed.data.h...
|
|
|
|
OBJ_EXTRA_ORDER_DEPS += $(HEADER_BUILD)/compressed.data.h
|
|
|
|
# ...and enable the MP_COMPRESSED_ROM_TEXT macro (used by MP_ERROR_TEXT).
|
|
|
|
CFLAGS += -DMICROPY_ROM_TEXT_COMPRESSION=1
|
|
|
|
endif
|
|
|
|
|
2020-04-13 00:52:10 -04:00
|
|
|
# QSTR generation uses the same CFLAGS, with these modifications.
|
2020-12-13 00:15:04 -05:00
|
|
|
QSTR_GEN_FLAGS = -DNO_QSTR
|
2020-04-13 00:52:10 -04:00
|
|
|
# Note: := to force evaluation immediately.
|
|
|
|
QSTR_GEN_CFLAGS := $(CFLAGS)
|
2020-10-08 10:40:17 -04:00
|
|
|
QSTR_GEN_CFLAGS += $(QSTR_GEN_FLAGS)
|
|
|
|
QSTR_GEN_CXXFLAGS := $(CXXFLAGS)
|
|
|
|
QSTR_GEN_CXXFLAGS += $(QSTR_GEN_FLAGS)
|
2020-04-13 00:52:10 -04:00
|
|
|
|
2014-01-24 04:05:30 -05:00
|
|
|
# This file expects that OBJ contains a list of all of the object files.
|
|
|
|
# The directory portion of each object file is used to locate the source
|
2016-11-14 16:15:45 -05:00
|
|
|
# and should not contain any ..'s but rather be relative to the top of the
|
2014-01-24 04:05:30 -05:00
|
|
|
# tree.
|
|
|
|
#
|
|
|
|
# So for example, py/map.c would have an object file name py/map.o
|
2023-03-18 11:17:02 -04:00
|
|
|
# The object files will go into the build directory and maintain the same
|
2014-01-24 04:05:30 -05:00
|
|
|
# directory structure as the source tree. So the final dependency will look
|
|
|
|
# like this:
|
|
|
|
#
|
|
|
|
# build/py/map.o: py/map.c
|
|
|
|
#
|
|
|
|
# We set vpath to point to the top of the tree so that the source files
|
|
|
|
# can be located. By following this scheme, it allows a single build rule
|
|
|
|
# to be used to compile all .c files.
|
|
|
|
|
2023-10-19 16:42:36 -04:00
|
|
|
# CIRCUITPY-CHANGE: adds STEPECHO
|
2019-04-05 15:41:40 -04:00
|
|
|
vpath %.S . $(TOP) $(USER_C_MODULES)
|
2014-01-24 04:05:30 -05:00
|
|
|
$(BUILD)/%.o: %.S
|
2017-02-24 09:59:59 -05:00
|
|
|
$(STEPECHO) "CC $<"
|
2014-01-24 04:05:30 -05:00
|
|
|
$(Q)$(CC) $(CFLAGS) -c -o $@ $<
|
|
|
|
|
2019-04-05 15:41:40 -04:00
|
|
|
vpath %.s . $(TOP) $(USER_C_MODULES)
|
2014-01-24 04:05:30 -05:00
|
|
|
$(BUILD)/%.o: %.s
|
2017-02-24 09:59:59 -05:00
|
|
|
$(STEPECHO) "AS $<"
|
2014-01-24 04:05:30 -05:00
|
|
|
$(Q)$(AS) -o $@ $<
|
|
|
|
|
|
|
|
define compile_c
|
2017-02-24 09:59:59 -05:00
|
|
|
$(STEPECHO) "CC $<"
|
2014-01-24 04:05:30 -05:00
|
|
|
$(Q)$(CC) $(CFLAGS) -c -MD -o $@ $<
|
|
|
|
@# The following fixes the dependency file.
|
|
|
|
@# See http://make.paulandlesley.org/autodep.html for details.
|
2015-05-06 08:34:33 -04:00
|
|
|
@# Regex adjusted from the above to play better with Windows paths, etc.
|
2014-04-06 20:35:45 -04:00
|
|
|
@$(CP) $(@:.o=.d) $(@:.o=.P); \
|
2015-05-05 14:39:28 -04:00
|
|
|
$(SED) -e 's/#.*//' -e 's/^.*: *//' -e 's/ *\\$$//' \
|
2014-01-24 04:05:30 -05:00
|
|
|
-e '/^$$/ d' -e 's/$$/ :/' < $(@:.o=.d) >> $(@:.o=.P); \
|
2014-04-06 20:35:45 -04:00
|
|
|
$(RM) -f $(@:.o=.d)
|
2014-01-24 04:05:30 -05:00
|
|
|
endef
|
|
|
|
|
2020-10-08 10:19:26 -04:00
|
|
|
define compile_cxx
|
|
|
|
$(ECHO) "CXX $<"
|
2022-09-13 19:57:47 -04:00
|
|
|
$(Q)$(CXX) $(CXXFLAGS) -c -MD -o $@ $< || (echo -e $(HELP_BUILD_ERROR); false)
|
2020-10-08 10:19:26 -04:00
|
|
|
@# The following fixes the dependency file.
|
|
|
|
@# See http://make.paulandlesley.org/autodep.html for details.
|
|
|
|
@# Regex adjusted from the above to play better with Windows paths, etc.
|
|
|
|
@$(CP) $(@:.o=.d) $(@:.o=.P); \
|
|
|
|
$(SED) -e 's/#.*//' -e 's/^.*: *//' -e 's/ *\\$$//' \
|
|
|
|
-e '/^$$/ d' -e 's/$$/ :/' < $(@:.o=.d) >> $(@:.o=.P); \
|
|
|
|
$(RM) -f $(@:.o=.d)
|
|
|
|
endef
|
|
|
|
|
2023-10-19 16:42:36 -04:00
|
|
|
# CIRCUITPY-CHANGE: add $(DEVICES_MODULES) and $(BUILD)
|
2023-09-29 23:01:02 -04:00
|
|
|
vpath %.c . $(TOP) $(USER_C_MODULES) $(DEVICES_MODULES) $(BUILD)
|
2014-01-24 04:05:30 -05:00
|
|
|
$(BUILD)/%.o: %.c
|
|
|
|
$(call compile_c)
|
|
|
|
|
2020-10-08 10:19:26 -04:00
|
|
|
vpath %.cpp . $(TOP) $(USER_C_MODULES)
|
|
|
|
$(BUILD)/%.o: %.cpp
|
|
|
|
$(call compile_cxx)
|
|
|
|
|
2014-03-15 02:41:28 -04:00
|
|
|
$(BUILD)/%.pp: %.c
|
2023-08-12 11:08:59 -04:00
|
|
|
$(STEPECHO) "PreProcess $<"
|
2019-06-24 08:11:56 -04:00
|
|
|
$(Q)$(CPP) $(CFLAGS) -Wp,-C,-dD,-dI -o $@ $<
|
2014-03-15 02:41:28 -04:00
|
|
|
|
2016-04-26 05:39:28 -04:00
|
|
|
# The following rule uses | to create an order only prerequisite. Order only
|
2014-01-24 04:05:30 -05:00
|
|
|
# prerequisites only get built if they don't exist. They don't cause timestamp
|
2014-04-17 13:03:27 -04:00
|
|
|
# checking to be performed.
|
2014-01-24 04:05:30 -05:00
|
|
|
#
|
2014-11-06 03:25:44 -05:00
|
|
|
# We don't know which source files actually need the generated.h (since
|
|
|
|
# it is #included from str.h). The compiler generated dependencies will cause
|
|
|
|
# the right .o's to get recompiled if the generated.h file changes. Adding
|
2016-04-26 05:39:28 -04:00
|
|
|
# an order-only dependency to all of the .o's will cause the generated .h
|
2014-11-06 03:25:44 -05:00
|
|
|
# to get built before we try to compile any of them.
|
py: Implement "common word" compression scheme for error messages.
The idea here is that there's a moderate amount of ROM used up by exception
text. Obviously we try to keep the messages short, and the code can enable
terse errors, but it still adds up. Listed below is the total string data
size for various ports:
bare-arm 2860
minimal 2876
stm32 8926 (PYBV11)
cc3200 3751
esp32 5721
This commit implements compression of these strings. It takes advantage of
the fact that these strings are all 7-bit ascii and extracts the top 128
frequently used words from the messages and stores them packed (dropping
their null-terminator), then uses (0x80 | index) inside strings to refer to
these common words. Spaces are automatically added around words, saving
more bytes. This happens transparently in the build process, mirroring the
steps that are used to generate the QSTR data. The MP_COMPRESSED_ROM_TEXT
macro wraps any literal string that should compressed, and it's
automatically decompressed in mp_decompress_rom_string.
There are many schemes that could be used for the compression, and some are
included in py/makecompresseddata.py for reference (space, Huffman, ngram,
common word). Results showed that the common-word compression gets better
results. This is before counting the increased cost of the Huffman
decoder. This might be slightly counter-intuitive, but this data is
extremely repetitive at a word-level, and the byte-level entropy coder
can't quite exploit that as efficiently. Ideally one would combine both
approaches, but for now the common-word approach is the one that is used.
For additional comparison, the size of the raw data compressed with gzip
and zlib is calculated, as a sort of proxy for a lower entropy bound. With
this scheme we come within 15% on stm32, and 30% on bare-arm (i.e. we use
x% more bytes than the data compressed with gzip -- not counting the code
overhead of a decoder, and how this would be hypothetically implemented).
The feature is disabled by default and can be enabled by setting
MICROPY_ROM_TEXT_COMPRESSION at the Makefile-level.
2019-09-26 08:19:29 -04:00
|
|
|
$(OBJ): | $(HEADER_BUILD)/qstrdefs.generated.h $(HEADER_BUILD)/mpversion.h $(OBJ_EXTRA_ORDER_DEPS)
|
2014-11-06 03:25:44 -05:00
|
|
|
|
2020-10-08 10:40:17 -04:00
|
|
|
# The logic for qstr regeneration (applied by makeqstrdefs.py) is:
|
2018-06-09 01:23:13 -04:00
|
|
|
# - if anything in QSTR_GLOBAL_DEPENDENCIES is newer, then process all source files ($^)
|
|
|
|
# - else, if list of newer prerequisites ($?) is not empty, then process just these ($?)
|
|
|
|
# - else, process all source files ($^) [this covers "make -B" which can set $? to empty]
|
2019-09-26 06:25:39 -04:00
|
|
|
# See more information about this process in docs/develop/qstr.rst.
|
2022-05-31 03:10:14 -04:00
|
|
|
$(HEADER_BUILD)/qstr.i.last: $(SRC_QSTR) $(QSTR_GLOBAL_DEPENDENCIES) | $(QSTR_GLOBAL_REQUIREMENTS)
|
2018-07-31 19:53:54 -04:00
|
|
|
$(STEPECHO) "GEN $@"
|
2020-10-08 10:40:17 -04:00
|
|
|
$(Q)$(PYTHON) $(PY_SRC)/makeqstrdefs.py pp $(CPP) output $(HEADER_BUILD)/qstr.i.last cflags $(QSTR_GEN_CFLAGS) cxxflags $(QSTR_GEN_CXXFLAGS) sources $^ dependencies $(QSTR_GLOBAL_DEPENDENCIES) changed_sources $?
|
py: Add rules for automated extraction of qstrs from sources.
- add template rule that converts a specified source file into a qstring file
- add special rule for generating a central header that contains all
extracted/autogenerated strings - defined by QSTR_DEFS_COLLECTED
variable. Each platform appends a list of sources that may contain
qstrings into a new build variable: SRC_QSTR. Any autogenerated
prerequisities are should be appened to SRC_QSTR_AUTO_DEPS variable.
- remove most qstrings from py/qstrdefs, keep only qstrings that
contain special characters - these cannot be easily detected in the
sources without additional annotations
- remove most manual qstrdefs, use qstrdef autogen for: py, cc3200,
stmhal, teensy, unix, windows, pic16bit:
- remove all micropython generic qstrdefs except for the special strings that contain special characters (e.g. /,+,<,> etc.)
- remove all port specific qstrdefs except for special strings
- append sources for qstr generation in platform makefiles (SRC_QSTR)
2016-03-10 04:22:41 -05:00
|
|
|
|
2016-04-19 07:39:08 -04:00
|
|
|
$(HEADER_BUILD)/qstr.split: $(HEADER_BUILD)/qstr.i.last
|
2023-08-12 11:08:59 -04:00
|
|
|
$(STEPECHO) "GEN $@"
|
py: Implement "common word" compression scheme for error messages.
The idea here is that there's a moderate amount of ROM used up by exception
text. Obviously we try to keep the messages short, and the code can enable
terse errors, but it still adds up. Listed below is the total string data
size for various ports:
bare-arm 2860
minimal 2876
stm32 8926 (PYBV11)
cc3200 3751
esp32 5721
This commit implements compression of these strings. It takes advantage of
the fact that these strings are all 7-bit ascii and extracts the top 128
frequently used words from the messages and stores them packed (dropping
their null-terminator), then uses (0x80 | index) inside strings to refer to
these common words. Spaces are automatically added around words, saving
more bytes. This happens transparently in the build process, mirroring the
steps that are used to generate the QSTR data. The MP_COMPRESSED_ROM_TEXT
macro wraps any literal string that should compressed, and it's
automatically decompressed in mp_decompress_rom_string.
There are many schemes that could be used for the compression, and some are
included in py/makecompresseddata.py for reference (space, Huffman, ngram,
common word). Results showed that the common-word compression gets better
results. This is before counting the increased cost of the Huffman
decoder. This might be slightly counter-intuitive, but this data is
extremely repetitive at a word-level, and the byte-level entropy coder
can't quite exploit that as efficiently. Ideally one would combine both
approaches, but for now the common-word approach is the one that is used.
For additional comparison, the size of the raw data compressed with gzip
and zlib is calculated, as a sort of proxy for a lower entropy bound. With
this scheme we come within 15% on stm32, and 30% on bare-arm (i.e. we use
x% more bytes than the data compressed with gzip -- not counting the code
overhead of a decoder, and how this would be hypothetically implemented).
The feature is disabled by default and can be enabled by setting
MICROPY_ROM_TEXT_COMPRESSION at the Makefile-level.
2019-09-26 08:19:29 -04:00
|
|
|
$(Q)$(PYTHON) $(PY_SRC)/makeqstrdefs.py split qstr $< $(HEADER_BUILD)/qstr _
|
2021-04-22 20:55:39 -04:00
|
|
|
$(Q)$(TOUCH) $@
|
2016-04-19 07:39:08 -04:00
|
|
|
|
|
|
|
$(QSTR_DEFS_COLLECTED): $(HEADER_BUILD)/qstr.split
|
2023-08-12 11:08:59 -04:00
|
|
|
$(STEPECHO) "GEN $@"
|
py: Implement "common word" compression scheme for error messages.
The idea here is that there's a moderate amount of ROM used up by exception
text. Obviously we try to keep the messages short, and the code can enable
terse errors, but it still adds up. Listed below is the total string data
size for various ports:
bare-arm 2860
minimal 2876
stm32 8926 (PYBV11)
cc3200 3751
esp32 5721
This commit implements compression of these strings. It takes advantage of
the fact that these strings are all 7-bit ascii and extracts the top 128
frequently used words from the messages and stores them packed (dropping
their null-terminator), then uses (0x80 | index) inside strings to refer to
these common words. Spaces are automatically added around words, saving
more bytes. This happens transparently in the build process, mirroring the
steps that are used to generate the QSTR data. The MP_COMPRESSED_ROM_TEXT
macro wraps any literal string that should compressed, and it's
automatically decompressed in mp_decompress_rom_string.
There are many schemes that could be used for the compression, and some are
included in py/makecompresseddata.py for reference (space, Huffman, ngram,
common word). Results showed that the common-word compression gets better
results. This is before counting the increased cost of the Huffman
decoder. This might be slightly counter-intuitive, but this data is
extremely repetitive at a word-level, and the byte-level entropy coder
can't quite exploit that as efficiently. Ideally one would combine both
approaches, but for now the common-word approach is the one that is used.
For additional comparison, the size of the raw data compressed with gzip
and zlib is calculated, as a sort of proxy for a lower entropy bound. With
this scheme we come within 15% on stm32, and 30% on bare-arm (i.e. we use
x% more bytes than the data compressed with gzip -- not counting the code
overhead of a decoder, and how this would be hypothetically implemented).
The feature is disabled by default and can be enabled by setting
MICROPY_ROM_TEXT_COMPRESSION at the Makefile-level.
2019-09-26 08:19:29 -04:00
|
|
|
$(Q)$(PYTHON) $(PY_SRC)/makeqstrdefs.py cat qstr _ $(HEADER_BUILD)/qstr $@
|
|
|
|
|
2022-05-31 03:10:14 -04:00
|
|
|
# Module definitions via MP_REGISTER_MODULE.
|
|
|
|
$(HEADER_BUILD)/moduledefs.split: $(HEADER_BUILD)/qstr.i.last
|
2017-02-24 09:59:59 -05:00
|
|
|
$(STEPECHO) "GEN $@"
|
2022-05-31 03:10:14 -04:00
|
|
|
$(Q)$(PYTHON) $(PY_SRC)/makeqstrdefs.py split module $< $(HEADER_BUILD)/module _
|
|
|
|
$(Q)$(TOUCH) $@
|
|
|
|
|
|
|
|
$(HEADER_BUILD)/moduledefs.collected: $(HEADER_BUILD)/moduledefs.split
|
2023-08-01 13:50:05 -04:00
|
|
|
$(STEPECHO) "GEN $@"
|
2022-05-31 03:10:14 -04:00
|
|
|
$(Q)$(PYTHON) $(PY_SRC)/makeqstrdefs.py cat module _ $(HEADER_BUILD)/module $@
|
|
|
|
|
2022-07-01 13:29:08 -04:00
|
|
|
# Module definitions via MP_REGISTER_ROOT_POINTER.
|
|
|
|
$(HEADER_BUILD)/root_pointers.split: $(HEADER_BUILD)/qstr.i.last
|
2023-09-19 11:10:12 -04:00
|
|
|
$(STEPECHO) "GEN $@"
|
2022-07-01 13:29:08 -04:00
|
|
|
$(Q)$(PYTHON) $(PY_SRC)/makeqstrdefs.py split root_pointer $< $(HEADER_BUILD)/root_pointer _
|
|
|
|
$(Q)$(TOUCH) $@
|
|
|
|
|
|
|
|
$(HEADER_BUILD)/root_pointers.collected: $(HEADER_BUILD)/root_pointers.split
|
2023-09-19 11:10:12 -04:00
|
|
|
$(STEPECHO) "GEN $@"
|
2022-07-01 13:29:08 -04:00
|
|
|
$(Q)$(PYTHON) $(PY_SRC)/makeqstrdefs.py cat root_pointer _ $(HEADER_BUILD)/root_pointer $@
|
|
|
|
|
py: Implement "common word" compression scheme for error messages.
The idea here is that there's a moderate amount of ROM used up by exception
text. Obviously we try to keep the messages short, and the code can enable
terse errors, but it still adds up. Listed below is the total string data
size for various ports:
bare-arm 2860
minimal 2876
stm32 8926 (PYBV11)
cc3200 3751
esp32 5721
This commit implements compression of these strings. It takes advantage of
the fact that these strings are all 7-bit ascii and extracts the top 128
frequently used words from the messages and stores them packed (dropping
their null-terminator), then uses (0x80 | index) inside strings to refer to
these common words. Spaces are automatically added around words, saving
more bytes. This happens transparently in the build process, mirroring the
steps that are used to generate the QSTR data. The MP_COMPRESSED_ROM_TEXT
macro wraps any literal string that should compressed, and it's
automatically decompressed in mp_decompress_rom_string.
There are many schemes that could be used for the compression, and some are
included in py/makecompresseddata.py for reference (space, Huffman, ngram,
common word). Results showed that the common-word compression gets better
results. This is before counting the increased cost of the Huffman
decoder. This might be slightly counter-intuitive, but this data is
extremely repetitive at a word-level, and the byte-level entropy coder
can't quite exploit that as efficiently. Ideally one would combine both
approaches, but for now the common-word approach is the one that is used.
For additional comparison, the size of the raw data compressed with gzip
and zlib is calculated, as a sort of proxy for a lower entropy bound. With
this scheme we come within 15% on stm32, and 30% on bare-arm (i.e. we use
x% more bytes than the data compressed with gzip -- not counting the code
overhead of a decoder, and how this would be hypothetically implemented).
The feature is disabled by default and can be enabled by setting
MICROPY_ROM_TEXT_COMPRESSION at the Makefile-level.
2019-09-26 08:19:29 -04:00
|
|
|
# Compressed error strings.
|
|
|
|
$(HEADER_BUILD)/compressed.split: $(HEADER_BUILD)/qstr.i.last
|
2023-08-01 13:50:05 -04:00
|
|
|
$(STEPECHO) "GEN $@"
|
py: Implement "common word" compression scheme for error messages.
The idea here is that there's a moderate amount of ROM used up by exception
text. Obviously we try to keep the messages short, and the code can enable
terse errors, but it still adds up. Listed below is the total string data
size for various ports:
bare-arm 2860
minimal 2876
stm32 8926 (PYBV11)
cc3200 3751
esp32 5721
This commit implements compression of these strings. It takes advantage of
the fact that these strings are all 7-bit ascii and extracts the top 128
frequently used words from the messages and stores them packed (dropping
their null-terminator), then uses (0x80 | index) inside strings to refer to
these common words. Spaces are automatically added around words, saving
more bytes. This happens transparently in the build process, mirroring the
steps that are used to generate the QSTR data. The MP_COMPRESSED_ROM_TEXT
macro wraps any literal string that should compressed, and it's
automatically decompressed in mp_decompress_rom_string.
There are many schemes that could be used for the compression, and some are
included in py/makecompresseddata.py for reference (space, Huffman, ngram,
common word). Results showed that the common-word compression gets better
results. This is before counting the increased cost of the Huffman
decoder. This might be slightly counter-intuitive, but this data is
extremely repetitive at a word-level, and the byte-level entropy coder
can't quite exploit that as efficiently. Ideally one would combine both
approaches, but for now the common-word approach is the one that is used.
For additional comparison, the size of the raw data compressed with gzip
and zlib is calculated, as a sort of proxy for a lower entropy bound. With
this scheme we come within 15% on stm32, and 30% on bare-arm (i.e. we use
x% more bytes than the data compressed with gzip -- not counting the code
overhead of a decoder, and how this would be hypothetically implemented).
The feature is disabled by default and can be enabled by setting
MICROPY_ROM_TEXT_COMPRESSION at the Makefile-level.
2019-09-26 08:19:29 -04:00
|
|
|
$(Q)$(PYTHON) $(PY_SRC)/makeqstrdefs.py split compress $< $(HEADER_BUILD)/compress _
|
|
|
|
$(Q)$(TOUCH) $@
|
|
|
|
|
|
|
|
$(HEADER_BUILD)/compressed.collected: $(HEADER_BUILD)/compressed.split
|
2023-08-01 13:50:05 -04:00
|
|
|
$(STEPECHO) "GEN $@"
|
py: Implement "common word" compression scheme for error messages.
The idea here is that there's a moderate amount of ROM used up by exception
text. Obviously we try to keep the messages short, and the code can enable
terse errors, but it still adds up. Listed below is the total string data
size for various ports:
bare-arm 2860
minimal 2876
stm32 8926 (PYBV11)
cc3200 3751
esp32 5721
This commit implements compression of these strings. It takes advantage of
the fact that these strings are all 7-bit ascii and extracts the top 128
frequently used words from the messages and stores them packed (dropping
their null-terminator), then uses (0x80 | index) inside strings to refer to
these common words. Spaces are automatically added around words, saving
more bytes. This happens transparently in the build process, mirroring the
steps that are used to generate the QSTR data. The MP_COMPRESSED_ROM_TEXT
macro wraps any literal string that should compressed, and it's
automatically decompressed in mp_decompress_rom_string.
There are many schemes that could be used for the compression, and some are
included in py/makecompresseddata.py for reference (space, Huffman, ngram,
common word). Results showed that the common-word compression gets better
results. This is before counting the increased cost of the Huffman
decoder. This might be slightly counter-intuitive, but this data is
extremely repetitive at a word-level, and the byte-level entropy coder
can't quite exploit that as efficiently. Ideally one would combine both
approaches, but for now the common-word approach is the one that is used.
For additional comparison, the size of the raw data compressed with gzip
and zlib is calculated, as a sort of proxy for a lower entropy bound. With
this scheme we come within 15% on stm32, and 30% on bare-arm (i.e. we use
x% more bytes than the data compressed with gzip -- not counting the code
overhead of a decoder, and how this would be hypothetically implemented).
The feature is disabled by default and can be enabled by setting
MICROPY_ROM_TEXT_COMPRESSION at the Makefile-level.
2019-09-26 08:19:29 -04:00
|
|
|
$(Q)$(PYTHON) $(PY_SRC)/makeqstrdefs.py cat compress _ $(HEADER_BUILD)/compress $@
|
py: Add rules for automated extraction of qstrs from sources.
- add template rule that converts a specified source file into a qstring file
- add special rule for generating a central header that contains all
extracted/autogenerated strings - defined by QSTR_DEFS_COLLECTED
variable. Each platform appends a list of sources that may contain
qstrings into a new build variable: SRC_QSTR. Any autogenerated
prerequisities are should be appened to SRC_QSTR_AUTO_DEPS variable.
- remove most qstrings from py/qstrdefs, keep only qstrings that
contain special characters - these cannot be easily detected in the
sources without additional annotations
- remove most manual qstrdefs, use qstrdef autogen for: py, cc3200,
stmhal, teensy, unix, windows, pic16bit:
- remove all micropython generic qstrdefs except for the special strings that contain special characters (e.g. /,+,<,> etc.)
- remove all port specific qstrdefs except for special strings
- append sources for qstr generation in platform makefiles (SRC_QSTR)
2016-03-10 04:22:41 -05:00
|
|
|
|
2014-01-24 04:05:30 -05:00
|
|
|
# $(sort $(var)) removes duplicates
|
|
|
|
#
|
|
|
|
# The net effect of this, is it causes the objects to depend on the
|
2014-04-17 13:03:27 -04:00
|
|
|
# object directories (but only for existence), and the object directories
|
2014-01-24 04:05:30 -05:00
|
|
|
# will be created if they don't exist.
|
|
|
|
OBJ_DIRS = $(sort $(dir $(OBJ)))
|
2014-11-06 03:25:44 -05:00
|
|
|
$(OBJ): | $(OBJ_DIRS)
|
2014-01-24 04:05:30 -05:00
|
|
|
$(OBJ_DIRS):
|
2017-02-24 09:59:59 -05:00
|
|
|
$(Q)$(MKDIR) -p $@
|
2014-01-24 04:05:30 -05:00
|
|
|
|
2014-04-16 17:10:33 -04:00
|
|
|
$(HEADER_BUILD):
|
2017-02-24 09:59:59 -05:00
|
|
|
$(Q)$(MKDIR) -p $@
|
2014-04-16 17:10:33 -04:00
|
|
|
|
2021-08-03 08:30:15 -04:00
|
|
|
ifneq ($(MICROPY_MPYCROSS_DEPENDENCY),)
|
|
|
|
# to automatically build mpy-cross, if needed
|
|
|
|
$(MICROPY_MPYCROSS_DEPENDENCY):
|
2022-08-11 20:32:20 -04:00
|
|
|
$(MAKE) -C $(abspath $(dir $@)..)
|
2021-08-03 08:30:15 -04:00
|
|
|
endif
|
|
|
|
|
2019-10-18 09:38:35 -04:00
|
|
|
ifneq ($(FROZEN_DIR),)
|
2021-12-08 00:04:11 -05:00
|
|
|
$(error Support for FROZEN_DIR was removed. Please use manifest.py instead, see https://docs.micropython.org/en/latest/reference/manifest.html)
|
2019-10-18 09:38:35 -04:00
|
|
|
endif
|
|
|
|
|
|
|
|
ifneq ($(FROZEN_MPY_DIR),)
|
2021-12-08 00:04:11 -05:00
|
|
|
$(error Support for FROZEN_MPY_DIR was removed. Please use manifest.py instead, see https://docs.micropython.org/en/latest/reference/manifest.html)
|
2019-09-09 10:49:02 -04:00
|
|
|
endif
|
|
|
|
|
2021-12-08 00:04:11 -05:00
|
|
|
ifneq ($(FROZEN_MANIFEST),)
|
2022-07-08 01:00:33 -04:00
|
|
|
# If we're using the default submodule path for micropython-lib, then make
|
|
|
|
# sure it's included in "make submodules".
|
|
|
|
ifeq ($(MPY_LIB_DIR),$(MPY_LIB_SUBMODULE_DIR))
|
|
|
|
GIT_SUBMODULES += lib/micropython-lib
|
|
|
|
endif
|
|
|
|
|
2023-06-06 00:24:41 -04:00
|
|
|
# Set compile options needed to enable frozen code.
|
|
|
|
CFLAGS += -DMICROPY_QSTR_EXTRA_POOL=mp_qstr_frozen_const_pool
|
|
|
|
CFLAGS += -DMICROPY_MODULE_FROZEN_MPY
|
|
|
|
CFLAGS += -DMICROPY_MODULE_FROZEN_STR
|
|
|
|
|
2021-12-08 00:04:11 -05:00
|
|
|
# to build frozen_content.c from a manifest
|
2023-10-19 16:42:36 -04:00
|
|
|
# CIRCUITPY-CHANGE: FROZEN_MANIFEST is constructed at build time
|
2023-10-10 22:10:17 -04:00
|
|
|
$(BUILD)/frozen_content.c: FORCE $(BUILD)/genhdr/qstrdefs.generated.h $(BUILD)/genhdr/root_pointers.h $(FROZEN_MANIFEST) | $(MICROPY_MPYCROSS_DEPENDENCY)
|
2022-09-13 19:57:47 -04:00
|
|
|
$(Q)test -e "$(MPY_LIB_DIR)/README.md" || (echo -e $(HELP_MPY_LIB_SUBMODULE); false)
|
2021-12-08 00:04:11 -05:00
|
|
|
$(Q)$(MAKE_MANIFEST) -o $@ -v "MPY_DIR=$(TOP)" -v "MPY_LIB_DIR=$(MPY_LIB_DIR)" -v "PORT_DIR=$(shell pwd)" -v "BOARD_DIR=$(BOARD_DIR)" -b "$(BUILD)" $(if $(MPY_CROSS_FLAGS),-f"$(MPY_CROSS_FLAGS)",) --mpy-tool-flags="$(MPY_TOOL_FLAGS)" $(FROZEN_MANIFEST)
|
2016-11-07 22:28:30 -05:00
|
|
|
endif
|
|
|
|
|
2014-01-24 04:05:30 -05:00
|
|
|
ifneq ($(PROG),)
|
2015-08-14 07:24:11 -04:00
|
|
|
# Build a standalone executable (unix does this)
|
2014-01-24 04:05:30 -05:00
|
|
|
|
2023-09-20 12:21:02 -04:00
|
|
|
# The executable should have an .exe extension for builds targeting 'pure'
|
2019-08-10 04:47:56 -04:00
|
|
|
# Windows, i.e. msvc or mingw builds, but not when using msys or cygwin's gcc.
|
|
|
|
COMPILER_TARGET := $(shell $(CC) -dumpmachine)
|
|
|
|
ifneq (,$(findstring mingw,$(COMPILER_TARGET)))
|
|
|
|
PROG := $(PROG).exe
|
|
|
|
endif
|
|
|
|
|
2022-08-02 15:39:02 -04:00
|
|
|
all: $(BUILD)/$(PROG)
|
2014-01-24 04:05:30 -05:00
|
|
|
|
2022-08-02 15:39:02 -04:00
|
|
|
$(BUILD)/$(PROG): $(OBJ)
|
2014-01-25 11:55:31 -05:00
|
|
|
$(ECHO) "LINK $@"
|
2015-12-09 17:49:25 -05:00
|
|
|
# Do not pass COPT here - it's *C* compiler optimizations. For example,
|
|
|
|
# we may want to compile using Thumb, but link with non-Thumb libc.
|
|
|
|
$(Q)$(CC) -o $@ $^ $(LIB) $(LDFLAGS)
|
2014-01-24 04:05:30 -05:00
|
|
|
ifndef DEBUG
|
2023-09-20 03:29:12 -04:00
|
|
|
ifdef STRIP
|
2019-08-10 04:47:56 -04:00
|
|
|
$(Q)$(STRIP) $(STRIPFLAGS_EXTRA) $@
|
2023-09-20 03:29:12 -04:00
|
|
|
endif
|
2014-01-24 04:05:30 -05:00
|
|
|
endif
|
2019-08-10 04:47:56 -04:00
|
|
|
$(Q)$(SIZE) $$(find $(BUILD) -path "$(BUILD)/build/frozen*.o") $@
|
2014-01-24 04:05:30 -05:00
|
|
|
|
|
|
|
clean: clean-prog
|
|
|
|
clean-prog:
|
2022-08-02 15:39:02 -04:00
|
|
|
$(RM) -f $(BUILD)/$(PROG)
|
|
|
|
$(RM) -f $(BUILD)/$(PROG).map
|
2014-01-24 04:05:30 -05:00
|
|
|
|
|
|
|
.PHONY: clean-prog
|
|
|
|
endif
|
|
|
|
|
2021-04-23 15:26:42 -04:00
|
|
|
submodules:
|
|
|
|
$(ECHO) "Updating submodules: $(GIT_SUBMODULES)"
|
|
|
|
ifneq ($(GIT_SUBMODULES),)
|
2021-08-17 06:20:29 -04:00
|
|
|
$(Q)git submodule sync $(addprefix $(TOP)/,$(GIT_SUBMODULES))
|
2021-04-23 15:26:42 -04:00
|
|
|
$(Q)git submodule update --init $(addprefix $(TOP)/,$(GIT_SUBMODULES))
|
|
|
|
endif
|
|
|
|
.PHONY: submodules
|
|
|
|
|
2016-08-29 17:59:17 -04:00
|
|
|
LIBMICROPYTHON = libmicropython.a
|
2017-03-29 17:08:27 -04:00
|
|
|
|
|
|
|
# We can execute extra commands after library creation using
|
|
|
|
# LIBMICROPYTHON_EXTRA_CMD. This may be needed e.g. to integrate
|
|
|
|
# with 3rd-party projects which don't have proper dependency
|
|
|
|
# tracking. Then LIBMICROPYTHON_EXTRA_CMD can e.g. touch some
|
|
|
|
# other file to cause needed effect, e.g. relinking with new lib.
|
2022-08-02 15:39:02 -04:00
|
|
|
lib $(BUILD)/$(LIBMICROPYTHON): $(OBJ)
|
|
|
|
$(Q)$(AR) rcs $(BUILD)/$(LIBMICROPYTHON) $^
|
2017-03-29 17:08:27 -04:00
|
|
|
$(LIBMICROPYTHON_EXTRA_CMD)
|
2016-06-15 18:11:24 -04:00
|
|
|
|
2014-01-24 04:05:30 -05:00
|
|
|
clean:
|
2016-08-04 16:40:15 -04:00
|
|
|
$(RM) -rf $(BUILD) $(CLEAN_EXTRA)
|
2014-01-24 04:05:30 -05:00
|
|
|
.PHONY: clean
|
|
|
|
|
|
|
|
print-cfg:
|
|
|
|
$(ECHO) "PY_SRC = $(PY_SRC)"
|
|
|
|
$(ECHO) "BUILD = $(BUILD)"
|
|
|
|
$(ECHO) "OBJ = $(OBJ)"
|
|
|
|
.PHONY: print-cfg
|
|
|
|
|
2014-06-16 01:33:14 -04:00
|
|
|
print-def:
|
|
|
|
@$(ECHO) "The following defines are built into the $(CC) compiler"
|
2021-04-22 20:55:39 -04:00
|
|
|
$(TOUCH) __empty__.c
|
2014-06-16 01:33:14 -04:00
|
|
|
@$(CC) -E -Wp,-dM __empty__.c
|
|
|
|
@$(RM) -f __empty__.c
|
|
|
|
|
2014-01-24 04:05:30 -05:00
|
|
|
-include $(OBJ:.o=.P)
|