mirror of
https://gitlab.freedesktop.org/mesa/mesa.git
synced 2026-05-05 05:18:08 +02:00
glsl: Generate ir_expression_operation_strings.h from Python
'diff -ud' is clean. v2: Massive rebase. v3: With much help from José Fonseca, fix the SCons build. Signed-off-by: Ian Romanick <ian.d.romanick@intel.com> Reviewed-by: Matt Turner <mattst88@gmail.com> Acked-by: Dylan Baker <dylan@pnwbakers.com>
This commit is contained in:
parent
90781eee4d
commit
fb44f69779
6 changed files with 44 additions and 153 deletions
|
|
@ -199,7 +199,11 @@ glsl/glcpp/glcpp-lex.c: glsl/glcpp/glcpp-lex.l
|
|||
|
||||
glsl/ir_expression_operation.h: glsl/ir_expression_operation.py
|
||||
$(MKDIR_GEN)
|
||||
$(PYTHON_GEN) $(srcdir)/glsl/ir_expression_operation.py > $@ || ($(RM) $@; false)
|
||||
$(PYTHON_GEN) $(srcdir)/glsl/ir_expression_operation.py enum > $@ || ($(RM) $@; false)
|
||||
|
||||
glsl/ir_expression_operation_strings.h: glsl/ir_expression_operation.py
|
||||
$(MKDIR_GEN)
|
||||
$(PYTHON_GEN) $(srcdir)/glsl/ir_expression_operation.py strings > $@ || ($(RM) $@; false)
|
||||
|
||||
# Only the parsers (specifically the header files generated at the same time)
|
||||
# need to be in BUILT_SOURCES. Though if we list the parser headers YACC is
|
||||
|
|
@ -211,6 +215,7 @@ BUILT_SOURCES += \
|
|||
glsl/glsl_parser.cpp \
|
||||
glsl/glsl_lexer.cpp \
|
||||
glsl/ir_expression_operation.h \
|
||||
glsl/ir_expression_operation_strings.h \
|
||||
glsl/glcpp/glcpp-parse.c \
|
||||
glsl/glcpp/glcpp-lex.c
|
||||
CLEANFILES += \
|
||||
|
|
@ -219,6 +224,7 @@ CLEANFILES += \
|
|||
glsl/glsl_parser.cpp \
|
||||
glsl/glsl_lexer.cpp \
|
||||
glsl/ir_expression_operation.h \
|
||||
glsl/ir_expression_operation_strings.h \
|
||||
glsl/glcpp/glcpp-parse.c \
|
||||
glsl/glcpp/glcpp-lex.c
|
||||
|
||||
|
|
|
|||
|
|
@ -39,7 +39,6 @@ LIBGLSL_FILES = \
|
|||
glsl/ir_equals.cpp \
|
||||
glsl/ir_expression_flattening.cpp \
|
||||
glsl/ir_expression_flattening.h \
|
||||
glsl/ir_expression_operation_strings.h \
|
||||
glsl/ir_function_can_inline.cpp \
|
||||
glsl/ir_function_detect_recursion.cpp \
|
||||
glsl/ir_function_inlining.h \
|
||||
|
|
@ -148,6 +147,7 @@ GLSL_COMPILER_CXX_FILES = \
|
|||
# libglsl generated sources
|
||||
LIBGLSL_GENERATED_FILES = \
|
||||
glsl/ir_expression_operation.h \
|
||||
glsl/ir_expression_operation_strings.h \
|
||||
glsl/glsl_lexer.cpp \
|
||||
glsl/glsl_parser.cpp \
|
||||
glsl/glsl_parser.h
|
||||
|
|
|
|||
|
|
@ -122,7 +122,14 @@ env.CodeGenerate(
|
|||
target = 'glsl/ir_expression_operation.h',
|
||||
script = 'glsl/ir_expression_operation.py',
|
||||
source = [],
|
||||
command = python_cmd + ' $SCRIPT > $TARGET'
|
||||
command = python_cmd + ' $SCRIPT enum > $TARGET'
|
||||
)
|
||||
|
||||
env.CodeGenerate(
|
||||
target = 'glsl/ir_expression_operation_strings.h',
|
||||
script = 'glsl/ir_expression_operation.py',
|
||||
source = [],
|
||||
command = python_cmd + ' $SCRIPT strings > $TARGET'
|
||||
)
|
||||
|
||||
glsl_compiler = env.Program(
|
||||
|
|
|
|||
1
src/compiler/glsl/.gitignore
vendored
1
src/compiler/glsl/.gitignore
vendored
|
|
@ -4,6 +4,7 @@ glsl_parser.h
|
|||
glsl_parser.output
|
||||
glsl_test
|
||||
ir_expression_operation.h
|
||||
ir_expression_operation_strings.h
|
||||
subtest-cr/
|
||||
subtest-lf/
|
||||
subtest-cr-lf/
|
||||
|
|
|
|||
|
|
@ -22,6 +22,7 @@
|
|||
# IN THE SOFTWARE.
|
||||
|
||||
import mako.template
|
||||
import sys
|
||||
|
||||
ir_expression_operation = [
|
||||
# Name operands string comment
|
||||
|
|
@ -318,7 +319,7 @@ def name_from_item(item):
|
|||
return "ir_{}op_{}".format(("un", "bin", "tri", "quad")[item[1]-1], item[0])
|
||||
|
||||
if __name__ == "__main__":
|
||||
enum_template = mako.template.Template("""/*
|
||||
copyright = """/*
|
||||
* Copyright (C) 2010 Intel Corporation
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a
|
||||
|
|
@ -340,7 +341,8 @@ if __name__ == "__main__":
|
|||
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
* DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
"""
|
||||
enum_template = mako.template.Template(copyright + """
|
||||
/* Update ir_expression::get_num_operands() and operator_strs when
|
||||
* updating this list.
|
||||
*/
|
||||
|
|
@ -362,15 +364,28 @@ ${item}
|
|||
ir_last_opcode = ir_quadop_${lasts[3][0]}
|
||||
};""")
|
||||
|
||||
lasts = [None, None, None, None]
|
||||
for item in reversed(ir_expression_operation):
|
||||
if isinstance(item, str):
|
||||
continue
|
||||
strings_template = mako.template.Template(copyright + """
|
||||
static const char *const operator_strs[] = {
|
||||
% for item in values:
|
||||
% if not isinstance(item, str):
|
||||
"${item[2] if item[2] is not None else item[0]}",
|
||||
% endif
|
||||
% endfor
|
||||
};""")
|
||||
|
||||
i = item[1] - 1
|
||||
if lasts[i] is None:
|
||||
lasts[i] = (item[0], i)
|
||||
if sys.argv[1] == "enum":
|
||||
lasts = [None, None, None, None]
|
||||
for item in reversed(ir_expression_operation):
|
||||
if isinstance(item, str):
|
||||
continue
|
||||
|
||||
print(enum_template.render(values=ir_expression_operation,
|
||||
lasts=lasts,
|
||||
name_from_item=name_from_item))
|
||||
i = item[1] - 1
|
||||
if lasts[i] is None:
|
||||
lasts[i] = (item[0], i)
|
||||
|
||||
print(enum_template.render(values=ir_expression_operation,
|
||||
lasts=lasts,
|
||||
name_from_item=name_from_item))
|
||||
elif sys.argv[1] == "strings":
|
||||
print(strings_template.render(values=ir_expression_operation,
|
||||
name_from_item=name_from_item))
|
||||
|
|
|
|||
|
|
@ -1,138 +0,0 @@
|
|||
/*
|
||||
* Copyright (C) 2010 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.
|
||||
*/
|
||||
|
||||
static const char *const operator_strs[] = {
|
||||
"~",
|
||||
"!",
|
||||
"neg",
|
||||
"abs",
|
||||
"sign",
|
||||
"rcp",
|
||||
"rsq",
|
||||
"sqrt",
|
||||
"exp",
|
||||
"log",
|
||||
"exp2",
|
||||
"log2",
|
||||
"f2i",
|
||||
"f2u",
|
||||
"i2f",
|
||||
"f2b",
|
||||
"b2f",
|
||||
"i2b",
|
||||
"b2i",
|
||||
"u2f",
|
||||
"i2u",
|
||||
"u2i",
|
||||
"d2f",
|
||||
"f2d",
|
||||
"d2i",
|
||||
"i2d",
|
||||
"d2u",
|
||||
"u2d",
|
||||
"d2b",
|
||||
"bitcast_i2f",
|
||||
"bitcast_f2i",
|
||||
"bitcast_u2f",
|
||||
"bitcast_f2u",
|
||||
"trunc",
|
||||
"ceil",
|
||||
"floor",
|
||||
"fract",
|
||||
"round_even",
|
||||
"sin",
|
||||
"cos",
|
||||
"dFdx",
|
||||
"dFdxCoarse",
|
||||
"dFdxFine",
|
||||
"dFdy",
|
||||
"dFdyCoarse",
|
||||
"dFdyFine",
|
||||
"packSnorm2x16",
|
||||
"packSnorm4x8",
|
||||
"packUnorm2x16",
|
||||
"packUnorm4x8",
|
||||
"packHalf2x16",
|
||||
"unpackSnorm2x16",
|
||||
"unpackSnorm4x8",
|
||||
"unpackUnorm2x16",
|
||||
"unpackUnorm4x8",
|
||||
"unpackHalf2x16",
|
||||
"bitfield_reverse",
|
||||
"bit_count",
|
||||
"find_msb",
|
||||
"find_lsb",
|
||||
"sat",
|
||||
"packDouble2x32",
|
||||
"unpackDouble2x32",
|
||||
"frexp_sig",
|
||||
"frexp_exp",
|
||||
"noise",
|
||||
"subroutine_to_int",
|
||||
"interpolate_at_centroid",
|
||||
"get_buffer_size",
|
||||
"ssbo_unsized_array_length",
|
||||
"vote_any",
|
||||
"vote_all",
|
||||
"vote_eq",
|
||||
"+",
|
||||
"-",
|
||||
"*",
|
||||
"imul_high",
|
||||
"/",
|
||||
"carry",
|
||||
"borrow",
|
||||
"%",
|
||||
"<",
|
||||
">",
|
||||
"<=",
|
||||
">=",
|
||||
"==",
|
||||
"!=",
|
||||
"all_equal",
|
||||
"any_nequal",
|
||||
"<<",
|
||||
">>",
|
||||
"&",
|
||||
"^",
|
||||
"|",
|
||||
"&&",
|
||||
"^^",
|
||||
"||",
|
||||
"dot",
|
||||
"min",
|
||||
"max",
|
||||
"pow",
|
||||
"ubo_load",
|
||||
"ldexp",
|
||||
"vector_extract",
|
||||
"interpolate_at_offset",
|
||||
"interpolate_at_sample",
|
||||
"fma",
|
||||
"lrp",
|
||||
"csel",
|
||||
"bitfield_extract",
|
||||
"vector_insert",
|
||||
"bitfield_insert",
|
||||
"vector",
|
||||
};
|
||||
Loading…
Add table
Reference in a new issue