}
}
+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.
*
{
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 :
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(");");
}
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;
}
}
+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.
*/
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(';');