2018-08-23 14:21:22 +03:00
|
|
|
#!/usr/bin/env python
|
2018-01-18 22:29:49 +03:00
|
|
|
|
|
|
|
#NOTE: If you make modifications here, consider whether they should
|
|
|
|
#be duplicated in ../lsteamclient/gen_wrapper.py
|
|
|
|
|
2023-02-24 04:34:28 +03:00
|
|
|
CLANG_PATH='/usr/lib/clang/15'
|
2019-09-17 18:53:26 +03:00
|
|
|
|
2023-09-23 23:31:13 +03:00
|
|
|
from clang.cindex import Cursor, CursorKind, Index, TypeKind
|
2023-09-16 21:13:49 +03:00
|
|
|
import concurrent.futures
|
2018-01-18 22:29:49 +03:00
|
|
|
import os
|
|
|
|
import re
|
|
|
|
|
2023-09-20 22:02:50 +03:00
|
|
|
SDK_VERSIONS = [
|
2023-09-20 02:15:52 +03:00
|
|
|
"v1.26.7",
|
2023-02-24 04:49:42 +03:00
|
|
|
"v1.23.7",
|
2021-03-19 18:15:18 +03:00
|
|
|
"v1.16.8",
|
2020-10-13 17:09:11 +03:00
|
|
|
"v1.14.15",
|
2020-10-13 17:04:51 +03:00
|
|
|
"v1.13.10",
|
2020-08-11 21:28:05 +03:00
|
|
|
"v1.12.5",
|
2020-08-11 21:24:59 +03:00
|
|
|
"v1.11.11",
|
2020-03-18 21:50:21 +03:00
|
|
|
"v1.10.30",
|
2020-03-18 21:50:17 +03:00
|
|
|
"v1.9.16",
|
2019-12-31 23:26:20 +03:00
|
|
|
"v1.8.19",
|
2019-12-31 23:05:30 +03:00
|
|
|
"v1.7.15",
|
2019-08-16 17:10:37 +03:00
|
|
|
"v1.6.10",
|
2019-07-13 13:17:57 +03:00
|
|
|
"v1.5.17",
|
2019-06-28 22:27:56 +03:00
|
|
|
"v1.4.18",
|
2019-06-28 22:25:08 +03:00
|
|
|
"v1.3.22",
|
2019-06-28 22:22:25 +03:00
|
|
|
"v1.2.10",
|
2018-12-14 22:20:13 +03:00
|
|
|
"v1.1.3b",
|
2018-10-23 20:30:09 +03:00
|
|
|
"v1.0.17",
|
|
|
|
"v1.0.16",
|
2018-06-05 17:37:23 +03:00
|
|
|
"v1.0.15",
|
|
|
|
"v1.0.14",
|
|
|
|
"v1.0.13",
|
2018-01-31 19:31:32 +03:00
|
|
|
"v1.0.12",
|
2018-01-18 22:29:49 +03:00
|
|
|
"v1.0.11",
|
|
|
|
"v1.0.10",
|
|
|
|
"v1.0.9",
|
|
|
|
"v1.0.8",
|
|
|
|
"v1.0.7",
|
|
|
|
"v1.0.6",
|
|
|
|
"v1.0.5",
|
|
|
|
"v1.0.4",
|
2018-12-10 20:31:46 +03:00
|
|
|
"v1.0.3a", #non-public build used by The Lab, see Proton github PR#2075
|
2018-01-18 22:29:49 +03:00
|
|
|
"v1.0.3",
|
|
|
|
"v1.0.2",
|
|
|
|
"v1.0.1",
|
|
|
|
"v1.0.0",
|
|
|
|
"v0.9.20",
|
|
|
|
"v0.9.19",
|
|
|
|
"v0.9.18",
|
|
|
|
"v0.9.17",
|
|
|
|
"v0.9.16",
|
|
|
|
"v0.9.15",
|
|
|
|
"v0.9.14",
|
|
|
|
"v0.9.13",
|
|
|
|
"v0.9.12",
|
|
|
|
# "v0.9.11", problematic GetComponentState, may cause crash since we don't implement it
|
|
|
|
"v0.9.10",
|
|
|
|
"v0.9.9",
|
|
|
|
"v0.9.8",
|
|
|
|
"v0.9.7",
|
|
|
|
"v0.9.6",
|
|
|
|
# "v0.9.5", doesn't compile, fixed in 0.9.6
|
|
|
|
"v0.9.4",
|
|
|
|
"0.9.3",
|
|
|
|
"0.9.2",
|
|
|
|
"0.9.1",
|
|
|
|
"0.9.0",
|
|
|
|
]
|
|
|
|
|
2023-09-16 21:13:49 +03:00
|
|
|
ABIS = ['u32', 'u64', 'w32', 'w64']
|
|
|
|
|
2023-09-20 22:15:40 +03:00
|
|
|
SDK_SOURCES = {
|
|
|
|
"ivrclientcore.h": [
|
2018-01-18 22:29:49 +03:00
|
|
|
[ #classes
|
2023-09-20 22:15:40 +03:00
|
|
|
"IVRApplications",
|
|
|
|
"IVRChaperone",
|
|
|
|
"IVRChaperoneSetup",
|
|
|
|
"IVRCompositor",
|
|
|
|
"IVRControlPanel",
|
|
|
|
"IVRDriverManager",
|
|
|
|
"IVRExtendedDisplay",
|
|
|
|
"IVRNotifications",
|
|
|
|
"IVRInput",
|
|
|
|
"IVRIOBuffer",
|
|
|
|
"IVRMailbox",
|
|
|
|
"IVROverlay",
|
|
|
|
"IVRRenderModels",
|
|
|
|
"IVRResources",
|
|
|
|
"IVRScreenshots",
|
|
|
|
"IVRSettings",
|
|
|
|
"IVRSystem",
|
|
|
|
"IVRTrackedCamera",
|
|
|
|
"IVRHeadsetView",
|
|
|
|
"IVROverlayView",
|
|
|
|
"IVRClientCore",
|
2018-01-18 22:29:49 +03:00
|
|
|
], [ #vrclient-allocated structs
|
2023-09-20 22:15:40 +03:00
|
|
|
"RenderModel_t",
|
|
|
|
"RenderModel_TextureMap_t",
|
|
|
|
],
|
|
|
|
],
|
|
|
|
}
|
2018-01-18 22:29:49 +03:00
|
|
|
|
2023-09-20 22:15:40 +03:00
|
|
|
SDK_CLASSES = {klass: source for source, value in SDK_SOURCES.items()
|
|
|
|
for klass in value[0]}
|
|
|
|
SDK_STRUCTS = {klass: source for source, value in SDK_SOURCES.items()
|
|
|
|
for klass in value[1]}
|
2023-09-20 22:15:40 +03:00
|
|
|
|
2023-09-20 18:27:42 +03:00
|
|
|
# these structs are manually confirmed to be equivalent
|
|
|
|
EXEMPT_STRUCTS = {
|
|
|
|
"HmdColor_t",
|
|
|
|
"HmdMatrix33_t",
|
|
|
|
"HmdMatrix34_t",
|
|
|
|
"HmdMatrix44_t",
|
|
|
|
"HmdQuad_t",
|
|
|
|
"HmdQuaternion_t",
|
|
|
|
"HmdQuaternionf_t",
|
|
|
|
"HmdVector2_t",
|
|
|
|
"HmdVector3_t",
|
|
|
|
"HmdVector3d_t",
|
|
|
|
"HmdVector4_t",
|
2023-09-29 10:58:52 +03:00
|
|
|
"IntersectionMaskCircle_t",
|
|
|
|
"IntersectionMaskRectangle_t",
|
2023-09-28 11:59:50 +03:00
|
|
|
"CVRSettingHelper",
|
2023-09-20 18:27:42 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
# structs for which the size is important, either because of arrays or size parameters
|
|
|
|
SIZED_STRUCTS = {
|
|
|
|
"CameraVideoStreamFrameHeader_t",
|
|
|
|
"Compositor_BenchmarkResults",
|
|
|
|
"Compositor_CumulativeStats",
|
|
|
|
"Compositor_StageRenderSettings",
|
|
|
|
"InputAnalogActionData_t",
|
|
|
|
"InputBindingInfo_t",
|
|
|
|
"InputDigitalActionData_t",
|
|
|
|
"InputOriginInfo_t",
|
|
|
|
"InputPoseActionData_t",
|
|
|
|
"InputSkeletalActionData_t",
|
|
|
|
"InputSkeletonActionData_t",
|
|
|
|
"Texture_t",
|
|
|
|
"TrackedDevicePose_t",
|
|
|
|
"VRActiveActionSet_t",
|
|
|
|
"VRBoneTransform_t",
|
|
|
|
"VRControllerState001_t",
|
|
|
|
"VREvent_t",
|
|
|
|
"VROverlayIntersectionMaskPrimitive_t",
|
|
|
|
"VROverlayView_t",
|
|
|
|
}
|
|
|
|
|
2023-09-20 22:02:50 +03:00
|
|
|
STRUCTS_NEXT_IS_SIZE = [
|
|
|
|
"VREvent_t",
|
|
|
|
"VRControllerState001_t",
|
|
|
|
"InputAnalogActionData_t",
|
|
|
|
"InputDigitalActionData_t",
|
|
|
|
"InputPoseActionData_t",
|
|
|
|
"InputSkeletalActionData_t",
|
|
|
|
"CameraVideoStreamFrameHeader_t",
|
|
|
|
"Compositor_CumulativeStats",
|
|
|
|
"VRActiveActionSet_t",
|
|
|
|
"InputOriginInfo_t",
|
|
|
|
"InputBindingInfo_t",
|
2019-09-18 18:59:28 +03:00
|
|
|
]
|
|
|
|
|
2023-09-20 22:02:50 +03:00
|
|
|
STRUCTS_NEXT_IS_SIZE_UNHANDLED = [
|
|
|
|
"VROverlayIntersectionMaskPrimitive_t" # not next, but next-next uint32 is the size
|
2019-09-18 18:59:28 +03:00
|
|
|
]
|
|
|
|
|
2023-09-20 22:02:50 +03:00
|
|
|
STRUCTS_SIZE_FIELD = {
|
|
|
|
"Compositor_OverlaySettings": ["size"],
|
|
|
|
"Compositor_FrameTiming": ["size", "m_nSize"],
|
|
|
|
"DriverDirectMode_FrameTiming": ["m_nSize"],
|
2019-09-18 18:59:28 +03:00
|
|
|
}
|
|
|
|
|
2023-09-23 23:31:13 +03:00
|
|
|
PATH_CONV_METHODS_UTOW = {
|
|
|
|
"IVRScreenshots_GetScreenshotPropertyFilename": {
|
|
|
|
"pchFilename": {"len": "cchFilename"},
|
|
|
|
"ret_size": True,
|
2020-03-18 21:50:21 +03:00
|
|
|
},
|
|
|
|
|
2023-09-23 23:31:13 +03:00
|
|
|
# maybe?
|
|
|
|
# "IVRRenderModels_GetRenderModelOriginalPath": {
|
|
|
|
# "pchOriginalPath": {"len": unOriginalPathLen},
|
2019-03-18 23:02:30 +03:00
|
|
|
# },
|
2023-09-23 23:31:13 +03:00
|
|
|
# "IVRResources_GetResourceFullPath": {
|
|
|
|
# "pchPathBuffer": {"len": unBufferLen},
|
2019-03-18 23:02:30 +03:00
|
|
|
# },
|
2023-09-23 23:31:13 +03:00
|
|
|
# IVRInput::GetInputSourceHandle
|
|
|
|
# IVRIOBuffer::Open
|
|
|
|
# TODO: LaunchInternalProcess, need steam cooperation
|
|
|
|
}
|
2019-03-18 23:02:30 +03:00
|
|
|
|
2023-09-23 23:31:13 +03:00
|
|
|
PATH_CONV_METHODS_WTOU = {
|
|
|
|
"IVRInput_SetActionManifestPath": {"pchActionManifestPath"},
|
|
|
|
"IVRCompositor_SetOverlayFromFile": {"pchFilePath"},
|
|
|
|
"IVROverlay_SetOverlayFromFile": {"pchFilePath"},
|
|
|
|
"IVRApplications_AddApplicationManifest": {"pchApplicationManifestFullPath"},
|
|
|
|
"IVRApplications_RemoveApplicationManifest": {"pchApplicationManifestFullPath"},
|
|
|
|
"IVRScreenshots_RequestScreenshot": {"pchVRFilename", "pchPreviewFilename"},
|
|
|
|
"IVRScreenshots_TakeStereoScreenshot": {"pchVRFilename", "pchPreviewFilename"},
|
|
|
|
"IVRScreenshots_SubmitScreenshot": {"pchSourcePreviewFilename", "pchSourceVRFilename"},
|
|
|
|
"IVRControlPanel_undoc23": {"a"},
|
|
|
|
"IVRControlPanel_undoc27": {"a"},
|
|
|
|
"IVRCompositor_SetStageOverride_Async": {"pchRenderModelPath"},
|
|
|
|
|
|
|
|
# maybe?
|
|
|
|
# "IVRResources_GetResourceFullPath": {"pchResourceTypeDirectory"},
|
|
|
|
# IVRInput::GetInputSourceHandle
|
|
|
|
# IVRIOBuffer::Open
|
|
|
|
# TODO: LaunchInternalProcess, need steam cooperation
|
|
|
|
}
|
2019-03-01 19:41:24 +03:00
|
|
|
|
2023-09-21 21:33:54 +03:00
|
|
|
all_classes = {}
|
2023-09-20 23:21:42 +03:00
|
|
|
all_records = {}
|
2023-09-21 21:33:54 +03:00
|
|
|
all_structs = {}
|
2023-09-20 23:21:42 +03:00
|
|
|
all_sources = {}
|
|
|
|
all_versions = {}
|
2023-09-29 10:58:52 +03:00
|
|
|
unique_structs = []
|
2023-09-20 23:21:42 +03:00
|
|
|
|
2018-01-18 22:29:49 +03:00
|
|
|
|
2023-09-27 09:32:39 +03:00
|
|
|
MANUAL_METHODS = {
|
2023-09-27 10:09:37 +03:00
|
|
|
"IVRClientCore_BIsHmdPresent": True,
|
|
|
|
"IVRClientCore_Init": True,
|
|
|
|
"IVRClientCore_GetGenericInterface": True,
|
|
|
|
"IVRClientCore_Cleanup": True,
|
2023-09-27 09:32:39 +03:00
|
|
|
"IVRSystem_GetDXGIOutputInfo": True,
|
|
|
|
"IVRSystem_GetOutputDevice": lambda ver, abi: ver > 16,
|
2023-09-27 09:43:42 +03:00
|
|
|
"IVRCompositor_Submit": lambda ver, abi: ver > 8,
|
|
|
|
"IVRCompositor_SetSkyboxOverride": lambda ver, abi: ver > 8,
|
|
|
|
"IVRCompositor_PostPresentHandoff": True,
|
|
|
|
"IVRCompositor_WaitGetPoses": lambda ver, abi: ver > 15 and ver < 27,
|
|
|
|
"IVRCompositor_GetVulkanDeviceExtensionsRequired": True,
|
2023-09-27 09:40:10 +03:00
|
|
|
"IVRRenderModels_LoadTextureD3D11_Async": True,
|
|
|
|
"IVRRenderModels_FreeTextureD3D11": True,
|
|
|
|
"IVRRenderModels_LoadIntoTextureD3D11_Async": True,
|
2023-09-27 10:09:37 +03:00
|
|
|
"IVRMailbox_undoc3": True,
|
2023-09-27 09:43:42 +03:00
|
|
|
"IVROverlay_SetOverlayTexture": True,
|
2023-09-27 09:43:42 +03:00
|
|
|
"IVRInput_GetDigitalActionData": lambda ver, abi: ver > 3,
|
2023-09-27 09:32:39 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
def is_manual_method(klass, method, abi):
|
|
|
|
version = re.search(r'(\d+)$', klass.version)
|
|
|
|
|
2023-09-20 18:27:42 +03:00
|
|
|
key = f'{klass.name}_{method.name}'
|
2023-09-27 09:32:39 +03:00
|
|
|
needs_manual = MANUAL_METHODS.get(key, False)
|
|
|
|
|
|
|
|
if callable(needs_manual) and version:
|
|
|
|
return needs_manual(int(version[0]), abi)
|
|
|
|
return needs_manual
|
|
|
|
|
|
|
|
|
2023-09-20 18:27:42 +03:00
|
|
|
class Padding:
|
|
|
|
def __init__(self, offset, size):
|
|
|
|
self.offset = offset
|
|
|
|
self.size = size
|
|
|
|
|
|
|
|
|
|
|
|
class Field:
|
|
|
|
def __init__(self, cursor, struct, type, offset, name=None):
|
|
|
|
self._cursor = cursor
|
|
|
|
self._type = type
|
|
|
|
|
|
|
|
self.name = cursor.spelling if not name else name
|
|
|
|
self.type = cursor.type
|
|
|
|
self.size = self.type.get_size()
|
|
|
|
self.offset = offset
|
|
|
|
|
|
|
|
def needs_conversion(self, other):
|
|
|
|
return self._type.needs_conversion(other._type)
|
|
|
|
|
|
|
|
|
|
|
|
class BasicType:
|
|
|
|
def __init__(self, type, abi):
|
|
|
|
self._type = type.get_canonical()
|
|
|
|
self._abi = abi
|
2023-09-29 10:58:52 +03:00
|
|
|
self._decl_order = 0
|
|
|
|
self._conv_cache = {}
|
|
|
|
|
|
|
|
self.size = self._type.get_size()
|
|
|
|
self.id = self._type.spelling
|
|
|
|
|
|
|
|
@property
|
|
|
|
def order(self):
|
|
|
|
return self._decl_order
|
|
|
|
|
|
|
|
def set_used(self, order=-1):
|
|
|
|
if self._decl_order <= order:
|
|
|
|
return
|
|
|
|
self._decl_order = order
|
2023-09-20 18:27:42 +03:00
|
|
|
|
|
|
|
def needs_conversion(self, other):
|
2023-09-29 10:58:52 +03:00
|
|
|
if self._type.kind == TypeKind.POINTER and self._type.get_pointee().kind == TypeKind.FUNCTIONPROTO:
|
|
|
|
return self._abi != other._abi
|
2023-09-20 18:27:42 +03:00
|
|
|
return False
|
|
|
|
|
|
|
|
|
|
|
|
class Struct:
|
|
|
|
def __init__(self, sdkver, abi, cursor):
|
|
|
|
self._cursor = cursor
|
|
|
|
self._sdkver = sdkver
|
|
|
|
self._abi = abi
|
|
|
|
self._fields = None
|
2023-09-29 10:58:52 +03:00
|
|
|
self._decl_order = 0
|
2023-09-28 15:49:12 +03:00
|
|
|
self._conv_cache = {}
|
2023-09-20 18:27:42 +03:00
|
|
|
|
|
|
|
self.name = canonical_typename(self._cursor)
|
|
|
|
self.name = self.name.removeprefix("vr::")
|
|
|
|
self.type = self._cursor.type.get_canonical()
|
|
|
|
self.size = self.type.get_size()
|
|
|
|
self.align = self.type.get_align()
|
2023-09-28 15:49:12 +03:00
|
|
|
self.id = f'{abi}_{self.name}_{sdkver}'
|
2023-09-20 18:27:42 +03:00
|
|
|
|
2023-09-29 10:58:52 +03:00
|
|
|
if self._cursor.spelling in EXEMPT_STRUCTS:
|
|
|
|
self._fields = [Padding(0, self.size)]
|
|
|
|
|
|
|
|
@property
|
|
|
|
def order(self):
|
|
|
|
return self._decl_order
|
|
|
|
|
|
|
|
def set_used(self, order=-1):
|
|
|
|
if self._decl_order <= order:
|
|
|
|
return
|
|
|
|
self._decl_order = order
|
|
|
|
[f._type.set_used(order - 1) for f in self.fields]
|
|
|
|
|
2023-09-20 18:27:42 +03:00
|
|
|
@property
|
|
|
|
def padded_fields(self):
|
|
|
|
if self._fields: return self._fields
|
|
|
|
|
|
|
|
size, self._fields = 0, []
|
|
|
|
for cursor in self._cursor.get_children():
|
|
|
|
if cursor.kind == CursorKind.CXX_BASE_SPECIFIER \
|
|
|
|
and len(list(cursor.type.get_fields())) > 0:
|
|
|
|
base_type = Type(cursor.type, self._sdkver, self._abi)
|
|
|
|
self._fields += base_type.padded_fields
|
|
|
|
size = cursor.type.get_size()
|
|
|
|
break
|
|
|
|
|
|
|
|
for cursor in self.type.get_fields():
|
|
|
|
assert not cursor.is_bitfield()
|
|
|
|
offset = self.type.get_offset(cursor.spelling)
|
|
|
|
assert offset % 8 == 0
|
|
|
|
offset = offset // 8
|
|
|
|
# assert offset >= size or type(self) is Union
|
|
|
|
|
|
|
|
if size < offset: self._fields.append(Padding(size, offset - size))
|
|
|
|
field_type = Type(cursor.type, self._sdkver, self._abi)
|
|
|
|
self._fields.append(Field(cursor, self, field_type, offset))
|
|
|
|
size = max(size, offset + cursor.type.get_size())
|
|
|
|
|
|
|
|
if size < self.size: self._fields.append(Padding(size, self.size - size))
|
|
|
|
return self._fields
|
|
|
|
|
|
|
|
@property
|
|
|
|
def fields(self):
|
|
|
|
return [f for f in self.padded_fields if type(f) is not Padding]
|
|
|
|
|
2023-09-28 23:22:25 +03:00
|
|
|
def write_definition(self, out, prefix, converters):
|
2023-09-28 11:59:50 +03:00
|
|
|
version = all_versions[sdkver][self.name]
|
|
|
|
kind = 'union' if type(self) is Union else 'struct'
|
|
|
|
wrapped = len(prefix) > 0
|
|
|
|
|
|
|
|
out(f'#pragma pack( push, {self.align} )\n')
|
|
|
|
out(f'{kind} {prefix}{version}\n')
|
|
|
|
out(u'{\n')
|
|
|
|
for f in self.padded_fields:
|
|
|
|
if type(f) is Field:
|
|
|
|
out(f' {declspec(f._cursor, f.name, prefix, wrapped)};\n')
|
|
|
|
else:
|
|
|
|
out(f' uint8_t __pad_{f.offset}[{f.size}];\n')
|
2023-09-28 23:22:25 +03:00
|
|
|
for conv in converters:
|
|
|
|
out(u'#ifdef __cplusplus\n')
|
|
|
|
out(f' operator {conv}{version}() const;\n')
|
|
|
|
out(u'#endif /* __cplusplus */\n')
|
2023-09-28 11:59:50 +03:00
|
|
|
out(u'};\n')
|
|
|
|
out(u'#pragma pack( pop )\n\n')
|
|
|
|
|
|
|
|
def write_checks(self, out, prefix):
|
|
|
|
version = all_versions[sdkver][self.name]
|
|
|
|
|
|
|
|
out(f'C_ASSERT( sizeof({prefix}{version}) >= {self.size} );\n')
|
|
|
|
for f in self.fields:
|
|
|
|
out(f'C_ASSERT( offsetof({prefix}{version}, {f.name}) == {f.offset} );\n')
|
|
|
|
out(f'C_ASSERT( sizeof({prefix}{version}().{f.name}) >= {f.size} );\n')
|
|
|
|
out(u'\n')
|
|
|
|
|
2023-09-28 23:22:25 +03:00
|
|
|
def write_converter(self, prefix):
|
|
|
|
version = all_versions[sdkver][self.name]
|
|
|
|
out(f'{self._abi}_{version}::operator {prefix}{version}() const\n')
|
|
|
|
out(u'{\n')
|
|
|
|
out(f' {prefix}{version} ret;\n')
|
|
|
|
for field in self.fields:
|
|
|
|
out(f' ret.{field.name} = this->{field.name};\n')
|
|
|
|
out(u' return ret;\n')
|
|
|
|
out(u'}\n')
|
|
|
|
|
2023-09-20 18:27:42 +03:00
|
|
|
def needs_conversion(self, other):
|
2023-09-28 15:49:12 +03:00
|
|
|
if other.id in self._conv_cache:
|
|
|
|
return self._conv_cache[other.id]
|
|
|
|
self._conv_cache[other.id] = other._conv_cache[self.id] = True
|
|
|
|
|
2023-09-20 18:27:42 +03:00
|
|
|
if self.name in SIZED_STRUCTS and self.size != other.size:
|
|
|
|
return True
|
|
|
|
if len(self.fields) != len(other.fields):
|
|
|
|
return True
|
|
|
|
if any([a.offset != b.offset or a.needs_conversion(b)
|
|
|
|
for a, b in zip(self.fields, other.fields)]):
|
|
|
|
return True
|
|
|
|
|
2023-09-28 15:49:12 +03:00
|
|
|
self._conv_cache[other.id] = other._conv_cache[self.id] = False
|
2023-09-20 18:27:42 +03:00
|
|
|
return False
|
|
|
|
|
|
|
|
def get_children(self):
|
|
|
|
return self._cursor.get_children()
|
|
|
|
|
|
|
|
|
|
|
|
class Union(Struct):
|
|
|
|
def __init__(self, sdkver, abi, cursor):
|
|
|
|
super().__init__(sdkver, abi, cursor)
|
|
|
|
|
|
|
|
|
2023-09-24 18:15:41 +03:00
|
|
|
class Method:
|
|
|
|
def __init__(self, sdkver, abi, cursor, index, override):
|
|
|
|
self._sdkver = sdkver
|
|
|
|
self._abi = abi
|
|
|
|
|
|
|
|
self._cursor = cursor
|
|
|
|
self._index = index
|
|
|
|
self._override = override
|
|
|
|
|
|
|
|
self.result_type = cursor.result_type
|
|
|
|
self.spelling = cursor.spelling
|
|
|
|
|
|
|
|
@property
|
|
|
|
def name(self):
|
|
|
|
if self._override > 1: return f'{self.spelling}_{self._override}'
|
|
|
|
return self.spelling
|
|
|
|
|
|
|
|
def get_arguments(self):
|
|
|
|
return self._cursor.get_arguments()
|
|
|
|
|
|
|
|
def get_children(self):
|
|
|
|
return self._cursor.get_children()
|
|
|
|
|
|
|
|
|
|
|
|
class Destructor(Method):
|
|
|
|
def __init__(self, sdkver, abi, cursor, index, override):
|
|
|
|
super().__init__(sdkver, abi, cursor, index, override)
|
|
|
|
|
|
|
|
@property
|
|
|
|
def name(self):
|
|
|
|
if self._override > 1: return f'destructor_{self._override}'
|
|
|
|
return 'destructor'
|
|
|
|
|
|
|
|
|
2023-09-23 20:44:47 +03:00
|
|
|
class Class:
|
|
|
|
def __init__(self, sdkver, abi, cursor):
|
2023-09-20 18:27:42 +03:00
|
|
|
self._cursor = cursor
|
2023-09-23 20:44:47 +03:00
|
|
|
self._sdkver = sdkver
|
|
|
|
self._abi = abi
|
2023-09-20 18:27:42 +03:00
|
|
|
self._methods = None
|
2023-09-29 10:58:52 +03:00
|
|
|
self._decl_order = 0
|
2023-09-23 20:44:47 +03:00
|
|
|
|
2023-09-20 18:27:42 +03:00
|
|
|
self.name = cursor.spelling
|
|
|
|
self.filename = SDK_CLASSES.get(self.name, None)
|
|
|
|
versions = all_versions[sdkver]
|
|
|
|
self.version = versions.get(self.name, "")
|
2023-09-23 20:44:47 +03:00
|
|
|
|
2023-09-20 18:27:42 +03:00
|
|
|
self.type = self._cursor.type.get_canonical()
|
2023-09-29 10:58:52 +03:00
|
|
|
self.id = f'{abi}_{self.name}_{sdkver}'
|
2023-09-24 18:15:41 +03:00
|
|
|
|
|
|
|
@property
|
|
|
|
def methods(self):
|
|
|
|
if self._methods:
|
|
|
|
return self._methods
|
|
|
|
|
|
|
|
overrides = {}
|
|
|
|
is_method = lambda c: c.kind == CursorKind.CXX_METHOD and c.is_virtual_method()
|
|
|
|
in_vtable = lambda c: is_method(c) or c.kind == CursorKind.DESTRUCTOR
|
|
|
|
|
|
|
|
self._methods = []
|
|
|
|
for i, method in enumerate(filter(in_vtable, self._cursor.get_children())):
|
|
|
|
index, override = overrides.get(method.spelling, (i, 1))
|
|
|
|
overrides[method.spelling] = (index, override + 1)
|
|
|
|
if method.kind == CursorKind.DESTRUCTOR:
|
|
|
|
self._methods.append(Destructor(self._sdkver, self._abi, method, index, override))
|
|
|
|
else:
|
|
|
|
self._methods.append(Method(self._sdkver, self._abi, method, index, override))
|
|
|
|
|
|
|
|
return self._methods
|
|
|
|
|
2023-09-28 11:22:41 +03:00
|
|
|
@property
|
|
|
|
def full_name(self):
|
2023-09-20 18:27:42 +03:00
|
|
|
if len(self.version) == 0:
|
|
|
|
return self.name
|
|
|
|
return f'{self.name}_{self.version}'
|
|
|
|
|
2023-09-29 10:58:52 +03:00
|
|
|
@property
|
|
|
|
def order(self):
|
|
|
|
return self._decl_order
|
|
|
|
|
|
|
|
def set_used(self, order=-1):
|
|
|
|
if self._decl_order <= order:
|
|
|
|
return
|
|
|
|
self._decl_order = order
|
|
|
|
|
2023-09-20 18:27:42 +03:00
|
|
|
def needs_conversion(self, other):
|
|
|
|
return self._abi[0] != other._abi[0]
|
2023-09-28 11:22:41 +03:00
|
|
|
|
2023-09-29 10:58:52 +03:00
|
|
|
def __eq__(self, other):
|
|
|
|
return self._abi[0] == other._abi[0]
|
|
|
|
|
2023-09-28 11:22:41 +03:00
|
|
|
def write_definition(self, out, prefix):
|
|
|
|
out(f'struct {prefix}{self.full_name}\n')
|
|
|
|
out(u'{\n')
|
|
|
|
out(u'#ifdef __cplusplus\n')
|
|
|
|
for method in self.methods:
|
|
|
|
types = [declspec(p, "", prefix if prefix != "cpp" else None)
|
|
|
|
for p in method.get_arguments()]
|
|
|
|
if type(method) is Destructor:
|
|
|
|
out(f' virtual ~{prefix}{self.full_name}( {", ".join(types)} ) = 0;\n')
|
|
|
|
else:
|
|
|
|
method_name = f'{declspec(method.result_type, "", None)} {method.spelling}'
|
|
|
|
out(f' virtual {method_name}( {", ".join(types)} ) = 0;\n')
|
|
|
|
out(u'#endif /* __cplusplus */\n')
|
|
|
|
out(u'};\n\n')
|
|
|
|
|
2023-09-23 20:44:47 +03:00
|
|
|
def get_children(self):
|
|
|
|
return self._cursor.get_children()
|
|
|
|
|
|
|
|
|
2023-09-20 18:27:42 +03:00
|
|
|
def Record(sdkver, abi, cursor):
|
|
|
|
if cursor.type.get_declaration().kind == CursorKind.UNION_DECL:
|
|
|
|
return Union(sdkver, abi, cursor)
|
|
|
|
|
|
|
|
method_kinds = (CursorKind.CXX_METHOD, CursorKind.DESTRUCTOR)
|
|
|
|
is_method = lambda c: c.kind in method_kinds and c.is_virtual_method()
|
|
|
|
for _ in filter(is_method, cursor.get_children()):
|
|
|
|
return Class(sdkver, abi, cursor)
|
|
|
|
|
|
|
|
return Struct(sdkver, abi, cursor)
|
|
|
|
|
|
|
|
|
|
|
|
def Type(decl, sdkver, abi):
|
|
|
|
name = strip_ns(canonical_typename(decl))
|
|
|
|
if name not in all_structs:
|
|
|
|
return BasicType(decl, abi)
|
|
|
|
return all_structs[name][sdkver][abi]
|
|
|
|
|
|
|
|
|
2018-01-18 22:29:49 +03:00
|
|
|
def display_sdkver(s):
|
|
|
|
if s.startswith("v"):
|
|
|
|
s = s[1:]
|
|
|
|
return s.replace(".", "")
|
|
|
|
|
|
|
|
def strip_ns(name):
|
|
|
|
return name.replace("vr::","")
|
|
|
|
|
2022-10-22 18:28:35 +03:00
|
|
|
|
2023-09-23 18:54:08 +03:00
|
|
|
def underlying_type(decl):
|
|
|
|
if type(decl) is Cursor:
|
|
|
|
decl = decl.type
|
|
|
|
decl = decl.get_canonical()
|
|
|
|
if decl.kind == TypeKind.LVALUEREFERENCE: return underlying_type(decl.get_pointee())
|
|
|
|
if decl.kind == TypeKind.CONSTANTARRAY: return underlying_type(decl.element_type)
|
|
|
|
if decl.kind == TypeKind.POINTER: return underlying_type(decl.get_pointee())
|
|
|
|
return decl
|
|
|
|
|
|
|
|
|
2023-09-27 15:09:21 +03:00
|
|
|
def param_needs_conversion(decl):
|
|
|
|
decl = underlying_type(decl)
|
|
|
|
return decl.kind == TypeKind.RECORD and \
|
|
|
|
struct_needs_conversion(decl)
|
|
|
|
|
|
|
|
|
2023-09-28 11:22:41 +03:00
|
|
|
def callconv(cursor, prefix):
|
|
|
|
if type(cursor) is not Cursor or prefix is None:
|
2023-09-19 22:24:23 +03:00
|
|
|
return ''
|
|
|
|
canon = cursor.type.get_canonical()
|
|
|
|
if canon.kind != TypeKind.POINTER:
|
|
|
|
return ''
|
|
|
|
canon = canon.get_pointee()
|
|
|
|
if canon.kind != TypeKind.FUNCTIONPROTO:
|
|
|
|
return ''
|
|
|
|
if cursor.type.kind == TypeKind.TYPEDEF:
|
|
|
|
cursor = cursor.type.get_declaration()
|
|
|
|
|
|
|
|
tokens = cursor.get_tokens()
|
|
|
|
while next(tokens).spelling != '(': pass
|
2023-09-19 22:30:14 +03:00
|
|
|
token = next(tokens).spelling.strip('_')
|
|
|
|
token = token.replace('*', 'stdcall')
|
|
|
|
token = token.replace('S_CALLTYPE', 'cdecl')
|
|
|
|
return f'{prefix[0].upper()}_{token.upper()} '
|
2023-09-19 22:24:23 +03:00
|
|
|
|
|
|
|
|
2023-09-28 11:22:41 +03:00
|
|
|
def declspec_func(decl, name, prefix):
|
2023-09-28 11:59:50 +03:00
|
|
|
ret = declspec(decl.get_result(), "", prefix, False)
|
|
|
|
params = [declspec(a, "", prefix, False) for a in decl.argument_types()]
|
2023-09-19 22:24:23 +03:00
|
|
|
params = ", ".join(params) if len(params) else "void"
|
|
|
|
return f'{ret} ({name})({params})'
|
|
|
|
|
|
|
|
|
2023-09-28 11:59:50 +03:00
|
|
|
def declspec(decl, name, prefix, wrapped=False):
|
2023-09-28 11:22:41 +03:00
|
|
|
call = callconv(decl, prefix)
|
2022-10-22 18:28:35 +03:00
|
|
|
if type(decl) is Cursor:
|
|
|
|
decl = decl.type
|
2023-09-19 20:59:23 +03:00
|
|
|
if 'VRControllerState_t' not in decl.spelling: # FIXME
|
|
|
|
decl = decl.get_canonical()
|
2022-10-22 18:28:35 +03:00
|
|
|
|
|
|
|
const = 'const ' if decl.is_const_qualified() else ''
|
2023-09-19 20:59:23 +03:00
|
|
|
if decl.kind == TypeKind.FUNCTIONPROTO:
|
2023-09-28 11:22:41 +03:00
|
|
|
return declspec_func(decl, name, prefix)
|
2022-10-22 18:28:35 +03:00
|
|
|
if decl.kind in (TypeKind.POINTER, TypeKind.LVALUEREFERENCE):
|
|
|
|
decl = decl.get_pointee()
|
2023-09-28 11:59:50 +03:00
|
|
|
spec = declspec(decl, f"*{call}{const}{name}", prefix, False)
|
|
|
|
if wrapped:
|
|
|
|
return f'{prefix.upper()}PTR({spec}, {name})'
|
|
|
|
return spec
|
2022-10-22 18:28:35 +03:00
|
|
|
if decl.kind == TypeKind.CONSTANTARRAY:
|
|
|
|
decl, count = decl.element_type, decl.element_count
|
2023-09-28 11:59:50 +03:00
|
|
|
if wrapped:
|
|
|
|
spec = declspec(decl, const, prefix, False)
|
|
|
|
return f'{prefix.upper()}ARRAY({spec}, {count}, {name})'
|
|
|
|
return declspec(decl, f"({const}{name})[{count}]", prefix, False)
|
2022-10-22 18:28:35 +03:00
|
|
|
|
|
|
|
if len(name):
|
|
|
|
name = f' {name}'
|
|
|
|
|
|
|
|
if decl.kind in (TypeKind.UNEXPOSED, TypeKind.FUNCTIONPROTO):
|
|
|
|
return f'void{name}'
|
|
|
|
if decl.kind == TypeKind.ENUM:
|
2023-09-14 17:22:47 +03:00
|
|
|
return f'uint{decl.get_size() * 8}_t{name}'
|
2022-10-22 18:28:35 +03:00
|
|
|
|
2023-09-29 10:58:52 +03:00
|
|
|
type_name = decl.spelling.removeprefix("const ")
|
|
|
|
type_name = decl.spelling.removeprefix("vr::")
|
|
|
|
if type_name.startswith(('IVR', 'ID3D')):
|
|
|
|
return f'{const}void /*{type_name}*/{name}'
|
|
|
|
|
2023-09-28 11:59:50 +03:00
|
|
|
if prefix not in (None, "win") and decl.kind == TypeKind.RECORD \
|
|
|
|
and type_name in all_versions[sdkver] \
|
|
|
|
and type_name not in EXEMPT_STRUCTS:
|
|
|
|
if type_name in unique_structs:
|
|
|
|
return f'{const}{all_versions[sdkver][type_name]}{name}'
|
|
|
|
return f'{const}{prefix}{all_versions[sdkver][type_name]}{name}'
|
|
|
|
|
2022-10-22 18:28:35 +03:00
|
|
|
real_name = canonical_typename(decl)
|
|
|
|
real_name = real_name.removeprefix("const ")
|
|
|
|
real_name = real_name.removeprefix("vr::")
|
|
|
|
|
2023-09-28 11:22:41 +03:00
|
|
|
if prefix == "win" and real_name in SDK_STRUCTS:
|
2023-09-14 15:53:26 +03:00
|
|
|
type_name = f"win{real_name}_{display_sdkver(sdkver)}"
|
2023-09-28 11:22:41 +03:00
|
|
|
elif prefix == "win" and struct_needs_conversion(decl.get_canonical()) \
|
2022-10-22 18:28:35 +03:00
|
|
|
and not decl.is_const_qualified(): # FIXME
|
2023-09-14 15:53:26 +03:00
|
|
|
type_name = f"win{real_name}_{display_sdkver(sdkver)}"
|
2022-10-22 18:28:35 +03:00
|
|
|
else:
|
2023-09-14 15:53:26 +03:00
|
|
|
type_name = decl.spelling
|
|
|
|
type_name = type_name.removeprefix("const ")
|
|
|
|
type_name = type_name.removeprefix("vr::")
|
|
|
|
|
|
|
|
if type_name in ('void', 'bool', 'char', 'float', 'double'):
|
|
|
|
return f'{const}{type_name}{name}'
|
|
|
|
if type_name.startswith(('int', 'long', 'short', 'signed')):
|
|
|
|
return f'{const}int{decl.get_size() * 8}_t{name}'
|
|
|
|
if type_name.startswith(('uint', 'unsigned')):
|
|
|
|
return f'{const}uint{decl.get_size() * 8}_t{name}'
|
|
|
|
|
|
|
|
return f'{const}{type_name}{name}'
|
2022-10-22 18:28:35 +03:00
|
|
|
|
|
|
|
|
2023-09-27 16:18:31 +03:00
|
|
|
def handle_method_hpp(method, cppname, out):
|
2023-09-27 12:05:52 +03:00
|
|
|
returns_record = method.result_type.get_canonical().kind == TypeKind.RECORD
|
2022-10-22 18:28:35 +03:00
|
|
|
|
2023-09-27 12:05:52 +03:00
|
|
|
ret = "*_ret" if returns_record else "_ret"
|
2023-09-28 11:22:41 +03:00
|
|
|
ret = f'{declspec(method.result_type, ret, "win")}'
|
2022-10-22 18:28:35 +03:00
|
|
|
|
2023-09-27 12:05:52 +03:00
|
|
|
names = [p.spelling if p.spelling != "" else f'_{chr(0x61 + i)}'
|
|
|
|
for i, p in enumerate(method.get_arguments())]
|
2023-09-28 11:22:41 +03:00
|
|
|
params = [declspec(p, names[i], "win") for i, p in enumerate(method.get_arguments())]
|
2023-09-27 12:05:52 +03:00
|
|
|
|
|
|
|
if method.result_type.kind != TypeKind.VOID:
|
|
|
|
params = [ret] + params
|
|
|
|
params = ['void *linux_side'] + params
|
|
|
|
|
|
|
|
out(f'struct {cppname}_{method.name}_params\n')
|
|
|
|
out(u'{\n')
|
|
|
|
for param in params:
|
|
|
|
out(f' {param};\n')
|
|
|
|
out(u'};\n')
|
|
|
|
out(f'extern void {cppname}_{method.name}( struct {cppname}_{method.name}_params *params );\n\n')
|
2022-10-22 18:28:35 +03:00
|
|
|
|
|
|
|
|
2023-09-27 16:18:31 +03:00
|
|
|
def handle_method_cpp(method, classname, cppname, out):
|
2023-09-23 22:44:20 +03:00
|
|
|
returns_void = method.result_type.kind == TypeKind.VOID
|
2023-09-27 12:05:52 +03:00
|
|
|
returns_record = method.result_type.get_canonical().kind == TypeKind.RECORD
|
2023-09-23 17:11:42 +03:00
|
|
|
|
|
|
|
names = [p.spelling if p.spelling != "" else f'_{chr(0x61 + i)}'
|
|
|
|
for i, p in enumerate(method.get_arguments())]
|
|
|
|
|
2023-09-27 15:09:21 +03:00
|
|
|
need_convert = {n: p for n, p in zip(names, method.get_arguments())
|
|
|
|
if param_needs_conversion(p)}
|
|
|
|
|
2023-09-23 17:11:42 +03:00
|
|
|
names = ['linux_side'] + names
|
|
|
|
|
2023-09-27 12:05:52 +03:00
|
|
|
out(f'void {cppname}_{method.name}( struct {cppname}_{method.name}_params *params )\n')
|
2023-09-27 16:18:31 +03:00
|
|
|
out(u'{\n')
|
2023-09-28 11:22:41 +03:00
|
|
|
out(f' struct {cppname} *iface = (struct {cppname} *)params->linux_side;\n')
|
2023-09-23 17:11:42 +03:00
|
|
|
|
2023-09-20 18:27:42 +03:00
|
|
|
params = list(zip(names[1:], method.get_arguments()))
|
|
|
|
for i, (name, param) in enumerate(params[:-1]):
|
|
|
|
if underlying_type(param).kind != TypeKind.RECORD:
|
|
|
|
continue
|
|
|
|
next_name, next_param = params[i + 1]
|
|
|
|
if not any(w in next_name.lower() for w in ('count', 'len', 'size', 'num')):
|
|
|
|
continue
|
|
|
|
assert strip_ns(underlying_typename(param)) in SIZED_STRUCTS | EXEMPT_STRUCTS
|
|
|
|
|
|
|
|
for i, (name, param) in enumerate(params[1:]):
|
|
|
|
if underlying_type(param).kind != TypeKind.RECORD:
|
|
|
|
continue
|
|
|
|
prev_name, prev_param = params[i - 1]
|
|
|
|
if not any(w in prev_name.lower() for w in ('count', 'len', 'size', 'num')):
|
|
|
|
continue
|
|
|
|
if strip_ns(underlying_typename(param)) not in SIZED_STRUCTS | EXEMPT_STRUCTS:
|
|
|
|
print('Warning:', strip_ns(underlying_typename(param)), name, 'following', prev_name)
|
|
|
|
|
2023-09-27 15:09:21 +03:00
|
|
|
need_unwrap = {}
|
|
|
|
need_output = {}
|
|
|
|
|
|
|
|
for name, param in sorted(need_convert.items()):
|
|
|
|
type_name = strip_ns(underlying_typename(param))
|
|
|
|
|
|
|
|
if param.type.kind != TypeKind.POINTER:
|
2023-09-28 11:59:50 +03:00
|
|
|
out(f' {declspec(param, f"lin_{name}", None).removeprefix("const ")};\n')
|
2023-09-27 12:05:52 +03:00
|
|
|
out(f' win_to_lin_struct_{param.type.spelling}_{display_sdkver(sdkver)}( ¶ms->{name}, &lin_{name} );\n')
|
2023-09-23 17:11:42 +03:00
|
|
|
continue
|
|
|
|
|
2023-09-27 15:09:21 +03:00
|
|
|
pointee = param.type.get_pointee()
|
|
|
|
if pointee.kind == TypeKind.POINTER:
|
|
|
|
need_output[name] = param
|
2023-09-28 11:59:50 +03:00
|
|
|
out(f' {declspec(pointee, f"lin_{name}", None).removeprefix("const ")};\n')
|
2023-09-27 15:09:21 +03:00
|
|
|
continue
|
2018-01-18 22:29:49 +03:00
|
|
|
|
2023-09-27 15:09:21 +03:00
|
|
|
if type_name in SDK_STRUCTS:
|
|
|
|
need_unwrap[name] = param
|
|
|
|
continue
|
2018-01-18 22:29:49 +03:00
|
|
|
|
2023-09-27 15:09:21 +03:00
|
|
|
if not pointee.is_const_qualified():
|
|
|
|
need_output[name] = param
|
2019-09-17 20:54:01 +03:00
|
|
|
|
2023-09-28 11:59:50 +03:00
|
|
|
out(f' {declspec(pointee, f"lin_{name}", None).removeprefix("const ")};\n')
|
2023-09-27 12:05:52 +03:00
|
|
|
out(f' if (params->{name})\n')
|
|
|
|
out(f' struct_{type_name}_{display_sdkver(sdkver)}_win_to_lin( params->{name}, &lin_{name} );\n')
|
2023-09-23 18:54:08 +03:00
|
|
|
|
2023-09-27 16:08:47 +03:00
|
|
|
size_fixup = {}
|
2023-09-27 15:09:21 +03:00
|
|
|
size_param = {}
|
2023-09-27 12:05:52 +03:00
|
|
|
size_fixup = {}
|
2023-09-23 18:54:08 +03:00
|
|
|
params = list(zip(names[1:], method.get_arguments()))
|
|
|
|
params += [(None, None)] # for next_name, next_param
|
|
|
|
for i, (name, param) in enumerate(params[:-1]):
|
|
|
|
real_type = underlying_type(param)
|
|
|
|
if strip_ns(real_type.spelling) not in STRUCTS_NEXT_IS_SIZE:
|
|
|
|
continue
|
|
|
|
|
|
|
|
next_name, next_param = params[i + 1]
|
|
|
|
if not next_param or next_param.type.spelling != "uint32_t":
|
2023-09-27 15:09:21 +03:00
|
|
|
size_param[name] = ', -1'
|
2023-09-23 18:54:08 +03:00
|
|
|
elif struct_needs_size_adjustment(real_type.get_canonical()):
|
|
|
|
real_name = real_type.spelling
|
2023-09-27 12:05:52 +03:00
|
|
|
out(f' uint32_t lin_{next_name} = std::min( params->{next_name}, (uint32_t)sizeof({real_name}) );\n')
|
|
|
|
size_param[name] = f', params->{next_name}'
|
2023-09-27 16:08:47 +03:00
|
|
|
size_fixup[next_name] = True
|
2023-09-27 15:09:21 +03:00
|
|
|
elif name in need_convert:
|
|
|
|
assert name not in STRUCTS_NEXT_IS_SIZE_UNHANDLED
|
2023-09-27 12:05:52 +03:00
|
|
|
out(f' uint32_t lin_{next_name} = params->{next_name} ? sizeof(lin_{name}) : 0;\n')
|
|
|
|
size_param[name] = f', params->{next_name}'
|
2023-09-27 16:08:47 +03:00
|
|
|
size_fixup[next_name] = True
|
2023-09-23 18:54:08 +03:00
|
|
|
|
2023-09-23 22:44:20 +03:00
|
|
|
if returns_void:
|
2023-09-27 16:18:31 +03:00
|
|
|
out(u' ')
|
2023-09-27 12:05:52 +03:00
|
|
|
elif returns_record:
|
|
|
|
out(u' *params->_ret = ')
|
2018-01-18 22:29:49 +03:00
|
|
|
else:
|
2023-09-27 12:05:52 +03:00
|
|
|
out(u' params->_ret = ')
|
2018-01-18 22:29:49 +03:00
|
|
|
|
2023-09-27 15:09:21 +03:00
|
|
|
def param_call(name, param):
|
|
|
|
pfx = '&' if param.type.kind == TypeKind.POINTER else ''
|
2023-09-27 12:05:52 +03:00
|
|
|
if name in size_fixup: return f"lin_{name}"
|
|
|
|
if name in need_unwrap: return f'struct_{type_name}_{display_sdkver(sdkver)}_unwrap( params->{name} )'
|
|
|
|
if name in need_convert: return f"params->{name} ? {pfx}lin_{name} : nullptr"
|
2023-09-28 11:22:41 +03:00
|
|
|
return f'params->{name}'
|
2023-09-23 19:51:41 +03:00
|
|
|
|
2023-09-27 15:09:21 +03:00
|
|
|
params = [param_call(n, p) for n, p in zip(names[1:], method.get_arguments())]
|
2023-09-28 11:22:41 +03:00
|
|
|
out(f'iface->{method.spelling}( {", ".join(params)} );\n')
|
2023-09-23 19:51:41 +03:00
|
|
|
|
2023-09-27 15:09:21 +03:00
|
|
|
for name, param in sorted(need_output.items()):
|
|
|
|
type_name = strip_ns(underlying_typename(param))
|
|
|
|
if type_name in SDK_STRUCTS:
|
2023-09-27 12:05:52 +03:00
|
|
|
out(u' if (params->_ret == 0)\n')
|
|
|
|
out(f' *params->{name} = struct_{type_name}_{display_sdkver(sdkver)}_wrap( lin_{name} );\n')
|
2023-09-27 15:09:21 +03:00
|
|
|
continue
|
2023-09-27 12:05:52 +03:00
|
|
|
out(f' if (params->{name})\n')
|
|
|
|
out(f' struct_{type_name}_{display_sdkver(sdkver)}_lin_to_win( &lin_{name}, params->{name}{size_param.get(name, "")} );\n')
|
2023-09-23 22:44:20 +03:00
|
|
|
|
2023-09-27 16:18:31 +03:00
|
|
|
out(u'}\n\n')
|
2023-09-22 01:09:46 +03:00
|
|
|
|
|
|
|
|
2023-09-27 16:18:31 +03:00
|
|
|
def handle_thiscall_wrapper(klass, method, out):
|
2023-09-23 21:52:28 +03:00
|
|
|
returns_record = method.result_type.get_canonical().kind == TypeKind.RECORD
|
|
|
|
|
|
|
|
def param_stack_size(param):
|
|
|
|
if param.type.kind == TypeKind.LVALUEREFERENCE: return 4
|
|
|
|
return ((param.type.get_size() + 3) // 4) * 4
|
|
|
|
|
|
|
|
size = 4 + sum(param_stack_size(p) for p in method.get_arguments())
|
|
|
|
if returns_record: size += 4
|
|
|
|
|
2023-09-20 18:27:42 +03:00
|
|
|
name = f'win{klass.full_name}_{method.name}'
|
2023-09-27 16:18:31 +03:00
|
|
|
out(f'DEFINE_THISCALL_WRAPPER({name}, {size})\n')
|
2023-09-23 21:52:28 +03:00
|
|
|
|
|
|
|
|
2023-09-27 09:32:39 +03:00
|
|
|
def handle_method_c(klass, method, winclassname, cppname, out):
|
2023-09-23 22:44:20 +03:00
|
|
|
returns_void = method.result_type.kind == TypeKind.VOID
|
2023-09-22 01:09:46 +03:00
|
|
|
returns_record = method.result_type.get_canonical().kind == TypeKind.RECORD
|
2023-09-23 21:54:51 +03:00
|
|
|
|
2023-09-23 23:07:08 +03:00
|
|
|
ret = "*" if returns_record else ""
|
2023-09-28 11:22:41 +03:00
|
|
|
ret = f'{declspec(method.result_type, ret, "win")} '
|
2023-09-23 21:54:51 +03:00
|
|
|
|
|
|
|
names = [p.spelling if p.spelling != "" else f'_{chr(0x61 + i)}'
|
|
|
|
for i, p in enumerate(method.get_arguments())]
|
2023-09-28 11:22:41 +03:00
|
|
|
params = [declspec(p, names[i], "win") for i, p in enumerate(method.get_arguments())]
|
2023-09-23 21:54:51 +03:00
|
|
|
|
2023-09-22 01:09:46 +03:00
|
|
|
if returns_record:
|
2023-09-28 11:22:41 +03:00
|
|
|
params = [f'{declspec(method.result_type, "*_ret", "win")}'] + params
|
2023-09-23 22:44:20 +03:00
|
|
|
names = ['_ret'] + names
|
2023-09-23 21:54:51 +03:00
|
|
|
|
2023-09-24 15:50:45 +03:00
|
|
|
params = ['struct w_steam_iface *_this'] + params
|
2023-09-23 21:54:51 +03:00
|
|
|
names = ['_this'] + names
|
|
|
|
|
2023-09-27 09:32:39 +03:00
|
|
|
if is_manual_method(klass, method, 'w'):
|
|
|
|
out(f'extern {ret}__thiscall {winclassname}_{method.name}({", ".join(params)});\n\n')
|
|
|
|
return
|
|
|
|
|
2023-09-27 16:18:31 +03:00
|
|
|
out(f'{ret}__thiscall {winclassname}_{method.name}({", ".join(params)})\n')
|
|
|
|
out(u'{\n')
|
2023-09-23 21:54:51 +03:00
|
|
|
|
2023-09-27 12:05:52 +03:00
|
|
|
out(f' struct {cppname}_{method.name}_params params =\n')
|
|
|
|
out(u' {\n')
|
|
|
|
out(u' .linux_side = _this->u_iface,\n')
|
|
|
|
for name in names[1:]:
|
|
|
|
out(f' .{name} = {name},\n')
|
|
|
|
out(u' };\n')
|
2023-09-23 22:44:20 +03:00
|
|
|
|
2023-09-20 18:27:42 +03:00
|
|
|
path_conv_utow = PATH_CONV_METHODS_UTOW.get(f'{klass.name}_{method.spelling}', {})
|
|
|
|
path_conv_wtou = PATH_CONV_METHODS_WTOU.get(f'{klass.name}_{method.spelling}', {})
|
2023-09-22 01:09:46 +03:00
|
|
|
|
2023-09-23 23:31:13 +03:00
|
|
|
for name in filter(lambda x: x in names, sorted(path_conv_wtou)):
|
2023-10-03 00:08:17 +03:00
|
|
|
out(f' params.{name} = vrclient_dos_to_unix_path( {name} );\n')
|
2023-09-22 01:09:46 +03:00
|
|
|
|
2023-09-27 16:18:31 +03:00
|
|
|
out(u' TRACE("%p\\n", _this);\n')
|
2023-09-22 01:09:46 +03:00
|
|
|
|
2023-09-27 09:43:42 +03:00
|
|
|
if 'eTextureType' in names:
|
|
|
|
out(u' if (eTextureType == API_DirectX) FIXME( "Not implemented Direct3D API!\\n" );\n')
|
|
|
|
|
2023-09-27 12:05:52 +03:00
|
|
|
out(f' {cppname}_{method.name}( ¶ms );\n')
|
2023-09-23 22:44:20 +03:00
|
|
|
|
2023-09-23 23:31:13 +03:00
|
|
|
for name, conv in filter(lambda x: x[0] in names, path_conv_utow.items()):
|
|
|
|
out(u' ')
|
|
|
|
if "ret_size" in path_conv_utow:
|
2023-09-27 12:05:52 +03:00
|
|
|
out(u'params._ret = ')
|
|
|
|
out(f'vrclient_unix_path_to_dos_path( params._ret, {name}, {name}, {conv["len"]} );\n')
|
2023-09-23 22:44:20 +03:00
|
|
|
|
2023-09-24 16:30:59 +03:00
|
|
|
for name in filter(lambda x: x in names, sorted(path_conv_wtou)):
|
2023-10-03 00:08:17 +03:00
|
|
|
out(f' vrclient_free_path( params.{name} );\n')
|
2023-09-24 16:30:59 +03:00
|
|
|
|
2023-09-23 22:44:20 +03:00
|
|
|
if not returns_void:
|
2023-09-27 12:05:52 +03:00
|
|
|
out(u' return params._ret;\n')
|
2023-09-27 16:18:31 +03:00
|
|
|
out(u'}\n\n')
|
2018-01-18 22:29:49 +03:00
|
|
|
|
|
|
|
|
2018-07-27 10:40:01 +03:00
|
|
|
max_c_api_param_count = 0
|
|
|
|
|
2018-07-30 18:40:06 +03:00
|
|
|
def get_capi_thunk_params(method):
|
|
|
|
def toBOOL(x):
|
|
|
|
return "TRUE" if x else "FALSE"
|
2021-12-14 21:22:36 +03:00
|
|
|
returns_record = method.result_type.get_canonical().kind == TypeKind.RECORD
|
2023-09-24 17:39:53 +03:00
|
|
|
param_types = [x.type for x in method.get_arguments()]
|
2018-07-30 18:29:43 +03:00
|
|
|
if returns_record:
|
|
|
|
param_types.insert(0, method.result_type)
|
|
|
|
param_count = len(param_types)
|
|
|
|
has_float_params = any(x.spelling == "float" for x in param_types)
|
|
|
|
is_4th_float = param_count >= 4 and param_types[3].spelling == "float"
|
2018-07-30 18:40:06 +03:00
|
|
|
return "%s, %s, %s" % (param_count, toBOOL(has_float_params), toBOOL(is_4th_float))
|
|
|
|
|
2023-09-24 00:11:56 +03:00
|
|
|
|
2023-09-23 20:44:47 +03:00
|
|
|
def handle_class(klass):
|
2023-09-20 18:27:42 +03:00
|
|
|
cppname = f"cpp{klass.full_name}"
|
2023-09-24 00:11:56 +03:00
|
|
|
|
|
|
|
with open(f"vrclient_x64/{cppname}.h", "w") as file:
|
|
|
|
out = file.write
|
|
|
|
|
|
|
|
out(u'#ifdef __cplusplus\n')
|
|
|
|
out(u'extern "C" {\n')
|
|
|
|
out(u'#endif\n')
|
|
|
|
|
2023-09-28 11:22:41 +03:00
|
|
|
out(f'struct {cppname};\n')
|
|
|
|
|
2023-09-24 00:11:56 +03:00
|
|
|
for method in klass.methods:
|
|
|
|
if type(method) is Destructor:
|
|
|
|
continue
|
|
|
|
handle_method_hpp(method, cppname, out)
|
|
|
|
|
|
|
|
out(u'#ifdef __cplusplus')
|
|
|
|
out(u'\n}')
|
|
|
|
out(u'\n#endif\n')
|
|
|
|
|
|
|
|
with open(f"vrclient_x64/{cppname}.cpp", "w") as file:
|
|
|
|
out = file.write
|
|
|
|
|
|
|
|
out(u'#include "vrclient_private.h"\n')
|
|
|
|
out(u'#include "vrclient_defs.h"\n')
|
|
|
|
if os.path.isfile(f"openvr_{klass._sdkver}/ivrclientcore.h"):
|
|
|
|
out(f'#include "openvr_{klass._sdkver}/ivrclientcore.h"\n')
|
|
|
|
else:
|
|
|
|
out(f'#include "openvr_{klass._sdkver}/openvr.h"\n')
|
|
|
|
out(u'using namespace vr;\n')
|
|
|
|
out(u'extern "C" {\n')
|
|
|
|
out(u'#include "struct_converters.h"\n')
|
|
|
|
out(u'}\n')
|
|
|
|
out(f'#include "{cppname}.h"\n')
|
|
|
|
out(u'#ifdef __cplusplus\n')
|
|
|
|
out(u'extern "C" {\n')
|
2023-09-28 11:22:41 +03:00
|
|
|
out(u'#endif\n\n')
|
|
|
|
|
|
|
|
klass.write_definition(out, "cpp")
|
2023-09-24 00:11:56 +03:00
|
|
|
|
|
|
|
for method in klass.methods:
|
|
|
|
if type(method) is Destructor:
|
|
|
|
continue
|
2023-09-20 18:27:42 +03:00
|
|
|
handle_method_cpp(method, klass.name, cppname, out)
|
2023-09-24 00:11:56 +03:00
|
|
|
|
|
|
|
out(u'#ifdef __cplusplus\n')
|
|
|
|
out(u'}\n')
|
|
|
|
out(u'#endif\n')
|
|
|
|
|
2023-09-20 18:27:42 +03:00
|
|
|
winclassname = f'win{klass.full_name}'
|
|
|
|
with open(f'vrclient_x64/win{klass.name}.c', 'a') as file:
|
2023-09-24 00:20:53 +03:00
|
|
|
out = file.write
|
2023-09-24 00:11:56 +03:00
|
|
|
|
2023-09-24 00:20:53 +03:00
|
|
|
out(f'#include "{cppname}.h"\n\n')
|
2018-01-18 22:29:49 +03:00
|
|
|
|
2023-09-24 00:20:53 +03:00
|
|
|
for method in klass.methods:
|
|
|
|
handle_thiscall_wrapper(klass, method, out)
|
|
|
|
out('\n')
|
2023-09-24 18:15:41 +03:00
|
|
|
|
2023-09-24 00:20:53 +03:00
|
|
|
for method in klass.methods:
|
|
|
|
if type(method) is Destructor:
|
|
|
|
continue
|
2023-09-27 09:32:39 +03:00
|
|
|
handle_method_c(klass, method, winclassname, cppname, out)
|
2023-09-23 21:52:28 +03:00
|
|
|
|
2023-09-24 00:20:53 +03:00
|
|
|
out(f'extern vtable_ptr {winclassname}_vtable;\n\n')
|
|
|
|
out(u'#ifndef __GNUC__\n')
|
|
|
|
out(u'void __asm_dummy_vtables(void) {\n')
|
|
|
|
out(u'#endif\n')
|
|
|
|
out(f' __ASM_VTABLE({winclassname},\n')
|
|
|
|
for method in sorted(klass.methods, key=lambda x: (x._index, -x._override)):
|
|
|
|
out(f' VTABLE_ADD_FUNC({winclassname}_{method.name})\n')
|
|
|
|
out(u' );\n')
|
|
|
|
out(u'#ifndef __GNUC__\n')
|
|
|
|
out(u'}\n')
|
|
|
|
out(u'#endif\n\n')
|
2023-09-24 15:50:45 +03:00
|
|
|
out(f'struct w_steam_iface *create_{winclassname}(void *u_iface)\n')
|
2023-09-24 00:20:53 +03:00
|
|
|
out(u'{\n')
|
2023-09-24 15:50:45 +03:00
|
|
|
out(u' struct w_steam_iface *r = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*r));\n')
|
2023-09-24 00:20:53 +03:00
|
|
|
out(u' TRACE("-> %p\\n", r);\n')
|
|
|
|
out(f' r->vtable = &{winclassname}_vtable;\n')
|
2023-09-24 15:50:45 +03:00
|
|
|
out(u' r->u_iface = u_iface;\n')
|
2023-09-24 00:20:53 +03:00
|
|
|
out(u' return r;\n')
|
|
|
|
out(u'}\n\n')
|
2023-09-24 15:50:45 +03:00
|
|
|
out(f'void destroy_{winclassname}(struct w_steam_iface *object)\n')
|
2023-09-24 00:20:53 +03:00
|
|
|
out(u'{\n')
|
|
|
|
out(u' TRACE("%p\\n", object);\n')
|
|
|
|
out(u' HeapFree(GetProcessHeap(), 0, object);\n')
|
|
|
|
out(u'}\n\n')
|
|
|
|
|
|
|
|
# flat (FnTable) API
|
2023-09-24 15:50:45 +03:00
|
|
|
out(f'struct w_steam_iface *create_{winclassname}_FnTable(void *u_iface)\n')
|
2023-09-24 00:20:53 +03:00
|
|
|
out(u'{\n')
|
2023-09-24 15:50:45 +03:00
|
|
|
out(u' struct w_steam_iface *r = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*r));\n')
|
2023-09-24 00:20:53 +03:00
|
|
|
out(f' struct thunk *thunks = alloc_thunks({len(klass.methods)});\n')
|
|
|
|
out(f' struct thunk **vtable = HeapAlloc(GetProcessHeap(), 0, {len(klass.methods)} * sizeof(*vtable));\n')
|
|
|
|
out(u' int i;\n\n')
|
|
|
|
out(u' TRACE("-> %p, vtable %p, thunks %p\\n", r, vtable, thunks);\n')
|
|
|
|
for i, method in enumerate(klass.methods):
|
|
|
|
thunk_params = get_capi_thunk_params(method)
|
|
|
|
arguments = list(method.get_arguments())
|
|
|
|
global max_c_api_param_count
|
|
|
|
max_c_api_param_count = max(len(arguments), max_c_api_param_count)
|
|
|
|
out(f' init_thunk(&thunks[{i}], r, {winclassname}_{method.name}, {thunk_params});\n')
|
|
|
|
out(f' for (i = 0; i < {len(klass.methods)}; i++)\n')
|
|
|
|
out(u' vtable[i] = &thunks[i];\n')
|
2023-09-24 15:50:45 +03:00
|
|
|
out(u' r->u_iface = u_iface;\n')
|
2023-09-24 00:20:53 +03:00
|
|
|
out(u' r->vtable = (void *)vtable;\n')
|
|
|
|
out(u' return r;\n')
|
|
|
|
out(u'}\n\n')
|
2023-09-24 15:50:45 +03:00
|
|
|
out(f'void destroy_{winclassname}_FnTable(struct w_steam_iface *object)\n')
|
2023-09-24 00:20:53 +03:00
|
|
|
out(u'{\n')
|
2023-09-24 15:50:45 +03:00
|
|
|
out(u' TRACE("%p\\n", object);\n')
|
|
|
|
out(u' VirtualFree(object->vtable[0], 0, MEM_RELEASE);\n')
|
|
|
|
out(u' HeapFree(GetProcessHeap(), 0, object->vtable);\n')
|
|
|
|
out(u' HeapFree(GetProcessHeap(), 0, object);\n')
|
2023-09-24 00:20:53 +03:00
|
|
|
out(u'}\n\n')
|
2018-06-04 18:45:00 +03:00
|
|
|
|
2018-07-30 10:38:56 +03:00
|
|
|
constructors = open("vrclient_x64/win_constructors.h", "a")
|
2023-09-24 15:50:45 +03:00
|
|
|
constructors.write(f'extern struct w_steam_iface *create_{winclassname}(void *);\n')
|
|
|
|
constructors.write(f'extern struct w_steam_iface *create_{winclassname}_FnTable(void *);\n')
|
2018-01-18 22:29:49 +03:00
|
|
|
|
2018-07-30 10:38:56 +03:00
|
|
|
destructors = open("vrclient_x64/win_destructors.h", "a")
|
2023-09-24 15:50:45 +03:00
|
|
|
destructors.write(f'extern void destroy_{winclassname}(struct w_steam_iface *);\n')
|
|
|
|
destructors.write(f'extern void destroy_{winclassname}_FnTable(struct w_steam_iface *);\n')
|
2018-04-19 16:50:32 +03:00
|
|
|
|
2018-07-30 10:38:56 +03:00
|
|
|
constructors = open("vrclient_x64/win_constructors_table.dat", "a")
|
2023-09-23 20:44:47 +03:00
|
|
|
constructors.write(f" {{\"{klass.version}\", &create_{winclassname}, &destroy_{winclassname}}},\n")
|
|
|
|
constructors.write(f" {{\"FnTable:{klass.version}\", &create_{winclassname}_FnTable, &destroy_{winclassname}_FnTable}},\n")
|
2018-01-18 22:29:49 +03:00
|
|
|
|
2023-09-24 18:15:41 +03:00
|
|
|
generate_c_api_thunk_tests(winclassname, klass.methods)
|
2018-07-30 12:39:47 +03:00
|
|
|
|
2023-09-21 20:39:53 +03:00
|
|
|
|
|
|
|
def canonical_typename(cursor):
|
2023-09-20 18:27:42 +03:00
|
|
|
if type(cursor) in (Cursor, Struct):
|
2023-09-21 20:39:53 +03:00
|
|
|
return canonical_typename(cursor.type)
|
|
|
|
|
|
|
|
name = cursor.get_canonical().spelling
|
|
|
|
return name.removeprefix("const ")
|
|
|
|
|
2019-09-17 18:53:26 +03:00
|
|
|
|
2023-09-27 15:09:21 +03:00
|
|
|
def underlying_typename(decl):
|
|
|
|
return canonical_typename(underlying_type(decl))
|
|
|
|
|
|
|
|
|
2023-09-21 23:13:09 +03:00
|
|
|
def find_struct_abis(name):
|
2023-09-20 18:27:42 +03:00
|
|
|
name = strip_ns(name)
|
|
|
|
if not name in all_structs:
|
|
|
|
return None
|
|
|
|
structs = all_structs[name]
|
|
|
|
if not sdkver in structs:
|
|
|
|
return None
|
|
|
|
return structs[sdkver]
|
2019-09-17 20:54:01 +03:00
|
|
|
|
2019-09-17 18:53:26 +03:00
|
|
|
|
2023-09-28 15:49:12 +03:00
|
|
|
def struct_needs_conversion(struct):
|
2023-09-21 23:13:09 +03:00
|
|
|
name = canonical_typename(struct)
|
|
|
|
|
|
|
|
abis = find_struct_abis(name)
|
|
|
|
if abis is None:
|
2023-09-28 15:49:12 +03:00
|
|
|
return False
|
2023-09-20 18:27:42 +03:00
|
|
|
if abis['w32'].needs_conversion(abis['u32']):
|
2023-09-28 15:49:12 +03:00
|
|
|
return True
|
2023-09-20 18:27:42 +03:00
|
|
|
if abis['w64'].needs_conversion(abis['u64']):
|
2023-09-28 15:49:12 +03:00
|
|
|
return True
|
2023-09-21 23:13:09 +03:00
|
|
|
|
2023-09-20 18:27:42 +03:00
|
|
|
assert abis['u32'].size <= abis['w32'].size
|
|
|
|
if abis['u32'].size < abis['w32'].size:
|
2023-09-28 15:49:12 +03:00
|
|
|
return False
|
2023-09-20 18:27:42 +03:00
|
|
|
assert abis['u64'].size <= abis['w64'].size
|
|
|
|
if abis['u64'].size < abis['w64'].size:
|
2023-09-28 15:49:12 +03:00
|
|
|
return False
|
2023-09-21 23:13:09 +03:00
|
|
|
|
2023-09-28 15:49:12 +03:00
|
|
|
return False
|
2023-09-21 23:13:09 +03:00
|
|
|
|
2019-09-17 20:54:01 +03:00
|
|
|
|
2023-09-28 15:49:12 +03:00
|
|
|
def struct_needs_size_adjustment(struct):
|
2023-09-21 20:39:53 +03:00
|
|
|
name = canonical_typename(struct)
|
2023-09-20 18:27:42 +03:00
|
|
|
if name in EXEMPT_STRUCTS:
|
|
|
|
return False
|
2023-09-21 20:39:53 +03:00
|
|
|
|
2023-09-28 15:49:12 +03:00
|
|
|
abis = find_struct_abis(name)
|
|
|
|
if abis is None:
|
|
|
|
return False
|
|
|
|
if abis['w32'].needs_conversion(abis['u32']):
|
|
|
|
return False
|
|
|
|
if abis['w64'].needs_conversion(abis['u64']):
|
|
|
|
return False
|
2021-07-09 01:42:07 +03:00
|
|
|
|
2023-09-28 15:49:12 +03:00
|
|
|
assert abis['u32'].size <= abis['w32'].size
|
|
|
|
if abis['u32'].size < abis['w32'].size:
|
|
|
|
return True
|
|
|
|
assert abis['u64'].size <= abis['w64'].size
|
|
|
|
if abis['u64'].size < abis['w64'].size:
|
|
|
|
return True
|
2021-07-09 01:42:07 +03:00
|
|
|
|
2023-09-28 15:49:12 +03:00
|
|
|
return False
|
2019-09-17 20:54:01 +03:00
|
|
|
|
2021-07-09 01:42:07 +03:00
|
|
|
|
2019-09-17 18:53:26 +03:00
|
|
|
def get_field_attribute_str(field):
|
2019-09-17 23:16:30 +03:00
|
|
|
ftype = field.type.get_canonical()
|
2021-12-14 21:22:36 +03:00
|
|
|
if ftype.kind != TypeKind.RECORD:
|
2019-09-17 18:53:26 +03:00
|
|
|
return ""
|
2023-09-21 23:13:09 +03:00
|
|
|
name = canonical_typename(ftype)
|
|
|
|
abis = find_struct_abis(name)
|
2023-09-20 18:27:42 +03:00
|
|
|
if not abis:
|
|
|
|
return " __attribute__((aligned(8)))"
|
|
|
|
return f" __attribute__((aligned({abis['w32'].align})))"
|
2018-01-18 22:29:49 +03:00
|
|
|
|
|
|
|
generated_struct_handlers = []
|
|
|
|
cpp_files_need_close_brace = []
|
|
|
|
|
|
|
|
LIN_TO_WIN=1
|
2019-09-17 20:54:01 +03:00
|
|
|
WIN_TO_LIN=2
|
|
|
|
WRAPPERS=3
|
2018-01-18 22:29:49 +03:00
|
|
|
|
|
|
|
#because of struct packing differences between win32 and linux, we
|
|
|
|
#need to convert these structs from their linux layout to the win32
|
|
|
|
#layout.
|
2019-09-17 20:54:01 +03:00
|
|
|
def handle_struct(sdkver, struct):
|
2023-09-20 18:27:42 +03:00
|
|
|
handler_name = "%s_%s" % (struct.name, display_sdkver(sdkver))
|
2018-01-18 22:29:49 +03:00
|
|
|
|
|
|
|
if handler_name in generated_struct_handlers:
|
|
|
|
# we already have a handler for the struct struct of this size
|
|
|
|
return
|
|
|
|
|
2019-09-17 20:54:01 +03:00
|
|
|
which = set()
|
|
|
|
|
2019-09-17 23:16:30 +03:00
|
|
|
if struct_needs_conversion(struct.type.get_canonical()):
|
2019-09-17 20:54:01 +03:00
|
|
|
which.add(LIN_TO_WIN)
|
|
|
|
which.add(WIN_TO_LIN)
|
|
|
|
|
2023-09-20 18:27:42 +03:00
|
|
|
if strip_ns(struct.name) in SDK_STRUCTS:
|
2019-09-17 20:54:01 +03:00
|
|
|
which.add(WRAPPERS)
|
|
|
|
|
|
|
|
if len(which) == 0:
|
|
|
|
return
|
|
|
|
|
2018-01-18 22:29:49 +03:00
|
|
|
filename_base = "struct_converters_%s" % display_sdkver(sdkver)
|
2018-07-30 10:38:56 +03:00
|
|
|
cppname = "vrclient_x64/%s.cpp" % filename_base
|
2018-01-18 22:29:49 +03:00
|
|
|
file_exists = os.path.isfile(cppname)
|
|
|
|
cppfile = open(cppname, "a")
|
|
|
|
if not file_exists:
|
|
|
|
cppfile.write("#include <stdlib.h>\n");
|
|
|
|
cppfile.write("#include <string.h>\n");
|
|
|
|
cppfile.write("#include \"vrclient_private.h\"\n")
|
|
|
|
cppfile.write("#include \"vrclient_defs.h\"\n")
|
|
|
|
cppfile.write("#include \"openvr_%s/openvr.h\"\n" % sdkver)
|
|
|
|
cppfile.write("using namespace vr;\n")
|
|
|
|
cppfile.write("extern \"C\" {\n")
|
|
|
|
cppfile.write("#include \"struct_converters.h\"\n")
|
|
|
|
cpp_files_need_close_brace.append(cppname)
|
|
|
|
|
2018-07-30 10:38:56 +03:00
|
|
|
hfile = open("vrclient_x64/struct_converters.h", "a")
|
2018-01-18 22:29:49 +03:00
|
|
|
|
|
|
|
hfile.write("typedef struct win%s win%s;\n" % (handler_name, handler_name))
|
|
|
|
|
2019-03-19 18:12:23 +03:00
|
|
|
cppfile.write("#pragma pack(push, 8)\n")
|
2018-01-18 22:29:49 +03:00
|
|
|
cppfile.write("struct win%s {\n" % handler_name)
|
|
|
|
for m in struct.get_children():
|
2021-12-14 21:22:36 +03:00
|
|
|
if m.kind == CursorKind.FIELD_DECL:
|
|
|
|
if m.type.get_canonical().kind == TypeKind.CONSTANTARRAY:
|
2019-09-18 21:37:19 +03:00
|
|
|
cppfile.write(" %s %s[%u]" % (m.type.element_type.spelling, m.displayname, m.type.element_count))
|
2021-12-14 21:22:36 +03:00
|
|
|
elif m.type.get_canonical().kind == TypeKind.RECORD and \
|
2019-09-17 23:16:30 +03:00
|
|
|
struct_needs_conversion(m.type.get_canonical()):
|
2019-09-18 21:37:19 +03:00
|
|
|
cppfile.write(" win%s_%s %s" % (strip_ns(m.type.spelling), display_sdkver(sdkver), m.displayname))
|
2018-01-18 22:29:49 +03:00
|
|
|
else:
|
2021-12-14 21:22:36 +03:00
|
|
|
if m.type.get_canonical().kind == TypeKind.POINTER and \
|
|
|
|
m.type.get_pointee().kind == TypeKind.FUNCTIONPROTO:
|
2019-09-18 21:37:19 +03:00
|
|
|
cppfile.write(" void *%s /*fn pointer*/ " % m.displayname)
|
2019-09-17 20:54:01 +03:00
|
|
|
else:
|
2019-09-18 21:37:19 +03:00
|
|
|
cppfile.write(" %s %s" % (m.type.spelling, m.displayname))
|
|
|
|
cppfile.write(get_field_attribute_str(m) + ";\n")
|
2019-09-17 20:54:01 +03:00
|
|
|
if WRAPPERS in which:
|
2023-09-20 18:27:42 +03:00
|
|
|
cppfile.write("\n %s *linux_side;\n" % struct.name)
|
2019-03-19 18:12:23 +03:00
|
|
|
cppfile.write("} __attribute__ ((ms_struct));\n")
|
|
|
|
cppfile.write("#pragma pack(pop)\n\n")
|
2018-01-18 22:29:49 +03:00
|
|
|
|
2019-10-08 23:04:48 +03:00
|
|
|
def dump_converter(src, dst, size):
|
2019-09-17 20:54:01 +03:00
|
|
|
for m in struct.get_children():
|
2021-12-14 21:22:36 +03:00
|
|
|
if m.kind == CursorKind.FIELD_DECL:
|
|
|
|
if m.type.get_canonical().kind == TypeKind.CONSTANTARRAY:
|
2019-09-17 20:54:01 +03:00
|
|
|
#TODO: if this is a struct, or packed differently, we'll have to
|
|
|
|
# copy each element in a for-loop
|
2019-09-18 17:55:23 +03:00
|
|
|
cppfile.write(" memcpy(" + dst + "->" + m.displayname + ", " + src + "->" + m.displayname + ", sizeof(" + dst + "->" + m.displayname + "));\n")
|
2021-12-14 21:22:36 +03:00
|
|
|
elif m.type.get_canonical().kind == TypeKind.RECORD and \
|
2019-09-17 23:16:30 +03:00
|
|
|
struct_needs_conversion(m.type.get_canonical()):
|
2019-09-18 17:55:23 +03:00
|
|
|
cppfile.write(" struct_" + strip_ns(m.type.spelling) + "_" + display_sdkver(sdkver) + "_" + src + "_to_" + dst + \
|
|
|
|
"(&" + src + "->" + m.displayname + ", &" + dst + "->" + m.displayname + ");\n")
|
2023-09-20 18:27:42 +03:00
|
|
|
elif struct.name in STRUCTS_SIZE_FIELD and \
|
|
|
|
m.displayname in STRUCTS_SIZE_FIELD[struct.name]:
|
2019-09-18 18:59:28 +03:00
|
|
|
cppfile.write(" " + dst + "->" + m.displayname + " = sizeof(*" + dst + ");\n")
|
2019-10-08 23:04:48 +03:00
|
|
|
elif size and strip_ns(m.type.get_canonical().spelling) == "VREvent_Data_t":
|
|
|
|
#truncate variable-length data struct at the end of the parent struct
|
|
|
|
#XXX: dumb hard-coding. are the other types with lengths variable length?
|
|
|
|
cppfile.write(" memcpy(&" + dst + "->data, &" + src + "->data, " + size + " - (((char*)&" + dst + "->data) - ((char*)" + dst + ")));\n")
|
2019-09-17 20:54:01 +03:00
|
|
|
else:
|
2019-09-18 17:55:23 +03:00
|
|
|
cppfile.write(" " + dst + "->" + m.displayname + " = " + src + "->" + m.displayname + ";\n")
|
2019-09-17 20:54:01 +03:00
|
|
|
|
2023-09-20 18:27:42 +03:00
|
|
|
if strip_ns(struct.name) in STRUCTS_NEXT_IS_SIZE:
|
2019-10-08 23:04:48 +03:00
|
|
|
size_arg = "sz"
|
|
|
|
size_arg_type = ", uint32_t sz"
|
|
|
|
else:
|
|
|
|
size_arg = None
|
|
|
|
size_arg_type = ""
|
|
|
|
|
2019-09-18 17:55:23 +03:00
|
|
|
if LIN_TO_WIN in which:
|
2019-10-08 23:04:48 +03:00
|
|
|
hfile.write("extern void struct_%s_lin_to_win(void *l, void *w%s);\n" % (handler_name, size_arg_type))
|
|
|
|
cppfile.write("void struct_%s_lin_to_win(void *l, void *w%s)\n{\n" % (handler_name, size_arg_type))
|
2019-09-18 17:55:23 +03:00
|
|
|
cppfile.write(" struct win%s *win = (struct win%s *)w;\n" % (handler_name, handler_name))
|
2023-09-20 18:27:42 +03:00
|
|
|
cppfile.write(" %s *lin = (%s *)l;\n" % (struct.name, struct.name))
|
2019-10-08 23:04:48 +03:00
|
|
|
dump_converter("lin", "win", size_arg)
|
2019-09-17 20:54:01 +03:00
|
|
|
cppfile.write("}\n\n")
|
|
|
|
|
|
|
|
if WIN_TO_LIN in which:
|
2019-10-08 23:04:48 +03:00
|
|
|
#XXX: should pass size param here, too
|
2023-09-23 23:19:05 +03:00
|
|
|
hfile.write("extern void struct_%s_win_to_lin(const void *w, void *l);\n" % handler_name)
|
|
|
|
cppfile.write("void struct_%s_win_to_lin(const void *w, void *l)\n{\n" % handler_name)
|
2019-09-17 20:54:01 +03:00
|
|
|
cppfile.write(" struct win%s *win = (struct win%s *)w;\n" % (handler_name, handler_name))
|
2023-09-20 18:27:42 +03:00
|
|
|
cppfile.write(" %s *lin = (%s *)l;\n" % (struct.name, struct.name))
|
2019-10-08 23:04:48 +03:00
|
|
|
dump_converter("win", "lin", None)
|
2019-09-17 20:54:01 +03:00
|
|
|
cppfile.write("}\n\n")
|
|
|
|
|
|
|
|
if WRAPPERS in which:
|
2018-01-18 22:29:49 +03:00
|
|
|
hfile.write("extern struct win%s *struct_%s_wrap(void *l);\n" % (handler_name, handler_name))
|
2019-09-17 20:54:01 +03:00
|
|
|
|
2018-01-18 22:29:49 +03:00
|
|
|
cppfile.write("struct win%s *struct_%s_wrap(void *l)\n{\n" % (handler_name, handler_name))
|
|
|
|
cppfile.write(" struct win%s *win = (struct win%s *)malloc(sizeof(*win));\n" % (handler_name, handler_name))
|
2023-09-20 18:27:42 +03:00
|
|
|
cppfile.write(" %s *lin = (%s *)l;\n" % (struct.name, struct.name))
|
2019-09-17 20:54:01 +03:00
|
|
|
|
2019-10-08 23:04:48 +03:00
|
|
|
dump_converter("lin", "win", None)
|
2018-01-18 22:29:49 +03:00
|
|
|
|
|
|
|
cppfile.write(" win->linux_side = lin;\n");
|
|
|
|
cppfile.write(" return win;\n")
|
|
|
|
|
2019-09-17 20:54:01 +03:00
|
|
|
cppfile.write("}\n\n")
|
2018-01-18 22:29:49 +03:00
|
|
|
|
2023-09-20 18:27:42 +03:00
|
|
|
hfile.write("extern %s *struct_%s_unwrap(win%s *w);\n" % (struct.name, handler_name, handler_name))
|
2019-09-17 20:54:01 +03:00
|
|
|
|
2023-09-20 18:27:42 +03:00
|
|
|
cppfile.write("struct %s *struct_%s_unwrap(win%s *w)\n{\n" % (struct.name, handler_name, handler_name))
|
|
|
|
cppfile.write(" %s *ret = w->linux_side;\n" % struct.name)
|
2018-01-18 22:29:49 +03:00
|
|
|
cppfile.write(" free(w);\n")
|
|
|
|
cppfile.write(" return ret;\n")
|
|
|
|
cppfile.write("}\n\n")
|
|
|
|
|
|
|
|
generated_struct_handlers.append(handler_name)
|
|
|
|
|
|
|
|
|
2018-07-30 18:40:06 +03:00
|
|
|
def generate_x64_call_flat_method(cfile, param_count, has_floats, is_4th_float):
|
2018-07-27 10:40:01 +03:00
|
|
|
assert param_count >= 4
|
2018-07-30 18:40:06 +03:00
|
|
|
if is_4th_float:
|
|
|
|
assert has_floats
|
2018-07-27 10:40:01 +03:00
|
|
|
def l(line):
|
|
|
|
cfile.write(line + '\n')
|
|
|
|
|
|
|
|
stack_space = 0x20 # shadow register space
|
|
|
|
stack_space += 0x8 * (param_count - 3)
|
|
|
|
stack_space |= 0x8
|
|
|
|
src_offset = 0x20 + 0x8 + stack_space # shadow register space + ret
|
|
|
|
dst_offset = 0x20
|
|
|
|
|
2018-07-30 18:40:06 +03:00
|
|
|
name = "call_flat_method%s%s%s" % (param_count, "_f" if has_floats else "", "_f" if is_4th_float else "")
|
|
|
|
|
|
|
|
l(r"__ASM_GLOBAL_FUNC(%s," % name)
|
2018-07-27 10:40:01 +03:00
|
|
|
l(r' "subq $0x%x, %%rsp\n\t"' % stack_space);
|
2018-08-29 18:48:11 +03:00
|
|
|
l(r' __ASM_CFI(".cfi_adjust_cfa_offset %d\n\t")' % stack_space)
|
2018-07-27 10:40:01 +03:00
|
|
|
|
2018-07-30 18:40:06 +03:00
|
|
|
if is_4th_float:
|
|
|
|
l(r' "movq %%xmm3, 0x%x(%%rsp)\n\t"' % dst_offset)
|
|
|
|
else:
|
|
|
|
l(r' "movq %%r9, 0x%x(%%rsp)\n\t"' % dst_offset)
|
2018-07-27 10:40:01 +03:00
|
|
|
dst_offset += 8
|
|
|
|
|
|
|
|
for i in range(5, param_count + 1):
|
|
|
|
l(r' "movq 0x%x(%%rsp), %%rax\n\t" // copy parameter' % src_offset)
|
|
|
|
l(r' "movq %%rax, 0x%x(%%rsp)\n\t"' % dst_offset)
|
|
|
|
src_offset += 8
|
|
|
|
dst_offset += 8
|
|
|
|
|
|
|
|
l(r' "movq %r8, %r9\n\t" // shift over arguments')
|
|
|
|
l(r' "movq %rdx, %r8\n\t"')
|
|
|
|
l(r' "movq %rcx, %rdx\n\t"')
|
|
|
|
l(r' "movq %r10, %rcx\n\t" // add This pointer')
|
|
|
|
|
2018-07-30 18:40:06 +03:00
|
|
|
if has_floats:
|
2018-07-31 15:08:03 +03:00
|
|
|
l(r' "movaps %xmm2, %xmm3\n\t"')
|
|
|
|
l(r' "movaps %xmm1, %xmm2\n\t"')
|
|
|
|
l(r' "movaps %xmm0, %xmm1\n\t"')
|
2018-07-30 18:40:06 +03:00
|
|
|
|
2018-07-27 10:40:01 +03:00
|
|
|
l(r' "call *%r11\n\t"')
|
|
|
|
l(r' "addq $0x%x, %%rsp\n\t"' % stack_space);
|
2018-08-29 18:48:11 +03:00
|
|
|
l(r' __ASM_CFI(".cfi_adjust_cfa_offset -%d\n\t")' % stack_space)
|
2018-07-27 10:40:01 +03:00
|
|
|
l(r' "ret");')
|
2018-07-30 18:40:06 +03:00
|
|
|
l(r'extern void %s(void);' % name);
|
2018-07-27 10:40:01 +03:00
|
|
|
|
|
|
|
def generate_flatapi_c():
|
2018-07-30 10:38:56 +03:00
|
|
|
with open("vrclient_x64/flatapi.c", "w") as f:
|
2018-07-27 10:40:01 +03:00
|
|
|
f.write(r"""/* This file is auto-generated, do not edit. */
|
|
|
|
|
|
|
|
#include <stdarg.h>
|
|
|
|
|
|
|
|
#include "windef.h"
|
|
|
|
#include "winbase.h"
|
|
|
|
|
|
|
|
#include "cxx.h"
|
|
|
|
#include "flatapi.h"
|
|
|
|
|
|
|
|
#ifdef __i386__
|
|
|
|
__ASM_GLOBAL_FUNC(call_flat_method,
|
|
|
|
"popl %eax\n\t"
|
|
|
|
"pushl %ecx\n\t"
|
|
|
|
"pushl %eax\n\t"
|
|
|
|
"jmp *%edx");
|
|
|
|
#else
|
|
|
|
// handles "this" and up to 3 parameters
|
|
|
|
__ASM_GLOBAL_FUNC(call_flat_method,
|
|
|
|
"movq %r8, %r9\n\t" // shift over arguments
|
|
|
|
"movq %rdx, %r8\n\t"
|
|
|
|
"movq %rcx, %rdx\n\t"
|
|
|
|
"movq %r10, %rcx\n\t" // add This pointer
|
|
|
|
"jmp *%r11");
|
|
|
|
extern void call_flat_method(void);
|
2018-07-30 18:40:06 +03:00
|
|
|
|
|
|
|
__ASM_GLOBAL_FUNC(call_flat_method_f,
|
|
|
|
"movq %r8, %r9\n\t" // shift over arguments
|
|
|
|
"movq %rdx, %r8\n\t"
|
|
|
|
"movq %rcx, %rdx\n\t"
|
|
|
|
"movq %r10, %rcx\n\t" // add This pointer
|
2018-07-31 15:08:03 +03:00
|
|
|
"movaps %xmm2, %xmm3\n\t"
|
|
|
|
"movaps %xmm1, %xmm2\n\t"
|
|
|
|
"movaps %xmm0, %xmm1\n\t"
|
2018-07-30 18:40:06 +03:00
|
|
|
"jmp *%r11");
|
|
|
|
extern void call_flat_method_f(void);
|
2018-07-27 10:40:01 +03:00
|
|
|
""")
|
|
|
|
|
|
|
|
for i in range(4, max_c_api_param_count + 1):
|
|
|
|
f.write("\n")
|
2018-07-30 18:40:06 +03:00
|
|
|
generate_x64_call_flat_method(f, i, False, False)
|
|
|
|
for i in range(4, max_c_api_param_count + 1):
|
|
|
|
f.write("\n")
|
|
|
|
generate_x64_call_flat_method(f, i, True, False)
|
|
|
|
f.write("\n")
|
|
|
|
generate_x64_call_flat_method(f, i, True, True)
|
2018-07-27 10:40:01 +03:00
|
|
|
|
2018-07-30 18:40:06 +03:00
|
|
|
f.write('\npfn_call_flat_method\n')
|
|
|
|
f.write('get_call_flat_method_pfn( int param_count, BOOL has_floats, BOOL is_4th_float )\n{\n')
|
|
|
|
f.write(' if (!has_floats)\n')
|
|
|
|
f.write(' {\n')
|
2018-07-27 10:40:01 +03:00
|
|
|
f.write(' if (param_count <= 3) return call_flat_method;\n')
|
|
|
|
for i in range(4, max_c_api_param_count):
|
|
|
|
f.write(' if (param_count == %s) return call_flat_method%s;\n' % (i, i))
|
|
|
|
f.write(' return call_flat_method%s;\n' % max_c_api_param_count)
|
2018-07-30 18:40:06 +03:00
|
|
|
f.write(' }\n')
|
|
|
|
f.write(' if (is_4th_float)\n')
|
|
|
|
f.write(' {\n')
|
|
|
|
f.write(' if (param_count <= 3) return call_flat_method_f;\n')
|
|
|
|
for i in range(4, max_c_api_param_count):
|
|
|
|
f.write(' if (param_count == %s) return call_flat_method%s_f_f;\n' % (i, i))
|
|
|
|
f.write(' return call_flat_method%s_f_f;\n' % max_c_api_param_count)
|
|
|
|
f.write(' }\n')
|
|
|
|
f.write(' if (param_count <= 3) return call_flat_method_f;\n')
|
|
|
|
for i in range(4, max_c_api_param_count):
|
|
|
|
f.write(' if (param_count == %s) return call_flat_method%s_f;\n' % (i, i))
|
|
|
|
f.write(' return call_flat_method%s_f;\n' % max_c_api_param_count)
|
2018-07-27 10:40:01 +03:00
|
|
|
f.write('}\n')
|
|
|
|
|
|
|
|
f.write("#endif\n")
|
2018-01-18 22:29:49 +03:00
|
|
|
|
2023-09-24 18:15:41 +03:00
|
|
|
def generate_c_api_method_test(f, header, thunks_c, class_name, method):
|
2018-07-30 12:39:47 +03:00
|
|
|
thunk_params = get_capi_thunk_params(method)
|
2023-09-24 18:15:41 +03:00
|
|
|
f.write("\n init_thunk(t, this_ptr_value, %s_%s, %s);\n" % (class_name, method.name, thunk_params))
|
2018-07-30 12:39:47 +03:00
|
|
|
f.write(" ")
|
|
|
|
header.write("\n")
|
|
|
|
thunks_c.write("\n")
|
|
|
|
|
2021-12-14 21:22:36 +03:00
|
|
|
returns_record = method.result_type.get_canonical().kind == TypeKind.RECORD
|
2018-07-30 12:39:47 +03:00
|
|
|
if returns_record:
|
|
|
|
f.write("%s *" % strip_ns(method.result_type.spelling))
|
|
|
|
header.write("%s *" % strip_ns(method.result_type.spelling))
|
|
|
|
thunks_c.write("%s *" % strip_ns(method.result_type.spelling))
|
|
|
|
else:
|
|
|
|
f.write("%s " % strip_ns(method.result_type.spelling))
|
|
|
|
header.write("%s " % strip_ns(method.result_type.spelling))
|
|
|
|
thunks_c.write("%s " % strip_ns(method.result_type.spelling))
|
|
|
|
first_param = True
|
2023-09-24 18:15:41 +03:00
|
|
|
f.write('(__stdcall *capi_%s_%s)(' % (class_name, method.name))
|
|
|
|
header.write('__thiscall %s_%s(void *_this' % (class_name, method.name))
|
|
|
|
thunks_c.write('__thiscall %s_%s(void *_this' % (class_name, method.name))
|
2018-07-30 12:39:47 +03:00
|
|
|
if returns_record:
|
|
|
|
f.write("%s *_r" % strip_ns(method.result_type.spelling))
|
|
|
|
first_param = False
|
|
|
|
header.write(", %s *_r" % strip_ns(method.result_type.spelling))
|
|
|
|
thunks_c.write(", %s *_r" % strip_ns(method.result_type.spelling))
|
|
|
|
|
2023-09-24 17:39:53 +03:00
|
|
|
for param in method.get_arguments():
|
2021-12-14 21:22:36 +03:00
|
|
|
if param.type.kind == TypeKind.POINTER \
|
|
|
|
and param.type.get_pointee().kind == TypeKind.UNEXPOSED:
|
2018-07-30 12:39:47 +03:00
|
|
|
typename = "void *"
|
|
|
|
else:
|
|
|
|
typename = param.type.spelling.split("::")[-1].replace("&", "*");
|
|
|
|
if not first_param:
|
|
|
|
f.write(", ")
|
|
|
|
first_param = False
|
|
|
|
f.write("%s %s" % (typename, param.spelling))
|
|
|
|
header.write(", %s %s" % (typename, param.spelling))
|
|
|
|
thunks_c.write(", %s %s" % (typename, param.spelling))
|
|
|
|
f.write(") = (void *)t;\n")
|
|
|
|
header.write(");\n")
|
|
|
|
thunks_c.write(")\n{\n")
|
|
|
|
|
2018-07-31 14:45:58 +03:00
|
|
|
def get_param_typename(param):
|
2018-07-30 12:39:47 +03:00
|
|
|
param_size = param.type.get_size()
|
2021-12-14 21:22:36 +03:00
|
|
|
if param.type.kind == TypeKind.POINTER \
|
2018-07-30 12:39:47 +03:00
|
|
|
or param.type.spelling.endswith("&") \
|
|
|
|
or param.type.spelling == "vr::glSharedTextureHandle_t":
|
2018-07-31 14:45:58 +03:00
|
|
|
return "ptr"
|
2018-07-30 12:39:47 +03:00
|
|
|
elif param.type.spelling == "bool":
|
2018-07-31 14:45:58 +03:00
|
|
|
return "bool"
|
2018-07-30 12:39:47 +03:00
|
|
|
elif param.type.spelling == "float":
|
2018-07-31 14:45:58 +03:00
|
|
|
return "float"
|
2018-07-30 12:39:47 +03:00
|
|
|
elif param.type.spelling == "vr::HmdRect2_t":
|
2018-07-31 14:45:58 +03:00
|
|
|
return "HmdRect2"
|
2018-07-30 12:39:47 +03:00
|
|
|
elif param.type.spelling == "vr::HmdVector2_t":
|
2018-07-31 14:45:58 +03:00
|
|
|
return "HmdVector2"
|
2018-07-30 12:39:47 +03:00
|
|
|
elif param.type.spelling == "vr::HmdVector3_t":
|
2018-07-31 14:45:58 +03:00
|
|
|
return "HmdVector3"
|
2018-07-30 12:39:47 +03:00
|
|
|
elif param.type.spelling == "vr::HmdColor_t":
|
2018-07-31 14:45:58 +03:00
|
|
|
return "HmdColor"
|
2018-07-30 12:39:47 +03:00
|
|
|
elif param_size == 8:
|
2018-07-31 14:45:58 +03:00
|
|
|
return "uint64"
|
2018-07-30 12:39:47 +03:00
|
|
|
elif param_size == 4 or param_size == 2:
|
2018-07-31 14:45:58 +03:00
|
|
|
return "uint32"
|
2018-07-30 12:39:47 +03:00
|
|
|
else:
|
2018-07-31 14:45:58 +03:00
|
|
|
return "unknown"
|
|
|
|
|
|
|
|
thunks_c.write(" push_ptr_parameter(_this);\n")
|
|
|
|
if returns_record:
|
|
|
|
thunks_c.write(" push_ptr_parameter(_r);\n")
|
2023-09-24 17:39:53 +03:00
|
|
|
for param in method.get_arguments():
|
2018-07-31 14:45:58 +03:00
|
|
|
typename = get_param_typename(param)
|
2018-07-30 12:39:47 +03:00
|
|
|
thunks_c.write(" push_%s_parameter(%s);\n" % (typename, param.spelling))
|
2021-12-14 21:22:36 +03:00
|
|
|
if method.result_type.kind != TypeKind.VOID:
|
2018-07-30 12:39:47 +03:00
|
|
|
thunks_c.write(" return 0;\n")
|
|
|
|
thunks_c.write("}\n")
|
|
|
|
|
|
|
|
parameter_checks = []
|
|
|
|
def add_parameter_check(typename, value):
|
2023-09-24 18:15:41 +03:00
|
|
|
parameter_checks.append("check_%s_parameter(\"%s_%s\", %s)" % (typename, class_name, method.name, value))
|
2018-07-30 12:39:47 +03:00
|
|
|
add_parameter_check("ptr", "this_ptr_value")
|
|
|
|
f.write("\n")
|
|
|
|
f.write(" clear_parameters();\n")
|
2023-09-24 18:15:41 +03:00
|
|
|
f.write(" capi_%s_%s(" % (class_name, method.name))
|
2018-07-30 12:39:47 +03:00
|
|
|
first_param = True
|
|
|
|
if returns_record:
|
|
|
|
f.write("data_ptr_value")
|
|
|
|
first_param = False
|
|
|
|
add_parameter_check("ptr", "data_ptr_value")
|
2023-09-24 17:39:53 +03:00
|
|
|
for i, param in enumerate(method.get_arguments()):
|
2018-07-30 12:39:47 +03:00
|
|
|
i += 1
|
2018-07-31 14:45:58 +03:00
|
|
|
typename = get_param_typename(param)
|
|
|
|
if typename == "ptr":
|
2018-07-30 12:39:47 +03:00
|
|
|
v = "(void *)%s" % i
|
2018-07-31 14:45:58 +03:00
|
|
|
elif typename == "bool":
|
2018-07-30 12:39:47 +03:00
|
|
|
v = "1"
|
2018-07-31 14:45:58 +03:00
|
|
|
elif typename == "float":
|
2018-07-30 12:39:47 +03:00
|
|
|
v = "%s.0f" % i
|
2018-07-31 14:45:58 +03:00
|
|
|
elif typename == "HmdRect2":
|
|
|
|
v = "DEFAULT_RECT"
|
|
|
|
elif typename == "HmdVector2":
|
|
|
|
v = "DEFAULT_VECTOR2"
|
|
|
|
elif typename == "HmdVector3":
|
|
|
|
v = "DEFAULT_VECTOR3"
|
|
|
|
elif typename == "HmdColor":
|
|
|
|
v = "DEFAULT_COLOR"
|
|
|
|
else:
|
2018-07-30 12:39:47 +03:00
|
|
|
v = str(i)
|
|
|
|
if not first_param:
|
|
|
|
f.write(", ")
|
|
|
|
first_param = False
|
|
|
|
f.write(v)
|
2018-07-31 14:45:58 +03:00
|
|
|
add_parameter_check(typename, v)
|
2018-07-30 12:39:47 +03:00
|
|
|
f.write(");\n")
|
|
|
|
for c in parameter_checks:
|
|
|
|
f.write(" %s;\n" % c)
|
|
|
|
|
2023-09-24 18:15:41 +03:00
|
|
|
def generate_c_api_thunk_tests(winclassname, methods):
|
2018-07-30 12:39:47 +03:00
|
|
|
class_name = re.sub(r'^win[A-Za-z]+_', '', winclassname)
|
|
|
|
|
|
|
|
filename = "tests/capi_thunks_autogen.h"
|
|
|
|
file_exists = os.path.isfile(filename)
|
|
|
|
header = open(filename, "a")
|
|
|
|
if not file_exists:
|
|
|
|
header.write("""/* This file is auto-generated, do not edit. */
|
|
|
|
#include <stdarg.h>
|
|
|
|
#include <stdint.h>
|
|
|
|
|
|
|
|
#include "windef.h"
|
|
|
|
#include "winbase.h"
|
|
|
|
|
|
|
|
#include "cxx.h"
|
|
|
|
#include "flatapi.h"
|
|
|
|
#include "vrclient_defs.h"
|
|
|
|
|
|
|
|
#include "capi_thunks.h"
|
|
|
|
""")
|
|
|
|
header.write("\nvoid test_capi_thunks_%s(void);\n" % class_name)
|
|
|
|
|
|
|
|
filename = "tests/capi_thunks_autogen.c"
|
|
|
|
file_exists = os.path.isfile(filename)
|
|
|
|
thunks_c = open(filename, "a")
|
|
|
|
if not file_exists:
|
|
|
|
thunks_c.write("""/* This file is auto-generated, do not edit. */
|
|
|
|
#include "capi_thunks_autogen.h"
|
|
|
|
""")
|
|
|
|
|
|
|
|
filename = "tests/capi_thunks_tests_autogen.c"
|
|
|
|
file_exists = os.path.isfile(filename)
|
|
|
|
with open(filename, "a") as f:
|
|
|
|
if not file_exists:
|
|
|
|
f.write("""/* This file is auto-generated, do not edit. */
|
|
|
|
#include "capi_thunks_autogen.h"
|
|
|
|
""")
|
|
|
|
f.write("\nvoid test_capi_thunks_%s(void)\n{\n" % class_name)
|
|
|
|
f.write(" struct thunk *t = alloc_thunks(1);\n");
|
2023-09-24 18:15:41 +03:00
|
|
|
for method in methods:
|
|
|
|
generate_c_api_method_test(f, header, thunks_c, class_name, method)
|
2018-07-30 12:39:47 +03:00
|
|
|
f.write(" VirtualFree(t, 0, MEM_RELEASE);\n")
|
|
|
|
f.write("}\n")
|
|
|
|
|
|
|
|
filename = "tests/main_autogen.c"
|
|
|
|
file_exists = os.path.isfile(filename)
|
|
|
|
with open(filename, "a") as f:
|
|
|
|
if not file_exists:
|
|
|
|
f.write("""/* This file is auto-generated, do not edit. */
|
|
|
|
#include "capi_thunks_autogen.h"
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
|
|
|
|
int main(void)
|
|
|
|
{
|
|
|
|
""")
|
|
|
|
f.write(" test_capi_thunks_%s();\n" % class_name)
|
|
|
|
|
2018-01-18 22:29:49 +03:00
|
|
|
|
2023-09-16 16:24:23 +03:00
|
|
|
def enumerate_structs(cursor, vr_only=False):
|
|
|
|
for child in cursor.get_children():
|
|
|
|
if child.kind == CursorKind.NAMESPACE \
|
|
|
|
and child.displayname == "vr":
|
|
|
|
yield from child.get_children()
|
|
|
|
elif not vr_only:
|
|
|
|
yield child
|
|
|
|
|
|
|
|
|
2023-09-21 21:33:54 +03:00
|
|
|
def parse(sources, sdkver, abi):
|
2023-09-16 16:24:23 +03:00
|
|
|
args = [f'-m{abi[1:]}', '-I' + CLANG_PATH + '/include/']
|
|
|
|
if abi[0] == 'w':
|
|
|
|
args += ["-D_WIN32", "-U__linux__"]
|
|
|
|
args += ["-fms-extensions", "-mms-bitfields"]
|
|
|
|
args += ["-Wno-ignored-attributes", "-Wno-incompatible-ms-struct"]
|
|
|
|
if abi[0] == 'u':
|
|
|
|
args += ["-DGNUC"]
|
|
|
|
|
|
|
|
index = Index.create()
|
|
|
|
build = index.parse("source.cpp", args=args, unsaved_files=sources.items())
|
|
|
|
diagnostics = list(build.diagnostics)
|
|
|
|
for diag in diagnostics: print(diag)
|
|
|
|
assert len(diagnostics) == 0
|
|
|
|
|
2023-09-21 21:33:54 +03:00
|
|
|
return sdkver, abi, build
|
2023-09-16 16:24:23 +03:00
|
|
|
|
|
|
|
|
2023-09-20 23:21:42 +03:00
|
|
|
def load(sdkver):
|
|
|
|
prog = re.compile("^.*const\s*char.* \*?(\w*)_Version.*\"(.*)\"")
|
2022-01-06 17:55:22 +03:00
|
|
|
sdkdir = f'openvr_{sdkver}'
|
|
|
|
|
|
|
|
sources = {}
|
2023-09-20 23:21:42 +03:00
|
|
|
versions = {}
|
2022-01-06 17:55:22 +03:00
|
|
|
has_vrclientcore = False
|
|
|
|
for file in os.listdir(sdkdir):
|
|
|
|
x = open(f"{sdkdir}/{file}", "r")
|
|
|
|
if file == "ivrclientcore.h":
|
|
|
|
has_vrclientcore = True
|
|
|
|
|
2018-01-18 22:29:49 +03:00
|
|
|
for l in x:
|
|
|
|
if "_Version" in l:
|
|
|
|
result = prog.match(l)
|
|
|
|
if result:
|
|
|
|
iface, version = result.group(1, 2)
|
2023-09-20 23:21:42 +03:00
|
|
|
versions[iface] = version
|
2018-01-18 22:29:49 +03:00
|
|
|
|
2022-01-06 17:55:22 +03:00
|
|
|
if not has_vrclientcore:
|
|
|
|
source = [f'#include "{sdkdir}/openvr.h"']
|
|
|
|
else:
|
2023-09-20 22:15:40 +03:00
|
|
|
source = [f'#include "{sdkdir}/{file}"'
|
|
|
|
for file in SDK_SOURCES.keys()]
|
2022-01-06 17:55:22 +03:00
|
|
|
sources["source.cpp"] = "\n".join(source)
|
|
|
|
|
2023-09-20 23:21:42 +03:00
|
|
|
return versions, sources
|
|
|
|
|
|
|
|
|
2023-09-29 10:58:52 +03:00
|
|
|
def classify_struct(name):
|
|
|
|
if name in EXEMPT_STRUCTS:
|
|
|
|
return None
|
|
|
|
structs = all_structs[name]
|
|
|
|
|
|
|
|
prev = []
|
|
|
|
versions = {}
|
|
|
|
unique = True
|
|
|
|
|
|
|
|
for sdkver in filter(lambda v: v in structs, reversed(SDK_VERSIONS)):
|
|
|
|
abis = [structs[sdkver][a] for a in ABIS]
|
|
|
|
|
|
|
|
if any(abis[0].needs_conversion(a) for a in abis[1:]):
|
|
|
|
unique = False
|
|
|
|
|
|
|
|
def is_always_compatible(other):
|
|
|
|
for a, b in zip(abis, other):
|
|
|
|
if a.needs_conversion(b):
|
|
|
|
return False
|
|
|
|
return True
|
|
|
|
|
|
|
|
compat = next((k for k, v in prev if is_always_compatible(v)), None)
|
|
|
|
if compat:
|
|
|
|
versions[sdkver] = versions[compat]
|
|
|
|
else:
|
|
|
|
[abi.set_used() for abi in abis] # make sure order is computed
|
|
|
|
versions[sdkver] = f"{name}_{display_sdkver(sdkver)}"
|
|
|
|
prev += [(sdkver, abis)]
|
|
|
|
|
|
|
|
if unique:
|
|
|
|
unique_structs.append(name)
|
|
|
|
|
|
|
|
if len(set(versions.values())) == 1:
|
|
|
|
versions = {sdkver: name for sdkver in versions.keys()}
|
|
|
|
return versions
|
|
|
|
|
|
|
|
|
2023-09-21 21:33:54 +03:00
|
|
|
def generate(sdkver, structs):
|
2023-09-20 23:21:42 +03:00
|
|
|
print(f'generating SDK version {sdkver}...')
|
2023-09-21 21:33:54 +03:00
|
|
|
for child in structs['u32'].values():
|
|
|
|
handle_struct(sdkver, child)
|
2018-01-18 22:29:49 +03:00
|
|
|
|
2023-09-20 23:21:42 +03:00
|
|
|
|
|
|
|
for i, sdkver in enumerate(SDK_VERSIONS):
|
|
|
|
print(f'loading SDKs... {i * 100 // len(SDK_VERSIONS)}%', end='\r')
|
|
|
|
all_versions[sdkver], all_sources[sdkver] = load(sdkver)
|
|
|
|
print(u'loading SDKs... 100%')
|
|
|
|
|
2023-09-21 21:33:54 +03:00
|
|
|
|
|
|
|
tmp_classes = {}
|
|
|
|
|
2023-09-16 21:13:49 +03:00
|
|
|
with concurrent.futures.ThreadPoolExecutor() as executor:
|
|
|
|
arg0 = [sdkver for sdkver in SDK_VERSIONS for abi in ABIS]
|
|
|
|
arg1 = [abi for sdkver in SDK_VERSIONS for abi in ABIS]
|
|
|
|
def parse_map(sdkver, abi):
|
2023-09-21 21:33:54 +03:00
|
|
|
return parse(all_sources[sdkver], sdkver, abi)
|
2023-09-16 21:13:49 +03:00
|
|
|
|
|
|
|
results = executor.map(parse_map, arg0, arg1)
|
|
|
|
for i, result in enumerate(results):
|
|
|
|
print(f'parsing SDKs... {i * 100 // len(arg0)}%', end='\r')
|
2023-09-21 21:33:54 +03:00
|
|
|
sdkver, abi, build = result
|
2023-09-16 21:13:49 +03:00
|
|
|
if sdkver not in all_records: all_records[sdkver] = {}
|
2023-09-21 21:33:54 +03:00
|
|
|
if sdkver not in tmp_classes: tmp_classes[sdkver] = {}
|
2023-09-16 21:13:49 +03:00
|
|
|
|
2023-09-21 21:33:54 +03:00
|
|
|
versions = all_versions[sdkver]
|
2023-09-21 00:21:06 +03:00
|
|
|
|
2023-09-20 18:27:42 +03:00
|
|
|
structs = enumerate_structs(build.cursor, vr_only=True)
|
|
|
|
structs = filter(lambda c: c.is_definition(), structs)
|
|
|
|
structs = filter(lambda c: c.type.get_canonical().kind == TypeKind.RECORD, structs)
|
|
|
|
structs = filter(lambda c: c.kind != CursorKind.TYPEDEF_DECL, structs)
|
|
|
|
structs = filter(lambda c: c.spelling not in SDK_CLASSES, structs)
|
|
|
|
structs = [Record(sdkver, abi, c) for c in structs]
|
|
|
|
structs = {c.name: c for c in structs}
|
2023-09-21 00:21:06 +03:00
|
|
|
|
2023-09-21 21:33:54 +03:00
|
|
|
classes = enumerate_structs(build.cursor, vr_only=True)
|
|
|
|
classes = filter(lambda c: c.is_definition(), classes)
|
|
|
|
classes = filter(lambda c: c.kind == CursorKind.CLASS_DECL, classes)
|
|
|
|
classes = filter(lambda c: c.spelling in SDK_CLASSES, classes)
|
|
|
|
classes = filter(lambda c: c.spelling in versions, classes)
|
2023-09-23 20:44:47 +03:00
|
|
|
classes = [Class(sdkver, abi, c) for c in classes]
|
|
|
|
classes = {c.version: c for c in classes}
|
2023-09-21 21:33:54 +03:00
|
|
|
|
2023-09-20 18:27:42 +03:00
|
|
|
all_records[sdkver][abi] = structs
|
2023-09-21 21:33:54 +03:00
|
|
|
tmp_classes[sdkver][abi] = classes
|
2023-09-20 18:27:42 +03:00
|
|
|
|
|
|
|
for name, struct in structs.items():
|
|
|
|
if name not in all_structs:
|
|
|
|
all_structs[name] = {}
|
|
|
|
if sdkver not in all_structs[name]:
|
|
|
|
all_structs[name][sdkver] = {}
|
|
|
|
all_structs[name][sdkver][abi] = struct
|
2023-09-21 00:21:06 +03:00
|
|
|
|
2023-09-21 21:33:54 +03:00
|
|
|
for i, sdkver in enumerate(reversed(SDK_VERSIONS)):
|
|
|
|
all_classes.update(tmp_classes[sdkver]['u32'])
|
|
|
|
|
|
|
|
print('parsing SDKs... 100%')
|
2023-09-21 00:21:06 +03:00
|
|
|
|
|
|
|
|
2023-09-29 10:58:52 +03:00
|
|
|
tmp_structs = {}
|
|
|
|
|
|
|
|
for i, name in enumerate(all_structs.keys()):
|
|
|
|
print(f'classifying structs... {i * 100 // len(all_structs.keys())}%', end='\r')
|
|
|
|
versions = classify_struct(name)
|
|
|
|
for sdkver in SDK_VERSIONS:
|
|
|
|
if not versions or sdkver not in versions: continue
|
|
|
|
all_versions[sdkver][name] = versions[sdkver]
|
|
|
|
|
2023-09-28 11:59:50 +03:00
|
|
|
def struct_order(x):
|
|
|
|
name, structs = x if type(x) is tuple else (x, all_structs[x])
|
2023-09-29 10:58:52 +03:00
|
|
|
order = (struct.order for abis in structs.values()
|
|
|
|
for struct in abis.values())
|
|
|
|
return (min(order), name)
|
|
|
|
|
|
|
|
for name, structs in sorted(all_structs.items(), key=struct_order):
|
|
|
|
tmp_structs[name] = {}
|
|
|
|
for sdkver in filter(lambda v: v in structs, SDK_VERSIONS):
|
|
|
|
tmp_structs[name][sdkver] = {a: structs[sdkver][a] for a in ABIS}
|
|
|
|
|
|
|
|
all_structs = tmp_structs
|
|
|
|
|
|
|
|
print('classifying structs... 100%')
|
|
|
|
|
|
|
|
|
2023-09-24 00:20:53 +03:00
|
|
|
for klass in all_classes.values():
|
2023-09-20 18:27:42 +03:00
|
|
|
with open(f"vrclient_x64/win{klass.name}.c", "w") as file:
|
2023-09-24 00:20:53 +03:00
|
|
|
out = file.write
|
|
|
|
|
|
|
|
out(u'/* This file is auto-generated, do not edit. */\n')
|
|
|
|
out(u'#include <stdarg.h>\n')
|
|
|
|
out(u'#include <stdint.h>\n')
|
|
|
|
out(u'\n')
|
|
|
|
out(u'#include "windef.h"\n')
|
|
|
|
out(u'#include "winbase.h"\n')
|
|
|
|
out(u'#include "wine/debug.h"\n')
|
|
|
|
out(u'\n')
|
|
|
|
out(u'#include "vrclient_defs.h"\n')
|
|
|
|
out(u'\n')
|
|
|
|
out(u'#include "vrclient_private.h"\n')
|
|
|
|
out(u'\n')
|
|
|
|
out(u'#include "struct_converters.h"\n')
|
|
|
|
out(u'\n')
|
|
|
|
out(u'#include "flatapi.h"\n')
|
|
|
|
out(u'\n')
|
|
|
|
out(u'WINE_DEFAULT_DEBUG_CHANNEL(vrclient);\n')
|
|
|
|
out(u'\n')
|
|
|
|
|
|
|
|
|
2023-09-23 20:44:47 +03:00
|
|
|
for _, klass in sorted(all_classes.items()):
|
|
|
|
sdkver = klass._sdkver
|
|
|
|
handle_class(klass)
|
2023-09-21 00:21:06 +03:00
|
|
|
|
|
|
|
|
2023-09-16 21:13:49 +03:00
|
|
|
for sdkver in SDK_VERSIONS:
|
2023-09-20 18:27:42 +03:00
|
|
|
generate(sdkver, all_records[sdkver])
|
2023-09-20 23:21:42 +03:00
|
|
|
|
|
|
|
|
2018-01-18 22:29:49 +03:00
|
|
|
for f in cpp_files_need_close_brace:
|
|
|
|
m = open(f, "a")
|
|
|
|
m.write("\n}\n")
|
2018-07-27 10:40:01 +03:00
|
|
|
|
2018-07-30 12:39:47 +03:00
|
|
|
with open("tests/main_autogen.c", "a") as f:
|
|
|
|
f.write(" printf(\"All tests executed.\\n\");\n")
|
|
|
|
f.write("}\n")
|
|
|
|
|
2018-07-27 10:40:01 +03:00
|
|
|
generate_flatapi_c()
|
2023-09-28 11:59:50 +03:00
|
|
|
|
|
|
|
|
|
|
|
declared = {}
|
|
|
|
|
|
|
|
with open('vrclient_x64/vrclient_structs_generated.h', 'w') as file:
|
|
|
|
out = file.write
|
|
|
|
|
|
|
|
for name in sorted(unique_structs, key=struct_order):
|
|
|
|
if name in EXEMPT_STRUCTS: continue
|
|
|
|
for sdkver, abis in all_structs[name].items():
|
|
|
|
if name not in all_versions[sdkver]: continue
|
|
|
|
|
|
|
|
version = all_versions[sdkver][name]
|
|
|
|
if f'struct {version}' in declared: continue
|
|
|
|
declared[f'struct {version}'] = True
|
|
|
|
|
|
|
|
kind = 'union' if type(abis['w64']) is Union else 'struct'
|
|
|
|
|
|
|
|
out(f'typedef {kind} {version} {version};\n')
|
2023-09-28 23:22:25 +03:00
|
|
|
abis['w64'].write_definition(out, "", [])
|
2023-09-28 11:59:50 +03:00
|
|
|
|
|
|
|
for name, structs in all_structs.items():
|
|
|
|
if name in EXEMPT_STRUCTS: continue
|
|
|
|
if name in unique_structs: continue
|
|
|
|
for sdkver, abis in structs.items():
|
|
|
|
if name not in all_versions[sdkver]: continue
|
|
|
|
|
|
|
|
version = all_versions[sdkver][name]
|
|
|
|
if f'typedef {version}' in declared: continue
|
|
|
|
declared[f'typedef {version}'] = True
|
|
|
|
|
|
|
|
kind = 'union' if type(abis['w64']) is Union else 'struct'
|
|
|
|
|
|
|
|
if type(abis['w64']) is Class:
|
|
|
|
out(f'typedef {kind} u_{version} u_{version};\n')
|
|
|
|
out(f'typedef {kind} u_{version} u64_{version};\n')
|
|
|
|
out(f'typedef {kind} u_{version} u32_{version};\n')
|
|
|
|
out(f'typedef {kind} w_{version} w_{version};\n')
|
|
|
|
out(f'typedef {kind} w_{version} w64_{version};\n')
|
|
|
|
out(f'typedef {kind} w_{version} w32_{version};\n')
|
|
|
|
continue
|
|
|
|
|
|
|
|
if abis["w64"].needs_conversion(abis["u64"]):
|
|
|
|
out(f'typedef {kind} u64_{version} u64_{version};\n')
|
|
|
|
else:
|
|
|
|
out(f'typedef {kind} w64_{version} u64_{version};\n')
|
|
|
|
out(f'typedef {kind} w64_{version} w64_{version};\n')
|
|
|
|
|
|
|
|
if abis["w32"].needs_conversion(abis["u32"]):
|
|
|
|
out(f'typedef {kind} u32_{version} u32_{version};\n')
|
|
|
|
else:
|
|
|
|
out(f'typedef {kind} w32_{version} u32_{version};\n')
|
|
|
|
out(f'typedef {kind} w32_{version} w32_{version};\n')
|
|
|
|
|
|
|
|
for name, structs in all_structs.items():
|
|
|
|
if name in EXEMPT_STRUCTS: continue
|
|
|
|
if name in unique_structs: continue
|
|
|
|
for sdkver, abis in structs.items():
|
|
|
|
if name not in all_versions[sdkver]: continue
|
|
|
|
|
|
|
|
version = all_versions[sdkver][name]
|
|
|
|
if f'struct {version}' in declared: continue
|
|
|
|
declared[f'struct {version}'] = True
|
|
|
|
|
|
|
|
kind = 'union' if type(abis['w64']) is Union else 'struct'
|
|
|
|
|
|
|
|
if type(abis['w64']) is Class:
|
|
|
|
abis['w64'].write_definition(out, "w_")
|
|
|
|
abis['u64'].write_definition(out, "u_")
|
|
|
|
continue
|
|
|
|
|
2023-09-28 23:22:25 +03:00
|
|
|
if not abis["w64"].needs_conversion(abis["u64"]):
|
|
|
|
abis['w64'].write_definition(out, "w64_", [])
|
|
|
|
else:
|
|
|
|
abis['w64'].write_definition(out, "w64_", ["u64_"])
|
|
|
|
abis['u64'].write_definition(out, "u64_", ["w64_"])
|
2023-09-28 11:59:50 +03:00
|
|
|
|
2023-09-28 23:22:25 +03:00
|
|
|
if not abis["w32"].needs_conversion(abis["u32"]):
|
|
|
|
abis['w32'].write_definition(out, "w32_", [])
|
|
|
|
else:
|
|
|
|
abis['w32'].write_definition(out, "w32_", ["u32_"])
|
|
|
|
abis['u32'].write_definition(out, "u32_", ["w32_"])
|
2023-09-28 11:59:50 +03:00
|
|
|
|
|
|
|
out(u'#ifdef __i386__\n')
|
|
|
|
out(f'typedef w32_{version} w_{version};\n')
|
|
|
|
out(f'typedef u32_{version} u_{version};\n')
|
|
|
|
out(u'#endif\n')
|
|
|
|
out(u'#ifdef __x86_64__\n')
|
|
|
|
out(f'typedef w64_{version} w_{version};\n')
|
|
|
|
out(f'typedef u64_{version} u_{version};\n')
|
|
|
|
out(u'#endif\n')
|
|
|
|
out(u'\n')
|
|
|
|
|
|
|
|
|
|
|
|
with open('vrclient_x64/unixlib_generated.cpp', 'w') as file:
|
|
|
|
out = file.write
|
|
|
|
|
|
|
|
out(u'/* This file is auto-generated, do not edit. */\n\n')
|
|
|
|
out(u'#include "vrclient_structs.h"\n\n')
|
|
|
|
|
|
|
|
for name in sorted(unique_structs, key=struct_order):
|
2023-09-28 23:22:25 +03:00
|
|
|
for sdkver, abis in all_structs[name].items():
|
2023-09-28 11:59:50 +03:00
|
|
|
if name not in all_versions[sdkver]: continue
|
|
|
|
|
|
|
|
version = all_versions[sdkver][name]
|
|
|
|
if f'checks {version}' in declared: continue
|
|
|
|
declared[f'checks {version}'] = True
|
|
|
|
|
|
|
|
abis['w64'].write_checks(out, "")
|
|
|
|
|
|
|
|
for name, structs in all_structs.items():
|
|
|
|
if name in EXEMPT_STRUCTS: continue
|
|
|
|
if name in unique_structs: continue
|
|
|
|
for sdkver, abis in structs.items():
|
|
|
|
if name not in all_versions[sdkver]: continue
|
|
|
|
|
|
|
|
version = all_versions[sdkver][name]
|
|
|
|
if f'checks {version}' in declared: continue
|
|
|
|
declared[f'checks {version}'] = True
|
|
|
|
|
|
|
|
if type(abis['w64']) is Class:
|
|
|
|
continue
|
|
|
|
|
|
|
|
abis['w64'].write_checks(out, "w64_")
|
|
|
|
abis['u64'].write_checks(out, "u64_")
|
|
|
|
abis['w32'].write_checks(out, "w32_")
|
|
|
|
abis['u32'].write_checks(out, "u32_")
|
2023-09-28 23:22:25 +03:00
|
|
|
|
|
|
|
for sdkver, abis in structs.items():
|
|
|
|
if name not in all_versions[sdkver]: continue
|
|
|
|
|
|
|
|
version = all_versions[sdkver][name]
|
|
|
|
if f'struct {version} convert' in declared: continue
|
|
|
|
declared[f'struct {version} convert'] = True
|
|
|
|
|
|
|
|
if type(abis['w64']) in (Class, Union):
|
|
|
|
continue
|
|
|
|
|
|
|
|
if abis["w64"].needs_conversion(abis["u64"]):
|
|
|
|
out(u'#ifdef __x86_64__\n')
|
|
|
|
abis['w64'].write_converter('u64_')
|
|
|
|
out(u'\n')
|
|
|
|
abis['u64'].write_converter('w64_')
|
|
|
|
out(u'#endif\n\n')
|
|
|
|
|
|
|
|
if abis["w32"].needs_conversion(abis["u32"]):
|
|
|
|
out(u'#ifdef __i386__\n')
|
|
|
|
abis['w32'].write_converter('u32_')
|
|
|
|
out(u'\n')
|
|
|
|
abis['u32'].write_converter('w32_')
|
|
|
|
out(u'#endif\n\n')
|