mirror of
https://github.com/KhronosGroup/Vulkan-Utility-Libraries.git
synced 2025-05-14 16:58:43 +00:00

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.
25 lines
805 B
Python
25 lines
805 B
Python
#!/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
|