[v2] kbuild: support byacc as alternative YACC to bison
diff mbox series

Message ID 20191029150119.19823-1-e5ten.arch@gmail.com
State New
Headers show
Series
  • [v2] kbuild: support byacc as alternative YACC to bison
Related show

Commit Message

Ethan Sommer Oct. 29, 2019, 3:01 p.m. UTC
Switches to a more portable set of flags for generating the same file
names instead of the bison-specific --defines, uses the more portable -V
instead of --version, and explicitly defines YYSTYPE in lex.l, which
bison implicitly defines if not present but byacc does not.

Add %locations to dtc-parser.y to explicitly enable location tracking
for byacc, and define YYERROR_CALL explicitly to prevent the locations
directive from causing it to be defined to a 2-parameter call to
yyerror, which dtc-parser.y defines to accept one parameter.

Requires byacc to be built with --enable-btyacc.

Signed-off-by: Ethan Sommer <e5ten.arch@gmail.com>
---
 scripts/Makefile.host     | 2 +-
 scripts/dtc/dtc-parser.y  | 4 ++++
 scripts/genksyms/Makefile | 2 +-
 scripts/genksyms/lex.l    | 2 ++
 4 files changed, 8 insertions(+), 2 deletions(-)

Comments

Frank Rowand Oct. 29, 2019, 3:58 p.m. UTC | #1
Hi Ethan,

On 10/29/19 10:01 AM, Ethan Sommer wrote:
> Switches to a more portable set of flags for generating the same file
> names instead of the bison-specific --defines, uses the more portable -V
> instead of --version, and explicitly defines YYSTYPE in lex.l, which
> bison implicitly defines if not present but byacc does not.
> 
> Add %locations to dtc-parser.y to explicitly enable location tracking
> for byacc, and define YYERROR_CALL explicitly to prevent the locations
> directive from causing it to be defined to a 2-parameter call to
> yyerror, which dtc-parser.y defines to accept one parameter.
> 
> Requires byacc to be built with --enable-btyacc.
> 
> Signed-off-by: Ethan Sommer <e5ten.arch@gmail.com>
> ---
>  scripts/Makefile.host     | 2 +-
>  scripts/dtc/dtc-parser.y  | 4 ++++
>  scripts/genksyms/Makefile | 2 +-
>  scripts/genksyms/lex.l    | 2 ++
>  4 files changed, 8 insertions(+), 2 deletions(-)
> 
> diff --git a/scripts/Makefile.host b/scripts/Makefile.host
> index 4c51c95d40f4..64e98e1d4825 100644
> --- a/scripts/Makefile.host
> +++ b/scripts/Makefile.host
> @@ -11,7 +11,7 @@ $(obj)/%.lex.c: $(src)/%.l FORCE
>  # YACC
>  # ---------------------------------------------------------------------------
>  quiet_cmd_bison = YACC    $(basename $@).[ch]
> -      cmd_bison = $(YACC) -o $(basename $@).c --defines=$(basename $@).h -t -l $<
> +      cmd_bison = $(YACC) -b $(basename $(basename $@)) -d -t -l $<
>  
>  $(obj)/%.tab.c $(obj)/%.tab.h: $(src)/%.y FORCE
>  	$(call if_changed,bison)
> diff --git a/scripts/dtc/dtc-parser.y b/scripts/dtc/dtc-parser.y
> index 2ed4dc1f07fd..40dcf4f149da 100644
> --- a/scripts/dtc/dtc-parser.y
> +++ b/scripts/dtc/dtc-parser.y

For file scripts/dtc/dtc-parser.y:

This file is maintained in the upstream dtc project.  We pull changes
from that project into the Linux kernel source tree.

The file is located at the root level of the upstream project.

Info on submitting patches is in the upstream file "Documentation/manual.txt":

   1) Sources

   Source code for the Device Tree Compiler can be found at git.kernel.org.

   The upstream repository is here:

       git://git.kernel.org/pub/scm/utils/dtc/dtc.git
       https://git.kernel.org/pub/scm/utils/dtc/dtc.git

   The gitweb interface for the upstream respository is:

       https://git.kernel.org/cgit/utils/dtc/dtc.git/

   1.1) Submitting Patches

   Patches should be sent to the maintainers:
           David Gibson <david@gibson.dropbear.id.au>
           Jon Loeliger <jdl@jdl.com>
   and CCed to <devicetree-compiler@vger.kernel.org>.

-Frank


> @@ -2,6 +2,8 @@
>  /*
>   * (C) Copyright David Gibson <dwg@au1.ibm.com>, IBM Corporation.  2005.
>   */
> +%locations
> +
>  %{
>  #include <stdio.h>
>  #include <inttypes.h>
> @@ -17,6 +19,8 @@ extern void yyerror(char const *s);
>  		treesource_error = true; \
>  	} while (0)
>  
> +#define YYERROR_CALL(msg) yyerror(msg)
> +
>  extern struct dt_info *parser_output;
>  extern bool treesource_error;
>  %}
> diff --git a/scripts/genksyms/Makefile b/scripts/genksyms/Makefile
> index 78629f515e78..397c2dc8182b 100644
> --- a/scripts/genksyms/Makefile
> +++ b/scripts/genksyms/Makefile
> @@ -15,7 +15,7 @@ genksyms-objs	:= genksyms.o parse.tab.o lex.lex.o
>  ifeq ($(findstring 1,$(KBUILD_EXTRA_WARN)),)
>  
>  quiet_cmd_bison_no_warn = $(quiet_cmd_bison)
> -      cmd_bison_no_warn = $(YACC) --version >/dev/null; \
> +      cmd_bison_no_warn = $(YACC) -V >/dev/null; \
>  			  $(cmd_bison) 2>/dev/null
>  
>  $(obj)/pars%.tab.c $(obj)/pars%.tab.h: $(src)/pars%.y FORCE
> diff --git a/scripts/genksyms/lex.l b/scripts/genksyms/lex.l
> index e265c5d96861..0580c088527f 100644
> --- a/scripts/genksyms/lex.l
> +++ b/scripts/genksyms/lex.l
> @@ -19,6 +19,8 @@
>  #include "genksyms.h"
>  #include "parse.tab.h"
>  
> +extern YYSTYPE yylval;
> +
>  /* We've got a two-level lexer here.  We let flex do basic tokenization
>     and then we categorize those basic tokens in the second stage.  */
>  #define YY_DECL		static int yylex1(void)
>
Masahiro Yamada Oct. 30, 2019, 2:58 a.m. UTC | #2
On Wed, Oct 30, 2019 at 12:02 AM Ethan Sommer <e5ten.arch@gmail.com> wrote:
>
> Switches to a more portable set of flags for generating the same file
> names instead of the bison-specific --defines, uses the more portable -V
> instead of --version, and explicitly defines YYSTYPE in lex.l, which
> bison implicitly defines if not present but byacc does not.
>
> Add %locations to dtc-parser.y to explicitly enable location tracking
> for byacc, and define YYERROR_CALL explicitly to prevent the locations
> directive from causing it to be defined to a 2-parameter call to
> yyerror, which dtc-parser.y defines to accept one parameter.
>
> Requires byacc to be built with --enable-btyacc.
>
> Signed-off-by: Ethan Sommer <e5ten.arch@gmail.com>
> ---
>  scripts/Makefile.host     | 2 +-
>  scripts/dtc/dtc-parser.y  | 4 ++++
>  scripts/genksyms/Makefile | 2 +-
>  scripts/genksyms/lex.l    | 2 ++
>  4 files changed, 8 insertions(+), 2 deletions(-)
>
> diff --git a/scripts/Makefile.host b/scripts/Makefile.host
> index 4c51c95d40f4..64e98e1d4825 100644
> --- a/scripts/Makefile.host
> +++ b/scripts/Makefile.host
> @@ -11,7 +11,7 @@ $(obj)/%.lex.c: $(src)/%.l FORCE
>  # YACC
>  # ---------------------------------------------------------------------------
>  quiet_cmd_bison = YACC    $(basename $@).[ch]
> -      cmd_bison = $(YACC) -o $(basename $@).c --defines=$(basename $@).h -t -l $<
> +      cmd_bison = $(YACC) -b $(basename $(basename $@)) -d -t -l $<


Hmm, this is unfortunate since there is no common way to
specify the header path directly.

I am not sure how much effort we should invent
to support non-GNU implementation
since we already rely on various GNU tools.

If we decide to support byacc,
we must carry the restriction
that bans GNU-extension.






>  $(obj)/%.tab.c $(obj)/%.tab.h: $(src)/%.y FORCE
>         $(call if_changed,bison)
> diff --git a/scripts/dtc/dtc-parser.y b/scripts/dtc/dtc-parser.y
> index 2ed4dc1f07fd..40dcf4f149da 100644
> --- a/scripts/dtc/dtc-parser.y
> +++ b/scripts/dtc/dtc-parser.y
> @@ -2,6 +2,8 @@
>  /*
>   * (C) Copyright David Gibson <dwg@au1.ibm.com>, IBM Corporation.  2005.
>   */
> +%locations
> +
>  %{
>  #include <stdio.h>
>  #include <inttypes.h>
> @@ -17,6 +19,8 @@ extern void yyerror(char const *s);
>                 treesource_error = true; \
>         } while (0)
>
> +#define YYERROR_CALL(msg) yyerror(msg)
> +
>  extern struct dt_info *parser_output;
>  extern bool treesource_error;
>  %}
> diff --git a/scripts/genksyms/Makefile b/scripts/genksyms/Makefile
> index 78629f515e78..397c2dc8182b 100644
> --- a/scripts/genksyms/Makefile
> +++ b/scripts/genksyms/Makefile
> @@ -15,7 +15,7 @@ genksyms-objs := genksyms.o parse.tab.o lex.lex.o
>  ifeq ($(findstring 1,$(KBUILD_EXTRA_WARN)),)
>
>  quiet_cmd_bison_no_warn = $(quiet_cmd_bison)
> -      cmd_bison_no_warn = $(YACC) --version >/dev/null; \
> +      cmd_bison_no_warn = $(YACC) -V >/dev/null; \
>                           $(cmd_bison) 2>/dev/null
>
>  $(obj)/pars%.tab.c $(obj)/pars%.tab.h: $(src)/pars%.y FORCE
> diff --git a/scripts/genksyms/lex.l b/scripts/genksyms/lex.l
> index e265c5d96861..0580c088527f 100644
> --- a/scripts/genksyms/lex.l
> +++ b/scripts/genksyms/lex.l
> @@ -19,6 +19,8 @@
>  #include "genksyms.h"
>  #include "parse.tab.h"
>
> +extern YYSTYPE yylval;
> +
>  /* We've got a two-level lexer here.  We let flex do basic tokenization
>     and then we categorize those basic tokens in the second stage.  */
>  #define YY_DECL                static int yylex1(void)
> --
> 2.23.0
>


--
Best Regards
Masahiro Yamada
Ethan Sommer Nov. 3, 2019, 8:30 p.m. UTC | #3
> Hmm, this is unfortunate since there is no common way to
> specify the header path directly.
>
> I am not sure how much effort we should invent
> to support non-GNU implementation
> since we already rely on various GNU tools.
>
> If we decide to support byacc,
> we must carry the restriction
> that bans GNU-extension.

I just realized that I accidentally only responded to Masahiro with my
previous email from a few days ago so I'll just quote it here:
"I feel like changing 10 lines to support a different yacc
implementation that supports most of the GNU-specific features here
isn't the same thing as banning all GNU extensions, and in regards to
the file prefix, the method in my patch creates the same file names as
the bison-specific one for the 3 cases it is used for, and the flags
used for it are POSIX yacc compatible. In my opinion increasing
compatibility shouldn't have to be all or nothing, and it makes sense to
make changes that increase compatibility without outright banning GNU
extensions entirely."

Aside from that, patch to dtc has just been applied, so pulling the latest
upstream changes as well as the v2 of this patch should be what would be
needed to support byacc.

Patch
diff mbox series

diff --git a/scripts/Makefile.host b/scripts/Makefile.host
index 4c51c95d40f4..64e98e1d4825 100644
--- a/scripts/Makefile.host
+++ b/scripts/Makefile.host
@@ -11,7 +11,7 @@  $(obj)/%.lex.c: $(src)/%.l FORCE
 # YACC
 # ---------------------------------------------------------------------------
 quiet_cmd_bison = YACC    $(basename $@).[ch]
-      cmd_bison = $(YACC) -o $(basename $@).c --defines=$(basename $@).h -t -l $<
+      cmd_bison = $(YACC) -b $(basename $(basename $@)) -d -t -l $<
 
 $(obj)/%.tab.c $(obj)/%.tab.h: $(src)/%.y FORCE
 	$(call if_changed,bison)
diff --git a/scripts/dtc/dtc-parser.y b/scripts/dtc/dtc-parser.y
index 2ed4dc1f07fd..40dcf4f149da 100644
--- a/scripts/dtc/dtc-parser.y
+++ b/scripts/dtc/dtc-parser.y
@@ -2,6 +2,8 @@ 
 /*
  * (C) Copyright David Gibson <dwg@au1.ibm.com>, IBM Corporation.  2005.
  */
+%locations
+
 %{
 #include <stdio.h>
 #include <inttypes.h>
@@ -17,6 +19,8 @@  extern void yyerror(char const *s);
 		treesource_error = true; \
 	} while (0)
 
+#define YYERROR_CALL(msg) yyerror(msg)
+
 extern struct dt_info *parser_output;
 extern bool treesource_error;
 %}
diff --git a/scripts/genksyms/Makefile b/scripts/genksyms/Makefile
index 78629f515e78..397c2dc8182b 100644
--- a/scripts/genksyms/Makefile
+++ b/scripts/genksyms/Makefile
@@ -15,7 +15,7 @@  genksyms-objs	:= genksyms.o parse.tab.o lex.lex.o
 ifeq ($(findstring 1,$(KBUILD_EXTRA_WARN)),)
 
 quiet_cmd_bison_no_warn = $(quiet_cmd_bison)
-      cmd_bison_no_warn = $(YACC) --version >/dev/null; \
+      cmd_bison_no_warn = $(YACC) -V >/dev/null; \
 			  $(cmd_bison) 2>/dev/null
 
 $(obj)/pars%.tab.c $(obj)/pars%.tab.h: $(src)/pars%.y FORCE
diff --git a/scripts/genksyms/lex.l b/scripts/genksyms/lex.l
index e265c5d96861..0580c088527f 100644
--- a/scripts/genksyms/lex.l
+++ b/scripts/genksyms/lex.l
@@ -19,6 +19,8 @@ 
 #include "genksyms.h"
 #include "parse.tab.h"
 
+extern YYSTYPE yylval;
+
 /* We've got a two-level lexer here.  We let flex do basic tokenization
    and then we categorize those basic tokens in the second stage.  */
 #define YY_DECL		static int yylex1(void)