From 3939556fc39165039e34a27971d9adfa95a19129 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mart=C3=AD=20Bol=C3=ADvar?= Date: Wed, 12 Feb 2020 21:45:23 -0800 Subject: [PATCH] scripts: gen_defines: re-work write_bus() with augmented nodes MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This too is an attempt to reimplement the previous behavior exactly, modulo the order in which things are defined. This is the last function which is calling into the previous implementation's out_node and node_*_alias() functions, so these can be removed now. Signed-off-by: Martí Bolívar --- scripts/dts/gen_defines.py | 99 ++++++-------------------------------- 1 file changed, 15 insertions(+), 84 deletions(-) diff --git a/scripts/dts/gen_defines.py b/scripts/dts/gen_defines.py index fa3b7b19f2c..fb059e683b5 100755 --- a/scripts/dts/gen_defines.py +++ b/scripts/dts/gen_defines.py @@ -730,8 +730,18 @@ def write_bus(node): if node.bus_node.label is None: err(f"missing 'label' property on bus node {node.bus_node!r}") - # #define DT__BUS_NAME - out_node_s(node, "BUS_NAME", str2ident(node.bus_node.label)) + primary_macro = None + def write_bus_node_for_ident(node, ident): + # #define DT__BUS_NAME + + nonlocal primary_macro + if primary_macro is None: + primary_macro = out(f"{ident}_BUS_NAME", + quote_str(str2ident(node.bus_node.label))) + else: + out(f"{ident}_BUS_NAME", primary_macro) + + for_each_ident(node, write_bus_node_for_ident) for compat in node.compats: # #define DT__BUS_ 1 @@ -775,45 +785,6 @@ def node_ident(node): return ident -def node_aliases(node): - # Returns a list of aliases for 'node', used e.g. when building macro names - - return node_path_aliases(node) + node_instance_aliases(node) - - -def node_path_aliases(node): - # Returns a list of aliases for 'node', based on the aliases registered for - # it in the /aliases node. Used e.g. when building macro names. - - if node.matching_compat is None: - return [] - - compat_s = str2ident(node.matching_compat) - - aliases = [] - for alias in node.aliases: - aliases.append(f"ALIAS_{str2ident(alias)}") - # TODO: See if we can remove or deprecate this form - aliases.append(f"{compat_s}_{str2ident(alias)}") - - return aliases - - -def node_instance_aliases(node): - # Returns a list of aliases for 'node', based on the compatible string and - # the instance number (each node with a particular compatible gets its own - # instance number, starting from zero). - # - # This is a list since a node can have multiple 'compatible' strings, each - # with their own instance number. - - res = [] - for compat in node.compats: - instance_no = node.edt.compat2enabled[compat].index(node) - res.append(f"INST_{instance_no}_{str2ident(compat)}") - return res - - def write_addr_size(edt, prop_name, prefix): # Writes _BASE_ADDRESS and _SIZE for the node pointed at by # the /chosen property named 'prop_name', if it exists @@ -1130,47 +1101,6 @@ def str2ident(s): .upper() -def out_node(node, ident, val, name_alias=None, deprecation_msg=None): - # Writes a - # - # _ = - # - # assignment, along with a set of - # - # _ - # - # aliases, for each path/instance alias for the node. If 'name_alias' (a - # string) is passed, then these additional aliases are generated: - # - # _ - # _ (for each node alias) - # - # 'name_alias' is used for reg-names and the like. - # - # If a 'deprecation_msg' string is passed, the generated identifiers will - # generate a warning if used, via __WARN()). - # - # Returns the identifier used for the macro that provides the value - # for 'ident' within 'node', e.g. DT_MFG_MODEL_CTL_GPIOS_PIN. - - node_prefix = node_ident(node) - - aliases = [f"{alias}_{ident}" for alias in node_aliases(node)] - if name_alias is not None: - aliases.append(f"{node_prefix}_{name_alias}") - aliases += [f"{alias}_{name_alias}" for alias in node_aliases(node)] - - return out(f"{node_prefix}_{ident}", val, aliases, deprecation_msg) - - -def out_node_s(node, ident, s, name_alias=None, deprecation_msg=None): - # Like out_node(), but emits 's' as a string literal - # - # Returns the generated macro name for 'ident'. - - return out_node(node, ident, quote_str(s), name_alias, deprecation_msg) - - def out_s(ident, val): # Like out(), but puts quotes around 'val' and escapes any double # quotes and backslashes within it @@ -1188,7 +1118,8 @@ def out(ident, val, aliases=(), deprecation_msg=None): # header, these look like '#define '. For the configuration # file, the value is just repeated as '=' for each alias. # - # See out_node() for the meaning of 'deprecation_msg'. + # If a 'deprecation_msg' string is passed, the generated identifiers will + # generate a warning if used, via __WARN()). # # Returns the generated macro name for 'ident'. @@ -1215,7 +1146,7 @@ def out(ident, val, aliases=(), deprecation_msg=None): def out_define(ident, val, deprecation_msg, out_file): - # out() helper for writing a #define. See out_node() for the meaning of + # out() helper for writing a #define. See out() for the meaning of # 'deprecation_msg'. s = f"#define DT_{ident:40}"