Parse (and reject) asm goto.
authorChristoph Mallon <christoph.mallon@gmx.de>
Fri, 26 Oct 2012 05:03:24 +0000 (07:03 +0200)
committerChristoph Mallon <christoph.mallon@gmx.de>
Thu, 8 Nov 2012 14:01:40 +0000 (15:01 +0100)
ast.c
ast.h
ast_t.h
parser.c

diff --git a/ast.c b/ast.c
index 032e9fe..da758db 100644 (file)
--- a/ast.c
+++ b/ast.c
@@ -1035,6 +1035,16 @@ static void print_asm_clobbers(asm_clobber_t const *const clobbers)
        }
 }
 
+static void print_asm_labels(asm_label_t const *const labels)
+{
+       print_string(" :");
+       separator_t sep = { " ", ", " };
+       for (asm_label_t const *i = labels; i; i = i->next) {
+               print_string(sep_next(&sep));
+               print_string(i->label->base.symbol->string);
+       }
+}
+
 /**
  * Print an assembler statement.
  *
@@ -1044,10 +1054,12 @@ static void print_asm_statement(asm_statement_t const *const stmt)
 {
        print_string("asm");
        if (stmt->is_volatile) print_string(" volatile");
+       if (stmt->labels)      print_string(" goto");
        print_char('(');
        print_quoted_string(&stmt->asm_text, '"');
 
        unsigned const n =
+               stmt->labels   ? 4 :
                stmt->clobbers ? 3 :
                stmt->inputs   ? 2 :
                stmt->outputs  ? 1 :
@@ -1055,6 +1067,7 @@ static void print_asm_statement(asm_statement_t const *const stmt)
        if (n >= 1) print_asm_arguments(stmt->outputs);
        if (n >= 2) print_asm_arguments(stmt->inputs);
        if (n >= 3) print_asm_clobbers( stmt->clobbers);
+       if (n >= 4) print_asm_labels(   stmt->labels);
 
        print_string(");");
 }
diff --git a/ast.h b/ast.h
index 7647899..f7c0ce4 100644 (file)
--- a/ast.h
+++ b/ast.h
@@ -71,6 +71,7 @@ typedef struct do_while_statement_t                  do_while_statement_t;
 typedef struct for_statement_t                       for_statement_t;
 typedef struct asm_argument_t                        asm_argument_t;
 typedef struct asm_clobber_t                         asm_clobber_t;
+typedef struct asm_label_t                           asm_label_t;
 typedef struct asm_statement_t                       asm_statement_t;
 typedef struct ms_try_statement_t                    ms_try_statement_t;
 typedef struct leave_statement_t                     leave_statement_t;
diff --git a/ast_t.h b/ast_t.h
index 516e6f7..7e72895 100644 (file)
--- a/ast_t.h
+++ b/ast_t.h
@@ -601,12 +601,18 @@ struct asm_clobber_t {
        asm_clobber_t *next;
 };
 
+struct asm_label_t {
+       label_t     *label;
+       asm_label_t *next;
+};
+
 struct asm_statement_t {
        statement_base_t base;
        string_t         asm_text;
        asm_argument_t  *inputs;
        asm_argument_t  *outputs;
        asm_clobber_t   *clobbers;
+       asm_label_t     *labels;
        bool             is_volatile;
 };
 
index 45485c7..76343b5 100644 (file)
--- a/parser.c
+++ b/parser.c
@@ -8747,6 +8747,24 @@ static void parse_asm_clobbers(asm_clobber_t **anchor)
        }
 }
 
+static void parse_asm_labels(asm_label_t **anchor)
+{
+       if (token.kind == T_IDENTIFIER) {
+               add_anchor_token(',');
+               do {
+                       label_t *const label = get_label("while parsing 'asm goto' labels");
+                       if (label) {
+                               asm_label_t *const asm_label = allocate_ast_zero(sizeof(*asm_label));
+                               asm_label->label = label;
+
+                               *anchor = asm_label;
+                               anchor  = &asm_label->next;
+                       }
+               } while (accept(','));
+               rem_anchor_token(',');
+       }
+}
+
 /**
  * Parse an asm statement.
  */
@@ -8763,15 +8781,28 @@ static statement_t *parse_asm_statement(void)
        if (accept(T_volatile))
                asm_statement->is_volatile = true;
 
+       bool const asm_goto = accept(T_goto);
+
        expect('(');
        rem_anchor_token(T_STRING_LITERAL);
        asm_statement->asm_text = parse_string_literals("asm statement");
 
        if (accept(':')) parse_asm_arguments(&asm_statement->outputs, true);
        if (accept(':')) parse_asm_arguments(&asm_statement->inputs, false);
-       rem_anchor_token(':');
        if (accept(':')) parse_asm_clobbers( &asm_statement->clobbers);
 
+       rem_anchor_token(':');
+       if (accept(':')) {
+               if (!asm_goto)
+                       warningf(WARN_OTHER, &statement->base.source_position, "assembler statement with labels should be 'asm goto'");
+               parse_asm_labels(&asm_statement->labels);
+               if (asm_statement->labels)
+                       errorf(&statement->base.source_position, "'asm goto' not supported");
+       } else {
+               if (asm_goto)
+                       warningf(WARN_OTHER, &statement->base.source_position, "'asm goto' without labels");
+       }
+
        rem_anchor_token(')');
        expect(')');
        expect(';');