mirror of
https://github.com/yuzu-emu/mbedtls.git
synced 2024-11-29 19:04:19 +01:00
Separate the parsing and generation parts of MacroCollector
Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
This commit is contained in:
parent
58fd20c464
commit
7bb85c2640
@ -205,11 +205,8 @@ BIT_TEST_TEMPLATE = '''\
|
|||||||
}\
|
}\
|
||||||
'''
|
'''
|
||||||
|
|
||||||
class MacroCollector:
|
class PSAMacroCollector:
|
||||||
"""Collect PSA crypto macro definitions from C header files.
|
"""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):
|
def __init__(self):
|
||||||
@ -303,6 +300,13 @@ class MacroCollector:
|
|||||||
line = re.sub(self._nonascii_re, rb'', line).decode('ascii')
|
line = re.sub(self._nonascii_re, rb'', line).decode('ascii')
|
||||||
self.read_line(line)
|
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
|
@staticmethod
|
||||||
def _make_return_case(name):
|
def _make_return_case(name):
|
||||||
return 'case %(name)s: return "%(name)s";' % {'name': name}
|
return 'case %(name)s: return "%(name)s";' % {'name': name}
|
||||||
@ -404,7 +408,7 @@ class MacroCollector:
|
|||||||
output_file.write(OUTPUT_TEMPLATE % data)
|
output_file.write(OUTPUT_TEMPLATE % data)
|
||||||
|
|
||||||
def generate_psa_constants(header_file_names, output_file_name):
|
def generate_psa_constants(header_file_names, output_file_name):
|
||||||
collector = MacroCollector()
|
collector = CaseBuilder()
|
||||||
for header_file_name in header_file_names:
|
for header_file_name in header_file_names:
|
||||||
with open(header_file_name, 'rb') as header_file:
|
with open(header_file_name, 'rb') as header_file:
|
||||||
collector.read_file(header_file)
|
collector.read_file(header_file)
|
||||||
|
Loading…
Reference in New Issue
Block a user