Skip to content

Commit

Permalink
v: parser: rv64: asm: Support for base+displacement addressing
Browse files Browse the repository at this point in the history
  • Loading branch information
raw-bin committed Feb 22, 2024
1 parent 0a4aa81 commit 5b787bb
Showing 1 changed file with 26 additions and 2 deletions.
28 changes: 26 additions & 2 deletions vlib/v/parser/parser.v
Original file line number Diff line number Diff line change
Expand Up @@ -1313,8 +1313,15 @@ fn (mut p Parser) asm_stmt(is_top_level bool) ast.AsmStmt {
pos: number_lit.pos
}
} else {
args << ast.IntegerLiteral{
...number_lit
if arch == .rv64 {
if (p.tok.kind == .lpar) && (p.peek_token(2).kind == .rpar) {
mut addressing := p.asm_addressing_rv64()
args << addressing
}
} else {
args << ast.IntegerLiteral{
...number_lit
}
}
}
}
Expand Down Expand Up @@ -1567,6 +1574,23 @@ fn (mut p Parser) reg_or_alias() ast.AsmArg {
// }
// }

fn (mut p Parser) asm_addressing_rv64() ast.AsmAddressing {
pos := p.tok.pos()
p.check(.lpar)
displacement := ast.AsmArg(ast.AsmDisp{
val: p.peek_token(-2).lit
pos: p.tok.pos()
})
base := p.reg_or_alias()
p.check(.rpar)
return ast.AsmAddressing{
mode: .base_plus_displacement
base: base
displacement: displacement
pos: pos.extend(p.prev_tok.pos())
}
}

fn (mut p Parser) asm_addressing() ast.AsmAddressing {
pos := p.tok.pos()
p.check(.lsbr)
Expand Down

0 comments on commit 5b787bb

Please sign in to comment.