From: Bryan English Date: Sat, 22 Aug 2026 02:48:28 +0000 (-0400) Subject: more labels in asm output X-Git-Url: https://rethought.computer/gitweb//gitweb//git?a=commitdiff_plain;h=01630460a1c488e170996ac23995d578394ee355;p=sorel-lang.git more labels in asm output --- diff --git a/sorel-codegen/src/lib.rs b/sorel-codegen/src/lib.rs index 72a6c86..577501c 100644 --- a/sorel-codegen/src/lib.rs +++ b/sorel-codegen/src/lib.rs @@ -1,2 +1 @@ pub mod riscv64_asm; - diff --git a/sorel-codegen/src/riscv64_asm.rs b/sorel-codegen/src/riscv64_asm.rs index 4b2f272..b276366 100644 --- a/sorel-codegen/src/riscv64_asm.rs +++ b/sorel-codegen/src/riscv64_asm.rs @@ -216,18 +216,22 @@ impl<'a> CodeGen<'a> { self.copy_to_top_of_stack("t0"); }, IR::Store8 => { // ( x addr -- ) + self.label("# store 8"); self.pop_some_to("t0 t1"); self.line("sb t0, 0(t1)"); // store x at addr }, IR::Store16 => { // ( x addr -- ) + self.label("# store 16"); self.pop_some_to("t0 t1"); self.line("sh t0, 0(t1)"); // store x at addr }, IR::Store32 => { // ( x addr -- ) + self.label("# store 32"); self.pop_some_to("t0 t1"); self.line("sw t0, 0(t1)"); // store x at addr }, IR::Store => { // ( x addr -- ) + self.label("# store 64"); self.pop_some_to("t0 t1"); self.line("sd t0, 0(t1)"); // store x at addr }, @@ -250,12 +254,15 @@ impl<'a> CodeGen<'a> { self.pop_call_push("t0 t1", "sub t0, t0, t1", "t0"); }, IR::MultiplyU64 => { + self.label("# multiply"); self.pop_call_push("t0 t1", "mul t0, t0, t1", "t0"); }, IR::DivideU64 => { + self.label("# divide"); self.pop_call_push("t0 t1", "div t0, t0, t1", "t0"); }, IR::ModU64 => { + self.label("# mod"); self.pop_call_push("t0 t1", "rem t0, t0, t1", "t0"); }, IR::Dup => { @@ -300,6 +307,7 @@ impl<'a> CodeGen<'a> { self.move_stack_ptr_by_cells(1); }, IR::Equals => { + self.label("# equals"); // Yes, this is the same as subtract, since we're treating 0 as true, and // others as false. self.pop_call_push("t0 t1", "sub t0, t0, t1", "t0"); @@ -319,27 +327,35 @@ impl<'a> CodeGen<'a> { self.push_from("t0"); }, IR::BitwiseOr => { + self.label("# |"); self.pop_call_push("t0 t1", "or t0, t0, t1", "t0"); }, IR::Sys0 => { + self.label("# syscall 0 args"); self.pop_call_push("a7", "ecall", "a0"); }, IR::Sys1 => { + self.label("# syscall 1 arg"); self.pop_call_push("a0 a7", "ecall", "a0"); }, IR::Sys2 => { + self.label("# syscall 2 args"); self.pop_call_push("a0 a1 a7", "ecall", "a0"); }, IR::Sys3 => { + self.label("# syscall 3 args"); self.pop_call_push("a0 a1 a2 a7", "ecall", "a0"); }, IR::Sys4 => { + self.label("# syscall 4 args"); self.pop_call_push("a0 a1 a2 a3 a7", "ecall", "a0"); }, IR::Sys5 => { + self.label("# syscall 5 args"); self.pop_call_push("a0 a1 a2 a3 a4 a7", "ecall", "a0"); }, IR::Sys6 => { + self.label("# syscall 6 args"); self.pop_call_push("a0 a1 a2 a3 a4 a5 a7", "ecall", "a0"); }, // https://cmput229.github.io/229-labs-RISCV/RISC-V-Examples_Public/03-Conditionals/03b-If_Else.html