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

pull/9622/head
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.scope = scope
p.check(.semicolon) p.check(.semicolon)
for p.tok.kind == .name { 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{} mut comments := []ast.Comment{}
for p.tok.kind == .comment { for p.tok.kind == .comment {
comments << p.comment() comments << p.comment()
} }
if reg is ast.AsmRegister {
clobbered << ast.AsmClobbered{ clobbered << ast.AsmClobbered{
reg: reg reg: reg
comments: comments comments: comments
} }
} else {
p.error('not a register: $reg')
}
if p.tok.kind in [.rcbr, .semicolon] { if p.tok.kind in [.rcbr, .semicolon] {
break break
} }

View File

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