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
pos token.Position
pub mut:
segment string // fs:
displacement AsmArg // 8, 16 or 32 bit literal value
base 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')
}
ast.AsmAddressing {
if arg.segment != '' {
g.write('%%$arg.segment:')
}
base := arg.base
index := arg.index
displacement := arg.displacement
@ -2500,7 +2503,6 @@ fn (mut g Gen) asm_arg(arg ast.AsmArg, stmt ast.AsmStmt) {
}
.displacement {
g.asm_arg(displacement, stmt)
g.write('()')
}
.base_plus_displacement {
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 {
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 {
.name {
args << p.reg_or_alias()
@ -985,7 +991,9 @@ fn (mut p Parser) asm_stmt(is_top_level bool) ast.AsmStmt {
break
}
.lsbr {
args << p.asm_addressing()
mut addressing := p.asm_addressing()
addressing.segment = segment
args << addressing
}
.rcbr {
break