Skip to content

Commit

Permalink
Merge pull request #55 from vkottler/dev/3.1.3
Browse files Browse the repository at this point in the history
3.1.3 - Some pruning for XMC4700
  • Loading branch information
vkottler authored Oct 17, 2023
2 parents e254170 + 21b9783 commit 0a1665f
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 5 deletions.
7 changes: 7 additions & 0 deletions ifgen/commands/svd.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
# internal
from ifgen import PKG_NAME
from ifgen.svd import register_processors
from ifgen.svd.group import base, enums
from ifgen.svd.task import SvdProcessingTask


Expand All @@ -31,6 +32,12 @@ def svd_cmd(args: _Namespace) -> int:
)
assert path is not None, args.svd_file

enable_pruning = path.with_suffix("").name in {"XMC4700"}

# Only enable certain pruning strategies for certain processors.
enums.PRUNE_ENUMS = enable_pruning
base.PRUNE_STRUCTS = enable_pruning

SvdProcessingTask.svd(path).generate_configs(args.output)

return 0
Expand Down
5 changes: 4 additions & 1 deletion ifgen/svd/group/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ def peripherals(self) -> Iterator[Peripheral]:
yield from self.derivatives


PRUNE_STRUCTS = False


def get_derived(
peripheral: Peripheral, peripherals: list[Peripheral]
) -> Optional[Peripheral]:
Expand All @@ -35,7 +38,7 @@ def get_derived(
result = peripheral.derived_elem

# Check if this peripheral is equivalent to some other peripheral.
else:
elif PRUNE_STRUCTS:
for other in peripherals:
# Always return None if you get far enough to see yourself in the
# list. That way this peripheral becomes the effective 'root'.
Expand Down
30 changes: 27 additions & 3 deletions ifgen/svd/group/enums.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"""

# built-in
from os.path import commonprefix
from typing import Any

# internal
Expand All @@ -17,11 +18,15 @@
}

BY_HASH: dict[str, dict[int, str]] = {}
PRUNE_ENUMS = False


def get_enum_name(name: str, peripheral: str, raw_mapping: EnumValues) -> str:
"""Get the name of an enumeration."""

if not PRUNE_ENUMS:
return name

hashed = hash(
",".join(
name + f"={val['value']}" for name, val in raw_mapping.items()
Expand Down Expand Up @@ -123,8 +128,27 @@ def translate_enums(enum: EnumeratedValues) -> EnumValues:
else:
enum_data["value"] = int(value_str)

result[
handle_enum_name(name, value.raw_data.get("description"))
] = enum_data
final_name = handle_enum_name(name, value.raw_data.get("description"))
assert final_name

# Truncate.
final_name = (
final_name if len(final_name) < 51 else final_name[:45] + "_cont"
)
assert len(final_name) < 51

while final_name in result:
final_name += "_"

assert final_name not in result, (name, final_name)
result[final_name] = enum_data

# Remove common prefix (if present) from enums.
length = len(commonprefix(list(result)))
if length > 1:
result = {
key[length:] if length < len(key) else key: value
for key, value in result.items()
}

return result
2 changes: 1 addition & 1 deletion local/variables/package.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
---
major: 3
minor: 1
patch: 2
patch: 3
entry: ig

0 comments on commit 0a1665f

Please sign in to comment.