diff options
author | Damien George <damien@micropython.org> | 2024-02-09 17:41:48 +1100 |
---|---|---|
committer | Damien George <damien@micropython.org> | 2024-02-16 14:17:01 +1100 |
commit | a3a73b64a3be5b5cc2b50444c819d81f8347d52f (patch) | |
tree | 20b1663339655490360b9f609d22074a366b0cca /tools/mpy-tool.py | |
parent | e2ff00e81113d7a3f32f860652017644b5d68bf1 (diff) |
tools/mpy-tool.py: Skip generating frozen mp_raw_code_t when possible.
This reduces frozen code size by using the bytecode directly as the
`mp_proto_fun_t`.
Signed-off-by: Damien George <damien@micropython.org>
Diffstat (limited to 'tools/mpy-tool.py')
-rwxr-xr-x | tools/mpy-tool.py | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/tools/mpy-tool.py b/tools/mpy-tool.py index 33e59c807..38567b37e 100755 --- a/tools/mpy-tool.py +++ b/tools/mpy-tool.py @@ -911,6 +911,13 @@ class RawCode(object): raw_code_type = "mp_raw_code_t" else: raw_code_type = "mp_raw_code_truncated_t" + + empty_children = len(self.children) == 0 and prelude_ptr is None + generate_minimal = self.code_kind == MP_CODE_BYTECODE and empty_children + + if generate_minimal: + print("#if MICROPY_PERSISTENT_CODE_SAVE") + print("static const %s proto_fun_%s = {" % (raw_code_type, self.escaped_name)) print(" .proto_fun_indicator[0] = MP_PROTO_FUN_INDICATOR_RAW_CODE_0,") print(" .proto_fun_indicator[1] = MP_PROTO_FUN_INDICATOR_RAW_CODE_1,") @@ -961,6 +968,11 @@ class RawCode(object): print(" .asm_type_sig = %u," % type_sig) print("};") + if generate_minimal: + print("#else") + print("#define proto_fun_%s fun_data_%s[0]" % (self.escaped_name, self.escaped_name)) + print("#endif") + global raw_code_count, raw_code_content raw_code_count += 1 raw_code_content += 4 * 4 |