From 674438c9ff2b2ccd4a5b608be5426f8905717f46 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Arnim=20L=C3=A4uger?= Date: Fri, 23 Nov 2007 19:52:19 +0000 Subject: [PATCH] make SVF parser/lexer backwards compatible to pre-2.5.31 flex for those the error location feature is skipped in svf_flex.l git-svn-id: https://urjtag.svn.sourceforge.net/svnroot/urjtag/trunk@783 b68d4a1b-bc3d-0410-92ed-d4ac073336b7 --- jtag/configure.ac | 53 +++++++++++++++++++++++++++++++++++++--- jtag/src/svf/Makefile.am | 15 +++++++----- jtag/src/svf/svf_bison.y | 1 - jtag/src/svf/svf_flex.l | 48 +++++++++++++++++++++++++++++------- 4 files changed, 97 insertions(+), 20 deletions(-) diff --git a/jtag/configure.ac b/jtag/configure.ac index c1f9d96d..92dbd492 100644 --- a/jtag/configure.ac +++ b/jtag/configure.ac @@ -57,9 +57,53 @@ AM_GNU_GETTEXT_VERSION(0.14.1) AC_PROG_CC AC_PROG_RANLIB -AC_PROG_LEX AC_PROG_YACC +# check for lex/flex +AC_PROG_LEX +# check for modern version of flex +AC_PROG_AWK +AC_PROG_SED +if test "$LEX" == flex ; then + # compare >= 2.5.31 + flex_ref_v1=2 + flex_ref_v2=5 + flex_ref_v3=31 + flex_ref_version="$flex_ref_v1.$flex_ref_v2.$flex_ref_v3" + AC_MSG_CHECKING([for flex >= $flex_ref_version]) + + modern_flex=no + flex_version=`$LEX --version | $AWK '{print $2}'` + flex_v1=`echo $flex_version | $AWK -F . '{print $1}' | $SED -e 's/[a-zA-Z]//g'` + flex_v2=`echo $flex_version | $AWK -F . '{print $2}' | $SED -e 's/[a-zA-Z]//g'` + flex_v3=`echo $flex_version | $AWK -F . '{print $3}' | $SED -e 's/[a-zA-Z]//g'` + + if test -n "$flex_v1" -a "$flex_v1" -gt "$flex_ref_v1" ; then + modern_flex=yes + fi + if test -n "$flex_v1" -a "$flex_v1" -eq "$flex_ref_v1" ; then + if test "$flex_v2" -gt "$flex_ref_v2" ; then + modern_flex=yes + fi + if test "$flex_v2" -eq "$flex_ref_v2" ; then + if test "$flex_v3" -ge "$flex_ref_v3" ; then + modern_flex=yes + fi + fi + fi + + if test "$modern_flex" == yes ; then + AC_DEFINE([HAVE_MODERN_FLEX], 1, [Define if flex version is >= $flex_ref_version]) + AC_MSG_RESULT([yes - flex $flex_version]) + AM_CONDITIONAL([BISON_LOCATIONS], true) + else + AC_MSG_RESULT([no - flex $flex_version]) + AM_CONDITIONAL([BISON_LOCATIONS], false) + fi +fi + + + AC_CONFIG_SUBDIRS(libbrux) AC_ARG_WITH(include, @@ -163,8 +207,9 @@ fi AC_MSG_RESULT([ jtag is now configured for - USB cable support : $FLAG_HAVELIBUSB + USB cable support : $FLAG_HAVELIBUSB FTDI cable support - via libftdi : $FLAG_HAVELIBFTDI - via libftd2xx : $FLAG_HAVELIBFTD2XX + via libftdi : $FLAG_HAVELIBFTDI + via libftd2xx : $FLAG_HAVELIBFTD2XX + Parser error locations : $modern_flex ($LEX $flex_version) ]) diff --git a/jtag/src/svf/Makefile.am b/jtag/src/svf/Makefile.am index 9d0ddc5f..04e87e90 100644 --- a/jtag/src/svf/Makefile.am +++ b/jtag/src/svf/Makefile.am @@ -1,7 +1,5 @@ # -# $Id: Makefile.am,v 1.16 2003/09/14 20:04:24 telka Exp $ -# -# Copyright (C) 2002 ETC s.r.o. +# $Id$ # # This program is free software; you can redistribute it and/or # modify it under the terms of the GNU General Public License @@ -18,11 +16,18 @@ # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA # 02111-1307, USA. # -# Written by Marcel Telka , 2002. +# Written by A. Laeuger , 2007. # include $(top_srcdir)/Makefile.rules +AM_YFLAGS = -d + +if BISON_LOCATIONS +AM_LFLAGS = --bison-locations +AM_YFLAGS += --locations +endif + noinst_LIBRARIES = libsvf.a libsvf_a_SOURCES = \ @@ -30,8 +35,6 @@ libsvf_a_SOURCES = \ svf_flex.l \ svf.c -AM_YFLAGS = -d - CLEANFILES = \ svf_bison.c \ svf_bison.h \ diff --git a/jtag/src/svf/svf_bison.y b/jtag/src/svf/svf_bison.y index 77e778b8..5e9ead63 100644 --- a/jtag/src/svf/svf_bison.y +++ b/jtag/src/svf/svf_bison.y @@ -25,7 +25,6 @@ */ %pure-parser -%locations %{ #include diff --git a/jtag/src/svf/svf_flex.l b/jtag/src/svf/svf_flex.l index b15ec1e2..416551ca 100644 --- a/jtag/src/svf/svf_flex.l +++ b/jtag/src/svf/svf_flex.l @@ -24,26 +24,52 @@ */ -%option bison-locations +/* + * Note: This lexer supports bison_locations if HAVE_MODERN_FLEX is + defined. Apart from this, the option --bison-locations has + to be specified on the command line. + Both the define and the command line option are controlled + by the configure script that enables this feature based on + the available version of flex. + */ + %{ #include #include +#include #include "svf.h" #include "svf_bison.h" static int map_keyw_ident(YYSTYPE *, char *); static void align_string(char *); + +/* autodetected by configure based on current flex version */ +#ifdef HAVE_MODERN_FLEX static void fix_yylloc(YYLTYPE *, char *); static void fix_yylloc_nl(YYLTYPE *, char *); +#define FIX_YYLLOC(lloc, text) fix_yylloc(lloc, text); +#define FIX_YYLLOC_NL(lloc, text) fix_yylloc_nl(lloc, text); + +#else + +#define MAP_KEYW_IDENT(LVAL, TEXT) map_keyw_ident(LVAL, TEXT) +#define FIX_YYLLOC(lloc, text) +#define FIX_YYLLOC_NL(lloc, text) + +#define YY_DECL int yylex (YYSTYPE *yylval) + +#endif /* HAVE_MODERN_FLEX */ int yywrap(void) { return(1); } +#ifdef HAVE_MODERN_FLEX #define YY_USER_INIT do { yylloc->first_line = yylloc->last_line = yylloc->first_column = yylloc->last_column = 0; } while (0) +#endif /* HAVE_MODERN_FLEX */ %} @@ -64,7 +90,7 @@ COMMENT (!.*)|("//".*)[^\n] /* token is a keyword or identifier */ int keyw; - fix_yylloc(yylloc, yytext); + FIX_YYLLOC(yylloc, yytext); keyw = map_keyw_ident(yylval, yytext); /* enable detection of VECTOR_STRING when this is a PIO command */ @@ -80,7 +106,7 @@ COMMENT (!.*)|("//".*)[^\n] /* token is a real number */ yylval->dvalue = strtod(yytext, (char **) NULL); - fix_yylloc(yylloc, yytext); + FIX_YYLLOC(yylloc, yytext); return(NUMBER); } /* end of real number */ @@ -95,7 +121,7 @@ COMMENT (!.*)|("//".*)[^\n] /* token is a vector string */ char *cstring; - fix_yylloc_nl(yylloc, yytext); + FIX_YYLLOC_NL(yylloc, yytext); align_string(yytext); cstring = calloc(strlen(yytext) + 1, sizeof(char)); @@ -109,7 +135,7 @@ COMMENT (!.*)|("//".*)[^\n] /* token is a hexadecimal value (2) */ char *cstring; - fix_yylloc_nl(yylloc, yytext); + FIX_YYLLOC_NL(yylloc, yytext); align_string(yytext); cstring = calloc(strlen(yytext) + 1, sizeof(char)); @@ -121,29 +147,31 @@ COMMENT (!.*)|("//".*)[^\n] {WSPACE}+ { /* token is a white space character */ - fix_yylloc(yylloc, yytext); + FIX_YYLLOC(yylloc, yytext); } /* end of white space */ {COMMENT} { /* token is a comment */ - fix_yylloc(yylloc, yytext); + FIX_YYLLOC(yylloc, yytext); } /* end of comment */ [()] { /* left or right parenthes */ - fix_yylloc(yylloc, yytext); + FIX_YYLLOC(yylloc, yytext); return(yytext[0]); } /* end of left or right parenthesis */ \n { /* token is a new line character */ +#ifdef HAVE_MODERN_FLEX yylloc->first_line = yylloc->last_line; yylloc->first_column = yylloc->last_column; ++yylloc->last_line; yylloc->last_column = 0; +#endif /* HAVE_MODERN_FLEX */ } /* end of new line */ @@ -153,7 +181,7 @@ COMMENT (!.*)|("//".*)[^\n] /* release expect_vector */ BEGIN(INITIAL); - fix_yylloc(yylloc, yytext); + FIX_YYLLOC(yylloc, yytext); return(yytext[0]); } /* end of statement character */ @@ -275,6 +303,7 @@ align_string(char *str) } +#ifdef HAVE_MODERN_FLEX static void fix_yylloc(YYLTYPE * yylloc, char *str) { @@ -300,3 +329,4 @@ fix_yylloc_nl(YYLTYPE * yylloc, char *str) } } } +#endif /* HAVE_MODERN_FLEX */