From d2610d8cbb94ccf8f7ee53b9f113b3aae50eac2e Mon Sep 17 00:00:00 2001 From: Dmitry Selyutin Date: Tue, 2 Aug 2022 14:06:39 +0300 Subject: [PATCH] power_enums: introduce base enum class --- src/openpower/decoder/power_enums.py | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/src/openpower/decoder/power_enums.py b/src/openpower/decoder/power_enums.py index d5ffffab..f006b962 100644 --- a/src/openpower/decoder/power_enums.py +++ b/src/openpower/decoder/power_enums.py @@ -14,7 +14,10 @@ regfile size in HDL. this is SPRreduced and the supported list is in get_spr_enum """ -from enum import Enum, unique +from enum import ( + Enum as _Enum, + unique, +) import csv import os from os.path import dirname, join @@ -63,6 +66,26 @@ def get_signal_name(name): name = "is_" + name return name.lower().replace(' ', '_') + +class Enum(_Enum): + @classmethod + def _missing_(cls, value): + if isinstance(value, str): + try: + if value == "": + value = 0 + else: + value = int(value, 0) + except ValueError: + pass + keys = {item.name:item for item in cls} + values = {item.value:item for item in cls} + item = keys.get(value, values.get(value)) + if item is None: + raise ValueError(value) + return item + + # this corresponds to which Function Unit (pipeline-with-Reservation-Stations) # is to process and guard the operation. they are roughly divided by having # the same register input/output signature (X-Form, etc.) -- 2.30.2