Remove consecutive platform defines

Generated code must macro-guard platform specific code, but did it in a
naive fashion where consecutive guards for the same platform repeated the
macro. With the help of PlatformGuardHelper, the code generation will elide
redundant macro guards.
This commit is contained in:
Charles Giessen 2023-10-17 13:42:43 -06:00 committed by Charles Giessen
parent 89b8b0df6d
commit dcfce25b43
8 changed files with 116 additions and 522 deletions

View file

@ -0,0 +1,25 @@
#!/usr/bin/python3 -i
#
# Copyright 2023 The Khronos Group Inc.
# Copyright 2023 Valve Corporation
# Copyright 2023 LunarG, Inc.
# Copyright 2023 RasterGrid Kft.
#
# SPDX-License-Identifier: Apache-2.0
class PlatformGuardHelper():
"""Used to elide platform guards together, so redundant #endif then #ifdefs are removed
Note - be sure to call addGuard(None) when done to add a trailing #endif if needed
"""
def __init__(self):
self.currentGuard = None
def addGuard(self, guard):
out = []
if self.currentGuard != guard:
if self.currentGuard != None:
out.append(f'#endif // {self.currentGuard}\n')
if guard != None:
out.append(f'#ifdef {guard}\n')
self.currentGuard = guard
return out