From 7bb85c26404bffe5dcb2c67dbf442476fb5cd604 Mon Sep 17 00:00:00 2001 From: Gilles Peskine Date: Mon, 25 Jan 2021 21:36:53 +0100 Subject: [PATCH] Separate the parsing and generation parts of MacroCollector Signed-off-by: Gilles Peskine --- scripts/generate_psa_constants.py | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/scripts/generate_psa_constants.py b/scripts/generate_psa_constants.py index 4cb91df6d..64b3c9dfa 100755 --- a/scripts/generate_psa_constants.py +++ b/scripts/generate_psa_constants.py @@ -205,11 +205,8 @@ BIT_TEST_TEMPLATE = '''\ }\ ''' -class MacroCollector: +class PSAMacroCollector: """Collect PSA crypto macro definitions from C header files. - - 1. Call `read_file` on the input header file(s). - 2. Call `write_file` to write ``psa_constant_names_generated.c``. """ def __init__(self): @@ -303,6 +300,13 @@ class MacroCollector: line = re.sub(self._nonascii_re, rb'', line).decode('ascii') self.read_line(line) +class CaseBuilder(PSAMacroCollector): + """Collect PSA crypto macro definitions and write value recognition functions. + + 1. Call `read_file` on the input header file(s). + 2. Call `write_file` to write ``psa_constant_names_generated.c``. + """ + @staticmethod def _make_return_case(name): return 'case %(name)s: return "%(name)s";' % {'name': name} @@ -404,7 +408,7 @@ class MacroCollector: output_file.write(OUTPUT_TEMPLATE % data) def generate_psa_constants(header_file_names, output_file_name): - collector = MacroCollector() + collector = CaseBuilder() for header_file_name in header_file_names: with open(header_file_name, 'rb') as header_file: collector.read_file(header_file)