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

@ -8,6 +8,7 @@
import os
from generators.base_generator import BaseGenerator
from generators.generator_utils import PlatformGuardHelper
class DispatchTableOutputGenerator(BaseGenerator):
def __init__(self):
@ -39,10 +40,11 @@ typedef struct VkuInstanceDispatchTable_ {
PFN_GetPhysicalDeviceProcAddr GetPhysicalDeviceProcAddr;
''')
guard_helper = PlatformGuardHelper()
for command in [x for x in self.vk.commands.values() if x.instance]:
out.extend([f'#ifdef {command.protect}\n'] if command.protect else [])
out.extend(guard_helper.addGuard(command.protect))
out.append(f' PFN_{command.name} {command.name[2:]};\n')
out.extend([f'#endif // {command.protect}\n'] if command.protect else [])
out.extend(guard_helper.addGuard(None))
out.append('} VkuInstanceDispatchTable;\n')
out.append('''
@ -50,9 +52,9 @@ typedef struct VkuInstanceDispatchTable_ {
typedef struct VkuDeviceDispatchTable_ {
''')
for command in [x for x in self.vk.commands.values() if x.device]:
out.extend([f'#ifdef {command.protect}\n'] if command.protect else [])
out.extend(guard_helper.addGuard(command.protect))
out.append(f' PFN_{command.name} {command.name[2:]};\n')
out.extend([f'#endif // {command.protect}\n'] if command.protect else [])
out.extend(guard_helper.addGuard(None))
out.append('} VkuDeviceDispatchTable;\n')
out.append('''
@ -63,9 +65,9 @@ static inline void vkuInitDeviceDispatchTable(VkDevice device, VkuDeviceDispatch
''')
for command in [x for x in self.vk.commands.values() if x.device and x.name != 'vkGetDeviceProcAddr']:
out.extend([f'#ifdef {command.protect}\n'] if command.protect else [])
out.extend(guard_helper.addGuard(command.protect))
out.append(f' table->{command.name[2:]} = (PFN_{command.name})gdpa(device, "{command.name}");\n')
out.extend([f'#endif // {command.protect}\n'] if command.protect else [])
out.extend(guard_helper.addGuard(None))
out.append('}\n')
out.append('''
@ -85,9 +87,9 @@ static inline void vkuInitInstanceDispatchTable(VkInstance instance, VkuInstance
'vkEnumerateInstanceVersion',
'vkGetInstanceProcAddr',
]]:
out.extend([f'#ifdef {command.protect}\n'] if command.protect else [])
out.extend(guard_helper.addGuard(command.protect))
out.append(f' table->{command.name[2:]} = (PFN_{command.name})gipa(instance, "{command.name}");\n')
out.extend([f'#endif // {command.protect}\n'] if command.protect else [])
out.extend(guard_helper.addGuard(None))
out.append('}')
self.write("".join(out))