diff options
author | Eric Anholt <[email protected]> | 2017-12-28 12:59:33 -0800 |
---|---|---|
committer | Eric Anholt <[email protected]> | 2018-01-03 14:25:23 -0800 |
commit | d3e8a4b96c80955e832981534b1f4c3856b6fdb4 (patch) | |
tree | ee5621390ae0403b4d3d195d429f1c20b37bb79c /src/broadcom/cle/gen_pack_header.py | |
parent | 48cabc1e751bf537f4fdb2721d7a7492c8e401a1 (diff) |
broadcom/xml: Fix up safe name confusion with prefixing.
For enums we were doubling the underscore if the value had a numeric first
character of its name (which safe_name() adds an underscore to). A little
helper function cleans up the other instance of prefixing while also
fixing this.
Diffstat (limited to 'src/broadcom/cle/gen_pack_header.py')
-rw-r--r-- | src/broadcom/cle/gen_pack_header.py | 27 |
1 files changed, 13 insertions, 14 deletions
diff --git a/src/broadcom/cle/gen_pack_header.py b/src/broadcom/cle/gen_pack_header.py index 78ad9ad31a4..a23b69b6758 100644 --- a/src/broadcom/cle/gen_pack_header.py +++ b/src/broadcom/cle/gen_pack_header.py @@ -82,6 +82,11 @@ def safe_name(name): return name +def prefixed_upper_name(prefix, name): + if prefix: + name = prefix + "_" + name + return safe_name(name).upper() + def num_from_str(num_str): if num_str.lower().startswith('0x'): return int(num_str, base=16) @@ -164,15 +169,9 @@ class Field(object): print(" %-36s %s%s;" % (type, self.name, dim)) - if len(self.values) > 0 and self.default == None: - if self.prefix: - prefix = self.prefix + "_" - else: - prefix = "" - for value in self.values: - print("#define %-40s %d" % ((prefix + value.name).replace("__", "_"), - value.value)) + name = prefixed_upper_name(self.prefix, value.name) + print("#define %-40s %d" % (name, value.value)) def overlaps(self, field): return self != field and max(self.start, field.start) <= min(self.end, field.end) @@ -371,7 +370,7 @@ class Group(object): class Value(object): def __init__(self, attrs): - self.name = safe_name(attrs["name"]).upper() + self.name = attrs["name"] self.value = int(attrs["value"]) class Parser(object): @@ -440,7 +439,7 @@ class Parser(object): self.enum = safe_name(attrs["name"]) self.enums.add(attrs["name"]) if "prefix" in attrs: - self.prefix = safe_name(attrs["prefix"]) + self.prefix = attrs["prefix"] else: self.prefix= None elif name == "value": @@ -544,11 +543,11 @@ class Parser(object): def emit_enum(self): print('enum %s {' % self.gen_prefix(self.enum)) for value in self.values: + name = value.name if self.prefix: - name = self.prefix + "_" + value.name - else: - name = value.name - print(' % -36s = %6d,' % (name.upper(), value.value)) + name = self.prefix + "_" + name + name = safe_name(name).upper() + print(' % -36s = %6d,' % (name, value.value)) print('};\n') def parse(self, filename): |