all: Remove third argument to MP_REGISTER_MODULE.

It's no longer needed because this macro is now processed after
preprocessing the source code via cpp (in the qstr extraction stage), which
means unused MP_REGISTER_MODULE's are filtered out by the preprocessor.

Signed-off-by: Damien George <damien@micropython.org>
This commit is contained in:
Damien George
2022-05-31 22:56:11 +10:00
parent 47f634300c
commit efe23aca71
103 changed files with 173 additions and 134 deletions

View File

@@ -1,7 +1,7 @@
#!/usr/bin/env python
# This pre-processor parses a single file containing a list of
# MP_REGISTER_MODULE(module_name, obj_module, enabled_define)
# MP_REGISTER_MODULE(module_name, obj_module)
# These are used to generate a header with the required entries for
# "mp_rom_map_elem_t mp_builtin_module_table[]" in py/objmodule.c
@@ -12,14 +12,14 @@ import io
import argparse
pattern = re.compile(r"\s*MP_REGISTER_MODULE\((.*?),\s*(.*?),\s*(.*?)\);", flags=re.DOTALL)
pattern = re.compile(r"\s*MP_REGISTER_MODULE\((.*?),\s*(.*?)\);", flags=re.DOTALL)
def find_module_registrations(filename):
"""Find any MP_REGISTER_MODULE definitions in the provided file.
:param str filename: path to file to check
:return: List[(module_name, obj_module, enabled_define)]
:return: List[(module_name, obj_module)]
"""
global pattern
@@ -30,31 +30,24 @@ def find_module_registrations(filename):
def generate_module_table_header(modules):
"""Generate header with module table entries for builtin modules.
:param List[(module_name, obj_module, enabled_define)] modules: module defs
:param List[(module_name, obj_module)] modules: module defs
:return: None
"""
# Print header file for all external modules.
mod_defs = set()
print("// Automatically generated by makemoduledefs.py.\n")
for module_name, obj_module, enabled_define in modules:
for module_name, obj_module in modules:
mod_def = "MODULE_DEF_{}".format(module_name.upper())
mod_defs.add(mod_def)
print(
(
"#if ({enabled_define})\n"
" extern const struct _mp_obj_module_t {obj_module};\n"
" #undef {mod_def}\n"
" #define {mod_def} {{ MP_ROM_QSTR({module_name}), MP_ROM_PTR(&{obj_module}) }},\n"
"#else\n"
" #ifndef {mod_def}\n"
" #define {mod_def}\n"
" #endif\n"
"#endif\n"
"extern const struct _mp_obj_module_t {obj_module};\n"
"#undef {mod_def}\n"
"#define {mod_def} {{ MP_ROM_QSTR({module_name}), MP_ROM_PTR(&{obj_module}) }},\n"
).format(
module_name=module_name,
obj_module=obj_module,
enabled_define=enabled_define,
mod_def=mod_def,
)
)