summaryrefslogtreecommitdiff
path: root/src/parser
diff options
context:
space:
mode:
authorLam Wei Lun <weilun.lam@gmail.com>2026-02-01 20:23:54 +0800
committerLam Wei Lun <weilun.lam@gmail.com>2026-02-01 20:23:54 +0800
commitc4b73a1e99bda3cdfabe7ff3b64066b310ee7292 (patch)
treea9ac8db385f82865e1bed5798ceaf63920587b2d /src/parser
parentfcc9210aa32d671e16b392cf48546c4e2001ff8f (diff)
parenteafd8c67012ea253436b79f703dc0702046703f8 (diff)
Merge with main
Diffstat (limited to 'src/parser')
-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;
}
}