From 5bfbcf7265dfc72d85f6adbf3b243355b16334d9 Mon Sep 17 00:00:00 2001 From: Brian Paul Date: Tue, 29 Jul 2008 17:12:19 -0600 Subject: mesa: implement grammar/parsing for precision/invariant syntax Plus, fix some issues with pre-defined preprocessor symbols and version checking. --- src/mesa/shader/slang/library/slang_shader.syn | 71 +++++++++++++++++++++--- src/mesa/shader/slang/library/slang_shader_syn.h | 29 ++++++++++ 2 files changed, 93 insertions(+), 7 deletions(-) (limited to 'src/mesa/shader/slang/library') diff --git a/src/mesa/shader/slang/library/slang_shader.syn b/src/mesa/shader/slang/library/slang_shader.syn index 1764d1ae68..52a792ad17 100644 --- a/src/mesa/shader/slang/library/slang_shader.syn +++ b/src/mesa/shader/slang/library/slang_shader.syn @@ -51,10 +51,17 @@ /* revision number - increment after each change affecting emitted output */ .emtcode REVISION 3 -/* external declaration */ +/* external declaration (or precision or invariant stmt) */ .emtcode EXTERNAL_NULL 0 .emtcode EXTERNAL_FUNCTION_DEFINITION 1 .emtcode EXTERNAL_DECLARATION 2 +.emtcode DEFAULT_PRECISION 3 +.emtcode INVARIANT_STMT 4 + +/* precision */ +.emtcode PRECISION_LOW 0 +.emtcode PRECISION_MEDIUM 1 +.emtcode PRECISION_HIGH 2 /* declaration */ .emtcode DECLARATION_FUNCTION_PROTOTYPE 1 @@ -240,6 +247,9 @@ .errtext LBRACE_EXPECTED "2003: '{' expected but '$err_token$' found." .errtext LPAREN_EXPECTED "2004: '(' expected but '$err_token$' found." .errtext RPAREN_EXPECTED "2005: ')' expected but '$err_token$' found." +.errtext INVALID_PRECISION "2006: Invalid precision specifier '$err_token$'." +.errtext INVALID_PRECISION_TYPE "2007: Invalid precision type '$err_token$'." + /* tells whether the shader that is being parsed is a built-in shader or not */ /* 0 - normal behaviour */ @@ -1226,23 +1236,70 @@ asm_argument var_with_field variable_identifier .and dot .and field_selection .emit OP_FIELD; + /* - ::= - | -*/ + * ::= + * | + */ translation_unit optional_space .emit REVISION .and external_declaration .error INVALID_EXTERNAL_DECLARATION .and .loop external_declaration .and optional_space .and '\0' .error INVALID_EXTERNAL_DECLARATION .emit EXTERNAL_NULL; + /* - ::= - | -*/ + * ::= + * | + */ external_declaration + precision_stmt .emit DEFAULT_PRECISION .or + invariant_stmt .emit INVARIANT_STMT .or function_definition .emit EXTERNAL_FUNCTION_DEFINITION .or declaration .emit EXTERNAL_DECLARATION; + +/* + * ::= "precision" + */ +precision_stmt + "precision" .and space .and precision .error INVALID_PRECISION .and space .and prectype .error INVALID_PRECISION_TYPE .and semicolon; + +/* + * ::= "lowp" + * | "mediump" + * | "highp" + */ +precision + "lowp" .emit PRECISION_LOW .or + "mediump" .emit PRECISION_MEDIUM .or + "highp" .emit PRECISION_HIGH; + +/* + * ::= "int" + * | "float" + * | "a sampler type" + */ +prectype + "int" .emit TYPE_SPECIFIER_INT .or + "float" .emit TYPE_SPECIFIER_FLOAT .or + "sampler1D" .emit TYPE_SPECIFIER_SAMPLER1D .or + "sampler2D" .emit TYPE_SPECIFIER_SAMPLER2D .or + "sampler3D" .emit TYPE_SPECIFIER_SAMPLER3D .or + "samplerCube" .emit TYPE_SPECIFIER_SAMPLERCUBE .or + "sampler1DShadow" .emit TYPE_SPECIFIER_SAMPLER1DSHADOW .or + "sampler2DShadow" .emit TYPE_SPECIFIER_SAMPLER2DSHADOW .or + "sampler2DRect" .emit TYPE_SPECIFIER_SAMPLER2DRECT .or + "sampler2DRectShadow" .emit TYPE_SPECIFIER_SAMPLER2DRECTSHADOW; + + +/* + * ::= "invariant" identifier; + */ +invariant_stmt + "invariant" .and space .and identifier .and semicolon; + + + /* :: */ diff --git a/src/mesa/shader/slang/library/slang_shader_syn.h b/src/mesa/shader/slang/library/slang_shader_syn.h index fe37adcac4..c0fef6e4e3 100644 --- a/src/mesa/shader/slang/library/slang_shader_syn.h +++ b/src/mesa/shader/slang/library/slang_shader_syn.h @@ -6,6 +6,11 @@ ".emtcode EXTERNAL_NULL 0\n" ".emtcode EXTERNAL_FUNCTION_DEFINITION 1\n" ".emtcode EXTERNAL_DECLARATION 2\n" +".emtcode DEFAULT_PRECISION 3\n" +".emtcode INVARIANT_STMT 4\n" +".emtcode PRECISION_LOW 0\n" +".emtcode PRECISION_MEDIUM 1\n" +".emtcode PRECISION_HIGH 2\n" ".emtcode DECLARATION_FUNCTION_PROTOTYPE 1\n" ".emtcode DECLARATION_INIT_DECLARATOR_LIST 2\n" ".emtcode FUNCTION_ORDINARY 0\n" @@ -41,6 +46,7 @@ ".emtcode TYPE_QUALIFIER_UNIFORM 4\n" ".emtcode TYPE_QUALIFIER_FIXEDOUTPUT 5\n" ".emtcode TYPE_QUALIFIER_FIXEDINPUT 6\n" +".emtcode TYPE_QUALIFIER_INVARIANT_VARYING 7\n" ".emtcode TYPE_SPECIFIER_VOID 0\n" ".emtcode TYPE_SPECIFIER_BOOL 1\n" ".emtcode TYPE_SPECIFIER_BVEC2 2\n" @@ -137,6 +143,8 @@ ".errtext LBRACE_EXPECTED \"2003: '{' expected but '$err_token$' found.\"\n" ".errtext LPAREN_EXPECTED \"2004: '(' expected but '$err_token$' found.\"\n" ".errtext RPAREN_EXPECTED \"2005: ')' expected but '$err_token$' found.\"\n" +".errtext INVALID_PRECISION \"2006: Invalid precision specifier '$err_token$'.\"\n" +".errtext INVALID_PRECISION_TYPE \"2007: Invalid precision type '$err_token$'.\"\n" ".regbyte parsing_builtin 0\n" ".regbyte shader_type 0\n" "variable_identifier\n" @@ -597,8 +605,29 @@ " .loop external_declaration .and optional_space .and\n" " '\\0' .error INVALID_EXTERNAL_DECLARATION .emit EXTERNAL_NULL;\n" "external_declaration\n" +" precision_stmt .emit DEFAULT_PRECISION .or\n" +" invariant_stmt .emit INVARIANT_STMT .or\n" " function_definition .emit EXTERNAL_FUNCTION_DEFINITION .or\n" " declaration .emit EXTERNAL_DECLARATION;\n" +"precision_stmt\n" +" \"precision\" .and space .and precision .error INVALID_PRECISION .and space .and prectype .error INVALID_PRECISION_TYPE .and semicolon;\n" +"precision\n" +" \"lowp\" .emit PRECISION_LOW .or\n" +" \"mediump\" .emit PRECISION_MEDIUM .or\n" +" \"highp\" .emit PRECISION_HIGH;\n" +"prectype\n" +" \"int\" .emit TYPE_SPECIFIER_INT .or\n" +" \"float\" .emit TYPE_SPECIFIER_FLOAT .or\n" +" \"sampler1D\" .emit TYPE_SPECIFIER_SAMPLER1D .or\n" +" \"sampler2D\" .emit TYPE_SPECIFIER_SAMPLER2D .or\n" +" \"sampler3D\" .emit TYPE_SPECIFIER_SAMPLER3D .or\n" +" \"samplerCube\" .emit TYPE_SPECIFIER_SAMPLERCUBE .or\n" +" \"sampler1DShadow\" .emit TYPE_SPECIFIER_SAMPLER1DSHADOW .or\n" +" \"sampler2DShadow\" .emit TYPE_SPECIFIER_SAMPLER2DSHADOW .or\n" +" \"sampler2DRect\" .emit TYPE_SPECIFIER_SAMPLER2DRECT .or\n" +" \"sampler2DRectShadow\" .emit TYPE_SPECIFIER_SAMPLER2DRECTSHADOW;\n" +"invariant_stmt\n" +" \"invariant\" .and space .and identifier .and semicolon;\n" "function_definition\n" " function_prototype .and compound_statement_no_new_scope;\n" "digit_oct\n" -- cgit v1.2.3