1
0
mirror of https://github.com/vlang/v.git synced 2023-08-10 21:13:21 +03:00

parser: asm: add support for memory clobbers (#9618)

This commit is contained in:
crthpl 2021-04-06 12:25:24 -07:00 committed by GitHub
parent 89838f2e21
commit 018a88c3ce
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 11 additions and 8 deletions

View File

@ -1008,20 +1008,22 @@ fn (mut p Parser) asm_stmt(is_top_level bool) ast.AsmStmt {
p.scope = scope
p.check(.semicolon)
for p.tok.kind == .name {
reg := p.reg_or_alias()
reg := ast.AsmRegister{
name: p.tok.lit
typ: 0
size: -1
}
p.check(.name)
mut comments := []ast.Comment{}
for p.tok.kind == .comment {
comments << p.comment()
}
if reg is ast.AsmRegister {
clobbered << ast.AsmClobbered{
reg: reg
comments: comments
}
} else {
p.error('not a register: $reg')
clobbered << ast.AsmClobbered{
reg: reg
comments: comments
}
if p.tok.kind in [.rcbr, .semicolon] {
break
}

View File

@ -92,6 +92,7 @@ fn test_inline_asm() {
addq [in_data + rcx * 4 + 0], 2
; ; c (n.len - 1) // c is counter (loop) register
r (n.data) as in_data
; memory
}
assert n == [7, 11, 2, 6]