Lower asm expressions

This commit is contained in:
Lukas Wirth 2024-09-01 15:17:52 +02:00
parent 86658c66b4
commit 3b11ff8c4d
14 changed files with 612 additions and 97 deletions

View file

@ -329,9 +329,11 @@ fn parse_asm_expr(p: &mut Parser<'_>, m: Marker) -> Option<CompletedMarker> {
break;
}
let op = p.start();
// Parse clobber_abi
if p.eat_contextual_kw(T![clobber_abi]) {
parse_clobber_abi(p);
op.complete(p, ASM_CLOBBER_ABI);
allow_templates = false;
continue;
}
@ -339,6 +341,7 @@ fn parse_asm_expr(p: &mut Parser<'_>, m: Marker) -> Option<CompletedMarker> {
// Parse options
if p.eat_contextual_kw(T![options]) {
parse_options(p);
op.complete(p, ASM_OPTIONS);
allow_templates = false;
continue;
}
@ -353,27 +356,14 @@ fn parse_asm_expr(p: &mut Parser<'_>, m: Marker) -> Option<CompletedMarker> {
false
};
let op = p.start();
if p.eat(T![in]) {
let dir_spec = p.start();
if p.eat(T![in]) || p.eat_contextual_kw(T![out]) || p.eat_contextual_kw(T![lateout]) {
dir_spec.complete(p, ASM_DIR_SPEC);
parse_reg(p);
expr(p);
op.complete(p, ASM_REG_OPERAND);
} else if p.eat_contextual_kw(T![out]) {
parse_reg(p);
expr(p);
op.complete(p, ASM_REG_OPERAND);
} else if p.eat_contextual_kw(T![lateout]) {
parse_reg(p);
expr(p);
op.complete(p, ASM_REG_OPERAND);
} else if p.eat_contextual_kw(T![inout]) {
parse_reg(p);
expr(p);
if p.eat(T![=>]) {
expr(p);
}
op.complete(p, ASM_REG_OPERAND);
} else if p.eat_contextual_kw(T![inlateout]) {
} else if p.eat_contextual_kw(T![inout]) || p.eat_contextual_kw(T![inlateout]) {
dir_spec.complete(p, ASM_DIR_SPEC);
parse_reg(p);
expr(p);
if p.eat(T![=>]) {
@ -381,21 +371,26 @@ fn parse_asm_expr(p: &mut Parser<'_>, m: Marker) -> Option<CompletedMarker> {
}
op.complete(p, ASM_REG_OPERAND);
} else if p.eat_contextual_kw(T![label]) {
dir_spec.abandon(p);
block_expr(p);
op.complete(p, ASM_LABEL);
} else if p.eat(T![const]) {
dir_spec.abandon(p);
expr(p);
op.complete(p, ASM_CONST);
} else if p.eat_contextual_kw(T![sym]) {
expr(p);
dir_spec.abandon(p);
paths::type_path(p);
op.complete(p, ASM_SYM);
} else if allow_templates {
dir_spec.abandon(p);
op.abandon(p);
if expr(p).is_none() {
p.err_and_bump("expected asm template");
}
continue;
} else {
dir_spec.abandon(p);
op.abandon(p);
p.err_and_bump("expected asm operand");
if p.at(T!['}']) {
@ -424,11 +419,12 @@ fn parse_options(p: &mut Parser<'_>) {
T![att_syntax],
T![raw],
];
if !OPTIONS.iter().any(|&syntax| p.eat(syntax)) {
let m = p.start();
if !OPTIONS.iter().any(|&syntax| p.eat_contextual_kw(syntax)) {
p.err_and_bump("expected asm option");
continue;
}
m.complete(p, ASM_OPTION);
// Allow trailing commas
if p.eat(T![')']) {