glsl: build without bison
authorElla-0 <23418164+Ella-0@users.noreply.github.com>
Wed, 27 Jan 2021 14:16:08 +0000 (14:16 +0000)
committerMarge Bot <eric+marge@anholt.net>
Tue, 13 Apr 2021 19:12:48 +0000 (19:12 +0000)
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/8739>

meson.build
src/compiler/glsl/glcpp/meson.build
src/compiler/glsl/meson.build
src/intel/tools/i965_asm.h
src/intel/tools/i965_gram.y
src/intel/tools/meson.build
src/mesa/program/meson.build

index 7a95d87..8ef1e5f 100644 (file)
@@ -1724,6 +1724,8 @@ else
   asan_c_args = ['-DBUILT_WITH_ASAN=0']
 endif
 
+yacc_is_bison = true
+
 if build_machine.system() == 'windows'
   # Prefer the winflexbison versions, they're much easier to install and have
   # better windows support.
@@ -1746,7 +1748,12 @@ if build_machine.system() == 'windows'
     prog_bison = find_program('bison', 'yacc', required : with_any_opengl)
   endif
 else
-  prog_bison = find_program('bison', required : with_any_opengl)
+  prog_bison = find_program('bison', required : false)
+
+  if not prog_bison.found()
+    prog_bison = find_program('byacc', required : with_any_opengl)
+    yacc_is_bison = false
+  endif
 
   # Disable deprecated keyword warnings, since we have to use them for
   # old-bison compat.  See discussion in
index a4789b3..0c67d1f 100644 (file)
 # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
 # SOFTWARE.
 
+bison_command = []
+if yacc_is_bison
+  bison_command = [
+    prog_bison, '-o', '@OUTPUT0@', '-p', 'glcpp_parser_',
+    '--defines=@OUTPUT1@', '@INPUT@',
+  ]
+else
+  bison_command = [
+    prog_bison, '-o', '@OUTPUT0@', '-p', 'glcpp_parser_',
+    '-H', '@OUTPUT1@', '@INPUT@',
+  ]
+endif
+
 glcpp_parse = custom_target(
   'glcpp-parse.[ch]',
   input : 'glcpp-parse.y',
   output : ['glcpp-parse.c', 'glcpp-parse.h'],
-  command : [
-    prog_bison, '-o', '@OUTPUT0@', '-p', 'glcpp_parser_',
-    '--defines=@OUTPUT1@', '@INPUT@',
-  ],
+  command : bison_command
 )
 
 glcpp_lex = custom_target(
index 9263595..77febac 100644 (file)
 
 subdir('glcpp')
 
+bison_command = []
+if yacc_is_bison
+  bison_command = [
+    prog_bison, '-o', '@OUTPUT0@', '-p', '_mesa_glsl_', '--defines=@OUTPUT1@',
+    '@INPUT@',
+  ]
+else
+  bison_command = [
+    prog_bison, '-o', '@OUTPUT0@', '-p', '_mesa_glsl_', '-H', '@OUTPUT1@',
+    '@INPUT@',
+  ]
+endif
+
 glsl_parser = custom_target(
   'glsl_parser',
   input : 'glsl_parser.yy',
   output : ['glsl_parser.cpp', 'glsl_parser.h'],
-  command : [
-    prog_bison, '-o', '@OUTPUT0@', '-p', '_mesa_glsl_', '--defines=@OUTPUT1@',
-    '@INPUT@',
-  ],
+  command : bison_command
 )
 
 glsl_lexer_cpp = custom_target(
index a7e4e86..200b224 100644 (file)
@@ -40,7 +40,6 @@
 /* glibc < 2.27 defines OVERFLOW in /usr/include/math.h. */
 #undef OVERFLOW
 
-void yyerror (char *);
 int yyparse(void);
 int yylex(void);
 char *lex_text(void);
index 4e191ac..bfc875d 100644 (file)
 #include <strings.h>
 #include "i965_asm.h"
 
+#undef yyerror
+#ifdef YYBYACC
+struct YYLTYPE;
+void yyerror (struct YYLTYPE *, char *);
+#else
+void yyerror (char *);
+#endif
+
 #undef ALIGN16
 
 #define YYLTYPE YYLTYPE
@@ -467,11 +475,11 @@ add_label(struct brw_codegen *p, const char* label_name, enum instr_label_type t
 %token <llint> LONG
 %token NULL_TOKEN
 
-%precedence SUBREGNUM
+%nonassoc SUBREGNUM
 %left PLUS MINUS
-%precedence DOT
-%precedence EMPTYEXECSIZE
-%precedence LPAREN
+%nonassoc DOT
+%nonassoc EMPTYEXECSIZE
+%nonassoc LPAREN
 
 %type <integer> execsize simple_int exp
 %type <llint> exp2
@@ -1470,7 +1478,7 @@ simple_int:
 
 rellocation:
        relativelocation
-       | %empty { $$ = 0; }
+       | /* empty */ { $$ = 0; }
        ;
 
 relativelocation:
@@ -1482,7 +1490,7 @@ relativelocation:
 
 jumplabel:
        JUMP_LABEL      { $$ = $1; }
-       | %empty        { $$ = NULL; }
+       | /* empty */   { $$ = NULL; }
        ;
 
 jumplabeltarget:
@@ -1778,7 +1786,7 @@ exp:
 
 subregnum:
        DOT exp                         { $$ = $2; }
-       | %empty %prec SUBREGNUM        { $$ = 0; }
+       | /* empty */ %prec SUBREGNUM   { $$ = 0; }
        ;
 
 directgenreg:
@@ -2001,7 +2009,7 @@ immval:
 
 /* Regions */
 dstregion:
-       %empty
+       /* empty */
        {
                $$ = BRW_HORIZONTAL_STRIDE_1;
        }
@@ -2020,7 +2028,7 @@ indirectregion:
        ;
 
 region:
-       %empty
+       /* empty */
        {
                $$ = stride($$, 0, 1, 0);
        }
@@ -2111,7 +2119,7 @@ imm_type:
        ;
 
 writemask:
-       %empty
+       /* empty */
        {
                $$ = WRITEMASK_XYZW;
        }
@@ -2122,27 +2130,27 @@ writemask:
        ;
 
 writemask_x:
-       %empty  { $$ = 0; }
+       /* empty */     { $$ = 0; }
        | X     { $$ = 1 << BRW_CHANNEL_X; }
        ;
 
 writemask_y:
-       %empty  { $$ = 0; }
+       /* empty */     { $$ = 0; }
        | Y     { $$ = 1 << BRW_CHANNEL_Y; }
        ;
 
 writemask_z:
-       %empty  { $$ = 0; }
+       /* empty */     { $$ = 0; }
        | Z     { $$ = 1 << BRW_CHANNEL_Z; }
        ;
 
 writemask_w:
-       %empty  { $$ = 0; }
+       /* empty */     { $$ = 0; }
        | W     { $$ = 1 << BRW_CHANNEL_W; }
        ;
 
 swizzle:
-       %empty
+       /* empty */
        {
                $$ = BRW_SWIZZLE_NOOP;
        }
@@ -2165,7 +2173,7 @@ chansel:
 
 /* Instruction prediction and modifiers */
 predicate:
-       %empty
+       /* empty */
        {
                brw_push_insn_state(p);
                brw_set_default_predicate_control(p, BRW_PREDICATE_NONE);
@@ -2182,13 +2190,13 @@ predicate:
        ;
 
 predstate:
-       %empty          { $$ = 0; }
+       /* empty */     { $$ = 0; }
        | PLUS          { $$ = 0; }
        | MINUS         { $$ = 1; }
        ;
 
 predctrl:
-       %empty          { $$ = BRW_PREDICATE_NORMAL; }
+       /* empty */     { $$ = BRW_PREDICATE_NORMAL; }
        | DOT X         { $$ = BRW_PREDICATE_ALIGN16_REPLICATE_X; }
        | DOT Y         { $$ = BRW_PREDICATE_ALIGN16_REPLICATE_Y; }
        | DOT Z         { $$ = BRW_PREDICATE_ALIGN16_REPLICATE_Z; }
@@ -2209,12 +2217,12 @@ predctrl:
 
 /* Source Modification */
 negate:
-       %empty          { $$ = 0; }
+       /* empty */     { $$ = 0; }
        | MINUS         { $$ = 1; }
        ;
 
 abs:
-       %empty  { $$ = 0; }
+       /* empty */     { $$ = 0; }
        | ABS   { $$ = 1; }
        ;
 
@@ -2235,7 +2243,7 @@ cond_mod:
        ;
 
 condModifiers:
-       %empty  { $$ = BRW_CONDITIONAL_NONE; }
+       /* empty */     { $$ = BRW_CONDITIONAL_NONE; }
        | ZERO
        | EQUAL
        | NOT_ZERO
@@ -2250,13 +2258,13 @@ condModifiers:
        ;
 
 saturate:
-       %empty          { $$ = BRW_INSTRUCTION_NORMAL; }
+       /* empty */     { $$ = BRW_INSTRUCTION_NORMAL; }
        | SATURATE      { $$ = BRW_INSTRUCTION_SATURATE; }
        ;
 
 /* Execution size */
 execsize:
-       %empty %prec EMPTYEXECSIZE
+       /* empty */ %prec EMPTYEXECSIZE
        {
                $$ = 0;
        }
@@ -2271,7 +2279,7 @@ execsize:
 
 /* Instruction options */
 instoptions:
-       %empty
+       /* empty */
        {
                memset(&$$, 0, sizeof($$));
        }
@@ -2295,7 +2303,7 @@ instoption_list:
                $$ = $1;
                add_instruction_option(&$$, $2);
        }
-       | %empty
+       | /* empty */
        {
                memset(&$$, 0, sizeof($$));
        }
@@ -2334,8 +2342,13 @@ instoption:
 
 extern int yylineno;
 
+#ifdef YYBYACC
+void
+yyerror(YYLTYPE *ltype, char *msg)
+#else
 void
 yyerror(char *msg)
+#endif
 {
        fprintf(stderr, "%s: %d: %s at \"%s\"\n",
                input_filename, yylineno, msg, lex_text());
index 7c4cc3e..3653e1d 100644 (file)
@@ -161,14 +161,24 @@ if with_tools.contains('intel-ui')
   )
 endif
 
+bison_command = []
+if yacc_is_bison
+  bison_command = [
+    prog_bison, '@INPUT@', '--defines=@OUTPUT1@',
+    '--output=@OUTPUT0@'
+  ]
+else
+  bison_command = [
+    prog_bison, '-H', '@OUTPUT1@',
+    '-o', '@OUTPUT0@', '@INPUT@'
+  ]
+endif
+
 i965_gram_tab = custom_target(
   'i965_gram.tab.[ch]',
   input : 'i965_gram.y',
   output : ['i965_gram.tab.c', 'i965_gram.tab.h'],
-  command : [
-    prog_bison, '@INPUT@', '--defines=@OUTPUT1@',
-    '--output=@OUTPUT0@'
-  ]
+  command : bison_command
 )
 
 i965_lex_yy_c = custom_target(
index 5f3325f..1b76d32 100644 (file)
 # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
 # SOFTWARE.
 
+bison_command = []
+if yacc_is_bison
+  bison_command = [prog_bison, '-o', '@OUTPUT0@', '--defines=@OUTPUT1@', '@INPUT@']
+else
+  bison_command = [prog_bison, '-o', '@OUTPUT0@', '-H', '@OUTPUT1@', '@INPUT@']
+endif
+
 mesa_lex = custom_target(
   'mesa_lex',
   input : 'program_lexer.l',
@@ -29,5 +36,5 @@ program_parse_tab = custom_target(
   'program_parse_tab.[ch]',
   input : 'program_parse.y',
   output : ['program_parse.tab.c', 'program_parse.tab.h'],
-  command : [prog_bison, '-o', '@OUTPUT0@', '--defines=@OUTPUT1@', '@INPUT@'],
+  command : bison_command,
 )