From e31ae9cb6ecafca9a512ed15e0dd6b4577facaad Mon Sep 17 00:00:00 2001 From: Dmitry Selyutin Date: Tue, 2 Aug 2022 14:16:26 +0300 Subject: [PATCH] power_enums: better repr for Function enum --- src/openpower/decoder/power_enums.py | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/openpower/decoder/power_enums.py b/src/openpower/decoder/power_enums.py index 0cd4aab0..e414178c 100644 --- a/src/openpower/decoder/power_enums.py +++ b/src/openpower/decoder/power_enums.py @@ -22,6 +22,7 @@ import csv import os from os.path import dirname, join from collections import namedtuple +import functools def find_wiki_dir(): @@ -109,6 +110,20 @@ class Function(Enum): VL = 1 << 13 # setvl FPU = 1 << 14 # FPU + @functools.lru_cache(maxsize=None) + def __repr__(self): + counter = 0 + value = int(self.value) + if value != 0: + while value != 0: + counter += 1 + value >>= 1 + counter -= 1 + desc = f"(1 << {counter})" + else: + desc = "0" + return f"<{self.__class__.__name__}.{self.name}: {desc}>" + @unique class Form(Enum): -- 2.30.2