modified: src/ch2/quicksort.rs

This commit is contained in:
wangfiox 2024-06-10 18:45:37 +08:00
parent 61a4e5a461
commit b9716ac8c9
1 changed files with 38 additions and 3 deletions

View File

@ -3,8 +3,8 @@ pub mod tests {
use compiler::backend::*; use compiler::backend::*;
#[test] #[test]
pub fn quicksort() { pub fn quicksort_example() {
let quickSort = Func::new("QuickSort".into(), Vec::new()); let mut quickSort = Func::new("QuickSort".into(), Vec::new());
let mut bb0 = Block::new("bb0".into()); let mut bb0 = Block::new("bb0".into());
let addispsp_32 = Inst::Add(AddInst::new(REG_SP.into(), REG_SP.into(), (-32).into())); let addispsp_32 = Inst::Add(AddInst::new(REG_SP.into(), REG_SP.into(), (-32).into()));
@ -173,7 +173,42 @@ pub mod tests {
bb16.push_inst(mvs0a2); bb16.push_inst(mvs0a2);
bb16.push_inst(jlbb0_2); bb16.push_inst(jlbb0_2);
let lbb0_17 = Block::new("LBB0_17".into()); let mut lbb0_17 = Block::new("LBB0_17".into());
// let lia00 = Inst::Li(LiInst::new(REG_A0.into(), (0).into())); // let lia00 = Inst::Li(LiInst::new(REG_A0.into(), (0).into()));
let ldra24sp = Inst::Ld(LdInst::new(REG_RA.into(), (24).into(), REG_SP.into()));
let lds016sp = Inst::Ld(LdInst::new(REG_S0.into(), (16).into(), REG_SP.into()));
let lds18sp = Inst::Ld(LdInst::new(REG_S1.into(), (8).into(), REG_SP.into()));
let lds20sp = Inst::Ld(LdInst::new(REG_S2.into(), (0).into(), REG_SP.into()));
let addispsp32 = Inst::Add(AddInst::new(REG_SP.into(), REG_SP.into(), (32).into()));
let ret = Inst::Ret;
// li
lbb0_17.push_inst(ldra24sp);
lbb0_17.push_inst(lds016sp);
lbb0_17.push_inst(lds18sp);
lbb0_17.push_inst(lds20sp);
lbb0_17.push_inst(addispsp32);
lbb0_17.push_inst(ret);
quickSort.push_bb(bb0);
quickSort.push_bb(bb1);
quickSort.push_bb(lbb0_2);
quickSort.push_bb(lbb0_3);
quickSort.push_bb(bb4);
quickSort.push_bb(lbb0_5);
quickSort.push_bb(llb0_6);
quickSort.push_bb(lbb0_7);
quickSort.push_bb(bb8);
quickSort.push_bb(lbb0_9);
quickSort.push_bb(bb10);
quickSort.push_bb(lbb0_11);
quickSort.push_bb(lbb0_12);
quickSort.push_bb(lbb0_13);
quickSort.push_bb(lbb0_14);
quickSort.push_bb(lbb0_15);
quickSort.push_bb(bb16);
quickSort.push_bb(lbb0_17);
let asm = quickSort.gen_asm();
print!("{}", asm);
} }
} }