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-21 20:39:53 +03:00
|
|
|
from clang.cindex import Cursor, CursorKind, Index, Type, 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 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-20 22:02:50 +03:00
|
|
|
PATH_CONV = [
|
2019-03-01 19:41:24 +03:00
|
|
|
{
|
|
|
|
"parent_name": "SetActionManifestPath",
|
|
|
|
"l2w_names":[],
|
|
|
|
"l2w_lens":[],
|
|
|
|
"w2l_names": ["pchActionManifestPath"],
|
|
|
|
"w2l_arrays": [False],
|
|
|
|
"return_is_size": False
|
2019-03-18 23:02:30 +03:00
|
|
|
},
|
|
|
|
{
|
|
|
|
"parent_name": "SetOverlayFromFile",
|
|
|
|
"l2w_names":[],
|
|
|
|
"l2w_lens":[],
|
|
|
|
"w2l_names": ["pchFilePath"],
|
|
|
|
"w2l_arrays": [False],
|
|
|
|
"return_is_size": False
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"parent_name": "AddApplicationManifest",
|
|
|
|
"l2w_names":[],
|
|
|
|
"l2w_lens":[],
|
|
|
|
"w2l_names": ["pchApplicationManifestFullPath"],
|
|
|
|
"w2l_arrays": [False],
|
|
|
|
"return_is_size": False
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"parent_name": "RemoveApplicationManifest",
|
|
|
|
"l2w_names":[],
|
|
|
|
"l2w_lens":[],
|
|
|
|
"w2l_names": ["pchApplicationManifestFullPath"],
|
|
|
|
"w2l_arrays": [False],
|
|
|
|
"return_is_size": False
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"parent_name": "RequestScreenshot",
|
|
|
|
"l2w_names":[],
|
|
|
|
"l2w_lens":[],
|
|
|
|
"w2l_names": ["pchPreviewFilename", "pchVRFilename"],
|
|
|
|
"w2l_arrays": [False, False],
|
|
|
|
"return_is_size": False
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"parent_name": "TakeStereoScreenshot",
|
|
|
|
"l2w_names":[],
|
|
|
|
"l2w_lens":[],
|
|
|
|
"w2l_names": ["pchPreviewFilename", "pchVRFilename"],
|
|
|
|
"w2l_arrays": [False, False],
|
|
|
|
"return_is_size": False
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"parent_name": "SubmitScreenshot",
|
|
|
|
"l2w_names":[],
|
|
|
|
"l2w_lens":[],
|
|
|
|
"w2l_names": ["pchSourcePreviewFilename", "pchSourceVRFilename"],
|
|
|
|
"w2l_arrays": [False, False],
|
|
|
|
"return_is_size": False
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"parent_name": "GetScreenshotPropertyFilename",
|
|
|
|
"l2w_names":["pchFilename"],
|
|
|
|
"l2w_lens":["cchFilename"],
|
|
|
|
"w2l_names": [],
|
|
|
|
"w2l_arrays": [],
|
|
|
|
"return_is_size": True
|
|
|
|
},
|
2020-03-18 21:50:21 +03:00
|
|
|
{
|
|
|
|
"parent_name": "undoc23",
|
|
|
|
"l2w_names":[],
|
|
|
|
"l2w_lens":[],
|
|
|
|
"w2l_names": ["a"],
|
|
|
|
"w2l_arrays": [False],
|
|
|
|
"return_is_size": False
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"parent_name": "undoc27",
|
|
|
|
"l2w_names":[],
|
|
|
|
"l2w_lens":[],
|
|
|
|
"w2l_names": ["a"],
|
|
|
|
"w2l_arrays": [False],
|
|
|
|
"return_is_size": False
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"parent_name": "SetStageOverride_Async",
|
|
|
|
"l2w_names":[],
|
|
|
|
"l2w_lens":[],
|
|
|
|
"w2l_names": ["pchRenderModelPath"],
|
|
|
|
"w2l_arrays": [False],
|
|
|
|
"return_is_size": False
|
|
|
|
},
|
|
|
|
|
2019-03-18 23:02:30 +03:00
|
|
|
# {#maybe?
|
|
|
|
# "parent_name": "GetRenderModelOriginalPath",
|
|
|
|
# "l2w_names":[pchOriginalPath],
|
|
|
|
# "l2w_lens":[unOriginalPathLen],
|
|
|
|
# "w2l_names": [],
|
|
|
|
# "w2l_arrays": [],
|
|
|
|
# "return_is_size": False
|
|
|
|
# },
|
|
|
|
# {#maybe?
|
|
|
|
# "parent_name": "GetResourceFullPath",
|
|
|
|
# "l2w_names":[pchPathBuffer],
|
|
|
|
# "l2w_lens":[unBufferLen],
|
|
|
|
# "w2l_names": [pchResourceTypeDirectory],
|
|
|
|
# "w2l_arrays": [False],
|
|
|
|
# "return_is_size": False
|
|
|
|
# },
|
|
|
|
#IVRInput::GetInputSourceHandle
|
|
|
|
#IVRIOBuffer::Open
|
|
|
|
|
|
|
|
#TODO: LaunchInternalProcess, need steam cooperation
|
2019-03-01 19:41:24 +03:00
|
|
|
]
|
|
|
|
|
2019-09-17 20:54:01 +03:00
|
|
|
struct_conversion_cache = {}
|
2021-07-09 01:42:07 +03:00
|
|
|
struct_needs_size_adjustment_cache = {}
|
2019-09-17 20:54:01 +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 = {}
|
|
|
|
|
2018-01-18 22:29:49 +03:00
|
|
|
|
2021-05-03 22:10:55 +03:00
|
|
|
def ivrclientcore_is_hmd_present(cppname, method):
|
|
|
|
return "ivrclientcore_is_hmd_present"
|
|
|
|
|
2018-04-19 16:50:32 +03:00
|
|
|
def ivrclientcore_init(cppname, method):
|
|
|
|
if "002" in cppname:
|
|
|
|
return "ivrclientcore_002_init"
|
|
|
|
return "ivrclientcore_init"
|
|
|
|
|
|
|
|
def ivrclientcore_get_generic_interface(cppname, method):
|
|
|
|
return "ivrclientcore_get_generic_interface"
|
|
|
|
|
|
|
|
def ivrclientcore_cleanup(cppname, method):
|
|
|
|
return "ivrclientcore_cleanup"
|
|
|
|
|
2018-04-04 18:20:44 +03:00
|
|
|
def ivrsystem_get_dxgi_output_info(cppname, method):
|
2023-09-24 17:39:53 +03:00
|
|
|
arguments = list(method.get_arguments())
|
|
|
|
param_count = len(arguments)
|
2018-04-04 18:20:44 +03:00
|
|
|
return {
|
|
|
|
1: "get_dxgi_output_info",
|
|
|
|
2: "get_dxgi_output_info2"
|
|
|
|
}.get(param_count, "unhandled_get_dxgi_output_info_method")
|
|
|
|
|
2018-04-11 19:03:38 +03:00
|
|
|
def ivrsystem_get_output_device(cppname, method):
|
|
|
|
#introduced in 016, changed in 017
|
|
|
|
if "016" in cppname:
|
|
|
|
return "ivrsystem_016_get_output_device"
|
|
|
|
return "ivrsystem_get_output_device"
|
|
|
|
|
2018-04-04 18:20:44 +03:00
|
|
|
def ivrcompositor_submit(cppname, method):
|
|
|
|
if "005" in cppname:
|
|
|
|
return "ivrcompositor_005_submit"
|
|
|
|
if "006" in cppname:
|
|
|
|
return "ivrcompositor_006_submit"
|
|
|
|
if "007" in cppname:
|
|
|
|
return "ivrcompositor_007_submit"
|
|
|
|
if "008" in cppname:
|
|
|
|
return "ivrcompositor_008_submit"
|
|
|
|
return "ivrcompositor_submit"
|
|
|
|
|
2021-01-29 15:32:42 +03:00
|
|
|
def ivrcompositor_set_skybox_override(cppname, method):
|
|
|
|
if "008" in cppname:
|
|
|
|
return "ivrcompositor_008_set_skybox_override"
|
|
|
|
return "ivrcompositor_set_skybox_override"
|
|
|
|
|
2018-04-04 18:20:44 +03:00
|
|
|
def ivrcompositor_post_present_handoff(cppname, method):
|
|
|
|
return "ivrcompositor_post_present_handoff"
|
|
|
|
|
2018-04-04 18:20:44 +03:00
|
|
|
def ivrcompositor_wait_get_poses(cppname, method):
|
2020-03-23 01:38:50 +03:00
|
|
|
for version in ["016", "017", "018", "019", "020", "021", "022", "024", "026"]:
|
2018-04-04 18:20:44 +03:00
|
|
|
if version in cppname:
|
|
|
|
return "ivrcompositor_wait_get_poses"
|
|
|
|
return None
|
|
|
|
|
2018-04-11 18:10:22 +03:00
|
|
|
def ivrcompositor_get_vulkan_device_extensions_required(cppname, method):
|
|
|
|
return "ivrcompositor_get_vulkan_device_extensions_required"
|
|
|
|
|
2019-12-31 20:10:04 +03:00
|
|
|
def ivrrendermodels_load_texture_d3d11_async(cppname, method):
|
|
|
|
assert "004" in cppname or "005" in cppname or "006" in cppname
|
|
|
|
return "ivrrendermodels_load_texture_d3d11_async"
|
|
|
|
|
|
|
|
def ivrrendermodels_free_texture_d3d11(cppname, method):
|
|
|
|
assert "004" in cppname or "005" in cppname or "006" in cppname
|
|
|
|
return "ivrrendermodels_free_texture_d3d11"
|
|
|
|
|
2018-09-24 18:34:07 +03:00
|
|
|
def ivrrendermodels_load_into_texture_d3d11_async(cppname, method):
|
2018-10-23 20:30:09 +03:00
|
|
|
assert "005" in cppname or "006" in cppname
|
2018-09-24 18:34:07 +03:00
|
|
|
return "ivrrendermodels_load_into_texture_d3d11_async"
|
|
|
|
|
2020-03-18 21:50:30 +03:00
|
|
|
def ivrmailbox_undoc3(cppname, method):
|
|
|
|
assert "001" in cppname
|
|
|
|
return "ivrmailbox_undoc3"
|
|
|
|
|
2020-08-16 23:31:33 +03:00
|
|
|
def ivroverlay_set_overlay_texture(cppname, method):
|
|
|
|
if "001" in cppname:
|
|
|
|
return "ivroverlay_001_set_overlay_texture"
|
|
|
|
for version in ["002", "003", "004", "005"]:
|
|
|
|
if version in cppname:
|
|
|
|
return "ivroverlay_005_set_overlay_texture"
|
|
|
|
assert \
|
|
|
|
"007" in cppname or \
|
|
|
|
"008" in cppname or \
|
|
|
|
"010" in cppname or \
|
|
|
|
"011" in cppname or \
|
|
|
|
"012" in cppname or \
|
|
|
|
"013" in cppname or \
|
|
|
|
"014" in cppname or \
|
|
|
|
"016" in cppname or \
|
|
|
|
"017" in cppname or \
|
|
|
|
"018" in cppname or \
|
|
|
|
"019" in cppname or \
|
|
|
|
"020" in cppname or \
|
|
|
|
"021" in cppname or \
|
|
|
|
"022" in cppname or \
|
2021-03-19 18:15:18 +03:00
|
|
|
"024" in cppname or \
|
2023-02-24 04:49:42 +03:00
|
|
|
"025" in cppname or \
|
2023-09-20 02:15:52 +03:00
|
|
|
"026" in cppname or \
|
|
|
|
"027" in cppname
|
2020-08-16 23:31:33 +03:00
|
|
|
return "ivroverlay_set_overlay_texture"
|
|
|
|
|
2021-07-09 15:15:04 +03:00
|
|
|
def ivrinput_get_digital_action_data(cppname, method):
|
|
|
|
if "003" in cppname:
|
|
|
|
return None
|
|
|
|
return "ivrinput_get_digital_action_data"
|
|
|
|
|
2018-04-04 18:20:44 +03:00
|
|
|
method_overrides = [
|
2021-05-03 22:10:55 +03:00
|
|
|
("IVRClientCore", "BIsHmdPresent", ivrclientcore_is_hmd_present),
|
2018-04-19 16:50:32 +03:00
|
|
|
("IVRClientCore", "Init", ivrclientcore_init),
|
|
|
|
("IVRClientCore", "GetGenericInterface", ivrclientcore_get_generic_interface),
|
|
|
|
("IVRClientCore", "Cleanup", ivrclientcore_cleanup),
|
2018-04-04 18:20:44 +03:00
|
|
|
("IVRSystem", "GetDXGIOutputInfo", ivrsystem_get_dxgi_output_info),
|
2018-04-11 19:03:38 +03:00
|
|
|
("IVRSystem", "GetOutputDevice", ivrsystem_get_output_device),
|
2018-04-04 18:20:44 +03:00
|
|
|
("IVRCompositor", "Submit", ivrcompositor_submit),
|
2021-01-29 15:32:42 +03:00
|
|
|
("IVRCompositor", "SetSkyboxOverride", ivrcompositor_set_skybox_override),
|
2018-04-04 18:20:44 +03:00
|
|
|
("IVRCompositor", "PostPresentHandoff", ivrcompositor_post_present_handoff),
|
2018-04-04 18:20:44 +03:00
|
|
|
("IVRCompositor", "WaitGetPoses", ivrcompositor_wait_get_poses),
|
2018-04-11 18:10:22 +03:00
|
|
|
("IVRCompositor", "GetVulkanDeviceExtensionsRequired", ivrcompositor_get_vulkan_device_extensions_required),
|
2019-12-31 20:10:04 +03:00
|
|
|
("IVRRenderModels", "LoadTextureD3D11_Async", ivrrendermodels_load_texture_d3d11_async),
|
|
|
|
("IVRRenderModels", "FreeTextureD3D11", ivrrendermodels_free_texture_d3d11),
|
2018-09-24 18:34:07 +03:00
|
|
|
("IVRRenderModels", "LoadIntoTextureD3D11_Async", ivrrendermodels_load_into_texture_d3d11_async),
|
2020-03-18 21:50:30 +03:00
|
|
|
("IVRMailbox", "undoc3", ivrmailbox_undoc3),
|
2020-08-16 23:31:33 +03:00
|
|
|
("IVROverlay", "SetOverlayTexture", ivroverlay_set_overlay_texture),
|
2021-07-09 15:15:04 +03:00
|
|
|
("IVRInput", "GetDigitalActionData", ivrinput_get_digital_action_data),
|
2018-04-04 18:20:44 +03:00
|
|
|
]
|
|
|
|
|
|
|
|
method_overrides_data = [
|
2018-04-19 17:11:32 +03:00
|
|
|
("IVRClientCore", "struct client_core_data", None),
|
2018-04-04 18:20:44 +03:00
|
|
|
]
|
|
|
|
|
2023-09-23 20:44:47 +03:00
|
|
|
|
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):
|
|
|
|
self._sdkver = sdkver
|
|
|
|
self._abi = abi
|
|
|
|
|
|
|
|
self._cursor = cursor
|
|
|
|
|
|
|
|
self.spelling = cursor.spelling
|
|
|
|
self.filename = SDK_CLASSES[self.spelling]
|
|
|
|
self.version = all_versions[sdkver][self.spelling]
|
|
|
|
|
2023-09-24 18:15:41 +03:00
|
|
|
self._methods = None
|
|
|
|
|
|
|
|
@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-23 20:44:47 +03:00
|
|
|
def get_children(self):
|
|
|
|
return self._cursor.get_children()
|
|
|
|
|
|
|
|
|
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::","")
|
|
|
|
|
2019-03-01 19:41:24 +03:00
|
|
|
def get_path_converter(parent):
|
2023-09-20 22:02:50 +03:00
|
|
|
for conv in PATH_CONV:
|
2019-03-01 19:41:24 +03:00
|
|
|
if conv["parent_name"] in parent.spelling:
|
|
|
|
if None in conv["l2w_names"]:
|
|
|
|
return conv
|
2021-12-14 21:22:36 +03:00
|
|
|
if type(parent) == Type:
|
2019-03-01 19:41:24 +03:00
|
|
|
children = list(parent.get_fields())
|
|
|
|
else:
|
|
|
|
children = list(parent.get_children())
|
|
|
|
for child in children:
|
|
|
|
if child.spelling in conv["w2l_names"] or \
|
|
|
|
child.spelling in conv["l2w_names"]:
|
|
|
|
return conv
|
|
|
|
return None
|
|
|
|
|
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
|
|
|
|
|
|
|
|
|
2022-10-22 18:28:35 +03:00
|
|
|
def declspec(decl, name):
|
|
|
|
if type(decl) is Cursor:
|
|
|
|
decl = decl.type
|
|
|
|
|
|
|
|
const = 'const ' if decl.is_const_qualified() else ''
|
|
|
|
if decl.kind in (TypeKind.POINTER, TypeKind.LVALUEREFERENCE):
|
|
|
|
decl = decl.get_pointee()
|
|
|
|
return declspec(decl, f"*{const}{name}")
|
|
|
|
if decl.kind == TypeKind.CONSTANTARRAY:
|
|
|
|
decl, count = decl.element_type, decl.element_count
|
|
|
|
return declspec(decl, f"({const}{name})[{count}]")
|
|
|
|
|
|
|
|
if len(name):
|
|
|
|
name = f' {name}'
|
|
|
|
|
|
|
|
if decl.kind in (TypeKind.UNEXPOSED, TypeKind.FUNCTIONPROTO):
|
|
|
|
return f'void{name}'
|
|
|
|
if decl.kind == TypeKind.ENUM:
|
|
|
|
return f'{decl.spelling.split("::")[-1]}{name}'
|
|
|
|
|
|
|
|
real_name = canonical_typename(decl)
|
|
|
|
real_name = real_name.removeprefix("const ")
|
|
|
|
real_name = real_name.removeprefix("vr::")
|
|
|
|
|
|
|
|
if real_name in SDK_STRUCTS:
|
|
|
|
typename = f"win{real_name}_{display_sdkver(sdkver)}"
|
|
|
|
elif struct_needs_conversion(decl.get_canonical()) \
|
|
|
|
and not decl.is_const_qualified(): # FIXME
|
|
|
|
typename = f"win{real_name}_{display_sdkver(sdkver)}"
|
|
|
|
else:
|
|
|
|
typename = decl.spelling
|
|
|
|
typename = typename.removeprefix("const ")
|
|
|
|
typename = typename.removeprefix("vr::")
|
|
|
|
|
2023-09-23 23:19:05 +03:00
|
|
|
return f'{const}{typename}{name}'
|
2022-10-22 18:28:35 +03:00
|
|
|
|
|
|
|
|
2023-09-24 18:15:41 +03:00
|
|
|
def handle_method_hpp(method, cppname, cpp_h):
|
2023-09-23 23:07:08 +03:00
|
|
|
ret = f'{declspec(method.result_type, "")} '
|
2022-10-22 18:28:35 +03:00
|
|
|
|
|
|
|
params = [declspec(p, "") for p in method.get_arguments()]
|
|
|
|
params = ['void *'] + params
|
|
|
|
|
2023-09-24 18:15:41 +03:00
|
|
|
cpp_h.write(f'extern {ret}{cppname}_{method.name}({", ".join(params)});\n')
|
2022-10-22 18:28:35 +03:00
|
|
|
|
|
|
|
|
2023-09-24 18:15:41 +03:00
|
|
|
def handle_method_cpp(method, classname, cppname, cpp):
|
2023-09-23 22:44:20 +03:00
|
|
|
returns_void = method.result_type.kind == TypeKind.VOID
|
|
|
|
|
2023-09-23 23:07:08 +03:00
|
|
|
ret = f'{declspec(method.result_type, "")} '
|
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())]
|
|
|
|
params = [declspec(p, names[i]) for i, p in enumerate(method.get_arguments())]
|
|
|
|
|
|
|
|
names = ['linux_side'] + names
|
|
|
|
params = ['void *linux_side'] + params
|
|
|
|
|
2023-09-24 18:15:41 +03:00
|
|
|
cpp.write(f'{ret}{cppname}_{method.name}({", ".join(params)})\n')
|
2023-09-23 17:11:42 +03:00
|
|
|
cpp.write("{\n")
|
|
|
|
|
2023-09-23 22:44:20 +03:00
|
|
|
if not returns_void:
|
2023-09-23 23:07:08 +03:00
|
|
|
cpp.write(f' {declspec(method.result_type, "_ret")};\n')
|
2023-09-23 22:44:20 +03:00
|
|
|
|
2018-01-18 22:29:49 +03:00
|
|
|
do_lin_to_win = None
|
2019-09-17 20:54:01 +03:00
|
|
|
do_win_to_lin = None
|
2018-01-18 22:29:49 +03:00
|
|
|
do_wrap = None
|
|
|
|
do_unwrap = None
|
2023-09-22 01:09:46 +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 13:46:39 +03:00
|
|
|
#unspecified function pointer
|
2023-09-23 17:11:42 +03:00
|
|
|
continue
|
|
|
|
|
|
|
|
real_type = param.type;
|
|
|
|
while real_type.kind == TypeKind.POINTER:
|
|
|
|
real_type = real_type.get_pointee()
|
|
|
|
if param.type.kind == TypeKind.POINTER:
|
|
|
|
if strip_ns(param.type.get_pointee().get_canonical().spelling) in SDK_STRUCTS:
|
|
|
|
do_unwrap = (strip_ns(param.type.get_pointee().get_canonical().spelling), param.spelling)
|
|
|
|
elif param.type.get_pointee().get_canonical().kind == TypeKind.POINTER and \
|
|
|
|
strip_ns(param.type.get_pointee().get_pointee().get_canonical().spelling) in SDK_STRUCTS:
|
|
|
|
do_wrap = (strip_ns(param.type.get_pointee().get_pointee().get_canonical().spelling), param.spelling)
|
|
|
|
elif real_type.get_canonical().kind == TypeKind.RECORD and \
|
|
|
|
struct_needs_conversion(real_type.get_canonical()):
|
|
|
|
real_name = canonical_typename(real_type)
|
|
|
|
do_win_to_lin = (strip_ns(real_name), param.spelling)
|
|
|
|
if not real_type.is_const_qualified():
|
|
|
|
do_lin_to_win = (strip_ns(real_name), param.spelling)
|
2018-01-18 22:29:49 +03:00
|
|
|
|
2019-09-17 20:54:01 +03:00
|
|
|
if do_lin_to_win or do_win_to_lin:
|
2019-09-18 17:05:00 +03:00
|
|
|
if do_lin_to_win:
|
|
|
|
cpp.write(" %s lin;\n" % do_lin_to_win[0])
|
|
|
|
else:
|
|
|
|
cpp.write(" %s lin;\n" % do_win_to_lin[0])
|
2018-01-18 22:29:49 +03:00
|
|
|
|
|
|
|
if do_wrap:
|
|
|
|
cpp.write(" %s *lin;\n" % do_wrap[0])
|
|
|
|
|
2019-09-17 20:54:01 +03:00
|
|
|
if do_win_to_lin:
|
2019-10-08 23:04:48 +03:00
|
|
|
#XXX we should pass the struct size here
|
2019-09-17 20:54:01 +03:00
|
|
|
cpp.write(" if(%s)\n" % do_win_to_lin[1])
|
|
|
|
cpp.write(" struct_%s_%s_win_to_lin(%s, &lin);\n" % (strip_ns(do_win_to_lin[0]), display_sdkver(sdkver), do_win_to_lin[1]))
|
|
|
|
|
2023-09-23 18:54:08 +03:00
|
|
|
|
2023-09-27 16:08:47 +03:00
|
|
|
size_fixup = {}
|
2023-09-23 18:54:08 +03:00
|
|
|
convert_size_param = ""
|
|
|
|
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":
|
|
|
|
convert_size_param = ', -1'
|
|
|
|
elif struct_needs_size_adjustment(real_type.get_canonical()):
|
|
|
|
real_name = real_type.spelling
|
2023-09-27 16:08:47 +03:00
|
|
|
cpp.write(f' uint32_t lin_{next_name} = std::min({next_name}, (uint32_t)sizeof({real_name}));\n')
|
2023-09-23 18:54:08 +03:00
|
|
|
convert_size_param = f', {next_name}'
|
2023-09-27 16:08:47 +03:00
|
|
|
size_fixup[next_name] = True
|
2023-09-23 18:54:08 +03:00
|
|
|
elif do_win_to_lin and do_win_to_lin[1] == name:
|
|
|
|
assert do_win_to_lin[0] not in STRUCTS_NEXT_IS_SIZE_UNHANDLED
|
2023-09-27 16:08:47 +03:00
|
|
|
cpp.write(f' uint32_t lin_{next_name} = {next_name} ? sizeof(lin) : 0;\n')
|
2023-09-23 18:54:08 +03:00
|
|
|
convert_size_param = f', {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:
|
2018-01-18 22:29:49 +03:00
|
|
|
cpp.write(" ")
|
|
|
|
else:
|
2023-09-23 22:44:20 +03:00
|
|
|
cpp.write(" _ret = ")
|
2018-01-18 22:29:49 +03:00
|
|
|
|
2023-09-23 19:51:41 +03:00
|
|
|
params = []
|
|
|
|
for name, param in zip(names[1:], method.get_arguments()):
|
2023-09-27 16:08:47 +03:00
|
|
|
if name in size_fixup:
|
|
|
|
params.append(f'lin_{name}')
|
|
|
|
elif do_lin_to_win and do_lin_to_win[1] == name or \
|
2023-09-23 19:51:41 +03:00
|
|
|
do_win_to_lin and do_win_to_lin[1] == name or \
|
|
|
|
do_wrap and do_wrap[1] == name:
|
|
|
|
params.append("%s ? &lin : nullptr" % name)
|
|
|
|
elif do_unwrap and do_unwrap[1] == name:
|
|
|
|
params.append("struct_%s_%s_unwrap(%s)" % (strip_ns(do_unwrap[0]), display_sdkver(sdkver), do_unwrap[1]))
|
|
|
|
elif "&" in param.type.spelling:
|
|
|
|
params.append("*%s" % name)
|
2018-07-30 13:46:39 +03:00
|
|
|
else:
|
2023-09-23 19:51:41 +03:00
|
|
|
params.append("(%s)%s" % (param.type.spelling, name))
|
|
|
|
|
|
|
|
cpp.write(f'(({classname}*)linux_side)->{method.spelling}({", ".join(params)});\n')
|
|
|
|
|
2023-09-22 01:09:46 +03:00
|
|
|
if do_lin_to_win:
|
|
|
|
cpp.write(" if(%s)\n" % do_lin_to_win[1])
|
|
|
|
cpp.write(" struct_%s_%s_lin_to_win(&lin, %s%s);\n" % (strip_ns(do_lin_to_win[0]), display_sdkver(sdkver), do_lin_to_win[1], convert_size_param))
|
2023-09-23 22:44:20 +03:00
|
|
|
if do_wrap and not returns_void:
|
2023-09-22 01:09:46 +03:00
|
|
|
cpp.write(" if(_ret == 0)\n")
|
|
|
|
cpp.write(" *%s = struct_%s_%s_wrap(lin);\n" % (do_wrap[1], strip_ns(do_wrap[0]), display_sdkver(sdkver)))
|
2023-09-23 22:44:20 +03:00
|
|
|
|
|
|
|
if not returns_void:
|
|
|
|
cpp.write(u' return _ret;\n')
|
2023-09-22 01:09:46 +03:00
|
|
|
cpp.write("}\n\n")
|
|
|
|
|
|
|
|
|
2023-09-23 21:52:28 +03:00
|
|
|
def handle_thiscall_wrapper(klass, method, cfile):
|
|
|
|
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
|
|
|
|
|
|
|
|
name = f'win{klass.spelling}_{klass.version}_{method.name}'
|
|
|
|
cfile.write(f'DEFINE_THISCALL_WRAPPER({name}, {size})\n')
|
|
|
|
|
|
|
|
|
2023-09-24 18:15:41 +03:00
|
|
|
def handle_method_c(method, classname, winclassname, cppname, iface_version, cfile):
|
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 ""
|
|
|
|
ret = f'{declspec(method.result_type, ret)} '
|
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())]
|
|
|
|
params = [declspec(p, names[i]) for i, p in enumerate(method.get_arguments())]
|
|
|
|
|
2023-09-22 01:09:46 +03:00
|
|
|
if returns_record:
|
2023-09-23 23:07:08 +03:00
|
|
|
params = [f'{declspec(method.result_type, "*_ret")}'] + params
|
2023-09-23 22:44:20 +03:00
|
|
|
names = ['_ret'] + names
|
2023-09-23 21:54:51 +03:00
|
|
|
|
|
|
|
params = [f'{winclassname} *_this'] + params
|
|
|
|
names = ['_this'] + names
|
|
|
|
|
|
|
|
cfile.write(f'{ret}__thiscall {winclassname}_{method.name}({", ".join(params)})\n')
|
|
|
|
cfile.write("{\n")
|
|
|
|
|
|
|
|
if returns_record:
|
|
|
|
del params[1]
|
|
|
|
del names[1]
|
2023-09-22 01:09:46 +03:00
|
|
|
|
2023-09-23 22:44:20 +03:00
|
|
|
if not returns_record and not returns_void:
|
|
|
|
cfile.write(f' {ret}_ret;\n')
|
|
|
|
|
2023-09-22 01:09:46 +03:00
|
|
|
path_conv = get_path_converter(method)
|
|
|
|
|
|
|
|
if path_conv:
|
|
|
|
for i in range(len(path_conv["w2l_names"])):
|
|
|
|
if path_conv["w2l_arrays"][i]:
|
|
|
|
cfile.write(" const char **lin_%s = vrclient_dos_to_unix_stringlist(%s);\n" % (path_conv["w2l_names"][i], path_conv["w2l_names"][i]))
|
|
|
|
# TODO
|
|
|
|
pass
|
|
|
|
else:
|
|
|
|
cfile.write(" char lin_%s[PATH_MAX];\n" % path_conv["w2l_names"][i])
|
|
|
|
cfile.write(" vrclient_dos_path_to_unix_path(%s, lin_%s);\n" % (path_conv["w2l_names"][i], path_conv["w2l_names"][i]))
|
|
|
|
|
|
|
|
cfile.write(" TRACE(\"%p\\n\", _this);\n")
|
|
|
|
|
2023-09-23 22:44:20 +03:00
|
|
|
if returns_record:
|
|
|
|
cfile.write(u' *_ret = ')
|
|
|
|
elif not returns_void:
|
|
|
|
cfile.write(u' _ret = ')
|
2023-09-22 01:09:46 +03:00
|
|
|
else:
|
2023-09-23 22:44:20 +03:00
|
|
|
cfile.write(u' ')
|
2023-09-22 01:09:46 +03:00
|
|
|
|
|
|
|
should_gen_wrapper = strip_ns(method.result_type.spelling).startswith("IVR")
|
|
|
|
if should_gen_wrapper:
|
|
|
|
cfile.write("create_win_interface(pchNameAndVersion,\n ")
|
|
|
|
|
|
|
|
is_method_overridden = False
|
|
|
|
for classname_pattern, methodname, override_generator in method_overrides:
|
2023-09-24 18:15:41 +03:00
|
|
|
if method.name == methodname and classname_pattern in classname:
|
2023-09-22 01:09:46 +03:00
|
|
|
fn_name = override_generator(cppname, method)
|
|
|
|
if fn_name:
|
2023-09-23 21:54:51 +03:00
|
|
|
cfile.write("%s(%s_%s, " % (fn_name, cppname, method.name))
|
2023-09-22 01:09:46 +03:00
|
|
|
is_method_overridden = True
|
|
|
|
break
|
|
|
|
else:
|
2023-09-23 21:54:51 +03:00
|
|
|
cfile.write("%s_%s(" % (cppname, method.name))
|
|
|
|
|
|
|
|
def param_call(param, name):
|
|
|
|
if name == '_this': return '_this->linux_side'
|
|
|
|
if path_conv and name in path_conv["w2l_names"]: return f'{name} ? lin_{name} : NULL'
|
|
|
|
return name
|
|
|
|
|
|
|
|
params = ['_this'] + list(method.get_arguments())
|
|
|
|
cfile.write(", ".join([param_call(p, n) for p, n in zip(params, names)]))
|
|
|
|
|
|
|
|
if should_gen_wrapper:
|
|
|
|
cfile.write(")")
|
2023-09-22 01:09:46 +03:00
|
|
|
|
2018-01-18 22:29:49 +03:00
|
|
|
if should_gen_wrapper:
|
|
|
|
cfile.write(")")
|
2018-04-04 18:20:44 +03:00
|
|
|
if is_method_overridden:
|
2018-04-04 18:20:44 +03:00
|
|
|
cfile.write(", %s" % iface_version[iface_version.find("_") + 1:].lstrip("0"))
|
2018-04-19 17:11:32 +03:00
|
|
|
for classname_pattern, user_data_type, _ in method_overrides_data:
|
2018-04-04 18:20:44 +03:00
|
|
|
if classname_pattern in classname:
|
|
|
|
cfile.write(", &_this->user_data")
|
|
|
|
break
|
2018-01-18 22:29:49 +03:00
|
|
|
cfile.write(");\n")
|
2023-09-23 22:44:20 +03:00
|
|
|
|
2019-03-01 19:41:24 +03:00
|
|
|
if path_conv and len(path_conv["l2w_names"]) > 0:
|
|
|
|
for i in range(len(path_conv["l2w_names"])):
|
|
|
|
assert(path_conv["l2w_names"][i]) #otherwise, no name means string is in return value. needs special handling.
|
|
|
|
cfile.write(" ")
|
|
|
|
if path_conv["return_is_size"]:
|
2023-09-23 22:44:20 +03:00
|
|
|
cfile.write("_ret = ")
|
|
|
|
cfile.write("vrclient_unix_path_to_dos_path(_ret, %s, %s, %s);\n" % (path_conv["l2w_names"][i], path_conv["l2w_names"][i], path_conv["l2w_lens"][i]))
|
2019-03-01 19:41:24 +03:00
|
|
|
if path_conv:
|
|
|
|
for i in range(len(path_conv["w2l_names"])):
|
|
|
|
if path_conv["w2l_arrays"][i]:
|
2019-03-18 23:02:30 +03:00
|
|
|
cfile.write(" vrclient_free_stringlist(lin_%s);\n" % path_conv["w2l_names"][i])
|
2023-09-23 22:44:20 +03:00
|
|
|
|
|
|
|
if not returns_void:
|
|
|
|
cfile.write(u' return _ret;\n')
|
2018-01-18 22:29:49 +03:00
|
|
|
cfile.write("}\n\n")
|
|
|
|
|
|
|
|
|
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-23 20:44:47 +03:00
|
|
|
def handle_class(klass):
|
|
|
|
file_exists = os.path.isfile(f"vrclient_x64/win{klass.spelling}.c")
|
|
|
|
cfile = open(f"vrclient_x64/win{klass.spelling}.c", "a")
|
2018-01-18 22:29:49 +03:00
|
|
|
if not file_exists:
|
|
|
|
cfile.write("""/* This file is auto-generated, do not edit. */
|
|
|
|
#include <stdarg.h>
|
|
|
|
#include <stdint.h>
|
|
|
|
|
|
|
|
#include "windef.h"
|
|
|
|
#include "winbase.h"
|
|
|
|
#include "wine/debug.h"
|
|
|
|
|
|
|
|
#include "cxx.h"
|
|
|
|
|
|
|
|
#include "vrclient_defs.h"
|
|
|
|
|
|
|
|
#include "vrclient_private.h"
|
|
|
|
|
|
|
|
#include "struct_converters.h"
|
|
|
|
|
2018-06-04 18:45:00 +03:00
|
|
|
#include "flatapi.h"
|
|
|
|
|
2018-01-18 22:29:49 +03:00
|
|
|
WINE_DEFAULT_DEBUG_CHANNEL(vrclient);
|
|
|
|
|
|
|
|
""")
|
|
|
|
|
2023-09-23 20:44:47 +03:00
|
|
|
cppname = f"cpp{klass.spelling}_{klass.version}"
|
2018-07-30 10:38:56 +03:00
|
|
|
cpp = open("vrclient_x64/%s.cpp" % cppname, "w")
|
2018-01-18 22:29:49 +03:00
|
|
|
cpp.write("#include \"vrclient_private.h\"\n")
|
|
|
|
cpp.write("#include \"vrclient_defs.h\"\n")
|
|
|
|
if os.path.isfile("openvr_%s/ivrclientcore.h" % sdkver):
|
|
|
|
cpp.write("#include \"openvr_%s/ivrclientcore.h\"\n" % sdkver)
|
|
|
|
else:
|
|
|
|
cpp.write("#include \"openvr_%s/openvr.h\"\n" % sdkver)
|
|
|
|
cpp.write("using namespace vr;\n")
|
|
|
|
cpp.write("extern \"C\" {\n")
|
|
|
|
cpp.write("#include \"struct_converters.h\"\n")
|
|
|
|
cpp.write("}\n")
|
|
|
|
cpp.write("#include \"%s.h\"\n" % cppname)
|
|
|
|
cpp.write("#ifdef __cplusplus\nextern \"C\" {\n#endif\n")
|
|
|
|
|
2018-07-30 10:38:56 +03:00
|
|
|
cpp_h = open("vrclient_x64/%s.h" % cppname, "w")
|
2018-01-18 22:29:49 +03:00
|
|
|
cpp_h.write("#ifdef __cplusplus\nextern \"C\" {\n#endif\n")
|
|
|
|
|
2023-09-23 20:44:47 +03:00
|
|
|
winclassname = f"win{klass.spelling}_{klass.version}"
|
2018-01-18 22:29:49 +03:00
|
|
|
cfile.write("#include \"%s.h\"\n\n" % cppname)
|
|
|
|
cfile.write("typedef struct __%s {\n" % winclassname)
|
2018-06-04 18:45:00 +03:00
|
|
|
cfile.write(" vtable_ptr *vtable;\n") # make sure to keep this first (flat API depends on it)
|
2018-01-18 22:29:49 +03:00
|
|
|
cfile.write(" void *linux_side;\n")
|
2018-04-19 17:11:32 +03:00
|
|
|
for classname_pattern, user_data_type, _ in method_overrides_data:
|
2023-09-21 00:21:06 +03:00
|
|
|
if classname_pattern in klass.spelling:
|
2018-04-04 18:20:44 +03:00
|
|
|
cfile.write(" %s user_data;\n" % user_data_type)
|
|
|
|
break
|
2018-01-18 22:29:49 +03:00
|
|
|
cfile.write("} %s;\n\n" % winclassname)
|
2023-09-24 18:15:41 +03:00
|
|
|
|
2023-09-23 21:52:28 +03:00
|
|
|
for method in klass.methods:
|
|
|
|
handle_thiscall_wrapper(klass, method, cfile)
|
|
|
|
cfile.write('\n')
|
|
|
|
|
2023-09-24 18:15:41 +03:00
|
|
|
for method in klass.methods:
|
|
|
|
if type(method) is Destructor:
|
|
|
|
continue
|
|
|
|
handle_method_hpp(method, cppname, cpp_h)
|
|
|
|
|
|
|
|
for method in klass.methods:
|
|
|
|
if type(method) is Destructor:
|
|
|
|
continue
|
|
|
|
handle_method_cpp(method, klass.spelling, cppname, cpp)
|
|
|
|
|
|
|
|
for method in klass.methods:
|
|
|
|
if type(method) is Destructor:
|
|
|
|
continue
|
|
|
|
else:
|
|
|
|
handle_method_c(method, klass.spelling, winclassname, cppname, klass.version, cfile)
|
2018-01-18 22:29:49 +03:00
|
|
|
|
|
|
|
cfile.write("extern vtable_ptr %s_vtable;\n\n" % winclassname)
|
|
|
|
cfile.write("#ifndef __GNUC__\n")
|
|
|
|
cfile.write("void __asm_dummy_vtables(void) {\n")
|
|
|
|
cfile.write("#endif\n")
|
|
|
|
cfile.write(" __ASM_VTABLE(%s,\n" % winclassname)
|
2023-09-24 18:15:41 +03:00
|
|
|
for method in sorted(klass.methods, key=lambda x: (x._index, -x._override)):
|
|
|
|
cfile.write(f" VTABLE_ADD_FUNC({winclassname}_{method.name})\n")
|
2018-01-18 22:29:49 +03:00
|
|
|
cfile.write(" );\n")
|
|
|
|
cfile.write("#ifndef __GNUC__\n")
|
|
|
|
cfile.write("}\n")
|
|
|
|
cfile.write("#endif\n\n")
|
|
|
|
cfile.write("%s *create_%s(void *linux_side)\n{\n" % (winclassname, winclassname))
|
2018-04-04 18:20:44 +03:00
|
|
|
cfile.write(" %s *r = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(%s));\n" % (winclassname, winclassname))
|
2018-01-18 22:29:49 +03:00
|
|
|
cfile.write(" TRACE(\"-> %p\\n\", r);\n")
|
|
|
|
cfile.write(" r->vtable = &%s_vtable;\n" % winclassname)
|
|
|
|
cfile.write(" r->linux_side = linux_side;\n")
|
|
|
|
cfile.write(" return r;\n}\n\n")
|
2018-04-19 16:50:32 +03:00
|
|
|
cfile.write("void destroy_%s(void *object)\n{\n" % winclassname)
|
|
|
|
cfile.write(" TRACE(\"%p\\n\", object);\n")
|
2018-04-19 17:11:32 +03:00
|
|
|
for classname_pattern, user_data_type, user_data_destructor in method_overrides_data:
|
2023-09-21 00:21:06 +03:00
|
|
|
if user_data_destructor and classname_pattern in klass.spelling:
|
2018-04-19 17:11:32 +03:00
|
|
|
cfile.write(" struct __%s *win_object = object;\n" % winclassname)
|
|
|
|
cfile.write(" %s(&win_object->user_data);\n" % user_data_destructor)
|
|
|
|
break
|
2018-04-19 16:50:32 +03:00
|
|
|
cfile.write(" HeapFree(GetProcessHeap(), 0, object);\n}\n\n")
|
2018-01-18 22:29:49 +03:00
|
|
|
|
2018-06-04 18:45:00 +03:00
|
|
|
# flat (FnTable) API
|
|
|
|
cfile.write("%s *create_%s_FnTable(void *linux_side)\n{\n" % (winclassname, winclassname))
|
|
|
|
cfile.write(" %s *r = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(%s));\n" % (winclassname, winclassname))
|
2023-09-24 18:15:41 +03:00
|
|
|
cfile.write(" struct thunk *thunks = alloc_thunks(%d);\n" % len(klass.methods))
|
|
|
|
cfile.write(" struct thunk **vtable = HeapAlloc(GetProcessHeap(), 0, %d * sizeof(*vtable));\n" % len(klass.methods))
|
2018-06-04 18:45:00 +03:00
|
|
|
cfile.write(" int i;\n\n")
|
|
|
|
cfile.write(" TRACE(\"-> %p, vtable %p, thunks %p\\n\", r, vtable, thunks);\n")
|
2023-09-24 18:15:41 +03:00
|
|
|
for i, method in enumerate(klass.methods):
|
|
|
|
thunk_params = get_capi_thunk_params(method)
|
|
|
|
arguments = list(method.get_arguments())
|
2018-07-27 10:40:01 +03:00
|
|
|
global max_c_api_param_count
|
2023-09-24 17:39:53 +03:00
|
|
|
max_c_api_param_count = max(len(arguments), max_c_api_param_count)
|
2023-09-24 18:15:41 +03:00
|
|
|
cfile.write(" init_thunk(&thunks[%d], r, %s_%s, %s);\n" % (i, winclassname, method.name, thunk_params))
|
|
|
|
cfile.write(" for (i = 0; i < %d; i++)\n" % len(klass.methods))
|
2018-06-04 18:45:00 +03:00
|
|
|
cfile.write(" vtable[i] = &thunks[i];\n")
|
|
|
|
cfile.write(" r->linux_side = linux_side;\n")
|
|
|
|
cfile.write(" r->vtable = (void *)vtable;\n")
|
|
|
|
cfile.write(" return r;\n}\n\n")
|
|
|
|
cfile.write("void destroy_%s_FnTable(void *object)\n{\n" % winclassname)
|
|
|
|
cfile.write(" %s *win_object = object;\n" % winclassname)
|
|
|
|
cfile.write(" TRACE(\"%p\\n\", win_object);\n")
|
|
|
|
for classname_pattern, user_data_type, user_data_destructor in method_overrides_data:
|
2023-09-21 00:21:06 +03:00
|
|
|
if user_data_destructor and classname_pattern in klass.spelling:
|
2018-06-04 18:45:00 +03:00
|
|
|
cfile.write(" %s(&win_object->user_data);\n" % user_data_destructor)
|
|
|
|
break
|
|
|
|
cfile.write(" VirtualFree(win_object->vtable[0], 0, MEM_RELEASE);\n")
|
|
|
|
cfile.write(" HeapFree(GetProcessHeap(), 0, win_object->vtable);\n")
|
|
|
|
cfile.write(" HeapFree(GetProcessHeap(), 0, win_object);\n}\n\n")
|
|
|
|
|
2018-01-18 22:29:49 +03:00
|
|
|
cpp.write("#ifdef __cplusplus\n}\n#endif\n")
|
|
|
|
cpp_h.write("#ifdef __cplusplus\n}\n#endif\n")
|
|
|
|
|
2018-07-30 10:38:56 +03:00
|
|
|
constructors = open("vrclient_x64/win_constructors.h", "a")
|
2018-01-18 22:29:49 +03:00
|
|
|
constructors.write("extern void *create_%s(void *);\n" % winclassname)
|
2018-06-04 18:45:00 +03:00
|
|
|
constructors.write("extern void *create_%s_FnTable(void *);\n" % winclassname)
|
2018-01-18 22:29:49 +03:00
|
|
|
|
2018-07-30 10:38:56 +03:00
|
|
|
destructors = open("vrclient_x64/win_destructors.h", "a")
|
2018-04-19 16:50:32 +03:00
|
|
|
destructors.write("extern void destroy_%s(void *);\n" % winclassname)
|
2018-06-04 18:45:00 +03:00
|
|
|
destructors.write("extern void destroy_%s_FnTable(void *);\n" % winclassname)
|
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):
|
|
|
|
if type(cursor) is Cursor:
|
|
|
|
return canonical_typename(cursor.type)
|
|
|
|
|
|
|
|
name = cursor.get_canonical().spelling
|
|
|
|
return name.removeprefix("const ")
|
|
|
|
|
2019-09-17 18:53:26 +03:00
|
|
|
|
2023-09-21 23:13:09 +03:00
|
|
|
def find_struct_abis(name):
|
|
|
|
records = all_records[sdkver]
|
|
|
|
missing = [name not in records[abi] for abi in ABIS]
|
|
|
|
assert all(missing) or not any(missing)
|
|
|
|
if any(missing): return None
|
|
|
|
return {abi: records[abi][name].type for abi in ABIS}
|
2019-09-17 20:54:01 +03:00
|
|
|
|
2019-09-17 18:53:26 +03:00
|
|
|
|
2019-09-17 20:54:01 +03:00
|
|
|
def struct_needs_conversion_nocache(struct):
|
2023-09-21 23:13:09 +03:00
|
|
|
name = canonical_typename(struct)
|
|
|
|
|
|
|
|
abis = find_struct_abis(name)
|
|
|
|
if abis is None:
|
|
|
|
return False, False
|
|
|
|
|
|
|
|
names = {a: [f.spelling for f in abis[a].get_fields()]
|
|
|
|
for a in ABIS}
|
|
|
|
assert names['u32'] == names['u64']
|
|
|
|
assert names['u32'] == names['w32']
|
|
|
|
assert names['u32'] == names['w64']
|
|
|
|
|
|
|
|
offsets = {a: {f: abis[a].get_offset(f) for f in names[a]}
|
|
|
|
for a in ABIS}
|
|
|
|
if offsets['u32'] != offsets['w32']:
|
|
|
|
return True, False
|
|
|
|
if offsets['u64'] != offsets['w64']:
|
|
|
|
return True, False
|
|
|
|
|
|
|
|
types = {a: [f.type.get_canonical() for f in abis[a].get_fields()]
|
|
|
|
for a in ABIS}
|
|
|
|
if any(t.kind == TypeKind.RECORD and struct_needs_conversion(t)
|
|
|
|
for t in types['u32']):
|
|
|
|
return True, False
|
|
|
|
if any(t.kind == TypeKind.RECORD and struct_needs_conversion(t)
|
|
|
|
for t in types['u64']):
|
|
|
|
return True, False
|
|
|
|
|
|
|
|
assert abis['u32'].get_size() <= abis['w32'].get_size()
|
|
|
|
if abis['u32'].get_size() < abis['w32'].get_size():
|
|
|
|
return False, True
|
|
|
|
|
|
|
|
assert abis['u64'].get_size() <= abis['w64'].get_size()
|
|
|
|
if abis['u64'].get_size() < abis['w64'].get_size():
|
|
|
|
return False, True
|
|
|
|
|
|
|
|
return False, False
|
|
|
|
|
2019-09-17 20:54:01 +03:00
|
|
|
|
|
|
|
def struct_needs_conversion(struct):
|
2023-09-21 20:39:53 +03:00
|
|
|
name = canonical_typename(struct)
|
|
|
|
|
2019-09-17 20:54:01 +03:00
|
|
|
if not sdkver in struct_conversion_cache:
|
|
|
|
struct_conversion_cache[sdkver] = {}
|
2021-07-09 01:42:07 +03:00
|
|
|
struct_needs_size_adjustment_cache[sdkver] = {}
|
|
|
|
|
2023-09-21 20:39:53 +03:00
|
|
|
if not name in struct_conversion_cache[sdkver]:
|
|
|
|
struct_conversion_cache[sdkver][name], \
|
|
|
|
struct_needs_size_adjustment_cache[sdkver][name] = \
|
2021-07-09 01:42:07 +03:00
|
|
|
struct_needs_conversion_nocache(struct)
|
|
|
|
|
2023-09-21 20:39:53 +03:00
|
|
|
return struct_conversion_cache[sdkver][name]
|
2019-09-17 20:54:01 +03:00
|
|
|
|
2021-07-09 01:42:07 +03:00
|
|
|
def struct_needs_size_adjustment(struct):
|
2023-09-21 20:39:53 +03:00
|
|
|
name = canonical_typename(struct)
|
|
|
|
return not struct_needs_conversion(struct) and struct_needs_size_adjustment_cache[sdkver][name]
|
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)
|
|
|
|
align = abis['w32'].get_align()
|
2019-09-17 18:53:26 +03:00
|
|
|
return " __attribute__((aligned(" + str(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):
|
2018-01-18 22:29:49 +03:00
|
|
|
handler_name = "%s_%s" % (struct.displayname, display_sdkver(sdkver))
|
|
|
|
|
|
|
|
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 22:15:40 +03:00
|
|
|
if strip_ns(struct.displayname) 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:
|
2018-01-18 22:29:49 +03:00
|
|
|
cppfile.write("\n %s *linux_side;\n" % struct.displayname)
|
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 22:02:50 +03:00
|
|
|
elif struct.displayname in STRUCTS_SIZE_FIELD and \
|
|
|
|
m.displayname in STRUCTS_SIZE_FIELD[struct.displayname]:
|
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 22:02:50 +03:00
|
|
|
if strip_ns(struct.displayname) 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))
|
|
|
|
cppfile.write(" %s *lin = (%s *)l;\n" % (struct.displayname, struct.displayname))
|
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))
|
|
|
|
cppfile.write(" %s *lin = (%s *)l;\n" % (struct.displayname, struct.displayname))
|
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))
|
2019-09-17 20:54:01 +03:00
|
|
|
cppfile.write(" %s *lin = (%s *)l;\n" % (struct.displayname, struct.displayname))
|
|
|
|
|
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
|
|
|
|
|
|
|
hfile.write("extern %s *struct_%s_unwrap(win%s *w);\n" % (struct.displayname, handler_name, handler_name))
|
2019-09-17 20:54:01 +03:00
|
|
|
|
2018-01-18 22:29:49 +03:00
|
|
|
cppfile.write("struct %s *struct_%s_unwrap(win%s *w)\n{\n" % (struct.displayname, handler_name, handler_name))
|
|
|
|
cppfile.write(" %s *ret = w->linux_side;\n" % struct.displayname)
|
|
|
|
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-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] = {}
|
|
|
|
if sdkver not in all_structs: all_structs[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-21 21:33:54 +03:00
|
|
|
records = enumerate_structs(build.cursor)
|
|
|
|
# reverse the order to favor definitions over declarations
|
|
|
|
records = dict(reversed([(c.type.spelling, c) for c in records]))
|
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
|
|
|
|
|
|
|
structs = enumerate_structs(build.cursor, vr_only=True)
|
|
|
|
struct_kinds = (CursorKind.STRUCT_DECL, CursorKind.CLASS_DECL)
|
|
|
|
structs = filter(lambda c: c.kind in struct_kinds, structs)
|
|
|
|
structs = {c.spelling: c for c in structs}
|
2023-09-21 00:21:06 +03:00
|
|
|
|
2023-09-21 21:33:54 +03:00
|
|
|
all_records[sdkver][abi] = records
|
|
|
|
tmp_classes[sdkver][abi] = classes
|
|
|
|
all_structs[sdkver][abi] = structs
|
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-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-21 21:33:54 +03:00
|
|
|
generate(sdkver, all_structs[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()
|