diff --git a/src/ch2/quicksort.rs b/src/ch2/quicksort.rs index 309792e..a7d4568 100644 --- a/src/ch2/quicksort.rs +++ b/src/ch2/quicksort.rs @@ -3,8 +3,8 @@ pub mod tests { use compiler::backend::*; #[test] - pub fn quicksort() { - let quickSort = Func::new("QuickSort".into(), Vec::new()); + pub fn quicksort_example() { + let mut quickSort = Func::new("QuickSort".into(), Vec::new()); let mut bb0 = Block::new("bb0".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(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 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); } }