From 5b787bbffc7d4522822b85dfa215c6ff0e8f791f Mon Sep 17 00:00:00 2001 From: Robin Randhawa Date: Thu, 22 Feb 2024 15:09:16 +0000 Subject: [PATCH] v: parser: rv64: asm: Support for base+displacement addressing --- vlib/v/parser/parser.v | 28 ++++++++++++++++++++++++++-- 1 file changed, 26 insertions(+), 2 deletions(-) diff --git a/vlib/v/parser/parser.v b/vlib/v/parser/parser.v index 4a0ee6a29ee751..9676df3df52daa 100644 --- a/vlib/v/parser/parser.v +++ b/vlib/v/parser/parser.v @@ -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 + } } } } @@ -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)