]> granicus.if.org Git - yasm/commitdiff
Allow colons for EQU labels (e.g. "value: equ 5").
authorPeter Johnson <peter@tortall.net>
Sun, 26 Oct 2003 02:04:47 +0000 (02:04 -0000)
committerPeter Johnson <peter@tortall.net>
Sun, 26 Oct 2003 02:04:47 +0000 (02:04 -0000)
Reported by: Brian Gladman <brg@gladman.plus.com>

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

modules/parsers/nasm/nasm-bison.y
modules/parsers/nasm/tests/Makefile.inc
modules/parsers/nasm/tests/equcolon.asm [new file with mode: 0644]
modules/parsers/nasm/tests/equcolon.errwarn [new file with mode: 0644]
modules/parsers/nasm/tests/equcolon.hex [new file with mode: 0644]

index abbe8fa33d23619b9ff120a3d0e5df0ab4947bd2..2db48c22a7acfae0bfdd42afb48ccb8bcbe839c8 100644 (file)
@@ -45,6 +45,8 @@ static void nasm_parser_directive
      /*@null@*/ yasm_valparamhead *objext_valparams);
 static int fix_directive_symrec(/*@null@*/ yasm_expr__item *ei,
                                /*@null@*/ void *d);
+static void define_label(yasm_parser_nasm *parser_nasm, /*@only@*/ char *name,
+                        int local);
 
 #define nasm_parser_error(s)   yasm__parser_error(cur_line, s)
 #define YYPARSE_PARAM  parser_nasm_arg
@@ -76,6 +78,10 @@ static int fix_directive_symrec(/*@null@*/ yasm_expr__item *ei,
        int num_operands;
     } insn_operands;
     yasm_insn_operand *insn_operand;
+    struct {
+       char *name;
+       int local;
+    } label;
 }
 
 %token <intn> INTNUM
@@ -96,7 +102,7 @@ static int fix_directive_symrec(/*@null@*/ yasm_expr__item *ei,
 %type <ea> memaddr
 %type <exp> dvexpr expr direxpr
 %type <sym> explabel
-%type <str_val> label_id label_id_equ
+%type <label> label_id label
 %type <data> dataval
 %type <datahead> datavals
 %type <dir_valparams> directive_valparams
@@ -152,13 +158,23 @@ line: '\n'                { $$ = (yasm_bytecode *)NULL; }
 
 lineexp: exp
     | TIMES expr exp           { $$ = $3; yasm_bc_set_multiple($$, $2); }
-    | label                    { $$ = (yasm_bytecode *)NULL; }
-    | label exp                        { $$ = $2; }
-    | label TIMES expr exp     { $$ = $4; yasm_bc_set_multiple($$, $3); }
-    | label_id_equ EQU expr    {
-       yasm_symtab_define_equ(p_symtab, $1, $3, cur_line);
-       yasm_xfree($1);
+    | label                    {
+       $$ = (yasm_bytecode *)NULL;
+       define_label(parser_nasm, $1.name, $1.local);
+    }
+    | label exp                        {
+       $$ = $2;
+       define_label(parser_nasm, $1.name, $1.local);
+    }
+    | label TIMES expr exp     {
+       $$ = $4;
+       yasm_bc_set_multiple($$, $3);
+       define_label(parser_nasm, $1.name, $1.local);
+    }
+    | label EQU expr           {
        $$ = (yasm_bytecode *)NULL;
+       yasm_symtab_define_equ(p_symtab, $1.name, $3, cur_line);
+       yasm_xfree($1.name);
     }
 ;
 
@@ -225,34 +241,13 @@ dataval: dvexpr           { $$ = yasm_dv_create_expr($1); }
     }
 ;
 
-label: label_id            {
-       yasm_symtab_define_label(p_symtab, $1, parser_nasm->prev_bc, 1,
-                                cur_line);
-       yasm_xfree($1);
-    }
-    | label_id ':'  {
-       yasm_symtab_define_label(p_symtab, $1, parser_nasm->prev_bc, 1,
-                                cur_line);
-       yasm_xfree($1);
-    }
+label: label_id
+    | label_id ':'     { $$ = $1; }
 ;
 
-label_id: ID       {
-       $$ = $1;
-       if (parser_nasm->locallabel_base)
-           yasm_xfree(parser_nasm->locallabel_base);
-       parser_nasm->locallabel_base_len = strlen($1);
-       parser_nasm->locallabel_base =
-           yasm_xmalloc(parser_nasm->locallabel_base_len+1);
-       strcpy(parser_nasm->locallabel_base, $1);
-    }
-    | SPECIAL_ID
-    | LOCAL_ID
-;
-
-label_id_equ: ID
-    | SPECIAL_ID
-    | LOCAL_ID
+label_id: ID           { $$.name = $1; $$.local = 0; }
+    | SPECIAL_ID       { $$.name = $1; $$.local = 1; }
+    | LOCAL_ID         { $$.name = $1; $$.local = 1; }
 ;
 
 /* directives */
@@ -483,6 +478,23 @@ explabel: ID               {
 
 #undef parser_nasm
 
+static void
+define_label(yasm_parser_nasm *parser_nasm, char *name, int local)
+{
+    if (!local) {
+       if (parser_nasm->locallabel_base)
+           yasm_xfree(parser_nasm->locallabel_base);
+       parser_nasm->locallabel_base_len = strlen(name);
+       parser_nasm->locallabel_base =
+           yasm_xmalloc(parser_nasm->locallabel_base_len+1);
+       strcpy(parser_nasm->locallabel_base, name);
+    }
+
+    yasm_symtab_define_label(p_symtab, name, parser_nasm->prev_bc, 1,
+                            cur_line);
+    yasm_xfree(name);
+}
+
 static int
 fix_directive_symrec(yasm_expr__item *ei, void *d)
 {
index 5fc8c92c0e548fe494411f63d91ae7f17d628d45..c17fd86a21eee1ce02d724220472174a1305a56e 100644 (file)
@@ -6,6 +6,9 @@ EXTRA_DIST += modules/parsers/nasm/tests/nasm_test.sh
 EXTRA_DIST += modules/parsers/nasm/tests/endcomma.asm
 EXTRA_DIST += modules/parsers/nasm/tests/endcomma.errwarn
 EXTRA_DIST += modules/parsers/nasm/tests/endcomma.hex
+EXTRA_DIST += modules/parsers/nasm/tests/equcolon.asm
+EXTRA_DIST += modules/parsers/nasm/tests/equcolon.errwarn
+EXTRA_DIST += modules/parsers/nasm/tests/equcolon.hex
 EXTRA_DIST += modules/parsers/nasm/tests/equlocal.asm
 EXTRA_DIST += modules/parsers/nasm/tests/equlocal.errwarn
 EXTRA_DIST += modules/parsers/nasm/tests/equlocal.hex
diff --git a/modules/parsers/nasm/tests/equcolon.asm b/modules/parsers/nasm/tests/equcolon.asm
new file mode 100644 (file)
index 0000000..9963720
--- /dev/null
@@ -0,0 +1,3 @@
+equval:        equ     5
+equval2        equ     7
+db equval, equval2
diff --git a/modules/parsers/nasm/tests/equcolon.errwarn b/modules/parsers/nasm/tests/equcolon.errwarn
new file mode 100644 (file)
index 0000000..e69de29
diff --git a/modules/parsers/nasm/tests/equcolon.hex b/modules/parsers/nasm/tests/equcolon.hex
new file mode 100644 (file)
index 0000000..3a4ad9a
--- /dev/null
@@ -0,0 +1,2 @@
+05 
+07