Commit 6fe17bb7 authored by Paul Berry's avatar Paul Berry

piglit-dispatch: Code generation scripts.

This patch contains the code generation scripts that convert the files
gl.spec, gl.tm, and enumext.spec into C code, as well as the CMake
directives to run the scripts.

Code generation occurs in two phases: first the script
glapi/parse_glspec.py converts the .spec and .tm files into an
intermediate JSON format, which is stored in glapi/glapi.json.  Then,
the script tests/util/gen_dispatch.py converts the JSON file into two
files, tests/util/generated_dispatch.c and
tests/util/generated_dispatch.h.

There are two motivations for breaking code generation into two phases:
(1) there are other code generation tasks we may add in the future
(e.g. generating the tests/util/piglit-util-enum.c file), and it would
be nice not to have to rewrite any parsing code when we do so.  (2) if
the GL consortium ever decides to change the format of gl.spec, gl.tm,
and enumext.spec, then we only have to change parse_glspec.py.

These code generation scripts can be run by invoking "make
piglit_dispatch_gen" from the toplevel source directory.

v2: Add clarifying comments, remove a bogus "print" statement, and
raise an exception if an unrecognized multiplicity is encountered.
Also, handle "reference" multiplicity.

v3: Add APIENTRY to stub functions.  Rename "near" and "far" to avoid
problems on MSVC.  Get rid of "__" in function names.  Rename
initialize_dispatch_pointers => reset_dispatch_pointers.  Add
gl_10x_version parameter to get_core_proc().  Output generated code
relative to CMAKE_BINARY_DIR so that it won't pollute source
directories when building out of tree.  Add .gitignore so that
generated files are ignored when building in tree.  Add GL_VERSION_*
defines.
parent 6409a675
......@@ -169,6 +169,9 @@ configure_file(
"${piglit_BINARY_DIR}/tests/util/config.h"
)
include(cmake/piglit_glapi.cmake)
include(cmake/piglit_dispatch.cmake)
include_directories(src)
add_subdirectory(cmake/target_api)
add_subdirectory(generated_tests)
# Copyright 2012 Intel Corporation
#
# Permission is hereby granted, free of charge, to any person obtaining a
# copy of this software and associated documentation files (the "Software"),
# to deal in the Software without restriction, including without limitation
# the rights to use, copy, modify, merge, publish, distribute, sublicense,
# and/or sell copies of the Software, and to permit persons to whom the
# Software is furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice (including the next
# paragraph) shall be included in all copies or substantial portions of the
# Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
# THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
# IN THE SOFTWARE.
set(piglit_dispatch_gen_output_dir ${CMAKE_BINARY_DIR}/tests/util)
file(MAKE_DIRECTORY ${piglit_dispatch_gen_output_dir})
set(piglit_dispatch_gen_outputs
${piglit_dispatch_gen_output_dir}/generated_dispatch.c
${piglit_dispatch_gen_output_dir}/generated_dispatch.h
)
set(piglit_dispatch_gen_inputs
${CMAKE_SOURCE_DIR}/tests/util/gen_dispatch.py
${CMAKE_BINARY_DIR}/glapi/glapi.json
)
add_custom_command(
OUTPUT ${piglit_dispatch_gen_outputs}
DEPENDS ${piglit_dispatch_gen_inputs}
COMMAND ${python} ${piglit_dispatch_gen_inputs} ${piglit_dispatch_gen_outputs}
)
add_custom_target(piglit_dispatch_gen
DEPENDS ${piglit_dispatch_gen_outputs}
)
# Copyright 2012 Intel Corporation
#
# Permission is hereby granted, free of charge, to any person obtaining a
# copy of this software and associated documentation files (the "Software"),
# to deal in the Software without restriction, including without limitation
# the rights to use, copy, modify, merge, publish, distribute, sublicense,
# and/or sell copies of the Software, and to permit persons to whom the
# Software is furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice (including the next
# paragraph) shall be included in all copies or substantial portions of the
# Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
# THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
# IN THE SOFTWARE.
# Note: we're outputting the generated file to a subdirectory of
# ${CMAKE_SOURCE_DIR} so that we can check it back in to source
# control.
set(piglit_glapi_src_dir ${CMAKE_SOURCE_DIR}/glapi)
file(MAKE_DIRECTORY ${CMAKE_BINARY_DIR}/glapi)
set(piglit_glapi_output ${CMAKE_BINARY_DIR}/glapi/glapi.json)
set(piglit_glapi_inputs
${piglit_glapi_src_dir}/parse_glspec.py
${piglit_glapi_src_dir}/gl.tm
${piglit_glapi_src_dir}/gl.spec
${piglit_glapi_src_dir}/enumext.spec
)
add_custom_command(
OUTPUT ${piglit_glapi_output}
DEPENDS ${piglit_glapi_inputs}
COMMAND ${python} ${piglit_glapi_inputs} ${piglit_glapi_output}
)
This diff is collapsed.
config.h
\ No newline at end of file
config.h
generated_dispatch.c
generated_dispatch.h
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment