use min_infmachine_lltk::builder::*;
use min_infmachine_lltk::handler_builder::*;
use min_infmachine_lltk::*;
#[test]
fn test_handler_builder_1() {
let mut builder = mi_simple_hbuilder_new_1(Some(1));
{
let (func1b, ret) = builder.add_routine("func1", false);
let mut func1b = func1b.borrow_mut();
func1b.i(MINF_MR);
func1b.i(MINF_TBRF);
func1b.i(MINF_TBB);
func1b.i((MINF_TBRW1, MINF_TBRW0, ret));
}
{
let (func2b, ret) = builder.add_routine("func2", true);
let mut func2b = func2b.borrow_mut();
func2b.i(MINF_MRW0);
func2b.i(MINF_MAB);
func2b.i((MINF_MARW0, MINF_MARW1));
func2b.i((MINF_MR, ret));
}
builder.i(MINF_MRW0);
builder.call_01("func1", MINF_MR);
builder.i(MINF_TBR);
builder.call_01("func1", MINF_MAR);
builder.i(MINF_MRW1);
builder.call_01("func2", MINF_TBR);
builder.i(MINF_TBRW1);
builder.call_01("func2", MINF_TBR);
builder.i(MINF_STOP);
assert_eq!(
(
vec![
MinInfInstr::new(MINF_MRW0, MINF_MRW0, 1, 1),
(MINF_MR, MINF_MR, 9, 9).into(),
(MINF_TBR, MINF_TBR, 3, 3).into(),
(MINF_MAR, MINF_MAR, 11, 11).into(),
(MINF_MRW1, MINF_MRW1, 5, 5).into(),
(MINF_TBR, MINF_TBR, 16, 16).into(),
(MINF_TBRW1, MINF_TBRW1, 7, 7).into(),
(MINF_TBR, MINF_TBR, 18, 18).into(),
(MINF_STOP, MINF_STOP, 9, 9).into(),
(MINF_MARW0, MINF_MARW0, 10, 10).into(),
(MINF_MARF, MINF_MARF, 23, 23).into(),
(MINF_MARW1, MINF_MARW1, 12, 12).into(),
(MINF_MARF, MINF_MARF, 23, 23).into(),
(MINF_MAB, MINF_MAB, 14, 14).into(),
(MINF_MARW0, MINF_MARW0, 15, 15).into(),
(MINF_MR, MINF_MR, 2, 4).into(),
(MINF_TBRW0, MINF_TBRW0, 17, 17).into(),
(MINF_TBRF, MINF_TBRF, 27, 27).into(),
(MINF_TBRW1, MINF_TBRW1, 19, 19).into(),
(MINF_TBRF, MINF_TBRF, 27, 27).into(),
(MINF_TBB, MINF_TBB, 21, 21).into(),
(MINF_TBRW0, MINF_TBRW0, 22, 22).into(),
(MINF_MR, MINF_MR, 6, 8).into(),
(MINF_MR, MINF_MR, 24, 24).into(),
(MINF_TBRF, MINF_TBRF, 25, 25).into(),
(MINF_TBB, MINF_TBB, 26, 26).into(),
(MINF_TBRW1, MINF_TBRW0, 13, 13).into(),
(MINF_MRW0, MINF_MRW0, 28, 28).into(),
(MINF_MAB, MINF_MAB, 29, 29).into(),
(MINF_MARW0, MINF_MARW1, 30, 30).into(),
(MINF_MR, MINF_MR, 20, 20).into()
],
vec![
("func1".to_string(), 23),
("func1_0_putret_x_0".to_string(), 9),
("func1_0_putret_x_1".to_string(), 11),
("func1_after_ret_0".to_string(), 2),
("func1_after_ret_1".to_string(), 4),
("func1_return".to_string(), 13),
("func1_return_id_0_0".to_string(), 14),
("func2".to_string(), 27),
("func2_0_putret_x_0".to_string(), 16),
("func2_0_putret_x_1".to_string(), 18),
("func2_after_ret_0".to_string(), 6),
("func2_after_ret_1".to_string(), 8),
("func2_return".to_string(), 20),
("func2_return_id_0_0".to_string(), 21)
]
),
builder.to_code()
);
let mut builder = mi_simple_hbuilder_new_1(Some(1));
{
let (func1b, ret) = builder.add_routine("func1", false);
let mut func1b = func1b.borrow_mut();
{
let (func2b, ret) = func1b.add_routine("func2", true);
let mut func2b = func2b.borrow_mut();
func2b.i(MINF_MRW0);
func2b.i(MINF_MAB);
func2b.i((MINF_MARW0, MINF_MARW1));
func2b.i((MINF_MR, ret));
}
func1b.i(MINF_MR);
func1b.i(MINF_TBRF);
func1b.i(MINF_TBB);
func1b.i((MINF_TBRW1, MINF_TBRW0, ret));
}
builder.i(MINF_MRW0);
builder.call_01("func1", MINF_MR);
builder.i(MINF_TBR);
builder.call_01("func1", MINF_MAR);
builder.i(MINF_MRW1);
builder.call_01("func2", MINF_TBR);
builder.i(MINF_TBRW1);
builder.call_01("func2", MINF_TBR);
builder.i(MINF_STOP);
assert_eq!(
(
vec![
MinInfInstr::new(MINF_MRW0, MINF_MRW0, 1, 1),
(MINF_MR, MINF_MR, 9, 9).into(),
(MINF_TBR, MINF_TBR, 3, 3).into(),
(MINF_MAR, MINF_MAR, 11, 11).into(),
(MINF_MRW1, MINF_MRW1, 5, 5).into(),
(MINF_TBR, MINF_TBR, 16, 16).into(),
(MINF_TBRW1, MINF_TBRW1, 7, 7).into(),
(MINF_TBR, MINF_TBR, 18, 18).into(),
(MINF_STOP, MINF_STOP, 9, 9).into(),
(MINF_MARW0, MINF_MARW0, 10, 10).into(),
(MINF_MARF, MINF_MARF, 23, 23).into(),
(MINF_MARW1, MINF_MARW1, 12, 12).into(),
(MINF_MARF, MINF_MARF, 23, 23).into(),
(MINF_MAB, MINF_MAB, 14, 14).into(),
(MINF_MARW0, MINF_MARW0, 15, 15).into(),
(MINF_MR, MINF_MR, 2, 4).into(),
(MINF_TBRW0, MINF_TBRW0, 17, 17).into(),
(MINF_TBRF, MINF_TBRF, 27, 27).into(),
(MINF_TBRW1, MINF_TBRW1, 19, 19).into(),
(MINF_TBRF, MINF_TBRF, 27, 27).into(),
(MINF_TBB, MINF_TBB, 21, 21).into(),
(MINF_TBRW0, MINF_TBRW0, 22, 22).into(),
(MINF_MR, MINF_MR, 6, 8).into(),
(MINF_MR, MINF_MR, 24, 24).into(),
(MINF_TBRF, MINF_TBRF, 25, 25).into(),
(MINF_TBB, MINF_TBB, 26, 26).into(),
(MINF_TBRW1, MINF_TBRW0, 13, 13).into(),
(MINF_MRW0, MINF_MRW0, 28, 28).into(),
(MINF_MAB, MINF_MAB, 29, 29).into(),
(MINF_MARW0, MINF_MARW1, 30, 30).into(),
(MINF_MR, MINF_MR, 20, 20).into()
],
vec![
("func1".to_string(), 23),
("func1_0_putret_x_0".to_string(), 9),
("func1_0_putret_x_1".to_string(), 11),
("func1_after_ret_0".to_string(), 2),
("func1_after_ret_1".to_string(), 4),
("func1_return".to_string(), 13),
("func1_return_id_0_0".to_string(), 14),
("func2".to_string(), 27),
("func2_0_putret_x_0".to_string(), 16),
("func2_0_putret_x_1".to_string(), 18),
("func2_after_ret_0".to_string(), 6),
("func2_after_ret_1".to_string(), 8),
("func2_return".to_string(), 20),
("func2_return_id_0_0".to_string(), 21)
]
),
builder.to_code()
);
}
#[test]
fn test_handler_builder_1_1() {
let mut builder = mi_simple_hbuilder_new_1(Some(1));
{
let (func1b, ret) = builder.add_routine_l("func1".to_string(), false);
let mut func1b = func1b.borrow_mut();
func1b.i(MINF_MR);
func1b.i(MINF_TBRF);
func1b.i(MINF_TBB);
func1b.i((MINF_TBRW1, MINF_TBRW0, ret));
}
{
let (func2b, ret) = builder.add_routine_ll("func2".to_string(), true);
let mut func2b = func2b.borrow_mut();
func2b.i(MINF_MRW0);
func2b.i(MINF_MAB);
func2b.i((MINF_MARW0, MINF_MARW1));
func2b.i((MINF_MR, ret));
}
builder.i(MINF_MRW0);
builder.call_01("func1", MINF_MR);
builder.i(MINF_TBR);
builder.call_01("func1", MINF_MAR);
builder.i(MINF_MRW1);
builder.call_01("func2", MINF_TBR);
builder.i(MINF_TBRW1);
builder.call_01("func2", MINF_TBR);
builder.i(MINF_STOP);
assert_eq!(
(
vec![
MinInfInstr::new(MINF_MRW0, MINF_MRW0, 1, 1),
(MINF_MR, MINF_MR, 9, 9).into(),
(MINF_TBR, MINF_TBR, 3, 3).into(),
(MINF_MAR, MINF_MAR, 11, 11).into(),
(MINF_MRW1, MINF_MRW1, 5, 5).into(),
(MINF_TBR, MINF_TBR, 16, 16).into(),
(MINF_TBRW1, MINF_TBRW1, 7, 7).into(),
(MINF_TBR, MINF_TBR, 18, 18).into(),
(MINF_STOP, MINF_STOP, 9, 9).into(),
(MINF_MARW0, MINF_MARW0, 10, 10).into(),
(MINF_MARF, MINF_MARF, 23, 23).into(),
(MINF_MARW1, MINF_MARW1, 12, 12).into(),
(MINF_MARF, MINF_MARF, 23, 23).into(),
(MINF_MAB, MINF_MAB, 14, 14).into(),
(MINF_MARW0, MINF_MARW0, 15, 15).into(),
(MINF_MR, MINF_MR, 2, 4).into(),
(MINF_TBRW0, MINF_TBRW0, 17, 17).into(),
(MINF_TBRF, MINF_TBRF, 27, 27).into(),
(MINF_TBRW1, MINF_TBRW1, 19, 19).into(),
(MINF_TBRF, MINF_TBRF, 27, 27).into(),
(MINF_TBB, MINF_TBB, 21, 21).into(),
(MINF_TBRW0, MINF_TBRW0, 22, 22).into(),
(MINF_MR, MINF_MR, 6, 8).into(),
(MINF_MR, MINF_MR, 24, 24).into(),
(MINF_TBRF, MINF_TBRF, 25, 25).into(),
(MINF_TBB, MINF_TBB, 26, 26).into(),
(MINF_TBRW1, MINF_TBRW0, 13, 13).into(),
(MINF_MRW0, MINF_MRW0, 28, 28).into(),
(MINF_MAB, MINF_MAB, 29, 29).into(),
(MINF_MARW0, MINF_MARW1, 30, 30).into(),
(MINF_MR, MINF_MR, 20, 20).into()
],
vec![
("func1".to_string(), 23),
("func1_0_putret_x_0".to_string(), 9),
("func1_0_putret_x_1".to_string(), 11),
("func1_after_ret_0".to_string(), 2),
("func1_after_ret_1".to_string(), 4),
("func1_return".to_string(), 13),
("func1_return_id_0_0".to_string(), 14),
("func2".to_string(), 27),
("func2_0_putret_x_0".to_string(), 16),
("func2_0_putret_x_1".to_string(), 18),
("func2_after_ret_0".to_string(), 6),
("func2_after_ret_1".to_string(), 8),
("func2_return".to_string(), 20),
("func2_return_id_0_0".to_string(), 21)
]
),
builder.to_code()
);
}
#[test]
fn test_handler_builder_2() {
let mut builder = mi_simple_hbuilder_new_1(Some(3));
{
let (func1b, ret) = builder.add_routine("func1", false);
let mut func1b = func1b.borrow_mut();
func1b.i(MINF_MR);
func1b.i(MINF_TBRF);
func1b.i(MINF_TBB);
func1b.i((MINF_TBRW1, MINF_TBRW0, ret));
}
{
let (func2b, ret) = builder.add_routine("func2", true);
let mut func2b = func2b.borrow_mut();
func2b.i(MINF_MRW0);
func2b.i(MINF_MAB);
func2b.i((MINF_MARW0, MINF_MARW1));
func2b.i((MINF_MR, ret));
}
builder.i(MINF_MRW0);
builder.call_01("func1", MINF_MR);
builder.i(MINF_TBR);
builder.call("func1", MINF_MAR, MINF_MARW0);
builder.i(MINF_MRW1);
builder.call_fr0_01("func1", MINF_MR, "my_stop");
builder.i(MINF_TBR);
builder.call_fr0("func1", MINF_MRW1, MINF_MRW0, "my_stop");
builder.i(MINF_MRW1);
builder.call_fr1_01("func2", MINF_MR, "my_stop");
builder.i(MINF_TBRW1);
builder.call_fr1("func2", MINF_MRW1, MINF_MRW0, "my_stop");
builder.i(MINF_MRW1);
builder.call_2_01("func1", "func2", MINF_MR);
builder.i(MINF_TBRW1);
builder.call_2("func1", "func2", MINF_MRW0, MINF_MRW1);
builder.i(MINF_STOP);
builder.l("my_stop");
builder.i(MINF_STOP);
assert_eq!(
(
vec![
MinInfInstr::new(MINF_MRW0, MINF_MRW0, 1, 1),
(MINF_MR, MINF_MR, 18, 18).into(),
(MINF_TBR, MINF_TBR, 3, 3).into(),
(MINF_MAR, MINF_MARW0, 20, 20).into(),
(MINF_MRW1, MINF_MRW1, 5, 5).into(),
(MINF_MR, MINF_MR, 22, 17).into(),
(MINF_TBR, MINF_TBR, 7, 7).into(),
(MINF_MRW1, MINF_MRW0, 24, 17).into(),
(MINF_MRW1, MINF_MRW1, 9, 9).into(),
(MINF_MR, MINF_MR, 17, 53).into(),
(MINF_TBRW1, MINF_TBRW1, 11, 11).into(),
(MINF_MRW1, MINF_MRW0, 17, 55).into(),
(MINF_MRW1, MINF_MRW1, 13, 13).into(),
(MINF_MR, MINF_MR, 26, 57).into(),
(MINF_TBRW1, MINF_TBRW1, 15, 15).into(),
(MINF_MRW0, MINF_MRW1, 28, 59).into(),
(MINF_STOP, MINF_STOP, 17, 17).into(),
(MINF_STOP, MINF_STOP, 18, 18).into(),
(MINF_MARW0, MINF_MARW0, 19, 19).into(),
(MINF_MARF, MINF_MARF, 30, 30).into(),
(MINF_MARW1, MINF_MARW1, 21, 21).into(),
(MINF_MARF, MINF_MARF, 30, 30).into(),
(MINF_MARW0, MINF_MARW0, 23, 23).into(),
(MINF_MARF, MINF_MARF, 32, 32).into(),
(MINF_MARW1, MINF_MARW1, 25, 25).into(),
(MINF_MARF, MINF_MARF, 32, 32).into(),
(MINF_MARW0, MINF_MARW0, 27, 27).into(),
(MINF_MARF, MINF_MARF, 34, 34).into(),
(MINF_MARW1, MINF_MARW1, 29, 29).into(),
(MINF_MARF, MINF_MARF, 34, 34).into(),
(MINF_MARW0, MINF_MARW0, 31, 31).into(),
(MINF_MARF, MINF_MARF, 36, 36).into(),
(MINF_MARW1, MINF_MARW1, 33, 33).into(),
(MINF_MARF, MINF_MARF, 36, 36).into(),
(MINF_MARW0, MINF_MARW0, 35, 35).into(),
(MINF_MARF, MINF_MARF, 38, 38).into(),
(MINF_MARW0, MINF_MARW0, 37, 37).into(),
(MINF_MARF, MINF_MARF, 76, 76).into(),
(MINF_MARW1, MINF_MARW1, 39, 39).into(),
(MINF_MARF, MINF_MARF, 76, 76).into(),
(MINF_MAB, MINF_MAB, 41, 41).into(),
(MINF_MARW0, MINF_MARW0, 42, 42).into(),
(MINF_MAB, MINF_MAB, 43, 45).into(),
(MINF_MARW0, MINF_MARW0, 44, 44).into(),
(MINF_MAB, MINF_MAB, 47, 49).into(),
(MINF_MARW0, MINF_MARW0, 46, 46).into(),
(MINF_MAB, MINF_MAB, 51, 51).into(),
(MINF_MARW0, MINF_MARW0, 48, 48).into(),
(MINF_MR, MINF_MR, 2, 4).into(),
(MINF_MARW0, MINF_MARW0, 50, 50).into(),
(MINF_MR, MINF_MR, 6, 8).into(),
(MINF_MARW0, MINF_MARW0, 52, 52).into(),
(MINF_MR, MINF_MR, 14, 16).into(),
(MINF_TBRW0, MINF_TBRW0, 54, 54).into(),
(MINF_TBRF, MINF_TBRF, 61, 61).into(),
(MINF_TBRW1, MINF_TBRW1, 56, 56).into(),
(MINF_TBRF, MINF_TBRF, 61, 61).into(),
(MINF_TBRW0, MINF_TBRW0, 58, 58).into(),
(MINF_TBRF, MINF_TBRF, 63, 63).into(),
(MINF_TBRW1, MINF_TBRW1, 60, 60).into(),
(MINF_TBRF, MINF_TBRF, 63, 63).into(),
(MINF_TBRW0, MINF_TBRW0, 62, 62).into(),
(MINF_TBRF, MINF_TBRF, 65, 65).into(),
(MINF_TBRW1, MINF_TBRW1, 64, 64).into(),
(MINF_TBRF, MINF_TBRF, 65, 65).into(),
(MINF_TBRW0, MINF_TBRW0, 66, 66).into(),
(MINF_TBRF, MINF_TBRF, 80, 80).into(),
(MINF_TBB, MINF_TBB, 68, 68).into(),
(MINF_TBRW0, MINF_TBRW0, 69, 69).into(),
(MINF_TBB, MINF_TBB, 70, 70).into(),
(MINF_TBRW0, MINF_TBRW0, 71, 71).into(),
(MINF_TBB, MINF_TBB, 72, 74).into(),
(MINF_TBRW0, MINF_TBRW0, 73, 73).into(),
(MINF_MR, MINF_MR, 10, 12).into(),
(MINF_TBRW0, MINF_TBRW0, 75, 75).into(),
(MINF_MR, MINF_MR, 14, 16).into(),
(MINF_MR, MINF_MR, 77, 77).into(),
(MINF_TBRF, MINF_TBRF, 78, 78).into(),
(MINF_TBB, MINF_TBB, 79, 79).into(),
(MINF_TBRW1, MINF_TBRW0, 40, 40).into(),
(MINF_MRW0, MINF_MRW0, 81, 81).into(),
(MINF_MAB, MINF_MAB, 82, 82).into(),
(MINF_MARW0, MINF_MARW1, 83, 83).into(),
(MINF_MR, MINF_MR, 67, 67).into(),
],
vec![
("func1".to_string(), 76),
("func1_0_putret_1_0".to_string(), 36),
("func1_0_putret_1_1".to_string(), 38),
("func1_0_putret_2_00".to_string(), 30),
("func1_0_putret_2_01".to_string(), 32),
("func1_0_putret_2_10".to_string(), 34),
("func1_0_putret_x_0".to_string(), 18),
("func1_0_putret_x_1".to_string(), 20),
("func1_0_putret_x_10".to_string(), 22),
("func1_0_putret_x_100".to_string(), 26),
("func1_0_putret_x_101".to_string(), 28),
("func1_0_putret_x_11".to_string(), 24),
("func1_after_ret_0".to_string(), 2),
("func1_after_ret_1".to_string(), 4),
("func1_after_ret_2".to_string(), 6),
("func1_after_ret_3".to_string(), 8),
("func1_after_ret_4".to_string(), 14),
("func1_after_ret_5".to_string(), 16),
("func1_return".to_string(), 40),
("func1_return_id_0_0".to_string(), 41),
("func1_return_id_1_0".to_string(), 43),
("func1_return_id_1_1".to_string(), 45),
("func1_return_id_2_00".to_string(), 47),
("func1_return_id_2_01".to_string(), 49),
("func1_return_id_2_10".to_string(), 51),
("func2".to_string(), 80),
("func2_0_putret_1_0".to_string(), 65),
("func2_0_putret_2_00".to_string(), 61),
("func2_0_putret_2_01".to_string(), 63),
("func2_0_putret_x_0".to_string(), 53),
("func2_0_putret_x_1".to_string(), 55),
("func2_0_putret_x_10".to_string(), 57),
("func2_0_putret_x_11".to_string(), 59),
("func2_after_ret_0".to_string(), 10),
("func2_after_ret_1".to_string(), 12),
("func2_after_ret_2".to_string(), 14),
("func2_after_ret_3".to_string(), 16),
("func2_return".to_string(), 67),
("func2_return_id_0_0".to_string(), 68),
("func2_return_id_1_0".to_string(), 70),
("func2_return_id_2_00".to_string(), 72),
("func2_return_id_2_01".to_string(), 74),
("my_stop".to_string(), 17),
]
),
builder.to_code()
);
}
#[test]
fn test_handler_builder_skip_ret() {
let mut builder = mi_simple_hbuilder_new(Some(3), Some(5));
builder.i(MINF_MRW0);
builder.skip_ret(false);
builder.skip_ret(true);
builder.back_ret(false);
builder.back_ret(true);
builder.i(MINF_STOP);
assert_eq!(
(
vec![
MinInfInstr::new(MINF_MRW0, MINF_MRW0, 1, 1),
(MINF_MARF, MINF_MARF, 2, 2).into(),
(MINF_MARF, MINF_MARF, 3, 3).into(),
(MINF_MARF, MINF_MARF, 4, 4).into(),
(MINF_TBRF, MINF_TBRF, 5, 5).into(),
(MINF_TBRF, MINF_TBRF, 6, 6).into(),
(MINF_TBRF, MINF_TBRF, 7, 7).into(),
(MINF_TBRF, MINF_TBRF, 8, 8).into(),
(MINF_TBRF, MINF_TBRF, 9, 9).into(),
(MINF_MAB, MINF_MAB, 10, 10).into(),
(MINF_MAB, MINF_MAB, 11, 11).into(),
(MINF_MAB, MINF_MAB, 12, 12).into(),
(MINF_TBB, MINF_TBB, 13, 13).into(),
(MINF_TBB, MINF_TBB, 14, 14).into(),
(MINF_TBB, MINF_TBB, 15, 15).into(),
(MINF_TBB, MINF_TBB, 16, 16).into(),
(MINF_TBB, MINF_TBB, 17, 17).into(),
(MINF_STOP, MINF_STOP, 0, 0).into(),
],
vec![]
),
builder.to_code()
);
}
#[test]
fn test_handler_builder_routine_with_multiple_entries() {
let mut builder = mi_simple_hbuilder_new(Some(3), Some(3));
let number = 5;
{
let (builder, ret) = builder.add_routine_with_labels_l(
"routine0",
["routine0_a", "routine0_b", "routine0_c"],
true,
);
let mut builder = builder.borrow_mut();
builder.l("routine0_a");
builder.i((MINF_MR, MinInfRel::from(&ret)));
builder.l("routine0_b");
builder.i((MINF_MR, MinInfRel::from(&ret)));
builder.l("routine0_c");
builder.i((MINF_MR, MinInfRel::from(&ret)));
}
{
let ret_handler = builder.routine_handler("routine0");
let mut ret_handler = ret_handler.borrow_mut();
for i in 0..number {
let cslabel = format!("code{}s", i);
let cretlabel = format!("code{}_ret", i);
ret_handler.add_label(&cslabel, cretlabel);
}
}
let rets = {
let ret_handler = builder.routine_handler("routine0");
let ret_handler = ret_handler.borrow();
(0..number)
.map(|i| {
(0..3)
.map(|j| {
let cslabel = format!("code{}s", i);
ret_handler.jump_to_call_rl(&cslabel, j)
})
.collect::<Vec<_>>()
})
.collect::<Vec<_>>()
};
for i in 0..number {
let cretlabel = format!("code{}_ret", i);
for j in 0..3 {
let clabel = format!("code{}_{}", i, j);
builder.l(clabel.clone());
builder.i(MINF_MR);
builder.i((MINF_MR, MinInfRel::from(&rets[i][j])));
}
builder.l(cretlabel.clone());
builder.i(MINF_MR);
}
assert_eq!(
(
vec![
MinInfInstr::new(MINF_MR, MINF_MR, 1, 1),
(MINF_MR, MINF_MR, 35, 35).into(),
(MINF_MR, MINF_MR, 3, 3).into(),
(MINF_MR, MINF_MR, 55, 55).into(),
(MINF_MR, MINF_MR, 5, 5).into(),
(MINF_MR, MINF_MR, 75, 75).into(),
(MINF_MR, MINF_MR, 7, 7).into(),
(MINF_MR, MINF_MR, 8, 8).into(),
(MINF_MR, MINF_MR, 37, 37).into(),
(MINF_MR, MINF_MR, 10, 10).into(),
(MINF_MR, MINF_MR, 57, 57).into(),
(MINF_MR, MINF_MR, 12, 12).into(),
(MINF_MR, MINF_MR, 77, 77).into(),
(MINF_MR, MINF_MR, 14, 14).into(),
(MINF_MR, MINF_MR, 15, 15).into(),
(MINF_MR, MINF_MR, 39, 39).into(),
(MINF_MR, MINF_MR, 17, 17).into(),
(MINF_MR, MINF_MR, 59, 59).into(),
(MINF_MR, MINF_MR, 19, 19).into(),
(MINF_MR, MINF_MR, 79, 79).into(),
(MINF_MR, MINF_MR, 21, 21).into(),
(MINF_MR, MINF_MR, 22, 22).into(),
(MINF_MR, MINF_MR, 41, 41).into(),
(MINF_MR, MINF_MR, 24, 24).into(),
(MINF_MR, MINF_MR, 61, 61).into(),
(MINF_MR, MINF_MR, 26, 26).into(),
(MINF_MR, MINF_MR, 81, 81).into(),
(MINF_MR, MINF_MR, 28, 28).into(),
(MINF_MR, MINF_MR, 29, 29).into(),
(MINF_MR, MINF_MR, 43, 43).into(),
(MINF_MR, MINF_MR, 31, 31).into(),
(MINF_MR, MINF_MR, 63, 63).into(),
(MINF_MR, MINF_MR, 33, 33).into(),
(MINF_MR, MINF_MR, 83, 83).into(),
(MINF_MR, MINF_MR, 35, 35).into(),
(MINF_TBRW0, MINF_TBRW0, 36, 36).into(),
(MINF_TBRF, MINF_TBRF, 45, 45).into(),
(MINF_TBRW1, MINF_TBRW1, 38, 38).into(),
(MINF_TBRF, MINF_TBRF, 45, 45).into(),
(MINF_TBRW0, MINF_TBRW0, 40, 40).into(),
(MINF_TBRF, MINF_TBRF, 47, 47).into(),
(MINF_TBRW1, MINF_TBRW1, 42, 42).into(),
(MINF_TBRF, MINF_TBRF, 47, 47).into(),
(MINF_TBRW0, MINF_TBRW0, 44, 44).into(),
(MINF_TBRF, MINF_TBRF, 49, 49).into(),
(MINF_TBRW0, MINF_TBRW0, 46, 46).into(),
(MINF_TBRF, MINF_TBRF, 51, 51).into(),
(MINF_TBRW1, MINF_TBRW1, 48, 48).into(),
(MINF_TBRF, MINF_TBRF, 51, 51).into(),
(MINF_TBRW0, MINF_TBRW0, 50, 50).into(),
(MINF_TBRF, MINF_TBRF, 53, 53).into(),
(MINF_TBRW0, MINF_TBRW0, 52, 52).into(),
(MINF_TBRF, MINF_TBRF, 108, 108).into(),
(MINF_TBRW1, MINF_TBRW1, 54, 54).into(),
(MINF_TBRF, MINF_TBRF, 108, 108).into(),
(MINF_TBRW0, MINF_TBRW0, 56, 56).into(),
(MINF_TBRF, MINF_TBRF, 65, 65).into(),
(MINF_TBRW1, MINF_TBRW1, 58, 58).into(),
(MINF_TBRF, MINF_TBRF, 65, 65).into(),
(MINF_TBRW0, MINF_TBRW0, 60, 60).into(),
(MINF_TBRF, MINF_TBRF, 67, 67).into(),
(MINF_TBRW1, MINF_TBRW1, 62, 62).into(),
(MINF_TBRF, MINF_TBRF, 67, 67).into(),
(MINF_TBRW0, MINF_TBRW0, 64, 64).into(),
(MINF_TBRF, MINF_TBRF, 69, 69).into(),
(MINF_TBRW0, MINF_TBRW0, 66, 66).into(),
(MINF_TBRF, MINF_TBRF, 71, 71).into(),
(MINF_TBRW1, MINF_TBRW1, 68, 68).into(),
(MINF_TBRF, MINF_TBRF, 71, 71).into(),
(MINF_TBRW0, MINF_TBRW0, 70, 70).into(),
(MINF_TBRF, MINF_TBRF, 73, 73).into(),
(MINF_TBRW0, MINF_TBRW0, 72, 72).into(),
(MINF_TBRF, MINF_TBRF, 109, 109).into(),
(MINF_TBRW1, MINF_TBRW1, 74, 74).into(),
(MINF_TBRF, MINF_TBRF, 109, 109).into(),
(MINF_TBRW0, MINF_TBRW0, 76, 76).into(),
(MINF_TBRF, MINF_TBRF, 85, 85).into(),
(MINF_TBRW1, MINF_TBRW1, 78, 78).into(),
(MINF_TBRF, MINF_TBRF, 85, 85).into(),
(MINF_TBRW0, MINF_TBRW0, 80, 80).into(),
(MINF_TBRF, MINF_TBRF, 87, 87).into(),
(MINF_TBRW1, MINF_TBRW1, 82, 82).into(),
(MINF_TBRF, MINF_TBRF, 87, 87).into(),
(MINF_TBRW0, MINF_TBRW0, 84, 84).into(),
(MINF_TBRF, MINF_TBRF, 89, 89).into(),
(MINF_TBRW0, MINF_TBRW0, 86, 86).into(),
(MINF_TBRF, MINF_TBRF, 91, 91).into(),
(MINF_TBRW1, MINF_TBRW1, 88, 88).into(),
(MINF_TBRF, MINF_TBRF, 91, 91).into(),
(MINF_TBRW0, MINF_TBRW0, 90, 90).into(),
(MINF_TBRF, MINF_TBRF, 93, 93).into(),
(MINF_TBRW0, MINF_TBRW0, 92, 92).into(),
(MINF_TBRF, MINF_TBRF, 110, 110).into(),
(MINF_TBRW1, MINF_TBRW1, 94, 94).into(),
(MINF_TBRF, MINF_TBRF, 110, 110).into(),
(MINF_TBB, MINF_TBB, 96, 96).into(),
(MINF_TBRW0, MINF_TBRW0, 97, 97).into(),
(MINF_TBB, MINF_TBB, 98, 100).into(),
(MINF_TBRW0, MINF_TBRW0, 99, 99).into(),
(MINF_TBB, MINF_TBB, 102, 104).into(),
(MINF_TBRW0, MINF_TBRW0, 101, 101).into(),
(MINF_TBB, MINF_TBB, 106, 106).into(),
(MINF_TBRW0, MINF_TBRW0, 103, 103).into(),
(MINF_MR, MINF_MR, 6, 13).into(),
(MINF_TBRW0, MINF_TBRW0, 105, 105).into(),
(MINF_MR, MINF_MR, 20, 27).into(),
(MINF_TBRW0, MINF_TBRW0, 107, 107).into(),
(MINF_MR, MINF_MR, 34, 34).into(),
(MINF_MR, MINF_MR, 95, 95).into(),
(MINF_MR, MINF_MR, 95, 95).into(),
(MINF_MR, MINF_MR, 95, 95).into(),
],
vec![
("code0_0".to_string(), 0),
("code0_1".to_string(), 2),
("code0_2".to_string(), 4),
("code0_ret".to_string(), 6),
("code1_0".to_string(), 7),
("code1_1".to_string(), 9),
("code1_2".to_string(), 11),
("code1_ret".to_string(), 13),
("code2_0".to_string(), 14),
("code2_1".to_string(), 16),
("code2_2".to_string(), 18),
("code2_ret".to_string(), 20),
("code3_0".to_string(), 21),
("code3_1".to_string(), 23),
("code3_2".to_string(), 25),
("code3_ret".to_string(), 27),
("code4_0".to_string(), 28),
("code4_1".to_string(), 30),
("code4_2".to_string(), 32),
("code4_ret".to_string(), 34),
("routine0".to_string(), 108),
("routine0_0_putret_1_0".to_string(), 51),
("routine0_0_putret_1_1".to_string(), 53),
("routine0_0_putret_2_00".to_string(), 45),
("routine0_0_putret_2_01".to_string(), 47),
("routine0_0_putret_2_10".to_string(), 49),
("routine0_0_putret_x_0".to_string(), 35),
("routine0_0_putret_x_1".to_string(), 37),
("routine0_0_putret_x_10".to_string(), 39),
("routine0_0_putret_x_100".to_string(), 43),
("routine0_0_putret_x_11".to_string(), 41),
("routine0_1_putret_1_0".to_string(), 71),
("routine0_1_putret_1_1".to_string(), 73),
("routine0_1_putret_2_00".to_string(), 65),
("routine0_1_putret_2_01".to_string(), 67),
("routine0_1_putret_2_10".to_string(), 69),
("routine0_1_putret_x_0".to_string(), 55),
("routine0_1_putret_x_1".to_string(), 57),
("routine0_1_putret_x_10".to_string(), 59),
("routine0_1_putret_x_100".to_string(), 63),
("routine0_1_putret_x_11".to_string(), 61),
("routine0_2_putret_1_0".to_string(), 91),
("routine0_2_putret_1_1".to_string(), 93),
("routine0_2_putret_2_00".to_string(), 85),
("routine0_2_putret_2_01".to_string(), 87),
("routine0_2_putret_2_10".to_string(), 89),
("routine0_2_putret_x_0".to_string(), 75),
("routine0_2_putret_x_1".to_string(), 77),
("routine0_2_putret_x_10".to_string(), 79),
("routine0_2_putret_x_100".to_string(), 83),
("routine0_2_putret_x_11".to_string(), 81),
("routine0_a".to_string(), 108),
("routine0_b".to_string(), 109),
("routine0_c".to_string(), 110),
("routine0_return".to_string(), 95),
("routine0_return_id_0_0".to_string(), 96),
("routine0_return_id_1_0".to_string(), 98),
("routine0_return_id_1_1".to_string(), 100),
("routine0_return_id_2_00".to_string(), 102),
("routine0_return_id_2_01".to_string(), 104),
("routine0_return_id_2_10".to_string(), 106),
]
),
builder.to_code()
);
}
#[test]
fn test_handler_builder_indjump() {
let mut builder = mi_simple_hbuilder_new(Some(3), Some(5));
builder.i(MINF_MRW0);
builder.add_indjump(
"indjump0",
[
"jump0".to_string(),
"jump1".to_string(),
"jump2".to_string(),
"jump3".to_string(),
],
false,
false,
);
builder.add_indjump_l(
"indjump1",
[
"jump0".to_string(),
"jump1".to_string(),
"jump2".to_string(),
"jump3".to_string(),
],
false,
false,
);
builder.add_indjump_ll("indjump2", ["jump0", "jump2", "jump3"], true, false);
builder.i((MINF_MR, builder.indjump("indjump0")));
builder.i((MINF_MAR, builder.indjump("indjump1")));
builder.i((MINF_MRW0, builder.indjump("indjump2")));
builder.l("jump0");
builder.i(MINF_TBRF);
builder.i(MINF_STOP);
builder.l("jump1");
builder.i(MINF_MARW0);
builder.i(MINF_STOP);
builder.l("jump2");
builder.i(MINF_TBRW1);
builder.i(MINF_STOP);
builder.l("jump3");
builder.i(MINF_MRW0);
builder.i(MINF_STOP);
assert_eq!(
(
vec![
MinInfInstr::new(MINF_MRW0, MINF_MRW0, 1, 1),
(MINF_MR, MINF_MR, 12, 12).into(),
(MINF_MAR, MINF_MAR, 19, 19).into(),
(MINF_MRW0, MINF_MRW0, 26, 26).into(),
(MINF_TBRF, MINF_TBRF, 5, 5).into(),
(MINF_STOP, MINF_STOP, 6, 6).into(),
(MINF_MARW0, MINF_MARW0, 7, 7).into(),
(MINF_STOP, MINF_STOP, 8, 8).into(),
(MINF_TBRW1, MINF_TBRW1, 9, 9).into(),
(MINF_STOP, MINF_STOP, 10, 10).into(),
(MINF_MRW0, MINF_MRW0, 11, 11).into(),
(MINF_STOP, MINF_STOP, 12, 12).into(),
(MINF_MAB, MINF_MAB, 13, 13).into(),
(MINF_MARW0, MINF_MARW0, 14, 14).into(),
(MINF_MAB, MINF_MAB, 15, 17).into(),
(MINF_MARW0, MINF_MARW0, 16, 16).into(),
(MINF_MR, MINF_MR, 4, 6).into(),
(MINF_MARW0, MINF_MARW0, 18, 18).into(),
(MINF_MR, MINF_MR, 8, 10).into(),
(MINF_MAB, MINF_MAB, 20, 20).into(),
(MINF_MARW0, MINF_MARW0, 21, 21).into(),
(MINF_MAB, MINF_MAB, 22, 24).into(),
(MINF_MARW0, MINF_MARW0, 23, 23).into(),
(MINF_MR, MINF_MR, 4, 6).into(),
(MINF_MARW0, MINF_MARW0, 25, 25).into(),
(MINF_MR, MINF_MR, 8, 10).into(),
(MINF_TBB, MINF_TBB, 27, 27).into(),
(MINF_TBRW0, MINF_TBRW0, 28, 28).into(),
(MINF_TBB, MINF_TBB, 29, 31).into(),
(MINF_TBRW0, MINF_TBRW0, 30, 30).into(),
(MINF_MR, MINF_MR, 4, 8).into(),
(MINF_TBRW0, MINF_TBRW0, 32, 32).into(),
(MINF_MR, MINF_MR, 10, 10).into(),
],
vec![
("indjump0_indjump".to_string(), 12),
("indjump0_indjump_id_0_0".to_string(), 13),
("indjump0_indjump_id_1_0".to_string(), 15),
("indjump0_indjump_id_1_1".to_string(), 17),
("indjump1_indjump".to_string(), 19),
("indjump1_indjump_id_0_0".to_string(), 20),
("indjump1_indjump_id_1_0".to_string(), 22),
("indjump1_indjump_id_1_1".to_string(), 24),
("indjump2_indjump".to_string(), 26),
("indjump2_indjump_id_0_0".to_string(), 27),
("indjump2_indjump_id_1_0".to_string(), 29),
("indjump2_indjump_id_1_1".to_string(), 31),
("jump0".to_string(), 4),
("jump1".to_string(), 6),
("jump2".to_string(), 8),
("jump3".to_string(), 10),
]
),
builder.to_code()
);
}
#[test]
fn test_handler_builder_once_indjump() {
let mut builder = mi_simple_hbuilder_new(Some(3), Some(5));
builder.i(MINF_MRW0);
builder.once_indjump(
[
"jump0".to_string(),
"jump1".to_string(),
"jump2".to_string(),
"jump3".to_string(),
],
false,
false,
);
builder.once_indjump(
[
"jump0".to_string(),
"jump1".to_string(),
"jump2".to_string(),
"jump3".to_string(),
],
false,
false,
);
builder.once_indjump_l(["jump0", "jump2", "jump3"], true, false);
builder.l("jump0");
builder.i(MINF_TBRF);
builder.i(MINF_STOP);
builder.l("jump1");
builder.i(MINF_MARW0);
builder.i(MINF_STOP);
builder.l("jump2");
builder.i(MINF_TBRW1);
builder.i(MINF_STOP);
builder.l("jump3");
builder.i(MINF_MRW0);
builder.i(MINF_STOP);
assert_eq!(
(
vec![
MinInfInstr::new(MINF_MRW0, MINF_MRW0, 1, 1),
(MINF_MAB, MINF_MAB, 2, 2).into(),
(MINF_MARW0, MINF_MARW0, 3, 3).into(),
(MINF_MAB, MINF_MAB, 4, 6).into(),
(MINF_MARW0, MINF_MARW0, 5, 5).into(),
(MINF_MR, MINF_MR, 22, 24).into(),
(MINF_MARW0, MINF_MARW0, 7, 7).into(),
(MINF_MR, MINF_MR, 26, 28).into(),
(MINF_MAB, MINF_MAB, 9, 9).into(),
(MINF_MARW0, MINF_MARW0, 10, 10).into(),
(MINF_MAB, MINF_MAB, 11, 13).into(),
(MINF_MARW0, MINF_MARW0, 12, 12).into(),
(MINF_MR, MINF_MR, 22, 24).into(),
(MINF_MARW0, MINF_MARW0, 14, 14).into(),
(MINF_MR, MINF_MR, 26, 28).into(),
(MINF_TBB, MINF_TBB, 16, 16).into(),
(MINF_TBRW0, MINF_TBRW0, 17, 17).into(),
(MINF_TBB, MINF_TBB, 18, 20).into(),
(MINF_TBRW0, MINF_TBRW0, 19, 19).into(),
(MINF_MR, MINF_MR, 22, 26).into(),
(MINF_TBRW0, MINF_TBRW0, 21, 21).into(),
(MINF_MR, MINF_MR, 28, 28).into(),
(MINF_TBRF, MINF_TBRF, 23, 23).into(),
(MINF_STOP, MINF_STOP, 24, 24).into(),
(MINF_MARW0, MINF_MARW0, 25, 25).into(),
(MINF_STOP, MINF_STOP, 26, 26).into(),
(MINF_TBRW1, MINF_TBRW1, 27, 27).into(),
(MINF_STOP, MINF_STOP, 28, 28).into(),
(MINF_MRW0, MINF_MRW0, 29, 29).into(),
(MINF_STOP, MINF_STOP, 0, 0).into(),
],
vec![
("__hb_once_indjump_15_indjump".to_string(), 15),
("__hb_once_indjump_15_indjump_id_0_0".to_string(), 16),
("__hb_once_indjump_15_indjump_id_1_0".to_string(), 18),
("__hb_once_indjump_15_indjump_id_1_1".to_string(), 20),
("__hb_once_indjump_1_indjump".to_string(), 1),
("__hb_once_indjump_1_indjump_id_0_0".to_string(), 2),
("__hb_once_indjump_1_indjump_id_1_0".to_string(), 4),
("__hb_once_indjump_1_indjump_id_1_1".to_string(), 6),
("__hb_once_indjump_8_indjump".to_string(), 8),
("__hb_once_indjump_8_indjump_id_0_0".to_string(), 9),
("__hb_once_indjump_8_indjump_id_1_0".to_string(), 11),
("__hb_once_indjump_8_indjump_id_1_1".to_string(), 13),
("jump0".to_string(), 22),
("jump1".to_string(), 24),
("jump2".to_string(), 26),
("jump3".to_string(), 28),
]
),
builder.to_code()
);
}
#[test]
fn test_handler_builder_once_indjump_jb() {
let mut builder = mi_simple_hbuilder_new(Some(3), Some(5));
builder.i(MINF_MRW0);
builder.once_indjump_jb(
[
"jump0".to_string(),
"jump1".to_string(),
"jump2".to_string(),
"jump3".to_string(),
],
false,
false,
Some(3),
);
builder.once_indjump_jb(
[
"jump0".to_string(),
"jump1".to_string(),
"jump2".to_string(),
"jump3".to_string(),
],
false,
false,
Some(4),
);
builder.once_indjump_jb_l(["jump0", "jump2", "jump3"], true, false, Some(2));
builder.l("jump0");
builder.i(MINF_TBRF);
builder.i(MINF_STOP);
builder.l("jump1");
builder.i(MINF_MARW0);
builder.i(MINF_STOP);
builder.l("jump2");
builder.i(MINF_TBRW1);
builder.i(MINF_STOP);
builder.l("jump3");
builder.i(MINF_MRW0);
builder.i(MINF_STOP);
assert_eq!(
(
vec![
MinInfInstr::new(MINF_MRW0, MINF_MRW0, 1, 1),
(MINF_MAB, MINF_MAB, 2, 2).into(),
(MINF_MARW0, MINF_MARW0, 3, 3).into(),
(MINF_MAB, MINF_MAB, 4, 4).into(),
(MINF_MARW0, MINF_MARW0, 5, 5).into(),
(MINF_MAB, MINF_MAB, 6, 8).into(),
(MINF_MARW0, MINF_MARW0, 7, 7).into(),
(MINF_MR, MINF_MR, 28, 30).into(),
(MINF_MARW0, MINF_MARW0, 9, 9).into(),
(MINF_MR, MINF_MR, 32, 34).into(),
(MINF_MAB, MINF_MAB, 11, 11).into(),
(MINF_MARW0, MINF_MARW0, 12, 12).into(),
(MINF_MAB, MINF_MAB, 13, 13).into(),
(MINF_MARW0, MINF_MARW0, 14, 14).into(),
(MINF_MAB, MINF_MAB, 15, 15).into(),
(MINF_MARW0, MINF_MARW0, 16, 16).into(),
(MINF_MAB, MINF_MAB, 17, 19).into(),
(MINF_MARW0, MINF_MARW0, 18, 18).into(),
(MINF_MR, MINF_MR, 28, 30).into(),
(MINF_MARW0, MINF_MARW0, 20, 20).into(),
(MINF_MR, MINF_MR, 32, 34).into(),
(MINF_TBB, MINF_TBB, 22, 22).into(),
(MINF_TBRW0, MINF_TBRW0, 23, 23).into(),
(MINF_TBB, MINF_TBB, 24, 26).into(),
(MINF_TBRW0, MINF_TBRW0, 25, 25).into(),
(MINF_MR, MINF_MR, 28, 32).into(),
(MINF_TBRW0, MINF_TBRW0, 27, 27).into(),
(MINF_MR, MINF_MR, 34, 34).into(),
(MINF_TBRF, MINF_TBRF, 29, 29).into(),
(MINF_STOP, MINF_STOP, 30, 30).into(),
(MINF_MARW0, MINF_MARW0, 31, 31).into(),
(MINF_STOP, MINF_STOP, 32, 32).into(),
(MINF_TBRW1, MINF_TBRW1, 33, 33).into(),
(MINF_STOP, MINF_STOP, 34, 34).into(),
(MINF_MRW0, MINF_MRW0, 35, 35).into(),
(MINF_STOP, MINF_STOP, 0, 0).into(),
],
vec![
("__hb_once_indjump_10_indjump".to_string(), 10),
("__hb_once_indjump_10_indjump_id_0_0".to_string(), 11),
("__hb_once_indjump_10_indjump_id_1_0".to_string(), 13),
("__hb_once_indjump_10_indjump_id_2_00".to_string(), 15),
("__hb_once_indjump_10_indjump_id_3_000".to_string(), 17),
("__hb_once_indjump_10_indjump_id_3_001".to_string(), 19),
("__hb_once_indjump_1_indjump".to_string(), 1),
("__hb_once_indjump_1_indjump_id_0_0".to_string(), 2),
("__hb_once_indjump_1_indjump_id_1_0".to_string(), 4),
("__hb_once_indjump_1_indjump_id_2_00".to_string(), 6),
("__hb_once_indjump_1_indjump_id_2_01".to_string(), 8),
("__hb_once_indjump_21_indjump".to_string(), 21),
("__hb_once_indjump_21_indjump_id_0_0".to_string(), 22),
("__hb_once_indjump_21_indjump_id_1_0".to_string(), 24),
("__hb_once_indjump_21_indjump_id_1_1".to_string(), 26),
("jump0".to_string(), 28),
("jump1".to_string(), 30),
("jump2".to_string(), 32),
("jump3".to_string(), 34),
]
),
builder.to_code()
);
}
#[test]
fn test_handler_builder_longdata() {
let mut builder = mi_simple_hbuilder_new(Some(3), Some(5));
builder.add_longdata_handler("md", false, 1);
builder.add_longdata_handler("td", true, 1);
let l1 = builder.add_longdata("md", (&[143, 54], 0, 0), "j1");
let l2 = builder.add_longdata("td", (&[61, 14], 0, 0), "j2");
builder.i((MINF_MR, l1));
builder.l("j1");
builder.i((MINF_MR, l2));
builder.l("j2");
builder.i(MINF_STOP);
assert_eq!(
(
vec![
MinInfInstr::new(MINF_MR, MINF_MR, 47, 47),
(MINF_MR, MINF_MR, 93, 93).into(),
(MINF_STOP, MINF_STOP, 3, 3).into(),
(MINF_MARW1, MINF_MARW1, 4, 4).into(),
(MINF_MARF, MINF_MARF, 5, 5).into(),
(MINF_MARW1, MINF_MARW1, 6, 6).into(),
(MINF_MARF, MINF_MARF, 7, 7).into(),
(MINF_MARW0, MINF_MARW0, 8, 8).into(),
(MINF_MARF, MINF_MARF, 9, 9).into(),
(MINF_MARW0, MINF_MARW0, 10, 10).into(),
(MINF_MARF, MINF_MARF, 12, 12).into(),
(MINF_MR, MINF_MR, 3, 3).into(),
(MINF_MR, MINF_MR, 44, 44).into(),
(MINF_MARW0, MINF_MARW0, 14, 14).into(),
(MINF_MARF, MINF_MARF, 15, 15).into(),
(MINF_MARW1, MINF_MARW1, 16, 16).into(),
(MINF_MARF, MINF_MARF, 17, 17).into(),
(MINF_MARW1, MINF_MARW1, 18, 18).into(),
(MINF_MARF, MINF_MARF, 19, 19).into(),
(MINF_MARW0, MINF_MARW0, 20, 20).into(),
(MINF_MARF, MINF_MARF, 22, 22).into(),
(MINF_MR, MINF_MR, 13, 13).into(),
(MINF_MR, MINF_MR, 11, 11).into(),
(MINF_MARW0, MINF_MARW0, 24, 24).into(),
(MINF_MARF, MINF_MARF, 25, 25).into(),
(MINF_MARW0, MINF_MARW0, 26, 26).into(),
(MINF_MARF, MINF_MARF, 27, 27).into(),
(MINF_MARW0, MINF_MARW0, 28, 28).into(),
(MINF_MARF, MINF_MARF, 29, 29).into(),
(MINF_MARW1, MINF_MARW1, 30, 30).into(),
(MINF_MARF, MINF_MARF, 32, 32).into(),
(MINF_MR, MINF_MR, 23, 23).into(),
(MINF_MR, MINF_MR, 46, 46).into(),
(MINF_MARW1, MINF_MARW1, 34, 34).into(),
(MINF_MARF, MINF_MARF, 35, 35).into(),
(MINF_MARW1, MINF_MARW1, 36, 36).into(),
(MINF_MARF, MINF_MARF, 37, 37).into(),
(MINF_MARW1, MINF_MARW1, 38, 38).into(),
(MINF_MARF, MINF_MARF, 39, 39).into(),
(MINF_MARW1, MINF_MARW1, 40, 40).into(),
(MINF_MARF, MINF_MARF, 42, 42).into(),
(MINF_MR, MINF_MR, 33, 33).into(),
(MINF_MR, MINF_MR, 31, 31).into(),
(MINF_MR, MINF_MR, 21, 21).into(),
(MINF_MR, MINF_MR, 48, 48).into(),
(MINF_MR, MINF_MR, 41, 41).into(),
(MINF_MR, MINF_MR, 43, 43).into(),
(MINF_MR, MINF_MR, 45, 45).into(),
(MINF_MR, MINF_MR, 1, 1).into(),
(MINF_TBRW0, MINF_TBRW0, 50, 50).into(),
(MINF_TBRF, MINF_TBRF, 51, 51).into(),
(MINF_TBRW0, MINF_TBRW0, 52, 52).into(),
(MINF_TBRF, MINF_TBRF, 53, 53).into(),
(MINF_TBRW0, MINF_TBRW0, 54, 54).into(),
(MINF_TBRF, MINF_TBRF, 55, 55).into(),
(MINF_TBRW0, MINF_TBRW0, 56, 56).into(),
(MINF_TBRF, MINF_TBRF, 58, 58).into(),
(MINF_MR, MINF_MR, 49, 49).into(),
(MINF_MR, MINF_MR, 90, 90).into(),
(MINF_TBRW1, MINF_TBRW1, 60, 60).into(),
(MINF_TBRF, MINF_TBRF, 61, 61).into(),
(MINF_TBRW1, MINF_TBRW1, 62, 62).into(),
(MINF_TBRF, MINF_TBRF, 63, 63).into(),
(MINF_TBRW0, MINF_TBRW0, 64, 64).into(),
(MINF_TBRF, MINF_TBRF, 65, 65).into(),
(MINF_TBRW0, MINF_TBRW0, 66, 66).into(),
(MINF_TBRF, MINF_TBRF, 68, 68).into(),
(MINF_MR, MINF_MR, 59, 59).into(),
(MINF_MR, MINF_MR, 92, 92).into(),
(MINF_TBRW1, MINF_TBRW1, 70, 70).into(),
(MINF_TBRF, MINF_TBRF, 71, 71).into(),
(MINF_TBRW0, MINF_TBRW0, 72, 72).into(),
(MINF_TBRF, MINF_TBRF, 73, 73).into(),
(MINF_TBRW1, MINF_TBRW1, 74, 74).into(),
(MINF_TBRF, MINF_TBRF, 75, 75).into(),
(MINF_TBRW1, MINF_TBRW1, 76, 76).into(),
(MINF_TBRF, MINF_TBRF, 78, 78).into(),
(MINF_MR, MINF_MR, 69, 69).into(),
(MINF_MR, MINF_MR, 67, 67).into(),
(MINF_TBRW0, MINF_TBRW0, 80, 80).into(),
(MINF_TBRF, MINF_TBRF, 81, 81).into(),
(MINF_TBRW1, MINF_TBRW1, 82, 82).into(),
(MINF_TBRF, MINF_TBRF, 83, 83).into(),
(MINF_TBRW1, MINF_TBRW1, 84, 84).into(),
(MINF_TBRF, MINF_TBRF, 85, 85).into(),
(MINF_TBRW1, MINF_TBRW1, 86, 86).into(),
(MINF_TBRF, MINF_TBRF, 88, 88).into(),
(MINF_MR, MINF_MR, 79, 79).into(),
(MINF_MR, MINF_MR, 57, 57).into(),
(MINF_MR, MINF_MR, 87, 87).into(),
(MINF_MR, MINF_MR, 94, 94).into(),
(MINF_MR, MINF_MR, 77, 77).into(),
(MINF_MR, MINF_MR, 89, 89).into(),
(MINF_MR, MINF_MR, 91, 91).into(),
(MINF_MR, MINF_MR, 2, 2).into(),
],
vec![
("j1".to_string(), 1),
("j2".to_string(), 2),
("md_chunk_368f_16_0_putret_x_0".to_string(), 47),
("md_chunk_368f_16_return".to_string(), 48),
("md_chunk_36_8_0_putret_x_0".to_string(), 43),
("md_chunk_36_8_return".to_string(), 44),
("md_chunk_3_4".to_string(), 3),
("md_chunk_3_4_0_putret_x_0".to_string(), 11),
("md_chunk_3_4_return".to_string(), 12),
("md_chunk_6_4".to_string(), 13),
("md_chunk_6_4_0_putret_x_0".to_string(), 21),
("md_chunk_6_4_return".to_string(), 22),
("md_chunk_8_4".to_string(), 23),
("md_chunk_8_4_0_putret_x_0".to_string(), 31),
("md_chunk_8_4_return".to_string(), 32),
("md_chunk_8f_8_0_putret_x_0".to_string(), 45),
("md_chunk_8f_8_return".to_string(), 46),
("md_chunk_f_4".to_string(), 33),
("md_chunk_f_4_0_putret_x_0".to_string(), 41),
("md_chunk_f_4_return".to_string(), 42),
("td_chunk_0_4".to_string(), 49),
("td_chunk_0_4_0_putret_x_0".to_string(), 57),
("td_chunk_0_4_return".to_string(), 58),
("td_chunk_3_4".to_string(), 59),
("td_chunk_3_4_0_putret_x_0".to_string(), 67),
("td_chunk_3_4_return".to_string(), 68),
("td_chunk_3d_8_0_putret_x_0".to_string(), 91),
("td_chunk_3d_8_return".to_string(), 92),
("td_chunk_d_4".to_string(), 69),
("td_chunk_d_4_0_putret_x_0".to_string(), 77),
("td_chunk_d_4_return".to_string(), 78),
("td_chunk_e3d_16_0_putret_x_0".to_string(), 93),
("td_chunk_e3d_16_return".to_string(), 94),
("td_chunk_e_4".to_string(), 79),
("td_chunk_e_4_0_putret_x_0".to_string(), 87),
("td_chunk_e_4_return".to_string(), 88),
("td_chunk_e_8_0_putret_x_0".to_string(), 89),
("td_chunk_e_8_return".to_string(), 90),
]
),
builder.to_code()
);
}
#[test]
fn test_handler_builder_longdata_calls() {
let mut builder = mi_simple_hbuilder_new(Some(3), Some(5));
builder.add_longdata_handler("md", false, 2);
builder.add_longdata_handler("td", true, 1);
builder.ld_call_01("td", (&[], 12, 4), MINF_MR);
builder.ld_call("td", (&[], 12, 4), MINF_TBR, MINF_MAR);
builder.ld_call_fr0_01("td", (&[], 13, 4), MINF_MARF, "stop");
builder.ld_call_fr0("td", (&[], 11, 4), MINF_TBRW0, MINF_MARW1, "stop");
builder.ld_call_fr1_01("td", (&[], 2, 4), MINF_MARW1, "stop2");
builder.ld_call_fr1("td", (&[], 7, 4), MINF_TBRF, MINF_MAB, "stop2");
builder.ld_call_2_01("td", (&[], 9, 4), (&[], 5, 4), MINF_MARW0);
builder.ld_call_2("td", (&[], 8, 4), (&[], 6, 4), MINF_TBRW0, MINF_TBRF);
builder.ld_call_2x_01("td", "md", (&[], 7, 4), (&[], 10, 4), MINF_MARW0);
builder.ld_call_2x("md", "td", (&[], 9, 4), (&[], 5, 4), MINF_TBRW0, MINF_MARW1);
builder.l("stop");
builder.i(MINF_STOP);
builder.l("stop2");
builder.i(MINF_STOP);
assert_eq!(
(
vec![
MinInfInstr::new(MINF_MR, MINF_MR, 128, 128),
(MINF_TBR, MINF_MAR, 130, 130).into(),
(MINF_MARF, MINF_MARF, 143, 10).into(),
(MINF_TBRW0, MINF_MARW1, 118, 10).into(),
(MINF_MARW1, MINF_MARW1, 11, 48).into(),
(MINF_TBRF, MINF_MAB, 11, 83).into(),
(MINF_MARW0, MINF_MARW0, 108, 58).into(),
(MINF_TBRW0, MINF_TBRF, 98, 73).into(),
(MINF_MARW0, MINF_MARW0, 85, 38).into(),
(MINF_TBRW0, MINF_MARW1, 24, 60).into(),
(MINF_STOP, MINF_STOP, 11, 11).into(),
(MINF_STOP, MINF_STOP, 12, 12).into(),
(MINF_MARW1, MINF_MARW1, 13, 13).into(),
(MINF_MARF, MINF_MARF, 14, 14).into(),
(MINF_MARF, MINF_MARF, 15, 15).into(),
(MINF_MARW0, MINF_MARW0, 16, 16).into(),
(MINF_MARF, MINF_MARF, 17, 17).into(),
(MINF_MARF, MINF_MARF, 18, 18).into(),
(MINF_MARW0, MINF_MARW0, 19, 19).into(),
(MINF_MARF, MINF_MARF, 20, 20).into(),
(MINF_MARF, MINF_MARF, 21, 21).into(),
(MINF_MARW1, MINF_MARW1, 22, 22).into(),
(MINF_MARF, MINF_MARF, 23, 23).into(),
(MINF_MARF, MINF_MARF, 25, 25).into(),
(MINF_MR, MINF_MR, 12, 12).into(),
(MINF_MR, MINF_MR, 10, 10).into(),
(MINF_MARW0, MINF_MARW0, 27, 27).into(),
(MINF_MARF, MINF_MARF, 28, 28).into(),
(MINF_MARF, MINF_MARF, 29, 29).into(),
(MINF_MARW1, MINF_MARW1, 30, 30).into(),
(MINF_MARF, MINF_MARF, 31, 31).into(),
(MINF_MARF, MINF_MARF, 32, 32).into(),
(MINF_MARW0, MINF_MARW0, 33, 33).into(),
(MINF_MARF, MINF_MARF, 34, 34).into(),
(MINF_MARF, MINF_MARF, 35, 35).into(),
(MINF_MARW1, MINF_MARW1, 36, 36).into(),
(MINF_MARF, MINF_MARF, 37, 37).into(),
(MINF_MARF, MINF_MARF, 39, 39).into(),
(MINF_MR, MINF_MR, 26, 26).into(),
(MINF_MR, MINF_MR, 9, 9).into(),
(MINF_TBRW0, MINF_TBRW0, 41, 41).into(),
(MINF_TBRF, MINF_TBRF, 42, 42).into(),
(MINF_TBRW1, MINF_TBRW1, 43, 43).into(),
(MINF_TBRF, MINF_TBRF, 44, 44).into(),
(MINF_TBRW0, MINF_TBRW0, 45, 45).into(),
(MINF_TBRF, MINF_TBRF, 46, 46).into(),
(MINF_TBRW0, MINF_TBRW0, 47, 47).into(),
(MINF_TBRF, MINF_TBRF, 49, 49).into(),
(MINF_MR, MINF_MR, 40, 40).into(),
(MINF_MR, MINF_MR, 5, 5).into(),
(MINF_TBRW1, MINF_TBRW1, 51, 51).into(),
(MINF_TBRF, MINF_TBRF, 52, 52).into(),
(MINF_TBRW0, MINF_TBRW0, 53, 53).into(),
(MINF_TBRF, MINF_TBRF, 54, 54).into(),
(MINF_TBRW1, MINF_TBRW1, 55, 55).into(),
(MINF_TBRF, MINF_TBRF, 56, 56).into(),
(MINF_TBRW0, MINF_TBRW0, 57, 57).into(),
(MINF_TBRF, MINF_TBRF, 62, 62).into(),
(MINF_MARW0, MINF_MARW0, 59, 59).into(),
(MINF_MARF, MINF_MARF, 50, 50).into(),
(MINF_MARW1, MINF_MARW1, 61, 61).into(),
(MINF_MARF, MINF_MARF, 50, 50).into(),
(MINF_MAB, MINF_MAB, 63, 63).into(),
(MINF_MARW0, MINF_MARW0, 64, 64).into(),
(MINF_MR, MINF_MR, 7, 10).into(),
(MINF_TBRW0, MINF_TBRW0, 66, 66).into(),
(MINF_TBRF, MINF_TBRF, 67, 67).into(),
(MINF_TBRW1, MINF_TBRW1, 68, 68).into(),
(MINF_TBRF, MINF_TBRF, 69, 69).into(),
(MINF_TBRW1, MINF_TBRW1, 70, 70).into(),
(MINF_TBRF, MINF_TBRF, 71, 71).into(),
(MINF_TBRW0, MINF_TBRW0, 72, 72).into(),
(MINF_TBRF, MINF_TBRF, 74, 74).into(),
(MINF_MR, MINF_MR, 65, 65).into(),
(MINF_MR, MINF_MR, 8, 8).into(),
(MINF_TBRW1, MINF_TBRW1, 76, 76).into(),
(MINF_TBRF, MINF_TBRF, 77, 77).into(),
(MINF_TBRW1, MINF_TBRW1, 78, 78).into(),
(MINF_TBRF, MINF_TBRF, 79, 79).into(),
(MINF_TBRW1, MINF_TBRW1, 80, 80).into(),
(MINF_TBRF, MINF_TBRF, 81, 81).into(),
(MINF_TBRW0, MINF_TBRW0, 82, 82).into(),
(MINF_TBRF, MINF_TBRF, 87, 87).into(),
(MINF_MARW0, MINF_MARW0, 84, 84).into(),
(MINF_MARF, MINF_MARF, 75, 75).into(),
(MINF_MARW1, MINF_MARW1, 86, 86).into(),
(MINF_MARF, MINF_MARF, 75, 75).into(),
(MINF_MAB, MINF_MAB, 88, 88).into(),
(MINF_MARW0, MINF_MARW0, 89, 89).into(),
(MINF_MR, MINF_MR, 6, 9).into(),
(MINF_TBRW0, MINF_TBRW0, 91, 91).into(),
(MINF_TBRF, MINF_TBRF, 92, 92).into(),
(MINF_TBRW0, MINF_TBRW0, 93, 93).into(),
(MINF_TBRF, MINF_TBRF, 94, 94).into(),
(MINF_TBRW0, MINF_TBRW0, 95, 95).into(),
(MINF_TBRF, MINF_TBRF, 96, 96).into(),
(MINF_TBRW1, MINF_TBRW1, 97, 97).into(),
(MINF_TBRF, MINF_TBRF, 99, 99).into(),
(MINF_MR, MINF_MR, 90, 90).into(),
(MINF_MR, MINF_MR, 8, 8).into(),
(MINF_TBRW1, MINF_TBRW1, 101, 101).into(),
(MINF_TBRF, MINF_TBRF, 102, 102).into(),
(MINF_TBRW0, MINF_TBRW0, 103, 103).into(),
(MINF_TBRF, MINF_TBRF, 104, 104).into(),
(MINF_TBRW0, MINF_TBRW0, 105, 105).into(),
(MINF_TBRF, MINF_TBRF, 106, 106).into(),
(MINF_TBRW1, MINF_TBRW1, 107, 107).into(),
(MINF_TBRF, MINF_TBRF, 109, 109).into(),
(MINF_MR, MINF_MR, 100, 100).into(),
(MINF_MR, MINF_MR, 7, 7).into(),
(MINF_TBRW1, MINF_TBRW1, 111, 111).into(),
(MINF_TBRF, MINF_TBRF, 112, 112).into(),
(MINF_TBRW1, MINF_TBRW1, 113, 113).into(),
(MINF_TBRF, MINF_TBRF, 114, 114).into(),
(MINF_TBRW0, MINF_TBRW0, 115, 115).into(),
(MINF_TBRF, MINF_TBRF, 116, 116).into(),
(MINF_TBRW1, MINF_TBRW1, 117, 117).into(),
(MINF_TBRF, MINF_TBRF, 119, 119).into(),
(MINF_MR, MINF_MR, 110, 110).into(),
(MINF_MR, MINF_MR, 4, 4).into(),
(MINF_TBRW0, MINF_TBRW0, 121, 121).into(),
(MINF_TBRF, MINF_TBRF, 122, 122).into(),
(MINF_TBRW0, MINF_TBRW0, 123, 123).into(),
(MINF_TBRF, MINF_TBRF, 124, 124).into(),
(MINF_TBRW1, MINF_TBRW1, 125, 125).into(),
(MINF_TBRF, MINF_TBRF, 126, 126).into(),
(MINF_TBRW1, MINF_TBRW1, 127, 127).into(),
(MINF_TBRF, MINF_TBRF, 132, 132).into(),
(MINF_MARW0, MINF_MARW0, 129, 129).into(),
(MINF_MARF, MINF_MARF, 120, 120).into(),
(MINF_MARW1, MINF_MARW1, 131, 131).into(),
(MINF_MARF, MINF_MARF, 120, 120).into(),
(MINF_MAB, MINF_MAB, 133, 133).into(),
(MINF_MARW0, MINF_MARW0, 134, 134).into(),
(MINF_MR, MINF_MR, 1, 2).into(),
(MINF_TBRW1, MINF_TBRW1, 136, 136).into(),
(MINF_TBRF, MINF_TBRF, 137, 137).into(),
(MINF_TBRW0, MINF_TBRW0, 138, 138).into(),
(MINF_TBRF, MINF_TBRF, 139, 139).into(),
(MINF_TBRW1, MINF_TBRW1, 140, 140).into(),
(MINF_TBRF, MINF_TBRF, 141, 141).into(),
(MINF_TBRW1, MINF_TBRW1, 142, 142).into(),
(MINF_TBRF, MINF_TBRF, 144, 144).into(),
(MINF_MR, MINF_MR, 135, 135).into(),
(MINF_MR, MINF_MR, 3, 3).into(),
],
vec![
("md_chunk_9_4".to_string(), 12),
("md_chunk_9_4_0_putret_x_0".to_string(), 24),
("md_chunk_9_4_return".to_string(), 25),
("md_chunk_a_4".to_string(), 26),
("md_chunk_a_4_0_putret_x_0".to_string(), 38),
("md_chunk_a_4_return".to_string(), 39),
("md_next_0".to_string(), 10),
("stop".to_string(), 10),
("stop2".to_string(), 11),
("td_chunk_2_4".to_string(), 40),
("td_chunk_2_4_0_putret_x_0".to_string(), 48),
("td_chunk_2_4_return".to_string(), 49),
("td_chunk_5_4".to_string(), 50),
("td_chunk_5_4_0_putret_x_0".to_string(), 58),
("td_chunk_5_4_0_putret_x_1".to_string(), 60),
("td_chunk_5_4_return".to_string(), 62),
("td_chunk_5_4_return_id_0_0".to_string(), 63),
("td_chunk_6_4".to_string(), 65),
("td_chunk_6_4_0_putret_x_0".to_string(), 73),
("td_chunk_6_4_return".to_string(), 74),
("td_chunk_7_4".to_string(), 75),
("td_chunk_7_4_0_putret_x_0".to_string(), 83),
("td_chunk_7_4_0_putret_x_1".to_string(), 85),
("td_chunk_7_4_return".to_string(), 87),
("td_chunk_7_4_return_id_0_0".to_string(), 88),
("td_chunk_8_4".to_string(), 90),
("td_chunk_8_4_0_putret_x_0".to_string(), 98),
("td_chunk_8_4_return".to_string(), 99),
("td_chunk_9_4".to_string(), 100),
("td_chunk_9_4_0_putret_x_0".to_string(), 108),
("td_chunk_9_4_return".to_string(), 109),
("td_chunk_b_4".to_string(), 110),
("td_chunk_b_4_0_putret_x_0".to_string(), 118),
("td_chunk_b_4_return".to_string(), 119),
("td_chunk_c_4".to_string(), 120),
("td_chunk_c_4_0_putret_x_0".to_string(), 128),
("td_chunk_c_4_0_putret_x_1".to_string(), 130),
("td_chunk_c_4_return".to_string(), 132),
("td_chunk_c_4_return_id_0_0".to_string(), 133),
("td_chunk_d_4".to_string(), 135),
("td_chunk_d_4_0_putret_x_0".to_string(), 143),
("td_chunk_d_4_return".to_string(), 144),
("td_next_0".to_string(), 1),
("td_next_1".to_string(), 2),
("td_next_2".to_string(), 3),
("td_next_3".to_string(), 4),
("td_next_4".to_string(), 5),
("td_next_5".to_string(), 6),
("td_next_6".to_string(), 7),
("td_next_7".to_string(), 8),
("td_next_8".to_string(), 9),
]
),
builder.to_code()
);
}
#[test]
fn test_handler_builder_data() {
let mut builder = mi_simple_hbuilder_new(Some(3), Some(5));
builder.add_data_handler_ll("dh0", 5, 1, "end", true);
builder.add_data_handler_ll("dh1", 5, 1, "end2", false);
let j0 = builder.put_data("dh0", 17);
let j1 = builder.put_data("dh0", 19);
let j2 = builder.put_data("dh1", 26);
let j3 = builder.put_data("dh1", 21);
builder.i((MINF_MR, "t0", "t1"));
builder.l("t0");
builder.i((MINF_MR, j0, j1));
builder.l("t1");
builder.i((MINF_MR, j2, j3));
builder.l("end");
builder.i(MINF_STOP);
builder.l("end2");
builder.i(MINF_STOP);
assert_eq!(
(
vec![
MinInfInstr::new(MINF_MR, MINF_MR, 1, 2),
(MINF_MR, MINF_MR, 5, 7).into(),
(MINF_MR, MINF_MR, 21, 19).into(),
(MINF_STOP, MINF_STOP, 4, 4).into(),
(MINF_STOP, MINF_STOP, 5, 5).into(),
(MINF_TBRW1, MINF_TBRW1, 6, 6).into(),
(MINF_TBRF, MINF_TBRF, 9, 9).into(),
(MINF_TBRW1, MINF_TBRW1, 8, 8).into(),
(MINF_TBRF, MINF_TBRF, 11, 11).into(),
(MINF_TBRW0, MINF_TBRW0, 10, 10).into(),
(MINF_TBRF, MINF_TBRF, 13, 13).into(),
(MINF_TBRW1, MINF_TBRW1, 12, 12).into(),
(MINF_TBRF, MINF_TBRF, 13, 13).into(),
(MINF_TBRW0, MINF_TBRW0, 14, 14).into(),
(MINF_TBRF, MINF_TBRF, 15, 15).into(),
(MINF_TBRW0, MINF_TBRW0, 16, 16).into(),
(MINF_TBRF, MINF_TBRF, 17, 17).into(),
(MINF_TBRW1, MINF_TBRW1, 18, 18).into(),
(MINF_TBRF, MINF_TBRF, 3, 3).into(),
(MINF_MARW1, MINF_MARW1, 20, 20).into(),
(MINF_MARF, MINF_MARF, 23, 23).into(),
(MINF_MARW0, MINF_MARW0, 22, 22).into(),
(MINF_MARF, MINF_MARF, 25, 25).into(),
(MINF_MARW0, MINF_MARW0, 24, 24).into(),
(MINF_MARF, MINF_MARF, 27, 27).into(),
(MINF_MARW1, MINF_MARW1, 26, 26).into(),
(MINF_MARF, MINF_MARF, 29, 29).into(),
(MINF_MARW1, MINF_MARW1, 28, 28).into(),
(MINF_MARF, MINF_MARF, 31, 31).into(),
(MINF_MARW0, MINF_MARW0, 30, 30).into(),
(MINF_MARF, MINF_MARF, 33, 33).into(),
(MINF_MARW0, MINF_MARW0, 32, 32).into(),
(MINF_MARF, MINF_MARF, 35, 35).into(),
(MINF_MARW1, MINF_MARW1, 34, 34).into(),
(MINF_MARF, MINF_MARF, 35, 35).into(),
(MINF_MARW1, MINF_MARW1, 36, 36).into(),
(MINF_MARF, MINF_MARF, 4, 4).into(),
],
vec![
("dh0_putdata_1_1".to_string(), 17),
("dh0_putdata_2_10".to_string(), 15),
("dh0_putdata_3_100".to_string(), 13),
("dh0_putdata_4_1000".to_string(), 9),
("dh0_putdata_4_1001".to_string(), 11),
("dh0_putdata_5_10001".to_string(), 5),
("dh0_putdata_5_10011".to_string(), 7),
("dh1_putdata_1_1".to_string(), 35),
("dh1_putdata_2_10".to_string(), 31),
("dh1_putdata_2_11".to_string(), 33),
("dh1_putdata_3_101".to_string(), 27),
("dh1_putdata_3_110".to_string(), 29),
("dh1_putdata_4_1010".to_string(), 23),
("dh1_putdata_4_1101".to_string(), 25),
("dh1_putdata_5_10101".to_string(), 19),
("dh1_putdata_5_11010".to_string(), 21),
("end".to_string(), 3),
("end2".to_string(), 4),
("t0".to_string(), 1),
("t1".to_string(), 2),
]
),
builder.to_code()
);
}
#[test]
fn test_handler_builder_sv_1() {
let mut builder = mi_std_sv_hbuilder_new_1(Some(1), 1);
{
let (func1b, ret) = builder.add_routine("func1", false);
let mut func1b = func1b.borrow_mut();
func1b.i(MINF_MR);
func1b.i(MINF_TBRF);
func1b.i(MINF_TBB);
func1b.i((MINF_TBRW1, MINF_TBRW0, ret));
}
{
let (func2b, ret) = builder.add_routine("func2", true);
let mut func2b = func2b.borrow_mut();
func2b.i(MINF_MRW0);
func2b.i(MINF_MAB);
func2b.i((MINF_MARW0, MINF_MARW1));
func2b.i((MINF_MR, ret));
}
builder.i(MINF_MRW0);
builder.call_01("func1", MINF_MR);
builder.i(MINF_TBR);
builder.call_01("func1", MINF_MAR);
builder.i(MINF_MRW1);
builder.call_01("func2", MINF_TBR);
builder.i(MINF_TBRW1);
builder.call_01("func2", MINF_TBR);
builder.i(MINF_STOP);
assert_eq!(
(
vec![
MinInfInstr::new(MINF_MRW0, MINF_MRW0, 1, 1),
(MINF_MR, MINF_MR, 9, 9).into(),
(MINF_TBR, MINF_TBR, 3, 3).into(),
(MINF_MAR, MINF_MAR, 11, 11).into(),
(MINF_MRW1, MINF_MRW1, 5, 5).into(),
(MINF_TBR, MINF_TBR, 16, 16).into(),
(MINF_TBRW1, MINF_TBRW1, 7, 7).into(),
(MINF_TBR, MINF_TBR, 18, 18).into(),
(MINF_STOP, MINF_STOP, 9, 9).into(),
(MINF_MARW0, MINF_MARW0, 10, 10).into(),
(MINF_MARF, MINF_MARF, 23, 23).into(),
(MINF_MARW1, MINF_MARW1, 12, 12).into(),
(MINF_MARF, MINF_MARF, 23, 23).into(),
(MINF_MAB, MINF_MAB, 14, 14).into(),
(MINF_MARW0, MINF_MARW0, 15, 15).into(),
(MINF_MR, MINF_MR, 2, 4).into(),
(MINF_TBRW0, MINF_TBRW0, 17, 17).into(),
(MINF_TBRF, MINF_TBRF, 27, 27).into(),
(MINF_TBRW1, MINF_TBRW1, 19, 19).into(),
(MINF_TBRF, MINF_TBRF, 27, 27).into(),
(MINF_TBB, MINF_TBB, 21, 21).into(),
(MINF_TBRW0, MINF_TBRW0, 22, 22).into(),
(MINF_MR, MINF_MR, 6, 8).into(),
(MINF_MR, MINF_MR, 24, 24).into(),
(MINF_TBRF, MINF_TBRF, 25, 25).into(),
(MINF_TBB, MINF_TBB, 26, 26).into(),
(MINF_TBRW1, MINF_TBRW0, 13, 13).into(),
(MINF_MRW0, MINF_MRW0, 28, 28).into(),
(MINF_MAB, MINF_MAB, 29, 29).into(),
(MINF_MARW0, MINF_MARW1, 30, 30).into(),
(MINF_MR, MINF_MR, 20, 20).into()
],
vec![
("func1".to_string(), 23),
("func1_0_putret_x_0".to_string(), 9),
("func1_0_putret_x_1".to_string(), 11),
("func1_after_ret_0".to_string(), 2),
("func1_after_ret_1".to_string(), 4),
("func1_return".to_string(), 13),
("func1_return_id_0_0".to_string(), 14),
("func2".to_string(), 27),
("func2_0_putret_x_0".to_string(), 16),
("func2_0_putret_x_1".to_string(), 18),
("func2_after_ret_0".to_string(), 6),
("func2_after_ret_1".to_string(), 8),
("func2_return".to_string(), 20),
("func2_return_id_0_0".to_string(), 21)
]
),
builder.to_code()
);
}
#[test]
fn test_handler_builder_sv_2() {
let mut builder = mi_std_sv_hbuilder_new_1(Some(2), 1);
{
let (func1b, ret) = builder.add_routine("func1", false);
let mut func1b = func1b.borrow_mut();
func1b.i(MINF_MR);
func1b.i(MINF_TBRF);
func1b.call_01("func1", MINF_TBR);
func1b.i(MINF_TBB);
func1b.i((MINF_TBRW1, MINF_TBRW0, ret));
}
{
let (func2b, ret) = builder.add_routine("func2", true);
let mut func2b = func2b.borrow_mut();
func2b.i(MINF_MRW0);
func2b.i(MINF_MAB);
func2b.i((MINF_MARW0, MINF_MARW1));
func2b.call_01("func1", MINF_MAR);
func2b.i((MINF_MR, ret));
}
builder.i(MINF_MRW0);
builder.call_01("func1", MINF_MR);
builder.i(MINF_TBR);
builder.call_01("func1", MINF_MAR);
builder.i(MINF_MRW1);
builder.call_01("func2", MINF_TBR);
builder.i(MINF_TBRW1);
builder.call_01("func2", MINF_TBR);
builder.i(MINF_STOP);
assert_eq!(
(
vec![
MinInfInstr::new(MINF_MRW0, MINF_MRW0, 1, 1),
(MINF_MR, MINF_MR, 13, 13).into(),
(MINF_TBR, MINF_TBR, 3, 3).into(),
(MINF_MAR, MINF_MAR, 15, 15).into(),
(MINF_MRW1, MINF_MRW1, 5, 5).into(),
(MINF_TBR, MINF_TBR, 28, 28).into(),
(MINF_TBRW1, MINF_TBRW1, 7, 7).into(),
(MINF_TBR, MINF_TBR, 30, 30).into(),
(MINF_STOP, MINF_STOP, 9, 9).into(),
(MINF_MARW0, MINF_MARW0, 10, 10).into(),
(MINF_MARF, MINF_MARF, 17, 17).into(),
(MINF_MARW1, MINF_MARW1, 12, 12).into(),
(MINF_MARF, MINF_MARF, 17, 17).into(),
(MINF_MARW0, MINF_MARW0, 14, 14).into(),
(MINF_MARF, MINF_MARF, 19, 19).into(),
(MINF_MARW1, MINF_MARW1, 16, 16).into(),
(MINF_MARF, MINF_MARF, 19, 19).into(),
(MINF_MARW0, MINF_MARW0, 18, 18).into(),
(MINF_MARF, MINF_MARF, 39, 39).into(),
(MINF_MARW1, MINF_MARW1, 20, 20).into(),
(MINF_MARF, MINF_MARF, 39, 39).into(),
(MINF_MAB, MINF_MAB, 22, 22).into(),
(MINF_MARW0, MINF_MARW0, 23, 23).into(),
(MINF_MAB, MINF_MAB, 24, 26).into(),
(MINF_MARW0, MINF_MARW0, 25, 25).into(),
(MINF_MR, MINF_MR, 42, 48).into(),
(MINF_MARW0, MINF_MARW0, 27, 27).into(),
(MINF_MR, MINF_MR, 2, 4).into(),
(MINF_TBRW0, MINF_TBRW0, 29, 29).into(),
(MINF_TBRF, MINF_TBRF, 32, 32).into(),
(MINF_TBRW1, MINF_TBRW1, 31, 31).into(),
(MINF_TBRF, MINF_TBRF, 32, 32).into(),
(MINF_TBRW0, MINF_TBRW0, 33, 33).into(),
(MINF_TBRF, MINF_TBRF, 44, 44).into(),
(MINF_TBB, MINF_TBB, 35, 35).into(),
(MINF_TBRW0, MINF_TBRW0, 36, 36).into(),
(MINF_TBB, MINF_TBB, 37, 37).into(),
(MINF_TBRW0, MINF_TBRW0, 38, 38).into(),
(MINF_MR, MINF_MR, 6, 8).into(),
(MINF_MR, MINF_MR, 40, 40).into(),
(MINF_TBRF, MINF_TBRF, 41, 41).into(),
(MINF_TBR, MINF_TBR, 9, 9).into(),
(MINF_TBB, MINF_TBB, 43, 43).into(),
(MINF_TBRW1, MINF_TBRW0, 21, 21).into(),
(MINF_MRW0, MINF_MRW0, 45, 45).into(),
(MINF_MAB, MINF_MAB, 46, 46).into(),
(MINF_MARW0, MINF_MARW1, 47, 47).into(),
(MINF_MAR, MINF_MAR, 11, 11).into(),
(MINF_MR, MINF_MR, 34, 34).into(),
],
vec![
("func1".to_string(), 39),
("func1_0_putret_1_0".to_string(), 17),
("func1_0_putret_1_1".to_string(), 19),
("func1_0_putret_x_0".to_string(), 9),
("func1_0_putret_x_1".to_string(), 11),
("func1_0_putret_x_10".to_string(), 13),
("func1_0_putret_x_11".to_string(), 15),
("func1_after_ret_0".to_string(), 42),
("func1_after_ret_1".to_string(), 48),
("func1_after_ret_2".to_string(), 2),
("func1_after_ret_3".to_string(), 4),
("func1_return".to_string(), 21),
("func1_return_id_0_0".to_string(), 22),
("func1_return_id_1_0".to_string(), 24),
("func1_return_id_1_1".to_string(), 26),
("func2".to_string(), 44),
("func2_0_putret_1_0".to_string(), 32),
("func2_0_putret_x_0".to_string(), 28),
("func2_0_putret_x_1".to_string(), 30),
("func2_after_ret_0".to_string(), 6),
("func2_after_ret_1".to_string(), 8),
("func2_return".to_string(), 34),
("func2_return_id_0_0".to_string(), 35),
("func2_return_id_1_0".to_string(), 37),
]
),
builder.to_code()
);
}