switch-coreboot/util/dtc/dtc-parser.y
Mart Raudsepp 705439d7aa Fix a build error when using bison-2.4
This fixes one of the errors from using bison-2.4, but there are more.

This one in details is the following error:

  BISON   build/util/dtc/dtc-parser.tab.c
  HOSTCC  build/util/dtc/dtc-parser.tab.o
/home/leio/dev/coreboot-v3/util/dtc/dtc-parser.y: In function ‘yyuserAction’:
/home/leio/dev/coreboot-v3/util/dtc/dtc-parser.y:154: error: expected ‘;’ before ‘}’ token
make: *** [/home/leio/dev/coreboot-v3/build/util/dtc/dtc-parser.tab.o] Error 1

Note that 2.4.1 might be made to still work without the semi-colon for some languages, but I
understand 2.5 then still won't work without one. As it builds fine with this change with
bison-2.3, it should be safe to just add the semicolon.

The remaining error is the following:

/home/leio/dev/coreboot-v3/util/dtc/dtc-lexer.l: In function ‘yylex’:
/home/leio/dev/coreboot-v3/util/dtc/dtc-lexer.l:73: error: ‘yylval’ undeclared (first use in this function)
/home/leio/dev/coreboot-v3/util/dtc/dtc-lexer.l:73: error: (Each undeclared identifier is reported only once
/home/leio/dev/coreboot-v3/util/dtc/dtc-lexer.l:73: error: for each function it appears in.)

dtc-parser.tab.h doesn't seem to get an "extern YYSTYPE yylval" declaration, which per documentation should
only happen for pure parser cases ("%define api.pure"), but I can't find any such declaration in dtc to cause
the problem.

Note that upstream dtc builds fine with bison-2.4

Signed-off-by: Mart Raudsepp <mart.raudsepp@artecdesign.ee>
Acked-by: Carl-Daniel Hailfinger <c-d.hailfinger.devel.2006@gmx.net>

git-svn-id: svn://coreboot.org/repository/coreboot-v3@1004 f3766cd6-281f-0410-b1cd-43a5c92072e9
2008-11-12 17:04:15 +00:00

210 lines
4.5 KiB
Text

/*
* (C) Copyright David Gibson <dwg@au1.ibm.com>, IBM Corporation. 2005.
*
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation; either version 2 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
* USA
*/
%glr-parser
%locations
%{
#include "dtc.h"
int yylex (void);
void yyerror (char const *);
extern struct boot_info *the_boot_info;
%}
%union {
cell_t cval;
u8 byte;
char *str;
struct data data;
struct property *prop;
struct property *proplist;
struct node *node;
struct node *nodelist;
int datalen;
int hexlen;
u64 addr;
struct reserve_info *re;
}
%token <str> DT_MEMRESERVE
%token <addr> DT_ADDR
%token <str> DT_PROPNAME
%token <str> DT_NODENAME
%token <cval> DT_CELL
%token <byte> DT_BYTE
%token <data> DT_STRING
%token <str> DT_UNIT
%token <str> DT_LABEL
%token <str> DT_REF
%token <str> DT_FILENAME
%token <proplist> DT_CONFIG
%type <data> propdata
%type <re> memreserve
%type <re> memreserves
%type <data> celllist
%type <data> bytestring
%type <prop> propdef
%type <proplist> proplist
%type <node> devicetree
%type <node> nodedef
%type <node> subnode
%type <proplist> config
%type <nodelist> subnodes
%type <str> label
%type <str> nodename
%type <data> includepath
%type <data> structname
%%
/*sourcefile: memreserves devicetree {*/
sourcefile: devicetree {
/* the_boot_info = build_boot_info($1, $2);*/
the_boot_info = build_boot_info(0, $1);
}
;
memreserves: memreserve memreserves {
$$ = chain_reserve_entry($1, $2);
}
| /* empty */ {
$$ = NULL;
}
;
memreserve: DT_MEMRESERVE DT_ADDR DT_ADDR ';' {
$$ = build_reserve_entry($2, $3, NULL);
}
| DT_MEMRESERVE DT_ADDR '-' DT_ADDR ';' {
$$ = build_reserve_entry($2, $4 - $2 + 1, NULL);
}
;
devicetree: '/' nodedef {
$$ = name_node($2, "", NULL);
}
;
nodedef: '{' config proplist subnodes '}' ';' {
$$ = build_node($2, $3, $4);
}
;
proplist: propdef proplist {
$$ = chain_property($1, $2);
}
| /* empty */ {
$$ = NULL;
}
;
config: DT_CONFIG '('
includepath {
void switchin(FILE *f);
FILE *f;
/* The need for a cast here is silly */
char *name = (char *)$3.val;
/* TODO: keep track of which of these we have read in. If we have already done it, then
* don't do it twice.
*/
f = fopenfile(name);
if (! f){
perror(name);
exit(1);
}
switchin(f);
} '{' proplist '}' ';' {
void switchback(void);
switchback();
}
')' ';' {
int namelen;
char *name = strdup((char *)$3.val);
/* convention: first property is labeled with path */
$6->label = name;
/* convention: if it ends in .dts, strip that off */
namelen = strlen($6->label);
if ((namelen > 4) && (! strncmp(&name[namelen-4], ".dts", 4)))
$6->label[namelen-4] = '\0';
$$ = $6;
}
|
;
includepath: DT_STRING { $$ = $1; }
;
structname: DT_FILENAME {$$ = $1; }
;
propdef: label DT_PROPNAME '=' propdata ';' {
$$ = build_property($2, $4, $1);
}
| label DT_PROPNAME ';' {
$$ = build_property($2, empty_data, $1);
}
;
propdata: DT_STRING { $$ = $1; }
| '<' celllist '>' { $$ = $2; }
| '[' bytestring ']' { $$ = $2; }
;
celllist: celllist DT_CELL { $$ = data_append_cell($1, $2); }
| celllist DT_REF {
$$ = data_append_cell(data_add_fixup($1, $2), -1);
}
| /* empty */ { $$ = empty_data; }
;
bytestring: bytestring DT_BYTE { $$ = data_append_byte($1, $2); }
| /* empty */ { $$ = empty_data; }
;
subnodes: subnode subnodes {
$$ = chain_node($1, $2);
}
| /* empty */ { $$ = NULL; }
;
subnode: label nodename nodedef { $$ = name_node($3, $2, $1); }
;
nodename: DT_NODENAME { $$ = $1; }
| DT_PROPNAME { $$ = $1; }
;
label: DT_LABEL { $$ = $1; }
| /* empty */ { $$ = NULL; }
;
%%
void yyerror (char const *s)
{
fprintf (stderr, "%s at line %d\n", s, yylloc.first_line);
}