mirror of
https://github.com/KhronosGroup/Vulkan-Utility-Libraries.git
synced 2025-05-15 09:18:49 +00:00
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:
parent
89b8b0df6d
commit
dcfce25b43
8 changed files with 116 additions and 522 deletions
25
scripts/generators/generator_utils.py
Normal file
25
scripts/generators/generator_utils.py
Normal 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
|
Loading…
Add table
Add a link
Reference in a new issue