aboutsummaryrefslogtreecommitdiff
path: root/tasm/src/parser.y
diff options
context:
space:
mode:
authorKimplul <kimi.h.kuparinen@gmail.com>2024-03-31 23:10:44 +0300
committerKimplul <kimi.h.kuparinen@gmail.com>2024-03-31 23:10:44 +0300
commitab276c733ce9dc80983e5c8ae5c530e1477cf990 (patch)
treeef5da32c91d27da7a53a26e8d501f0ea616558c8 /tasm/src/parser.y
parenta152fbd956cc9cb9c05a233abe004ba3d12767a0 (diff)
downloadtri-ab276c733ce9dc80983e5c8ae5c530e1477cf990.tar.gz
tri-ab276c733ce9dc80983e5c8ae5c530e1477cf990.zip
implement more meta instructions
+ Also have a working draft of ABI names for registers, matches qbt currently but should probably codify somewhere
Diffstat (limited to 'tasm/src/parser.y')
-rw-r--r--tasm/src/parser.y24
1 files changed, 16 insertions, 8 deletions
diff --git a/tasm/src/parser.y b/tasm/src/parser.y
index 204fe0a..bb3090f 100644
--- a/tasm/src/parser.y
+++ b/tasm/src/parser.y
@@ -73,7 +73,7 @@
%token ecall ebreak pcall
%token fence
/* meta */
-%token mv li la nop
+%token mv li la nop call ret ble bgt
/* m (avoid name clash with stdlib div) */
%token mul diV rem
@@ -312,11 +312,11 @@ i
{emit_reloc(ctx, RELOC_B, $6);
emit_s(ctx, OPCODE_BRANCH, BRANCH_BGE, $2, $4, 0);}
- | ld width "," gpr "," imm "(" gpr ")"
- {emit_i(ctx, OPCODE_LOAD, check_width($2), $4, $8, $6);}
+ | ld width gpr "," imm "(" gpr ")"
+ {emit_i(ctx, OPCODE_LOAD, $3, check_width($2), $7, $5);}
- | st width "," gpr "," imm "(" gpr ")"
- {emit_s(ctx, OPCODE_STORE, check_width($2), $4, $8, $6);}
+ | st width gpr "," imm "(" gpr ")"
+ {emit_s(ctx, OPCODE_STORE, check_width($2), $3, $7, $5);}
| ecall
{emit_i(ctx, OPCODE_SYSTEM, X0_NUM, SYSTEM_ECALL, X0_NUM, 0);}
@@ -349,10 +349,18 @@ i
emit_i(ctx, OPCODE_OP_IMM, $2, OP_IMM_ADDI, $2, 0);}
| li gpr "," imm
- {emit_u(ctx, OPCODE_LUI, $2, tri_sr($4, 9));
+ {/** @todo skip lui if we can avoid it? */
+ emit_u(ctx, OPCODE_LUI, $2, tri_sr($4, 9));
emit_i(ctx, OPCODE_OP_IMM, $2, OP_IMM_ADDI, $2, tri_mask($4, 9));}
- /* stuff like call and ret TBD once I've come up with a proper register
- * calling convention so we know which register to use as ra */
+ | call gpr "," addr
+ {emit_reloc(ctx, RELOC_CALL, $4);
+ emit_u(ctx, OPCODE_AUIPC, $2, 0);
+ emit_i(ctx, OPCODE_JALR, $2, 0, $2, 0);}
+ | ret gpr
+ {emit_i(ctx, OPCODE_JALR, X0_NUM, 0, $2, 0);}
+ | ble gpr "," gpr "," addr
+ {emit_reloc(ctx, RELOC_B, $6);
+ emit_s(ctx, OPCODE_BRANCH, BRANCH_BGE, $4, $2, 0);}
m
: mul gpr "," gpr "," gpr