From 9cc7d29143910af2f4c3787413b7a00a76f71c7d Mon Sep 17 00:00:00 2001 From: wangfiox Date: Tue, 11 Jun 2024 18:50:51 +0800 Subject: [PATCH] modified: .gitignore modified: src/ch2/linkedlist.rs modified: src/ch2/mod.rs --- .gitignore | 1 + src/ch2/linkedlist.rs | 22 ++++++++++++++++++++-- src/ch2/mod.rs | 2 ++ 3 files changed, 23 insertions(+), 2 deletions(-) diff --git a/.gitignore b/.gitignore index ea8c4bf..3a8cabc 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ /target +.idea diff --git a/src/ch2/linkedlist.rs b/src/ch2/linkedlist.rs index b6755ea..de02c09 100644 --- a/src/ch2/linkedlist.rs +++ b/src/ch2/linkedlist.rs @@ -1,10 +1,28 @@ pub mod tests { - use compiler::backend::{AddInst, Block, BranchInst, BranchOp, Inst, JmpInst, MvInst, REG_A0, REG_A1, REG_A2, REG_RA, REG_S0, REG_S1, REG_S2, REG_SP, SdInst}; + use compiler::backend::{AddInst, Block, BranchInst, BranchOp, CallInst, Inst, JmpInst, MvInst, REG_A0, REG_A1, REG_A2, REG_RA, REG_S0, REG_S1, REG_S2, REG_SP, REG_ZERO, SdInst}; + use compiler::backend::Inst::Call; #[test] pub fn linked() { // createLinkedList let mut entry = Block::new("entry".into()); - let addispsp_16 = Inst::Add(AddInst::new(REG_SP.into(), REG_SP.into())) + let addispsp_16 = Inst::Add(AddInst::new(REG_SP.into(), REG_SP.into(), (-16).into())); + let lia08 = Inst::Add(AddInst::new(REG_A0.into(), REG_ZERO.into(), (-16).into())); + let sdra8sp = Inst::Sd(SdInst::new(REG_RA.into(), (8).into(), REG_SP.into())); + let sds00sp = Inst::Sd(SdInst::new(REG_S0.into(), (0).into(), REG_SP.into())); + let callmalloc = Inst::Call(CallInst::new("malloc@plt".into())); + let beqa0zerol2 = Inst::Branch(BranchInst::new(BranchOp::Beq, REG_A0.into(), REG_ZERO.into(), "L2".into())); + let mvs0a0 = Inst::Mv(MvInst::new(REG_S0.into(), REG_A0.into())); + let lia016 = Inst::Add(AddInst::new(REG_A0.into(), REG_ZERO.into(), (16).into())); + let callmalloc = Inst::Call(CallInst::new("malloc@plt".into())); + let sda00s0 = Inst::Sd(SdInst::new(REG_A0.into(), (0).into(), REG_S0.into())); + let beqa0zerol3 = Inst::Branch(BranchInst::new(BranchOp::Beq, REG_A0.into(), REG_ZERO.into(), "L3".into())); + + + + + + + } } \ No newline at end of file diff --git a/src/ch2/mod.rs b/src/ch2/mod.rs index 7c5c655..29d95b6 100644 --- a/src/ch2/mod.rs +++ b/src/ch2/mod.rs @@ -1,3 +1,5 @@ mod quicksort; +mod linkedlist; pub use quicksort::*; +pub use linkedlist::*;