From 2e0893dea11a108093cd9f138ce9726842f0e657 Mon Sep 17 00:00:00 2001 From: Dmitry Selyutin Date: Wed, 1 Jun 2022 18:07:11 +0000 Subject: [PATCH] sv_binutils: refactor CSV iteration --- src/openpower/sv/sv_binutils.py | 50 ++++++++++++++++----------------- 1 file changed, 25 insertions(+), 25 deletions(-) diff --git a/src/openpower/sv/sv_binutils.py b/src/openpower/sv/sv_binutils.py index 6ce8db19..46f7f687 100644 --- a/src/openpower/sv/sv_binutils.py +++ b/src/openpower/sv/sv_binutils.py @@ -670,7 +670,6 @@ class Codegen(_enum.Enum): ISA = _SVP64RM() FIELDS = {field.name:field.type for field in _dataclasses.fields(Record)} -FIELDS.update({field.name:field.type for field in _dataclasses.fields(Entry)}) def parse(path): visited = set() @@ -693,31 +692,32 @@ def parse(path): return True - def item_mapper(item): - (key, value) = item - key = key.lower().replace(" ", "_") - cls = FIELDS.get(key, object) - if not isinstance(value, cls): - if issubclass(cls, _enum.Enum): - value = {item.name:item for item in cls}[value] - else: - value = cls(value) - return (key, value) - - def item_filter(item): - (key, _) = item - return (key in FIELDS) - - for record in ISA.get_svp64_csv(path): - names = record.pop("comment").split("=")[-1].split("/") + for data in ISA.get_svp64_csv(path): + comment = data.pop("comment") + names = comment.split("=")[-1].split("/") names = set(filter(name_filter, names)) - if names: - rc = _RC[record["rc"] if record["rc"] else "NONE"] - if rc is _RC.RC: - names.update({f"{name}." for name in names}) - record = dict(filter(item_filter, map(item_mapper, record.items()))) - for name in map(Name, names): - yield Entry(name=name, record=Record(**record)) + if not names: + continue + rc = _RC[data["rc"] if data["rc"] else "NONE"] + if rc is _RC.RC: + names.update({f"{name}." for name in names}) + + record = {} + for (key, value) in data.items(): + key = key.lower().replace(" ", "_") + cls = FIELDS.get(key) + if cls is None: + continue + if not isinstance(value, cls): + if issubclass(cls, _enum.Enum): + value = {item.name:item for item in cls}[value] + else: + value = cls(value) + record[key] = value + record = Record(**record) + + for name in map(Name, names): + yield Entry(name=name, record=record) def main(codegen): -- 2.30.2