From 2eda0d235bde0e06211a39bc5b711ddf08f40629 Mon Sep 17 00:00:00 2001 From: Andrew Eikum Date: Tue, 17 Sep 2019 10:53:26 -0500 Subject: [PATCH] vrclient: Add alignment attribute if needed --- vrclient_x64/gen_wrapper.py | 25 +++++++++++++++++-- .../vrclient_x64/struct_converters_090.cpp | 2 +- .../vrclient_x64/struct_converters_091.cpp | 2 +- .../vrclient_x64/struct_converters_0910.cpp | 2 +- .../vrclient_x64/struct_converters_092.cpp | 2 +- .../vrclient_x64/struct_converters_093.cpp | 2 +- .../vrclient_x64/struct_converters_094.cpp | 2 +- .../vrclient_x64/struct_converters_096.cpp | 2 +- .../vrclient_x64/struct_converters_097.cpp | 2 +- .../vrclient_x64/struct_converters_098.cpp | 2 +- .../vrclient_x64/struct_converters_099.cpp | 2 +- 11 files changed, 33 insertions(+), 12 deletions(-) diff --git a/vrclient_x64/gen_wrapper.py b/vrclient_x64/gen_wrapper.py index 490f9473..1b74916f 100755 --- a/vrclient_x64/gen_wrapper.py +++ b/vrclient_x64/gen_wrapper.py @@ -5,6 +5,8 @@ from __future__ import print_function +CLANG_PATH='/usr/lib/clang/8.0.1' + import pprint import sys import clang.cindex @@ -699,6 +701,24 @@ WINE_DEFAULT_DEBUG_CHANNEL(vrclient); generate_c_api_thunk_tests(winclassname, methods, method_names) +def strip_const(typename): + return typename.replace("const ", "", 1) + +def find_windows_struct(struct): + for child in list(windows_build.cursor.get_children()): + if strip_const(struct.spelling) == child.spelling: + return child.type + return None + +def get_field_attribute_str(field): + if field.type.kind != clang.cindex.TypeKind.RECORD: + return "" + win_struct = find_windows_struct(field.type) + if win_struct is None: + align = field.type.get_align() + else: + align = win_struct.get_align() + return " __attribute__((aligned(" + str(align) + ")))" generated_struct_handlers = [] cpp_files_need_close_brace = [] @@ -744,7 +764,7 @@ def handle_struct(sdkver, struct, which): if m.type.kind == clang.cindex.TypeKind.CONSTANTARRAY: cppfile.write(" %s %s[%u];\n" % (m.type.element_type.spelling, m.displayname, m.type.element_count)) else: - cppfile.write(" %s %s;\n" % (m.type.spelling, m.displayname)) + cppfile.write(" %s %s%s;\n" % (m.type.spelling, m.displayname, get_field_attribute_str(m))) if which == WRAPPERS: cppfile.write("\n %s *linux_side;\n" % struct.displayname) cppfile.write("} __attribute__ ((ms_struct));\n") @@ -1105,7 +1125,8 @@ for sdkver in sdk_versions: if not os.path.isfile(input_name): continue index = clang.cindex.Index.create() - tu = index.parse(input_name, args=['-x', 'c++', '-std=c++11', '-DGNUC', '-Iopenvr_%s/' % sdkver, '-I/usr/lib/clang/8.0.1/include/']) + windows_build = index.parse(input_name, args=['-x', 'c++', '-m32', '-Iopenvr_%s/' % sdkver, '-I' + CLANG_PATH + '/include/', '-mms-bitfields', '-U__linux__', '-Wno-incompatible-ms-struct']) + tu = index.parse(input_name, args=['-x', 'c++', '-std=c++11', '-DGNUC', '-Iopenvr_%s/' % sdkver, '-I' + CLANG_PATH + '/include/']) diagnostics = list(tu.diagnostics) if len(diagnostics) > 0: diff --git a/vrclient_x64/vrclient_x64/struct_converters_090.cpp b/vrclient_x64/vrclient_x64/struct_converters_090.cpp index b5e41a6b..39ee5bcc 100644 --- a/vrclient_x64/vrclient_x64/struct_converters_090.cpp +++ b/vrclient_x64/vrclient_x64/struct_converters_090.cpp @@ -41,7 +41,7 @@ struct winRenderModel_t_090 { uint32_t unVertexCount; const uint16_t * rIndexData; uint32_t unTriangleCount; - vr::RenderModel_TextureMap_t diffuseTexture; + vr::RenderModel_TextureMap_t diffuseTexture __attribute__((aligned(4))); RenderModel_t *linux_side; } __attribute__ ((ms_struct)); diff --git a/vrclient_x64/vrclient_x64/struct_converters_091.cpp b/vrclient_x64/vrclient_x64/struct_converters_091.cpp index 7b5a8b1a..2d2f02f1 100644 --- a/vrclient_x64/vrclient_x64/struct_converters_091.cpp +++ b/vrclient_x64/vrclient_x64/struct_converters_091.cpp @@ -41,7 +41,7 @@ struct winRenderModel_t_091 { uint32_t unVertexCount; const uint16_t * rIndexData; uint32_t unTriangleCount; - vr::RenderModel_TextureMap_t diffuseTexture; + vr::RenderModel_TextureMap_t diffuseTexture __attribute__((aligned(4))); RenderModel_t *linux_side; } __attribute__ ((ms_struct)); diff --git a/vrclient_x64/vrclient_x64/struct_converters_0910.cpp b/vrclient_x64/vrclient_x64/struct_converters_0910.cpp index 576b4d46..f247a2b2 100644 --- a/vrclient_x64/vrclient_x64/struct_converters_0910.cpp +++ b/vrclient_x64/vrclient_x64/struct_converters_0910.cpp @@ -41,7 +41,7 @@ struct winRenderModel_t_0910 { uint32_t unVertexCount; const uint16_t * rIndexData; uint32_t unTriangleCount; - vr::RenderModel_TextureMap_t diffuseTexture; + vr::RenderModel_TextureMap_t diffuseTexture __attribute__((aligned(4))); RenderModel_t *linux_side; } __attribute__ ((ms_struct)); diff --git a/vrclient_x64/vrclient_x64/struct_converters_092.cpp b/vrclient_x64/vrclient_x64/struct_converters_092.cpp index 6b22438c..dad1a30e 100644 --- a/vrclient_x64/vrclient_x64/struct_converters_092.cpp +++ b/vrclient_x64/vrclient_x64/struct_converters_092.cpp @@ -41,7 +41,7 @@ struct winRenderModel_t_092 { uint32_t unVertexCount; const uint16_t * rIndexData; uint32_t unTriangleCount; - vr::RenderModel_TextureMap_t diffuseTexture; + vr::RenderModel_TextureMap_t diffuseTexture __attribute__((aligned(4))); RenderModel_t *linux_side; } __attribute__ ((ms_struct)); diff --git a/vrclient_x64/vrclient_x64/struct_converters_093.cpp b/vrclient_x64/vrclient_x64/struct_converters_093.cpp index 36146c13..81f19d17 100644 --- a/vrclient_x64/vrclient_x64/struct_converters_093.cpp +++ b/vrclient_x64/vrclient_x64/struct_converters_093.cpp @@ -41,7 +41,7 @@ struct winRenderModel_t_093 { uint32_t unVertexCount; const uint16_t * rIndexData; uint32_t unTriangleCount; - vr::RenderModel_TextureMap_t diffuseTexture; + vr::RenderModel_TextureMap_t diffuseTexture __attribute__((aligned(4))); RenderModel_t *linux_side; } __attribute__ ((ms_struct)); diff --git a/vrclient_x64/vrclient_x64/struct_converters_094.cpp b/vrclient_x64/vrclient_x64/struct_converters_094.cpp index 77cde976..2455df5a 100644 --- a/vrclient_x64/vrclient_x64/struct_converters_094.cpp +++ b/vrclient_x64/vrclient_x64/struct_converters_094.cpp @@ -41,7 +41,7 @@ struct winRenderModel_t_094 { uint32_t unVertexCount; const uint16_t * rIndexData; uint32_t unTriangleCount; - vr::RenderModel_TextureMap_t diffuseTexture; + vr::RenderModel_TextureMap_t diffuseTexture __attribute__((aligned(4))); RenderModel_t *linux_side; } __attribute__ ((ms_struct)); diff --git a/vrclient_x64/vrclient_x64/struct_converters_096.cpp b/vrclient_x64/vrclient_x64/struct_converters_096.cpp index 72a26ee3..7e8d6890 100644 --- a/vrclient_x64/vrclient_x64/struct_converters_096.cpp +++ b/vrclient_x64/vrclient_x64/struct_converters_096.cpp @@ -41,7 +41,7 @@ struct winRenderModel_t_096 { uint32_t unVertexCount; const uint16_t * rIndexData; uint32_t unTriangleCount; - vr::RenderModel_TextureMap_t diffuseTexture; + vr::RenderModel_TextureMap_t diffuseTexture __attribute__((aligned(4))); RenderModel_t *linux_side; } __attribute__ ((ms_struct)); diff --git a/vrclient_x64/vrclient_x64/struct_converters_097.cpp b/vrclient_x64/vrclient_x64/struct_converters_097.cpp index d41f34ab..cfca96b8 100644 --- a/vrclient_x64/vrclient_x64/struct_converters_097.cpp +++ b/vrclient_x64/vrclient_x64/struct_converters_097.cpp @@ -41,7 +41,7 @@ struct winRenderModel_t_097 { uint32_t unVertexCount; const uint16_t * rIndexData; uint32_t unTriangleCount; - vr::RenderModel_TextureMap_t diffuseTexture; + vr::RenderModel_TextureMap_t diffuseTexture __attribute__((aligned(4))); RenderModel_t *linux_side; } __attribute__ ((ms_struct)); diff --git a/vrclient_x64/vrclient_x64/struct_converters_098.cpp b/vrclient_x64/vrclient_x64/struct_converters_098.cpp index b4c2d813..cc3c0565 100644 --- a/vrclient_x64/vrclient_x64/struct_converters_098.cpp +++ b/vrclient_x64/vrclient_x64/struct_converters_098.cpp @@ -41,7 +41,7 @@ struct winRenderModel_t_098 { uint32_t unVertexCount; const uint16_t * rIndexData; uint32_t unTriangleCount; - vr::RenderModel_TextureMap_t diffuseTexture; + vr::RenderModel_TextureMap_t diffuseTexture __attribute__((aligned(4))); RenderModel_t *linux_side; } __attribute__ ((ms_struct)); diff --git a/vrclient_x64/vrclient_x64/struct_converters_099.cpp b/vrclient_x64/vrclient_x64/struct_converters_099.cpp index d6545c51..63232cd5 100644 --- a/vrclient_x64/vrclient_x64/struct_converters_099.cpp +++ b/vrclient_x64/vrclient_x64/struct_converters_099.cpp @@ -41,7 +41,7 @@ struct winRenderModel_t_099 { uint32_t unVertexCount; const uint16_t * rIndexData; uint32_t unTriangleCount; - vr::RenderModel_TextureMap_t diffuseTexture; + vr::RenderModel_TextureMap_t diffuseTexture __attribute__((aligned(4))); RenderModel_t *linux_side; } __attribute__ ((ms_struct));