]> granicus.if.org Git - yasm/commitdiff
NASM parser bugfixes, and add support for section names that include "-"
authorPeter Johnson <peter@tortall.net>
Sat, 30 Dec 2006 02:48:17 +0000 (02:48 -0000)
committerPeter Johnson <peter@tortall.net>
Sat, 30 Dec 2006 02:48:17 +0000 (02:48 -0000)
(such as the common .note.GNU-stack section).  While Yasm allows such section
names by enclosing with double-quotes, NASM allows this, so for compatibility
it makes sense for Yasm to as well.

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

modules/objfmts/elf/tests/Makefile.inc
modules/objfmts/elf/tests/nasm-sectname.asm [new file with mode: 0644]
modules/objfmts/elf/tests/nasm-sectname.hex [new file with mode: 0644]
modules/parsers/nasm/nasm-parse.c
modules/parsers/nasm/nasm-parser.h
modules/parsers/nasm/nasm-token.re

index e6d485f31d2c04e3d45ac656d4c5462d164f33f5..ffb8ffe092074cbcb992b9f44402ccc92e8d42f5 100644 (file)
@@ -43,6 +43,8 @@ EXTRA_DIST += modules/objfmts/elf/tests/elftypesize.hex
 EXTRA_DIST += modules/objfmts/elf/tests/elfvisibility.asm
 EXTRA_DIST += modules/objfmts/elf/tests/elfvisibility.errwarn
 EXTRA_DIST += modules/objfmts/elf/tests/elfvisibility.hex
+EXTRA_DIST += modules/objfmts/elf/tests/nasm-sectname.asm
+EXTRA_DIST += modules/objfmts/elf/tests/nasm-sectname.hex
 
 EXTRA_DIST += modules/objfmts/elf/tests/amd64/Makefile.inc
 EXTRA_DIST += modules/objfmts/elf/tests/gas64/Makefile.inc
diff --git a/modules/objfmts/elf/tests/nasm-sectname.asm b/modules/objfmts/elf/tests/nasm-sectname.asm
new file mode 100644 (file)
index 0000000..12a2505
--- /dev/null
@@ -0,0 +1,4 @@
+; XXX: this test should really be in parsers/nasm/tests, not here.
+section .note.GNU-stack
+section "more$$&complex"
+
diff --git a/modules/objfmts/elf/tests/nasm-sectname.hex b/modules/objfmts/elf/tests/nasm-sectname.hex
new file mode 100644 (file)
index 0000000..a78e2e2
--- /dev/null
@@ -0,0 +1,504 @@
+7f 
+45 
+4c 
+46 
+01 
+01 
+01 
+00 
+00 
+00 
+00 
+00 
+00 
+00 
+00 
+00 
+01 
+00 
+03 
+00 
+01 
+00 
+00 
+00 
+00 
+00 
+00 
+00 
+00 
+00 
+00 
+00 
+e0 
+00 
+00 
+00 
+00 
+00 
+00 
+00 
+34 
+00 
+00 
+00 
+00 
+00 
+28 
+00 
+07 
+00 
+01 
+00 
+00 
+00 
+00 
+00 
+00 
+00 
+00 
+00 
+00 
+00 
+00 
+00 
+00 
+2e 
+74 
+65 
+78 
+74 
+00 
+2e 
+6e 
+6f 
+74 
+65 
+2e 
+47 
+4e 
+55 
+2d 
+73 
+74 
+61 
+63 
+6b 
+00 
+6d 
+6f 
+72 
+65 
+24 
+24 
+26 
+63 
+6f 
+6d 
+70 
+6c 
+65 
+78 
+00 
+2e 
+73 
+74 
+72 
+74 
+61 
+62 
+00 
+2e 
+73 
+79 
+6d 
+74 
+61 
+62 
+00 
+2e 
+73 
+68 
+73 
+74 
+72 
+74 
+61 
+62 
+00 
+00 
+2d 
+00 
+00 
+00 
+00 
+00 
+00 
+00 
+00 
+00 
+00 
+00 
+00 
+00 
+00 
+00 
+00 
+00 
+00 
+01 
+00 
+00 
+00 
+00 
+00 
+00 
+00 
+00 
+00 
+00 
+00 
+04 
+00 
+f1 
+ff 
+00 
+00 
+00 
+00 
+00 
+00 
+00 
+00 
+00 
+00 
+00 
+00 
+03 
+00 
+06 
+00 
+00 
+00 
+00 
+00 
+00 
+00 
+00 
+00 
+00 
+00 
+00 
+00 
+03 
+00 
+05 
+00 
+00 
+00 
+00 
+00 
+00 
+00 
+00 
+00 
+00 
+00 
+00 
+00 
+03 
+00 
+04 
+00 
+00 
+00 
+00 
+00 
+00 
+00 
+00 
+00 
+00 
+00 
+00 
+00 
+00 
+00 
+00 
+00 
+00 
+00 
+00 
+00 
+00 
+00 
+00 
+00 
+00 
+00 
+00 
+00 
+00 
+00 
+00 
+00 
+00 
+00 
+00 
+00 
+00 
+00 
+00 
+00 
+00 
+00 
+00 
+00 
+00 
+00 
+00 
+00 
+00 
+00 
+00 
+00 
+36 
+00 
+00 
+00 
+03 
+00 
+00 
+00 
+00 
+00 
+00 
+00 
+00 
+00 
+00 
+00 
+40 
+00 
+00 
+00 
+40 
+00 
+00 
+00 
+00 
+00 
+00 
+00 
+00 
+00 
+00 
+00 
+00 
+00 
+00 
+00 
+00 
+00 
+00 
+00 
+26 
+00 
+00 
+00 
+03 
+00 
+00 
+00 
+00 
+00 
+00 
+00 
+00 
+00 
+00 
+00 
+80 
+00 
+00 
+00 
+03 
+00 
+00 
+00 
+00 
+00 
+00 
+00 
+00 
+00 
+00 
+00 
+00 
+00 
+00 
+00 
+00 
+00 
+00 
+00 
+2e 
+00 
+00 
+00 
+02 
+00 
+00 
+00 
+00 
+00 
+00 
+00 
+00 
+00 
+00 
+00 
+84 
+00 
+00 
+00 
+50 
+00 
+00 
+00 
+02 
+00 
+00 
+00 
+05 
+00 
+00 
+00 
+04 
+00 
+00 
+00 
+10 
+00 
+00 
+00 
+01 
+00 
+00 
+00 
+01 
+00 
+00 
+00 
+06 
+00 
+00 
+00 
+00 
+00 
+00 
+00 
+40 
+00 
+00 
+00 
+00 
+00 
+00 
+00 
+00 
+00 
+00 
+00 
+00 
+00 
+00 
+00 
+10 
+00 
+00 
+00 
+00 
+00 
+00 
+00 
+07 
+00 
+00 
+00 
+01 
+00 
+00 
+00 
+02 
+00 
+00 
+00 
+00 
+00 
+00 
+00 
+40 
+00 
+00 
+00 
+00 
+00 
+00 
+00 
+00 
+00 
+00 
+00 
+00 
+00 
+00 
+00 
+01 
+00 
+00 
+00 
+00 
+00 
+00 
+00 
+17 
+00 
+00 
+00 
+01 
+00 
+00 
+00 
+02 
+00 
+00 
+00 
+00 
+00 
+00 
+00 
+40 
+00 
+00 
+00 
+00 
+00 
+00 
+00 
+00 
+00 
+00 
+00 
+00 
+00 
+00 
+00 
+01 
+00 
+00 
+00 
+00 
+00 
+00 
+00 
index f5379bd80b946d1b288530d44f22fe9c61564ea3..fa1fccdd0a3772363b8caf461041a9996591bfd8 100644 (file)
@@ -112,7 +112,7 @@ destroy_curtok_(yasm_parser_nasm *parser_nasm)
        default:
            break;
     }
-    curtok = 0;            /* sanity */
+    curtok = NONE;         /* sanity */
 }
 #define destroy_curtok()    destroy_curtok_(parser_nasm)
 
@@ -130,8 +130,8 @@ demand_eol_(yasm_parser_nasm *parser_nasm)
        parser_nasm->tokch);
 
     do {
-       get_next_token();
        destroy_curtok();
+       get_next_token();
     } while (!is_eol());
 }
 #define demand_eol() demand_eol_(parser_nasm)
@@ -220,6 +220,10 @@ parse_line(yasm_parser_nasm *parser_nasm)
 {
     yasm_bytecode *bc;
 
+    bc = parse_exp(parser_nasm);
+    if (bc)
+       return bc;
+
     switch (curtok) {
        case LINE: /* LINE INTNUM '+' INTNUM FILENAME */
        {
@@ -342,11 +346,9 @@ parse_line(yasm_parser_nasm *parser_nasm)
            return bc;
        }
        default:
-           bc = parse_exp(parser_nasm);
-           if (!bc)
-               yasm_error_set(YASM_ERROR_SYNTAX,
-                   N_("label or instruction expected at start of line"));
-           return bc;
+           yasm_error_set(YASM_ERROR_SYNTAX,
+               N_("label or instruction expected at start of line"));
+           return NULL;
     }
 }
 
@@ -449,6 +451,12 @@ parse_times(yasm_parser_nasm *parser_nasm)
 static yasm_bytecode *
 parse_exp(yasm_parser_nasm *parser_nasm)
 {
+    yasm_bytecode *bc;
+
+    bc = parse_instr(parser_nasm);
+    if (bc)
+       return bc;
+
     switch (curtok) {
        case DECLARE_DATA:
        {
@@ -554,7 +562,7 @@ incbin_done:
                                         parser_nasm->linemap, cur_line);
        }
        default:
-           return parse_instr(parser_nasm);
+           return NULL;
     }
 }
 
index d5d975addad498cb797b875285811abd9c9bcd1a..8d443e1c5251ad30f2de5c5898d78847886679bf 100644 (file)
@@ -107,6 +107,7 @@ typedef struct yasm_parser_nasm {
     enum {
        INITIAL,
        DIRECTIVE,
+       SECTION_DIRECTIVE,
        DIRECTIVE2,
        LINECHG,
        LINECHG2,
index 58d762b068ffd51e94da80a56c9f1cdd0d024beb..995af09e43e6a9087fcc831a77bfc959f6358eba 100644 (file)
@@ -142,6 +142,8 @@ nasm_parser_lex(YYSTYPE *lvalp, yasm_parser_nasm *parser_nasm)
     switch (parser_nasm->state) {
        case DIRECTIVE:
            goto directive;
+       case SECTION_DIRECTIVE:
+           goto section_directive;
        case DIRECTIVE2:
            goto directive2;
        case LINECHG:
@@ -475,8 +477,12 @@ directive:
        }
 
        iletter+ {
-           parser_nasm->state = DIRECTIVE2;
            lvalp->str_val = yasm__xstrndup(TOK, TOKLEN);
+           if (yasm__strcasecmp(lvalp->str_val, "section") == 0 ||
+               yasm__strcasecmp(lvalp->str_val, "segment") == 0)
+               parser_nasm->state = SECTION_DIRECTIVE;
+           else
+               parser_nasm->state = DIRECTIVE2;
            RETURN(DIRECTIVE_NAME);
        }
 
@@ -488,6 +494,49 @@ directive:
        }
     */
 
+    /* section directive (the section name portion thereof) */
+section_directive:
+    SCANINIT();
+
+    /*!re2c
+       [a-zA-Z0-9_$#@~.?-]+ {
+           lvalp->str.contents = yasm__xstrndup(TOK, TOKLEN);
+           lvalp->str.len = TOKLEN;
+           parser_nasm->state = DIRECTIVE2;
+           RETURN(STRING);
+       }
+
+       quot            {
+           parser_nasm->state = DIRECTIVE2;
+           endch = s->tok[0];
+           goto stringconst;
+       }
+
+       ws+             {
+           parser_nasm->state = DIRECTIVE2;
+           goto section_directive;
+       }
+
+       "]" {
+           parser_nasm->state = INITIAL;
+           RETURN(s->tok[0]);
+       }
+
+       "\n"                    {
+           if (parser_nasm->save_input)
+               cursor = save_line(parser_nasm, cursor);
+           parser_nasm->state = INITIAL;
+           RETURN(s->tok[0]);
+       }
+
+       any {
+           yasm_warn_set(YASM_WARN_UNREC_CHAR,
+                         N_("ignoring unrecognized character `%s'"),
+                         yasm__conv_unprint(s->tok[0]));
+           goto section_directive;
+       }
+    */
+
     /* inner part of directive */
 directive2:
     SCANINIT();