summaryrefslogtreecommitdiff
path: root/src/parser/parser_stmt.c
diff options
context:
space:
mode:
authorZuhaitz Méndez Fernández de Aránguiz <zuhaitz@debian>2026-02-01 11:19:34 +0000
committerZuhaitz Méndez Fernández de Aránguiz <zuhaitz@debian>2026-02-01 11:19:34 +0000
commitf14c26996e2f69aaa25e284dd40320f9c00079e3 (patch)
tree7e93f1fe2ef2bbd82c16169bdfa46594b68c4f76 /src/parser/parser_stmt.c
parentaafd7e8739b14dd89b2e81148f2b07710f3c2c42 (diff)
Fix for #167
Diffstat (limited to 'src/parser/parser_stmt.c')
-rw-r--r--src/parser/parser_stmt.c35
1 files changed, 27 insertions, 8 deletions
diff --git a/src/parser/parser_stmt.c b/src/parser/parser_stmt.c
index 0677cf5..ae16243 100644
--- a/src/parser/parser_stmt.c
+++ b/src/parser/parser_stmt.c
@@ -842,7 +842,7 @@ ASTNode *parse_asm(ParserContext *ctx, Lexer *l)
}
}
- // Parse clobbers (: "eax", "memory")
+ // Parse clobbers (: "eax", "memory" OR : clobber("eax"), clobber("memory"))
char **clobbers = NULL;
int num_clobbers = 0;
@@ -865,17 +865,36 @@ ASTNode *parse_asm(ParserContext *ctx, Lexer *l)
continue;
}
- if (t.type == TOK_STRING)
+ // check for clobber("...")
+ if (t.type == TOK_IDENT && strncmp(t.start, "clobber", 7) == 0)
{
- lexer_next(l);
- // Extract string content
- char *clob = xmalloc(t.len);
- strncpy(clob, t.start + 1, t.len - 2);
- clob[t.len - 2] = 0;
- clobbers[num_clobbers++] = clob;
+ lexer_next(l); // eat clobber
+ if (lexer_peek(l).type != TOK_LPAREN)
+ {
+ zpanic_at(lexer_peek(l), "Expected ( after clobber");
+ }
+ lexer_next(l); // eat (
+
+ Token clob = lexer_next(l);
+ if (clob.type != TOK_STRING)
+ {
+ zpanic_at(clob, "Expected string literal for clobber");
+ }
+
+ if (lexer_peek(l).type != TOK_RPAREN)
+ {
+ zpanic_at(lexer_peek(l), "Expected ) after clobber string");
+ }
+ lexer_next(l); // eat )
+
+ char *c = xmalloc(clob.len);
+ strncpy(c, clob.start + 1, clob.len - 2);
+ c[clob.len - 2] = 0;
+ clobbers[num_clobbers++] = c;
}
else
{
+ zpanic_at(t, "Expected 'clobber(\"...\")' in clobber list");
break;
}
}