Thunks: Use libclang-based code generation for libXfixes

This commit is contained in:
Tony Wasserka 2021-12-10 11:24:57 +01:00
parent d3b14df840
commit e3a2c8dc80
5 changed files with 120 additions and 45 deletions

View File

@ -1,43 +0,0 @@
#!/usr/bin/python3
from ThunkHelpers import *
lib("libXfixes", "3")
fn("const char* XFixesGetCursorName(Display*, Cursor, Atom*)")
fn("int XFixesQueryExtension(Display*, int*, int*)")
fn("int XFixesQueryVersion(Display*, int*, int*)")
fn("int XFixesVersion()")
fn("PointerBarrier XFixesCreatePointerBarrier(Display*, Window, int, int, int, int, int, int, int*)")
fn("void XFixesChangeCursorByName(Display*, Cursor, const char*)")
fn("void XFixesChangeCursor(Display*, Cursor, Cursor)")
fn("void XFixesChangeSaveSet(Display*, Window, int, int, int)")
fn("void XFixesCopyRegion(Display*, XserverRegion, XserverRegion)")
fn("void XFixesDestroyPointerBarrier(Display*, PointerBarrier)")
fn("void XFixesDestroyRegion(Display*, XserverRegion)")
fn("void XFixesExpandRegion(Display*, XserverRegion, XserverRegion, unsigned int, unsigned int, unsigned int, unsigned int)")
fn("void XFixesHideCursor(Display*, Window)")
fn("void XFixesIntersectRegion(Display*, XserverRegion, XserverRegion, XserverRegion)")
fn("void XFixesInvertRegion(Display*, XserverRegion, XRectangle*, XserverRegion)")
fn("void XFixesRegionExtents(Display*, XserverRegion, XserverRegion)")
fn("void XFixesSelectCursorInput(Display*, Window, long unsigned int)")
fn("void XFixesSelectSelectionInput(Display*, Window, Atom, long unsigned int)")
fn("void XFixesSetCursorName(Display*, Cursor, const char*)")
fn("void XFixesSetGCClipRegion(Display*, GC, int, int, XserverRegion)")
fn("void XFixesSetPictureClipRegion(Display*, XID, int, int, XserverRegion)")
fn("void XFixesSetRegion(Display*, XserverRegion, XRectangle*, int)")
fn("void XFixesSetWindowShapeRegion(Display*, Window, int, int, int, XserverRegion)")
fn("void XFixesShowCursor(Display*, Window)")
fn("void XFixesSubtractRegion(Display*, XserverRegion, XserverRegion, XserverRegion)")
fn("void XFixesTranslateRegion(Display*, XserverRegion, int, int)")
fn("void XFixesUnionRegion(Display*, XserverRegion, XserverRegion, XserverRegion)")
fn("XFixesCursorImage* XFixesGetCursorImage(Display*)")
fn("XRectangle* XFixesFetchRegionAndBounds(Display*, XserverRegion, int*, XRectangle*)")
fn("XRectangle* XFixesFetchRegion(Display*, XserverRegion, int*)")
fn("XserverRegion XFixesCreateRegion(Display*, XRectangle*, int)")
fn("XserverRegion XFixesCreateRegionFromBitmap(Display*, Pixmap)")
fn("XserverRegion XFixesCreateRegionFromGC(Display*, GC)")
fn("XserverRegion XFixesCreateRegionFromPicture(Display*, XID)")
fn("XserverRegion XFixesCreateRegionFromWindow(Display*, Window, int)")
Generate()

View File

@ -50,6 +50,38 @@ function(generate NAME)
endif()
endfunction()
# Syntax: generate(libxyz libxyz-interface.cpp generator-targets...)
# This defines a targets and a custom command:
# - custom command: Main build step that runs the thunk generator on the given interface definition
# - libxyz-interface: Target for IDE integration (making sure libxyz-interface.cpp shows up as a source file in the project tree)
function(generate_new NAME)
list(POP_FRONT ARGN SOURCE_FILE)
# Target for IDE integration
add_library(${NAME}-interface EXCLUDE_FROM_ALL ${SOURCE_FILE})
# Run thunk generator for each of the given output files
foreach(WHAT IN LISTS ARGN)
set(OUTFOLDER "${CMAKE_CURRENT_BINARY_DIR}/gen/${NAME}")
set(OUTFILE "${OUTFOLDER}/${WHAT}.inl")
add_custom_command(OUTPUT ${OUTFOLDER}
COMMAND ${CMAKE_COMMAND} -E make_directory "${OUTFOLDER}")
add_custom_command(
OUTPUT "${OUTFILE}"
DEPENDS "${GENERATOR_EXE}"
DEPENDS "${OUTFOLDER}"
DEPENDS "${SOURCE_FILE}"
COMMAND "${GENERATOR_EXE}" "${SOURCE_FILE}" "${NAME}" "-${WHAT}" "${OUTFILE}" -- -std=c++17 -I"${CMAKE_CURRENT_SOURCE_DIR}/../include"
COMMAND_EXPAND_LISTS
)
list(APPEND OUTPUTS "${OUTFILE}")
endforeach()
set(GEN_${NAME} ${OUTPUTS} PARENT_SCOPE)
endfunction()
add_custom_target(ThunkGuestsInstall)
function(add_guest_lib_with_name NAME LIBNAME)
@ -112,7 +144,7 @@ add_guest_lib(Xext)
generate(libXrender thunks function_packs function_packs_public)
add_guest_lib(Xrender)
generate(libXfixes thunks function_packs function_packs_public)
generate_new(libXfixes ${CMAKE_CURRENT_SOURCE_DIR}/../libXfixes/libXfixes_interface.cpp thunks function_packs function_packs_public)
add_guest_lib(Xfixes)
set (VULKAN_LIBS

View File

@ -43,6 +43,38 @@ function(generate NAME)
endif()
endfunction()
# Syntax: generate(libxyz libxyz-interface.cpp generator-targets...)
# This defines a target and a custom command:
# - custom command: Main build step that runs the thunk generator on the given interface definition
# - libxyz-interface: Target for IDE integration (making sure libxyz-interface.cpp shows up as a source file in the project tree)
function(generate_new NAME)
list(POP_FRONT ARGN SOURCE_FILE)
# Target for IDE integration
add_library(${NAME}-interface EXCLUDE_FROM_ALL ${SOURCE_FILE})
# Run thunk generator for each of the given output files
foreach(WHAT IN LISTS ARGN)
set(OUTFOLDER "${CMAKE_CURRENT_BINARY_DIR}/gen/${NAME}")
set(OUTFILE "${OUTFOLDER}/${WHAT}.inl")
add_custom_command(OUTPUT ${OUTFOLDER}
COMMAND ${CMAKE_COMMAND} -E make_directory "${OUTFOLDER}")
add_custom_command(
OUTPUT "${OUTFILE}"
DEPENDS "${GENERATOR_EXE}"
DEPENDS "${OUTFOLDER}"
DEPENDS "${SOURCE_FILE}"
COMMAND "${GENERATOR_EXE}" "${SOURCE_FILE}" "${NAME}" "-${WHAT}" "${OUTFILE}" -- -std=c++17 -I"${CMAKE_CURRENT_SOURCE_DIR}/../include"
COMMAND_EXPAND_LISTS
)
list(APPEND OUTPUTS "${OUTFILE}")
endforeach()
set(GEN_${NAME} ${OUTPUTS} PARENT_SCOPE)
endfunction()
function(add_host_lib_with_name NAME LIBNAME)
set (SOURCE_FILE ../lib${NAME}/lib${NAME}_Host.cpp)
get_filename_component(SOURCE_FILE_ABS "${SOURCE_FILE}" ABSOLUTE)
@ -106,7 +138,7 @@ add_host_lib(Xext)
generate(libXrender function_unpacks tab_function_unpacks ldr ldr_ptrs)
add_host_lib(Xrender)
generate(libXfixes function_unpacks tab_function_unpacks ldr ldr_ptrs)
generate_new(libXfixes ${CMAKE_CURRENT_SOURCE_DIR}/../libXfixes/libXfixes_interface.cpp function_unpacks tab_function_unpacks ldr ldr_ptrs)
add_host_lib(Xfixes)
set (VULKAN_LIBS

View File

@ -0,0 +1,10 @@
namespace fexgen {
struct callback_annotation_base {
// Prevent annotating multiple callback strategies
bool prevent_multiple;
};
struct callback_stub : callback_annotation_base {};
struct callback_guest : callback_annotation_base {};
} // namespace fexgen

View File

@ -0,0 +1,44 @@
#include <common/GeneratorInterface.h>
#include <X11/extensions/Xfixes.h>
template<auto>
struct fex_gen_config {
unsigned version = 3;
};
template<> struct fex_gen_config<XFixesGetCursorName> {};
template<> struct fex_gen_config<XFixesQueryExtension> {};
template<> struct fex_gen_config<XFixesQueryVersion> {};
template<> struct fex_gen_config<XFixesVersion> {};
template<> struct fex_gen_config<XFixesCreatePointerBarrier> {};
template<> struct fex_gen_config<XFixesChangeCursorByName> {};
template<> struct fex_gen_config<XFixesChangeCursor> {};
template<> struct fex_gen_config<XFixesChangeSaveSet> {};
template<> struct fex_gen_config<XFixesCopyRegion> {};
template<> struct fex_gen_config<XFixesDestroyPointerBarrier> {};
template<> struct fex_gen_config<XFixesDestroyRegion> {};
template<> struct fex_gen_config<XFixesExpandRegion> {};
template<> struct fex_gen_config<XFixesHideCursor> {};
template<> struct fex_gen_config<XFixesIntersectRegion> {};
template<> struct fex_gen_config<XFixesInvertRegion> {};
template<> struct fex_gen_config<XFixesRegionExtents> {};
template<> struct fex_gen_config<XFixesSelectCursorInput> {};
template<> struct fex_gen_config<XFixesSelectSelectionInput> {};
template<> struct fex_gen_config<XFixesSetCursorName> {};
template<> struct fex_gen_config<XFixesSetGCClipRegion> {};
template<> struct fex_gen_config<XFixesSetPictureClipRegion> {};
template<> struct fex_gen_config<XFixesSetRegion> {};
template<> struct fex_gen_config<XFixesSetWindowShapeRegion> {};
template<> struct fex_gen_config<XFixesShowCursor> {};
template<> struct fex_gen_config<XFixesSubtractRegion> {};
template<> struct fex_gen_config<XFixesTranslateRegion> {};
template<> struct fex_gen_config<XFixesUnionRegion> {};
template<> struct fex_gen_config<XFixesGetCursorImage> {};
template<> struct fex_gen_config<XFixesFetchRegionAndBounds> {};
template<> struct fex_gen_config<XFixesFetchRegion> {};
template<> struct fex_gen_config<XFixesCreateRegion> {};
template<> struct fex_gen_config<XFixesCreateRegionFromBitmap> {};
template<> struct fex_gen_config<XFixesCreateRegionFromGC> {};
template<> struct fex_gen_config<XFixesCreateRegionFromPicture> {};
template<> struct fex_gen_config<XFixesCreateRegionFromWindow> {};