From 328320cc2b038a4f486655b9244a8c0b3facc56b Mon Sep 17 00:00:00 2001 From: Peter Johnson Date: Fri, 20 Jul 2007 03:28:24 +0000 Subject: [PATCH] Add support for GAS local labels (1:, 1f, 1b). Noticed by: Jung Lee svn path=/trunk/yasm/; revision=1898 --- modules/parsers/gas/gas-parser.c | 4 ++++ modules/parsers/gas/gas-parser.h | 5 +++++ modules/parsers/gas/gas-token.re | 29 +++++++++++++++++++++++++++++ 3 files changed, 38 insertions(+) diff --git a/modules/parsers/gas/gas-parser.c b/modules/parsers/gas/gas-parser.c index 16c792bd..9cc61382 100644 --- a/modules/parsers/gas/gas-parser.c +++ b/modules/parsers/gas/gas-parser.c @@ -41,6 +41,7 @@ gas_parser_do_parse(yasm_object *object, yasm_preproc *pp, FILE *f, yasm_errwarns *errwarns) { yasm_parser_gas parser_gas; + int i; parser_gas.object = object; parser_gas.linemap = linemap; @@ -71,6 +72,9 @@ gas_parser_do_parse(yasm_object *object, yasm_preproc *pp, FILE *f, parser_gas.rept = NULL; + for (i=0; i<10; i++) + parser_gas.local[i] = 0; + /* yacc debugging, needs YYDEBUG set in bison.y.in to work */ parser_gas.debug = 1; diff --git a/modules/parsers/gas/gas-parser.h b/modules/parsers/gas/gas-parser.h index 94ceff19..213e4696 100644 --- a/modules/parsers/gas/gas-parser.h +++ b/modules/parsers/gas/gas-parser.h @@ -149,6 +149,11 @@ typedef struct yasm_parser_gas { char peek_tokch; /*@null@*/ gas_rept *rept; + + /* Index of local labels; what's stored here is the /next/ index, + * so these are all 0 at start. + */ + unsigned long local[10]; } yasm_parser_gas; /* shorter access names to commonly used parser_gas fields */ diff --git a/modules/parsers/gas/gas-token.re b/modules/parsers/gas/gas-token.re index 457eee0e..efa400d0 100644 --- a/modules/parsers/gas/gas-token.re +++ b/modules/parsers/gas/gas-token.re @@ -529,6 +529,35 @@ scan: RETURN(LABEL); } + /* local label */ + [0-9] ':' { + /* increment label index */ + parser_gas->local[s->tok[0]-'0']++; + /* build local label name */ + lvalp->str_val = yasm_xmalloc(30); + sprintf(lvalp->str_val, "L%c\001%lu", s->tok[0], + parser_gas->local[s->tok[0]-'0']); + RETURN(LABEL); + } + + /* local label forward reference */ + [0-9] 'f' { + /* build local label name */ + lvalp->str_val = yasm_xmalloc(30); + sprintf(lvalp->str_val, "L%c\001%lu", s->tok[0], + parser_gas->local[s->tok[0]-'0']+1); + RETURN(ID); + } + + /* local label backward reference */ + [0-9] 'b' { + /* build local label name */ + lvalp->str_val = yasm_xmalloc(30); + sprintf(lvalp->str_val, "L%c\001%lu", s->tok[0], + parser_gas->local[s->tok[0]-'0']); + RETURN(ID); + } + /* identifier that may be an instruction, etc. */ [a-zA-Z][a-zA-Z0-9_$.]* { /* Can only be an instruction/prefix when not inside an -- 2.40.0