asm: add segment addressing and fix [10] (#12068)

pull/12077/head
crthpl 2021-10-05 08:57:15 -07:00 committed by GitHub
parent 514443a019
commit 7cf9c198fe
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 13 additions and 2 deletions

View File

@ -1260,6 +1260,7 @@ pub:
mode AddressingMode mode AddressingMode
pos token.Position pos token.Position
pub mut: pub mut:
segment string // fs:
displacement AsmArg // 8, 16 or 32 bit literal value displacement AsmArg // 8, 16 or 32 bit literal value
base AsmArg // gpr base AsmArg // gpr
index AsmArg // gpr index AsmArg // gpr

View File

@ -2488,6 +2488,9 @@ fn (mut g Gen) asm_arg(arg ast.AsmArg, stmt ast.AsmStmt) {
g.write('%$arg.name') g.write('%$arg.name')
} }
ast.AsmAddressing { ast.AsmAddressing {
if arg.segment != '' {
g.write('%%$arg.segment:')
}
base := arg.base base := arg.base
index := arg.index index := arg.index
displacement := arg.displacement displacement := arg.displacement
@ -2500,7 +2503,6 @@ fn (mut g Gen) asm_arg(arg ast.AsmArg, stmt ast.AsmStmt) {
} }
.displacement { .displacement {
g.asm_arg(displacement, stmt) g.asm_arg(displacement, stmt)
g.write('()')
} }
.base_plus_displacement { .base_plus_displacement {
g.asm_arg(displacement, stmt) g.asm_arg(displacement, stmt)

View File

@ -942,6 +942,12 @@ fn (mut p Parser) asm_stmt(is_top_level bool) ast.AsmStmt {
if p.prev_tok.position().line_nr < p.tok.position().line_nr { if p.prev_tok.position().line_nr < p.tok.position().line_nr {
break break
} }
mut segment := ''
if p.tok.kind == .name && p.peek_tok.kind == .colon {
segment = p.tok.lit
p.next()
p.next()
}
match p.tok.kind { match p.tok.kind {
.name { .name {
args << p.reg_or_alias() args << p.reg_or_alias()
@ -985,7 +991,9 @@ fn (mut p Parser) asm_stmt(is_top_level bool) ast.AsmStmt {
break break
} }
.lsbr { .lsbr {
args << p.asm_addressing() mut addressing := p.asm_addressing()
addressing.segment = segment
args << addressing
} }
.rcbr { .rcbr {
break break