diff --git a/modules/parsers/gas/gas-parser.c b/modules/parsers/gas/gas-parser.c index e1a3635f..f70e70ab 100644 --- a/modules/parsers/gas/gas-parser.c +++ b/modules/parsers/gas/gas-parser.c @@ -93,6 +93,16 @@ gas_parser_do_parse(yasm_object *object, yasm_preproc *pp, yasm_arch *a, yasm_errwarn_propagate(errwarns, parser_gas.rept->startline); } + /* Check for ending inside a comment */ + if (parser_gas.state == COMMENT) { + yasm_warn_set(YASM_WARN_GENERAL, N_("end of file in comment")); + /* XXX: Minus two to compensate for already having moved past the EOF + * in the linemap. + */ + yasm_errwarn_propagate(errwarns, + yasm_linemap_get_current(parser_gas.linemap)-2); + } + gas_parser_cleanup(&parser_gas); /* Free locallabel base if necessary */ diff --git a/modules/parsers/gas/gas-parser.h b/modules/parsers/gas/gas-parser.h index c26c939d..f736bb28 100644 --- a/modules/parsers/gas/gas-parser.h +++ b/modules/parsers/gas/gas-parser.h @@ -90,6 +90,7 @@ typedef struct yasm_parser_gas { Scanner s; enum { INITIAL, + COMMENT, SECTION_DIRECTIVE, INSTDIR } state; diff --git a/modules/parsers/gas/gas-token.re b/modules/parsers/gas/gas-token.re index bb65ae08..08e4d946 100644 --- a/modules/parsers/gas/gas-token.re +++ b/modules/parsers/gas/gas-token.re @@ -266,6 +266,8 @@ gas_parser_lex(YYSTYPE *lvalp, yasm_parser_gas *parser_gas) /* Jump to proper "exclusive" states */ switch (parser_gas->state) { + case COMMENT: + goto comment; case SECTION_DIRECTIVE: goto section_directive; default: @@ -478,6 +480,7 @@ scan: RETURN(ID); } + "/*" { parser_gas->state = COMMENT; goto comment; } "#" (any \ [\n])* { goto scan; } ws+ { goto scan; } @@ -497,6 +500,27 @@ scan: } */ + /* C-style comment; nesting not supported */ +comment: + SCANINIT(); + + /*!re2c + /* End of comment */ + "*/" { parser_gas->state = INITIAL; goto scan; } + + "\n" { + if (parser_gas->save_input) + cursor = save_line(parser_gas, cursor); + RETURN(s->tok[0]); + } + + any { + if (cursor == s->eof) + return 0; + goto comment; + } + */ + /* .section directive (the section name portion thereof) */ section_directive: SCANINIT(); diff --git a/modules/parsers/gas/tests/bin/Makefile.inc b/modules/parsers/gas/tests/bin/Makefile.inc index 6091c019..93b08f27 100644 --- a/modules/parsers/gas/tests/bin/Makefile.inc +++ b/modules/parsers/gas/tests/bin/Makefile.inc @@ -3,6 +3,9 @@ TESTS += modules/parsers/gas/tests/bin/gas_bin_test.sh EXTRA_DIST += modules/parsers/gas/tests/bin/gas_bin_test.sh +EXTRA_DIST += modules/parsers/gas/tests/bin/gas-comment.asm +EXTRA_DIST += modules/parsers/gas/tests/bin/gas-comment.errwarn +EXTRA_DIST += modules/parsers/gas/tests/bin/gas-comment.hex EXTRA_DIST += modules/parsers/gas/tests/bin/rept-err.asm EXTRA_DIST += modules/parsers/gas/tests/bin/rept-err.errwarn EXTRA_DIST += modules/parsers/gas/tests/bin/reptempty.asm diff --git a/modules/parsers/gas/tests/bin/gas-comment.asm b/modules/parsers/gas/tests/bin/gas-comment.asm new file mode 100644 index 00000000..ee68e554 --- /dev/null +++ b/modules/parsers/gas/tests/bin/gas-comment.asm @@ -0,0 +1,23 @@ +# This is a comment + +/* So is this */ + +.byte 0 /* at end of line? */ + +.byte 0 /* at end of line, +multi-line? */ + +/* start of line? */ .byte 0 + +/* What about +a multi-line +comment? -- at start of line? +*/ .byte 0 + +.byte 0, /* in middle? */ 1 + +# Illegal; 1 seen on next line +#.byte 0, /* in middle, +#spanning lines? */ 1 + +/* EOF in comment? diff --git a/modules/parsers/gas/tests/bin/gas-comment.errwarn b/modules/parsers/gas/tests/bin/gas-comment.errwarn new file mode 100644 index 00000000..1fb55a30 --- /dev/null +++ b/modules/parsers/gas/tests/bin/gas-comment.errwarn @@ -0,0 +1 @@ +-:23: warning: end of file in comment diff --git a/modules/parsers/gas/tests/bin/gas-comment.hex b/modules/parsers/gas/tests/bin/gas-comment.hex new file mode 100644 index 00000000..93d7888d --- /dev/null +++ b/modules/parsers/gas/tests/bin/gas-comment.hex @@ -0,0 +1,6 @@ +00 +00 +00 +00 +00 +01