]> granicus.if.org Git - yasm/commitdiff
Add support for GAS local labels (1:, 1f, 1b).
authorPeter Johnson <peter@tortall.net>
Fri, 20 Jul 2007 03:28:24 +0000 (03:28 -0000)
committerPeter Johnson <peter@tortall.net>
Fri, 20 Jul 2007 03:28:24 +0000 (03:28 -0000)
Noticed by: Jung Lee <moorang@gmail.com>

svn path=/trunk/yasm/; revision=1898

modules/parsers/gas/gas-parser.c
modules/parsers/gas/gas-parser.h
modules/parsers/gas/gas-token.re

index 16c792bd94b7c8da08cfadc9a1a2a7f11fa2b509..9cc61382e237826f8bb402b56c52d4e0f751d397 100644 (file)
@@ -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;
 
index 94ceff19d1690e26bcf9e58ec14c3042045a0199..213e4696e453d5638d2842d9f78d120c8f5e328b 100644 (file)
@@ -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 */
index 457eee0e04b96f9693ba2905b605f3137da5180c..efa400d0b3f9fa3c92f9b91ee97c3095571a8d9e 100644 (file)
@@ -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