From bedc35abc5cdf2bf14db9065e555826fb9171777 Mon Sep 17 00:00:00 2001 From: Mikael Pettersson Date: Mon, 20 Apr 2015 23:07:27 +0200 Subject: [PATCH] as: support line-comments starting with '#' --- TODO | 4 +--- as/scan.c | 19 +++++++++++++++++++ 2 files changed, 20 insertions(+), 3 deletions(-) diff --git a/TODO b/TODO index ffb1c7e..04d6789 100644 --- a/TODO +++ b/TODO @@ -43,9 +43,7 @@ Tools: - readelf: add support for relocs - readelf: add support for program headers - as: - * add line-comment character, e.g. '#' - + use it in doc/MUUO.txt - + use it in as/tests/*.s + * add C /* ... */ comments * support .ident: + change strtab to have a finalizer which returns an image array, + use standard output_section for strtab diff --git a/as/scan.c b/as/scan.c index c2d9285..a054a7f 100644 --- a/as/scan.c +++ b/as/scan.c @@ -311,6 +311,23 @@ static enum token do_number(struct scan_state *scan_state, union token_attribute return T_UINTEGER; } +static int do_line_comment(struct scan_state *scan_state) +{ + for (;;) { + int ch = scan_getchar(); + switch (ch) { + case '\n': + ++scan_state->linenr; + return T_NEWLINE; + case EOF: + badchar(scan_state, ch, "in line comment"); + return T_ERROR; + default: + continue; + } + } +} + enum token scan_token(struct scan_state *scan_state, union token_attribute *token_attr) { int ch; @@ -327,6 +344,8 @@ enum token scan_token(struct scan_state *scan_state, union token_attribute *toke case '\n': ++scan_state->linenr; return T_NEWLINE; + case '#': + return do_line_comment(scan_state); case EOF: return T_EOF; case '@':