use min_infmachine_lltk::builder::*;
use min_infmachine_lltk::*;
use std::collections::BTreeMap;
#[test]
fn test_min_inf_builder() {
let mut builder = MinInfBuilder::<String, MinInfBuildInstr<_>>::new();
builder.add_label("start".to_string());
builder.add_instr(MinInfBuildInstr::new(MINF_MARW0, MINF_MARW1, 1, 2));
builder.add_instr(MinInfBuildInstr::new(MINF_MARF, MINF_TBB, -1, 1));
builder.add_instr(MinInfBuildInstr::newp(MINF_MAB, MINF_TBRF));
builder.add_instr(MinInfBuildInstr::newp(MINF_MARF, MINF_TBRW1));
builder.add_instr(MinInfBuildInstr::new(
MINF_TBRW1, MINF_TBRW0, "code1", "code2",
));
builder.add_label("code1");
builder.add_instr(MinInfBuildInstr::newp(MINF_TBB, MINF_MRW1));
builder.add_instr(MinInfBuildInstr::newp(MINF_MARW1, MINF_TBB));
builder.add_instr(MinInfBuildInstr::newp_01(MINF_STOP));
builder.add_label("code2");
builder.add_instr(MinInfBuildInstr::newp(MINF_MAB, MINF_MRW0));
builder.add_instr(MinInfBuildInstr::newp(MINF_MARW0, MINF_TBRW1));
builder.add_instr(MinInfBuildInstr::newp(MINF_MARW1, MINF_TBB));
builder.add_instr(MinInfBuildInstr::newp_01(MINF_STOP2));
assert_eq!(
Ok((
vec![
MinInfInstr::new(MINF_MARW0, MINF_MARW1, 1, 2),
MinInfInstr::new(MINF_MARF, MINF_TBB, 0, 2),
MinInfInstr::new_next01(MINF_MAB, MINF_TBRF, 3),
MinInfInstr::new_next01(MINF_MARF, MINF_TBRW1, 4),
MinInfInstr::new(MINF_TBRW1, MINF_TBRW0, 5, 8),
MinInfInstr::new_next01(MINF_TBB, MINF_MRW1, 6),
MinInfInstr::new_next01(MINF_MARW1, MINF_TBB, 7),
MinInfInstr::new_01(MINF_STOP, 8),
MinInfInstr::new_next01(MINF_MAB, MINF_MRW0, 9),
MinInfInstr::new_next01(MINF_MARW0, MINF_TBRW1, 10),
MinInfInstr::new_next01(MINF_MARW1, MINF_TBB, 11),
MinInfInstr::new_01(MINF_STOP2, 0),
],
vec![
("code1".to_string(), 5),
("code2".to_string(), 8),
("start".to_string(), 0),
]
)),
builder.try_to_code().map_err(|x| x.to_string())
);
let mut builder = MinInfBuilder::<String, MinInfBuildInstr<_>>::new();
builder.add_label("start".to_string());
builder.add_instr(MinInfBuildInstr::new(MINF_MARW0, MINF_MARW1, 1, 2));
builder.add_instr(MinInfBuildInstr::new(MINF_MARF, MINF_TBB, -1, 1));
builder.add_instr(MinInfBuildInstr::newp(MINF_MAB, MINF_TBRF));
builder.add_instr(MinInfBuildInstr::newp(MINF_MARF, MINF_TBRW1));
builder.add_instr(MinInfBuildInstr::new(
MINF_TBRW1, MINF_TBRW0, "code1", "code2",
));
assert_eq!(
Err("Resolve error: Label code1 not found".to_string()),
builder.try_to_code().map_err(|x| x.to_string())
);
let mut builder = MinInfBuilder::<String, MinInfBuildInstr<_>>::new();
builder.add_label("start".to_string());
builder.add_instr(MinInfBuildInstr::new(MINF_MARW0, MINF_MARW1, 1, 2));
builder.add_instr(MinInfBuildInstr::new(MINF_MARF, MINF_TBB, -1, 1));
builder.add_instr(MinInfBuildInstr::newp(MINF_MAB, MINF_TBRF));
builder.add_instr(MinInfBuildInstr::newp(MINF_MARF, MINF_TBRW1));
assert_eq!(
Err(concat!(
"Nexts out of range: 3: MinInfInstr ",
"{ func_fr0: MemAddressReadForward, ",
"func_fr1: TempBufferReadWrite1, ",
"next_fr0: 4, next_fr1: 4 }"
)
.to_string()),
builder.try_to_code().map_err(|x| x.to_string())
);
}
#[test]
fn test_min_inf_builder_join() {
let mut builder = MinInfBuilder::<String, MinInfBuildInstr<_>>::new();
builder.add_label("start".to_string());
builder.add_instr(MinInfBuildInstr::new(MINF_MARW0, MINF_MARW1, 1, 2));
builder.add_instr(MinInfBuildInstr::new(MINF_MARF, MINF_TBB, -1, 1));
builder.add_instr(MinInfBuildInstr::newp(MINF_MAB, MINF_TBRF));
builder.add_instr(MinInfBuildInstr::newp(MINF_MARF, MINF_TBRW1));
builder.add_instr(MinInfBuildInstr::new(
MINF_TBRW1, MINF_TBRW0, "code1", "code2",
));
builder.add_label("code1");
builder.add_instr(MinInfBuildInstr::newp(MINF_TBB, MINF_MRW1));
builder.add_instr(MinInfBuildInstr::new_func01(MINF_TBB, 1, "start2"));
builder.add_instr(MinInfBuildInstr::newp(MINF_MARW1, MINF_TBB));
let mut builder2 = MinInfBuilder::<String, MinInfBuildInstr<String>>::new();
builder2.add_label("start2".to_string());
builder2.add_instr(MinInfBuildInstr::newp(MINF_MAB, MINF_TBRF));
builder2.add_instr(MinInfBuildInstr::newp(MINF_MARF, MINF_TBRW1));
builder2.add_label("code2");
builder2.add_instr(MinInfBuildInstr::newp(MINF_MAB, MINF_MRW0));
builder2.add_instr(MinInfBuildInstr::newp(MINF_MARW0, MINF_TBRW1));
builder2.add_instr(MinInfBuildInstr::newp(MINF_MARW1, MINF_TBB));
builder2.add_instr(MinInfBuildInstr::newp_01(MINF_STOP));
builder.join(builder2).unwrap();
assert_eq!(
Ok((
vec![
MinInfInstr::new(MINF_MARW0, MINF_MARW1, 1, 2),
MinInfInstr::new(MINF_MARF, MINF_TBB, 0, 2),
MinInfInstr::new_next01(MINF_MAB, MINF_TBRF, 3),
MinInfInstr::new_next01(MINF_MARF, MINF_TBRW1, 4),
MinInfInstr::new(MINF_TBRW1, MINF_TBRW0, 5, 10),
MinInfInstr::new_next01(MINF_TBB, MINF_MRW1, 6),
MinInfInstr::new_func01(MINF_TBB, 7, 8),
MinInfInstr::new_next01(MINF_MARW1, MINF_TBB, 8),
MinInfInstr::new_next01(MINF_MAB, MINF_TBRF, 9),
MinInfInstr::new_next01(MINF_MARF, MINF_TBRW1, 10),
MinInfInstr::new_next01(MINF_MAB, MINF_MRW0, 11),
MinInfInstr::new_next01(MINF_MARW0, MINF_TBRW1, 12),
MinInfInstr::new_next01(MINF_MARW1, MINF_TBB, 13),
MinInfInstr::new_01(MINF_STOP, 0),
],
vec![
("code1".to_string(), 5),
("code2".to_string(), 10),
("start".to_string(), 0),
("start2".to_string(), 8),
]
)),
builder.try_to_code().map_err(|x| x.to_string())
);
let mut builder = MinInfBuilder::<String, MinInfBuildInstr<_>>::new();
builder.add_label("start".to_string());
builder.add_instr(MinInfBuildInstr::new(MINF_MARW0, MINF_MARW1, 1, 2));
builder.add_instr(MinInfBuildInstr::new(MINF_MARF, MINF_TBB, -1, 1));
let mut builder2 = MinInfBuilder::<String, MinInfBuildInstr<String>>::new();
builder2.add_label("start".to_string());
builder2.add_instr(MinInfBuildInstr::newp(MINF_MAB, MINF_TBRF));
builder2.add_instr(MinInfBuildInstr::newp(MINF_MARF, MINF_TBRW1));
assert_eq!(
Err("Label start already exists".to_string()),
builder.join(builder2).map_err(|e| e.to_string())
);
}
#[test]
fn test_min_inf_builder_change_labels() {
let mut builder = MinInfBuilder::<String, MinInfBuildInstr<_>>::new();
builder.add_label("start".to_string());
builder.add_instr(MinInfBuildInstr::new(MINF_MARW0, MINF_MARW1, 1, 2));
builder.add_instr(MinInfBuildInstr::new(MINF_MARF, MINF_TBB, -1, 1));
builder.add_label("loop".to_string());
builder.add_instr(MinInfBuildInstr::new_next01(MINF_MAB, MINF_TBRF, "loop"));
builder.add_instr(MinInfBuildInstr::newp(MINF_MARF, MINF_TBRW1));
builder.add_instr(MinInfBuildInstr::new(
MINF_TBRW1, MINF_TBRW0, "code1", "code2",
));
builder.change_labels(|l| "copy1_".to_string() + l, false);
assert_eq!(
(
vec![
MinInfBuildInstr::new(MINF_MARW0, MINF_MARW1, 1, 2),
MinInfBuildInstr::new(MINF_MARF, MINF_TBB, -1, 1),
MinInfBuildInstr::new_next01(MINF_MAB, MINF_TBRF, "copy1_loop"),
MinInfBuildInstr::newp(MINF_MARF, MINF_TBRW1),
MinInfBuildInstr::new(MINF_TBRW1, MINF_TBRW0, "copy1_code1", "copy1_code2",)
],
BTreeMap::from_iter([
("copy1_loop".to_string(), 2),
("copy1_start".to_string(), 0),
])
),
(builder.get_code().clone(), builder.get_label_map().clone())
);
let mut builder = MinInfBuilder::<String, MinInfBuildInstr<_>>::new();
builder.add_label("start".to_string());
builder.add_instr(MinInfBuildInstr::new(MINF_MARW0, MINF_MARW1, 1, 2));
builder.add_instr(MinInfBuildInstr::new(MINF_MARF, MINF_TBB, -1, 1));
builder.add_label("loop".to_string());
builder.add_instr(MinInfBuildInstr::new_next01(MINF_MAB, MINF_TBRF, "loop"));
builder.add_instr(MinInfBuildInstr::newp(MINF_MARF, MINF_TBRW1));
builder.add_instr(MinInfBuildInstr::new(
MINF_TBRW1, MINF_TBRW0, "code1", "code2",
));
builder.change_labels(|l| "copy1_".to_string() + l, true);
assert_eq!(
(
vec![
MinInfBuildInstr::new(MINF_MARW0, MINF_MARW1, 1, 2),
MinInfBuildInstr::new(MINF_MARF, MINF_TBB, -1, 1),
MinInfBuildInstr::new_next01(MINF_MAB, MINF_TBRF, "copy1_loop"),
MinInfBuildInstr::newp(MINF_MARF, MINF_TBRW1),
MinInfBuildInstr::new(MINF_TBRW1, MINF_TBRW0, "code1", "code2",)
],
BTreeMap::from_iter([
("copy1_loop".to_string(), 2),
("copy1_start".to_string(), 0),
])
),
(builder.get_code().clone(), builder.get_label_map().clone())
);
}
#[test]
fn test_min_inf_builder_try_add_label() {
let mut builder = MinInfBuilder::<String, MinInfBuildInstr<_>>::new();
builder.add_label("start".to_string());
builder.add_instr(MinInfBuildInstr::new(MINF_MARW0, MINF_MARW1, 1, 2));
builder.add_instr(MinInfBuildInstr::new(MINF_MARF, MINF_TBB, -1, 1));
builder.add_instr(MinInfBuildInstr::newp(MINF_MAB, MINF_TBRF));
builder.add_instr(MinInfBuildInstr::newp(MINF_MARF, MINF_TBRW1));
builder.add_instr(MinInfBuildInstr::new(
MINF_TBRW1, MINF_TBRW0, "code1", "code2",
));
assert_eq!(
Err("Label start already exists".to_string()),
builder.try_add_label("start").map_err(|e| e.to_string())
);
}
#[test]
fn test_min_inf_builder_occurrence_label_map() {
let mut builder = MinInfBuilder::<String, MinInfBuildInstr<_>>::new();
builder.add_label("start".to_string());
builder.add_instr(MinInfBuildInstr::new(MINF_MARW0, MINF_MARW1, 1, 2));
builder.add_instr(MinInfBuildInstr::new(MINF_MARF, MINF_TBB, -1, 1));
builder.add_instr(MinInfBuildInstr::newp(MINF_MAB, MINF_TBRF));
builder.add_instr(MinInfBuildInstr::newp(MINF_MARF, MINF_TBRW1));
builder.add_instr(MinInfBuildInstr::new(
MINF_TBRW1, MINF_TBRW0, "code1", "code2",
));
builder.add_label("code1");
builder.add_instr(MinInfBuildInstr::newp(MINF_TBB, MINF_MRW1));
builder.add_instr(MinInfBuildInstr::newp(MINF_MARW1, MINF_TBB));
builder.add_instr(MinInfBuildInstr::newp_01(MINF_STOP));
builder.add_label("code2");
builder.add_instr(MinInfBuildInstr::new(MINF_MAB, MINF_MRW0, 1, "code2"));
builder.add_instr(MinInfBuildInstr::new(MINF_MARW0, MINF_TBRW1, "code1", 1));
builder.add_instr(MinInfBuildInstr::new(
MINF_MARW1,
MINF_TBB,
("code2", 1),
("code1", 2),
));
builder.add_instr(MinInfBuildInstr::newp_01(MINF_STOP2));
assert_eq!(
BTreeMap::from_iter([
("code1".to_string(), vec![(4, false), (9, false)]),
("code2".to_string(), vec![(4, true), (8, true)]),
]),
exact_label_occurrence_map(&builder)
);
}
#[test]
fn test_min_inf_builder_convs() {
assert_eq!(
MinInfRel::<String> {
label: Some("taxx".to_string()),
offset: 5
},
("taxx", 5).into()
);
assert_eq!(
MinInfRel::<String> {
label: Some("taxx".to_string()),
offset: 5
},
("taxx".to_string(), 5).into()
);
assert_eq!(
MinInfRel::<String> {
label: None,
offset: 9
},
9.into()
);
assert_eq!(
MinInfBuildInstr::<String>::new(MINF_MRW1, MINF_MRW1, MinInfRel::rel(1), MinInfRel::rel(1)),
MinInfBuildInstr::newp_01(MINF_MRW1)
);
assert_eq!(
MinInfBuildInstr::<String>::new(MINF_MRW1, MINF_MRW1, 1, 1),
MinInfBuildInstr::newp_01(MINF_MRW1)
);
assert_eq!(
MinInfBuildInstr::<String>::new(MINF_MRW1, MINF_MRW1, 1, 1),
MINF_MRW1.into()
);
assert_eq!(
MinInfBuildInstr::<String>::new(MINF_MRW1, MINF_TBRW0, 1, 1),
MinInfBuildInstr::newp(MINF_MRW1, MINF_TBRW0)
);
assert_eq!(
MinInfBuildInstr::<String>::new(MINF_MRW1, MINF_TBRW0, 1, 1),
(MINF_MRW1, MINF_TBRW0).into()
);
assert_eq!(
MinInfBuildInstr::<String>::new(MINF_MRW1, MINF_MRW1, 9, 12),
MinInfBuildInstr::new_func01(MINF_MRW1, 9, 12)
);
assert_eq!(
MinInfBuildInstr::<String>::new(MINF_MRW1, MINF_MRW1, 9, 12),
(MINF_MRW1, 9, 12).into()
);
assert_eq!(
MinInfBuildInstr::<String>::new(MINF_MRW1, MINF_MRW1, 9, "labl"),
MinInfBuildInstr::new_func01(MINF_MRW1, 9, "labl")
);
assert_eq!(
MinInfBuildInstr::<String>::new(MINF_MRW1, MINF_MRW1, 9, "labl"),
(MINF_MRW1, 9, "labl").into()
);
assert_eq!(
MinInfBuildInstr::<String>::new(MINF_MRW1, MINF_MAB, 12, 12),
MinInfBuildInstr::new_next01(MINF_MRW1, MINF_MAB, 12)
);
assert_eq!(
MinInfBuildInstr::<String>::new(MINF_MRW1, MINF_MAB, 12, 12),
(MINF_MRW1, MINF_MAB, 12).into()
);
}
#[test]
fn test_min_inf_builder_convs_2() {
assert_eq!(
MinInfRelSV::<String> {
rel: MinInfRel {
label: Some("taxx".to_string()),
offset: 5
},
value: None,
next_state_num: None,
},
("taxx".to_string(), 5isize).into()
);
assert_eq!(
MinInfRelSV::<String> {
rel: MinInfRel {
label: Some("taxx".to_string()),
offset: 5
},
value: None,
next_state_num: Some(7),
},
(("taxx".to_string(), 5isize), 7).into()
);
assert_eq!(
MinInfRelSV::<String> {
rel: MinInfRel {
label: Some("taxy".to_string()),
offset: 5
},
value: Some(2),
next_state_num: Some(7),
},
(("taxy".to_string(), 5isize), 2, 7).into()
);
assert_eq!(
MinInfRelSV::<String> {
rel: MinInfRel {
label: Some("taxy".to_string()),
offset: 5
},
value: Some(2),
next_state_num: Some(7),
},
(
MinInfRel {
label: Some("taxy".to_string()),
offset: 5
},
2,
7
)
.into()
);
assert_eq!(
MinInfBInstrSingleSV::new(
MINF_TBRF,
MINF_TBRF,
MinInfRelSV {
rel: MinInfRel {
label: Some("taxy".to_string()),
offset: 5
},
value: Some(2),
next_state_num: Some(7),
},
MinInfRelSV {
rel: MinInfRel {
label: Some("det".to_string()),
offset: 16
},
value: Some(3),
next_state_num: Some(9),
}
),
MinInfBInstrSingleSV::new_func01(
MINF_TBRF,
(("taxy".to_string(), 5isize), 2, 7),
(("det".to_string(), 16isize), 3, 9)
)
);
assert_eq!(
MinInfBInstrSingleSV::new(
MINF_TBRF,
MINF_TBRF,
(("taxy".to_string(), 5isize), 2, 7),
(("det".to_string(), 16isize), 3, 9)
),
MinInfBInstrSingleSV::new_func01(
MINF_TBRF,
(("taxy".to_string(), 5isize), 2, 7),
(("det".to_string(), 16isize), 3, 9)
)
);
assert_eq!(
MinInfBInstrSingleSV::new(
MINF_TBRF,
MINF_TBRF,
(("taxy".to_string(), 5isize), 2, 7),
(("det".to_string(), 16isize), 3, 9)
),
(
MINF_TBRF,
(("taxy".to_string(), 5isize), 2, 7),
(("det".to_string(), 16isize), 3, 9)
)
.into()
);
assert_eq!(
MinInfBInstrSingleSV::new(
MINF_TBRF,
MINF_MAB,
(("det".to_string(), 16isize), 3, 9),
(("det".to_string(), 16isize), 3, 9)
),
MinInfBInstrSingleSV::new_next01(MINF_TBRF, MINF_MAB, (("det".to_string(), 16isize), 3, 9))
);
assert_eq!(
MinInfBInstrSingleSV::new(
MINF_TBRF,
MINF_MAB,
(("det".to_string(), 16isize), 3, 9),
(("det".to_string(), 16isize), 3, 9)
),
(MINF_TBRF, MINF_MAB, (("det".to_string(), 16isize), 3, 9)).into()
);
assert_eq!(
MinInfBInstrSingleSV::new(
MINF_TBB,
MINF_MRW1,
(("taxy".to_string(), 5isize), 2, 7),
(("det".to_string(), 16isize), 3, 9)
),
(
MINF_TBB,
MINF_MRW1,
(("taxy".to_string(), 5isize), 2, 7),
(("det".to_string(), 16isize), 3, 9)
)
.into()
);
assert_eq!(
MinInfBInstrSingleSV::<String>::new(
MINF_MRW0,
MINF_TBRW1,
MinInfRel::next(),
MinInfRel::next(),
),
MinInfBInstrSingleSV::newp(MINF_MRW0, MINF_TBRW1)
);
assert_eq!(
MinInfBInstrSingleSV::<String>::new(
MINF_MRW0,
MINF_TBRW1,
MinInfRel::next(),
MinInfRel::next(),
),
(MINF_MRW0, MINF_TBRW1).into()
);
assert_eq!(
MinInfBInstrSingleSV::<String>::new(
MINF_MARW1,
MINF_MARW1,
MinInfRel::next(),
MinInfRel::next(),
),
MinInfBInstrSingleSV::newp_01(MINF_MARW1)
);
assert_eq!(
MinInfBInstrSingleSV::<String>::new(
MINF_MARW1,
MINF_MARW1,
MinInfRel::next(),
MinInfRel::next(),
),
MINF_MARW1.into()
);
assert_eq!(
MinInfBInstrSingleSV::<String>::new(
MINF_STOP,
MINF_TBRW1,
("super1", 4isize),
("super3", 7isize),
),
MinInfBuildInstr::new(MINF_STOP, MINF_TBRW1, ("super1", 4), ("super3", 7)).into()
);
}
#[test]
fn test_min_inf_binstr_single_sv_try_into_int_instr() {
assert_eq!(
Ok(MinInfBInstrSingleSVInt::new(
MINF_TBRF,
MINF_MAB,
(("sin".to_string(), 42isize), 1, 6),
(("det".to_string(), 144isize), 3, 9),
2,
10
)),
MinInfBInstrSingleSV::new(
MINF_TBRF,
MINF_MAB,
(("sin".to_string(), 7isize), 1, 6),
(("det".to_string(), 16isize), 3, 9)
)
.try_into_int_instr(2, 10)
.map_err(|e| e.to_string())
);
assert_eq!(
Ok(MinInfBInstrSingleSVInt::new(
MINF_TBRF,
MINF_MAB,
("sin".to_string(), 70isize),
("det".to_string(), 160isize),
2,
10
)),
MinInfBInstrSingleSV::new(
MINF_TBRF,
MINF_MAB,
("sin".to_string(), 7isize),
("det".to_string(), 16isize)
)
.try_into_int_instr(2, 10)
.map_err(|e| e.to_string())
);
assert_eq!(
Ok(MinInfBInstrSingleSVInt::new(
MINF_TBRF,
MINF_MAB,
(("sin".to_string(), 21isize), 1, 3),
("det".to_string(), 160isize),
2,
10
)),
MinInfBInstrSingleSV::new(
MINF_TBRF,
MINF_MAB,
(("sin".to_string(), 7isize), 1, 3),
("det".to_string(), 16isize)
)
.try_into_int_instr(2, 10)
.map_err(|e| e.to_string())
);
assert_eq!(
Err("Next state num out of range".to_string()),
MinInfBInstrSingleSV::new(
MINF_TBRF,
MINF_MAB,
(("sin".to_string(), 7isize), 1, 6),
(("det".to_string(), 16isize), 3, usize::MAX - 77)
)
.try_into_int_instr(2, 10)
.map_err(|e| e.to_string())
);
}
#[test]
fn test_min_inf_builder_convs_3() {
assert_eq!(
MinInfBInstrSV::<String>::new(vec![MinInfBInstrSingleSV::new(
MINF_MARW1,
MINF_TBR,
("hat".to_string(), 6isize),
("boom".to_string(), 8isize)
)]),
MinInfBInstrSV::new_many(MINF_MARW1, MINF_TBR, ("hat", 6), ("boom", 8))
);
assert_eq!(
MinInfBInstrSV::<String>::new(vec![MinInfBInstrSingleSV::new(
MINF_MARW1,
MINF_TBR,
("hat".to_string(), 6isize),
("boom".to_string(), 8isize)
)]),
(MINF_MARW1, MINF_TBR, ("hat", 6), ("boom", 8)).into()
);
assert_eq!(
MinInfBInstrSV::<String>::new(
(0..11)
.map(|i| MinInfBInstrSingleSV::new(
MINF_MARW1,
MINF_TBR,
(("hat".to_string(), 6isize), i, 11),
(("boom".to_string(), 8isize), i, 11)
))
.collect::<Vec<_>>()
),
MinInfBInstrSV::new_many_nc(MINF_MARW1, MINF_TBR, ("hat", 6), ("boom", 8), 11)
);
assert_eq!(
MinInfBInstrSV::<String>::new(
(0..11)
.map(|i| MinInfBInstrSingleSV::new(
MINF_MARW1,
MINF_TBR,
(("hat".to_string(), 6isize), i, 11),
(("boom".to_string(), 8isize), i, 11)
))
.collect::<Vec<_>>()
),
(MINF_MARW1, MINF_TBR, ("hat", 6), ("boom", 8), 11usize).into()
);
assert_eq!(
MinInfBInstrSV::<String>::new(
(0..11)
.map(|i| MinInfBInstrSingleSV::new(
MINF_MARW1,
MINF_TBR,
(("hat".to_string(), 6isize), i, 11),
(("boom".to_string(), 8isize), i, 11)
))
.collect::<Vec<_>>()
),
(
MinInfBuildInstr::new(MINF_MARW1, MINF_TBR, ("hat", 6), ("boom", 8)),
11usize
)
.into()
);
assert_eq!(
MinInfBInstrSV::<String>::new(vec![MinInfBInstrSingleSV::new(
MINF_TBR,
MINF_TBR,
("hat".to_string(), 5isize),
("boom".to_string(), 8isize)
)]),
MinInfBInstrSV::new_func01_many(MINF_TBR, ("hat", 5), ("boom", 8))
);
assert_eq!(
MinInfBInstrSV::<String>::new(vec![MinInfBInstrSingleSV::new(
MINF_TBR,
MINF_TBR,
("hat".to_string(), 5isize),
("boom".to_string(), 8isize)
)]),
(MINF_TBR, ("hat", 5), ("boom", 8)).into()
);
assert_eq!(
MinInfBInstrSV::<String>::new(
(0..7)
.map(|i| MinInfBInstrSingleSV::new(
MINF_TBR,
MINF_TBR,
(("hat".to_string(), 5isize), i, 7),
(("boom".to_string(), 8isize), i, 7)
))
.collect::<Vec<_>>()
),
MinInfBInstrSV::new_func01_many_nc(MINF_TBR, ("hat", 5), ("boom", 8), 7)
);
assert_eq!(
MinInfBInstrSV::<String>::new(
(0..7)
.map(|i| MinInfBInstrSingleSV::new(
MINF_TBR,
MINF_TBR,
(("hat".to_string(), 5isize), i, 7),
(("boom".to_string(), 8isize), i, 7)
))
.collect::<Vec<_>>()
),
(MINF_TBR, ("hat", 5), ("boom", 8), 7).into()
);
assert_eq!(
MinInfBInstrSV::<String>::new(vec![MinInfBInstrSingleSV::new(
MINF_MARW0,
MINF_TBRW1,
("boom".to_string(), 8isize),
("boom".to_string(), 8isize)
)]),
MinInfBInstrSV::new_next01_many(MINF_MARW0, MINF_TBRW1, ("boom", 8))
);
assert_eq!(
MinInfBInstrSV::<String>::new(vec![MinInfBInstrSingleSV::new(
MINF_MARW0,
MINF_TBRW1,
("boom".to_string(), 8isize),
("boom".to_string(), 8isize)
)]),
(MINF_MARW0, MINF_TBRW1, ("boom", 8)).into()
);
assert_eq!(
MinInfBInstrSV::<String>::new(
(0..15)
.map(|i| MinInfBInstrSingleSV::new(
MINF_MARW0,
MINF_TBRW1,
(("boom".to_string(), 8isize), i, 15),
(("boom".to_string(), 8isize), i, 15)
))
.collect::<Vec<_>>()
),
MinInfBInstrSV::new_next01_many_nc(MINF_MARW0, MINF_TBRW1, ("boom", 8), 15)
);
assert_eq!(
MinInfBInstrSV::<String>::new(
(0..15)
.map(|i| MinInfBInstrSingleSV::new(
MINF_MARW0,
MINF_TBRW1,
(("boom".to_string(), 8isize), i, 15),
(("boom".to_string(), 8isize), i, 15)
))
.collect::<Vec<_>>()
),
(MINF_MARW0, MINF_TBRW1, ("boom", 8), 15usize).into()
);
assert_eq!(
MinInfBInstrSV::<String>::new(vec![MinInfBInstrSingleSV::new(
MINF_MARW1,
MINF_TBR,
MinInfRel::next(),
MinInfRel::next()
)]),
MinInfBInstrSV::newp_many(MINF_MARW1, MINF_TBR)
);
assert_eq!(
MinInfBInstrSV::<String>::new(vec![MinInfBInstrSingleSV::new(
MINF_MARW1,
MINF_TBR,
MinInfRel::next(),
MinInfRel::next()
)]),
(MINF_MARW1, MINF_TBR).into()
);
assert_eq!(
MinInfBInstrSV::<String>::new(
(0..6)
.map(|i| MinInfBInstrSingleSV::new(
MINF_MARW1,
MINF_TBR,
(MinInfRel::next(), i, 6),
(MinInfRel::next(), i, 6)
))
.collect::<Vec<_>>()
),
MinInfBInstrSV::newp_many_nc(MINF_MARW1, MINF_TBR, 6)
);
assert_eq!(
MinInfBInstrSV::<String>::new(
(0..6)
.map(|i| MinInfBInstrSingleSV::new(
MINF_MARW1,
MINF_TBR,
(MinInfRel::next(), i, 6),
(MinInfRel::next(), i, 6)
))
.collect::<Vec<_>>()
),
(MINF_MARW1, MINF_TBR, 6usize).into()
);
assert_eq!(
MinInfBInstrSV::<String>::new(vec![MinInfBInstrSingleSV::new(
MINF_MARW0,
MINF_MARW0,
MinInfRel::next(),
MinInfRel::next()
)]),
MinInfBInstrSV::newp_01_many(MINF_MARW0)
);
assert_eq!(
MinInfBInstrSV::<String>::new(vec![MinInfBInstrSingleSV::new(
MINF_MARW0,
MINF_MARW0,
MinInfRel::next(),
MinInfRel::next()
)]),
MINF_MARW0.into()
);
assert_eq!(
MinInfBInstrSV::<String>::new(
(0..6)
.map(|i| MinInfBInstrSingleSV::new(
MINF_MARW0,
MINF_MARW0,
(MinInfRel::next(), i, 6),
(MinInfRel::next(), i, 6)
))
.collect::<Vec<_>>()
),
MinInfBInstrSV::newp_01_many_nc(MINF_MARW0, 6)
);
assert_eq!(
MinInfBInstrSV::<String>::new(
(0..6)
.map(|i| MinInfBInstrSingleSV::new(
MINF_MARW0,
MINF_MARW0,
(MinInfRel::next(), i, 6),
(MinInfRel::next(), i, 6)
))
.collect::<Vec<_>>()
),
(MINF_MARW0, 6usize).into()
);
assert_eq!(
MinInfBInstrSV::<String>::new(vec![MinInfBInstrSingleSV::new(
MINF_MARW1,
MINF_TBR,
("hat".to_string(), 6isize),
("boom".to_string(), 8isize)
)]),
MinInfBuildInstr::new(MINF_MARW1, MINF_TBR, ("hat", 6), ("boom", 8)).into()
);
assert_eq!(
MinInfBInstrSV::<String>::new(vec![
MinInfBInstrSingleSV::new(MINF_TBB, MINF_MAB, 1, 1),
MinInfBInstrSingleSV::new(MINF_MARW1, MINF_TBRW0, -1, 1),
MinInfBInstrSingleSV::new(MINF_MR, MINF_MRW1, 1, 1)
]),
MinInfBInstrSV::new_binstrs([
MinInfBuildInstr::from((MINF_TBB, MINF_MAB)),
(MINF_MARW1, MINF_TBRW0, -1, 1).into(),
(MINF_MR, MINF_MRW1).into()
])
);
assert_eq!(
MinInfBInstrSV::<String>::new(vec![
MinInfBInstrSingleSV::new(MINF_TBB, MINF_MAB, (1, 2, 5), (1, 2, 5)),
MinInfBInstrSingleSV::new(MINF_MARW1, MINF_TBRW0, (-1, 2, 5), (1, 2, 5)),
MinInfBInstrSingleSV::new(MINF_MR, MINF_MRW1, (1, 2, 5), (1, 2, 5))
]),
MinInfBInstrSV::new_binstrs_nextstate(
[
MinInfBuildInstr::from((MINF_TBB, MINF_MAB)),
(MINF_MARW1, MINF_TBRW0, -1, 1).into(),
(MINF_MR, MINF_MRW1).into()
],
2,
5
)
);
assert_eq!(
MinInfBInstrSV::<String>::new(vec![
MinInfBInstrSingleSV::new(MINF_TBB, MINF_MAB, (1, 4, 5), (1, 4, 5)),
MinInfBInstrSingleSV::new(MINF_TBB, MINF_MAB, (1, 1, 5), (1, 1, 5)),
MinInfBInstrSingleSV::new(MINF_TBB, MINF_MAB, (1, 2, 5), (1, 2, 5)),
]),
MinInfBInstrSV::new_binstr_nextvals(
MinInfBuildInstr::from((MINF_TBB, MINF_MAB)),
[4, 1, 2],
5
)
);
assert_eq!(
MinInfBInstrSV::<String>::new(vec![
MinInfBInstrSingleSV::new(MINF_TBB, MINF_MAB, (1, 4, 7), (1, 4, 7)),
MinInfBInstrSingleSV::new(MINF_TBB, MINF_MAB, (1, 6, 14), (1, 6, 14)),
MinInfBInstrSingleSV::new(MINF_TBB, MINF_MAB, (1, 3, 13), (1, 3, 13)),
]),
MinInfBInstrSV::new_binstr_nextstates(
MinInfBuildInstr::from((MINF_TBB, MINF_MAB)),
[(4, 7), (6, 14), (3, 13)]
)
);
assert_eq!(
MinInfBInstrSV::<String>::new(vec![
MinInfBInstrSingleSV::new(MINF_TBB, MINF_MAB, 1, 1),
MinInfBInstrSingleSV::new(MINF_MARW1, MINF_TBRW0, -1, 1),
MinInfBInstrSingleSV::new(MINF_MR, MINF_MRW1, 1, 1)
]),
([
MinInfBuildInstr::from((MINF_TBB, MINF_MAB)),
(MINF_MARW1, MINF_TBRW0, -1, 1).into(),
(MINF_MR, MINF_MRW1).into()
],)
.into()
);
}
#[test]
fn test_min_inf_builder_with_var_state() {
let builder = MinInfBuilder::<String, MinInfBInstrSingleSVInt<_>>::new();
let mut builder = MinInfWithStateVar::new(builder, 1);
builder.add_label("start".to_string());
builder.add_instr(MinInfBuildInstr::new(MINF_MARW0, MINF_MARW1, 1, 2));
builder.add_instr(MinInfBuildInstr::new(MINF_MARF, MINF_TBB, -1, 1));
builder.add_instr(MinInfBuildInstr::newp(MINF_MAB, MINF_TBRF));
builder.add_instr(MinInfBuildInstr::newp(MINF_MARF, MINF_TBRW1));
builder.add_instr(MinInfBuildInstr::new(
MINF_TBRW1, MINF_TBRW0, "code1", "code2",
));
builder.add_label("code1");
builder.add_instr(MinInfBuildInstr::newp(MINF_TBB, MINF_MRW1));
builder.add_instr(MinInfBuildInstr::newp(MINF_MARW1, MINF_TBB));
builder.add_instr(MinInfBuildInstr::newp_01(MINF_STOP));
builder.add_label("code2");
builder.add_instr(MinInfBuildInstr::newp(MINF_MAB, MINF_MRW0));
builder.add_instr(MinInfBuildInstr::newp(MINF_MARW0, MINF_TBRW1));
builder.add_instr(MinInfBuildInstr::newp(MINF_MARW1, MINF_TBB));
builder.add_instr(MinInfBuildInstr::newp_01(MINF_STOP2));
let builder = builder.free();
assert_eq!(
Ok((
vec![
MinInfInstr::new(MINF_MARW0, MINF_MARW1, 1, 2),
MinInfInstr::new(MINF_MARF, MINF_TBB, 0, 2),
MinInfInstr::new_next01(MINF_MAB, MINF_TBRF, 3),
MinInfInstr::new_next01(MINF_MARF, MINF_TBRW1, 4),
MinInfInstr::new(MINF_TBRW1, MINF_TBRW0, 5, 8),
MinInfInstr::new_next01(MINF_TBB, MINF_MRW1, 6),
MinInfInstr::new_next01(MINF_MARW1, MINF_TBB, 7),
MinInfInstr::new_01(MINF_STOP, 8),
MinInfInstr::new_next01(MINF_MAB, MINF_MRW0, 9),
MinInfInstr::new_next01(MINF_MARW0, MINF_TBRW1, 10),
MinInfInstr::new_next01(MINF_MARW1, MINF_TBB, 11),
MinInfInstr::new_01(MINF_STOP2, 0),
],
vec![
("code1".to_string(), 5),
("code2".to_string(), 8),
("start".to_string(), 0),
]
)),
builder.try_to_code().map_err(|x| x.to_string())
);
}
#[test]
fn test_min_inf_builder_with_var_state_sn3() {
let builder = MinInfBuilder::<String, MinInfBInstrSingleSVInt<_>>::new();
let mut builder = MinInfWithStateVar::new(builder, 3);
builder.add_label("start");
builder.add_instr(MinInfBuildInstr::new(MINF_MARW0, MINF_MARW1, 1, 2));
builder.add_instr(MinInfBuildInstr::new(MINF_MARF, MINF_TBB, -1, 1));
builder.add_instr(MinInfBuildInstr::newp(MINF_MAB, MINF_TBRF));
builder.add_instr(MinInfBuildInstr::newp(MINF_MARF, MINF_TBRW1));
builder.add_instr(MinInfBuildInstr::new(
MINF_TBRW1, MINF_TBRW0, "code1", "code2",
));
builder.add_label("code1");
builder.add_instr(MinInfBuildInstr::newp(MINF_TBB, MINF_MRW1));
builder.add_instr(MinInfBuildInstr::newp(MINF_MARW1, MINF_TBB));
builder.add_instr(MinInfBuildInstr::newp_01(MINF_STOP));
builder.add_label("code2");
builder.add_instr(MinInfBuildInstr::newp(MINF_MAB, MINF_MRW0));
builder.add_instr(MinInfBuildInstr::newp(MINF_MARW0, MINF_TBRW1));
builder.add_instr(MinInfBuildInstr::newp(MINF_MARW1, MINF_TBB));
builder.add_instr(MinInfBuildInstr::newp_01(MINF_STOP2));
let builder = builder.free();
assert_eq!(
Ok((
vec![
MinInfInstr::new(MINF_MARW0, MINF_MARW1, 3, 6),
MinInfInstr::new(MINF_MARW0, MINF_MARW1, 4, 7),
MinInfInstr::new(MINF_MARW0, MINF_MARW1, 5, 8),
MinInfInstr::new(MINF_MARF, MINF_TBB, 0, 6),
MinInfInstr::new(MINF_MARF, MINF_TBB, 1, 7),
MinInfInstr::new(MINF_MARF, MINF_TBB, 2, 8),
MinInfInstr::new_next01(MINF_MAB, MINF_TBRF, 9),
MinInfInstr::new_next01(MINF_MAB, MINF_TBRF, 10),
MinInfInstr::new_next01(MINF_MAB, MINF_TBRF, 11),
MinInfInstr::new_next01(MINF_MARF, MINF_TBRW1, 12),
MinInfInstr::new_next01(MINF_MARF, MINF_TBRW1, 13),
MinInfInstr::new_next01(MINF_MARF, MINF_TBRW1, 14),
MinInfInstr::new(MINF_TBRW1, MINF_TBRW0, 15, 24),
MinInfInstr::new(MINF_TBRW1, MINF_TBRW0, 16, 25),
MinInfInstr::new(MINF_TBRW1, MINF_TBRW0, 17, 26),
MinInfInstr::new_next01(MINF_TBB, MINF_MRW1, 18),
MinInfInstr::new_next01(MINF_TBB, MINF_MRW1, 19),
MinInfInstr::new_next01(MINF_TBB, MINF_MRW1, 20),
MinInfInstr::new_next01(MINF_MARW1, MINF_TBB, 21),
MinInfInstr::new_next01(MINF_MARW1, MINF_TBB, 22),
MinInfInstr::new_next01(MINF_MARW1, MINF_TBB, 23),
MinInfInstr::new_01(MINF_STOP, 24),
MinInfInstr::new_01(MINF_STOP, 25),
MinInfInstr::new_01(MINF_STOP, 26),
MinInfInstr::new_next01(MINF_MAB, MINF_MRW0, 27),
MinInfInstr::new_next01(MINF_MAB, MINF_MRW0, 28),
MinInfInstr::new_next01(MINF_MAB, MINF_MRW0, 29),
MinInfInstr::new_next01(MINF_MARW0, MINF_TBRW1, 30),
MinInfInstr::new_next01(MINF_MARW0, MINF_TBRW1, 31),
MinInfInstr::new_next01(MINF_MARW0, MINF_TBRW1, 32),
MinInfInstr::new_next01(MINF_MARW1, MINF_TBB, 33),
MinInfInstr::new_next01(MINF_MARW1, MINF_TBB, 34),
MinInfInstr::new_next01(MINF_MARW1, MINF_TBB, 35),
MinInfInstr::new_01(MINF_STOP2, 0),
MinInfInstr::new_01(MINF_STOP2, 0),
MinInfInstr::new_01(MINF_STOP2, 0),
],
vec![
("code1".to_string(), 15),
("code2".to_string(), 24),
("start".to_string(), 0),
]
)),
builder.try_to_code().map_err(|x| x.to_string())
);
}
#[test]
fn test_min_inf_builder_with_var_state_snx() {
let builder = MinInfBuilder::<String, MinInfBInstrSingleSVInt<_>>::new();
let mut builder = MinInfWithStateVar::new(builder, 3);
builder.add_label("start");
builder.add_instr(MinInfBuildInstr::new(MINF_MARW0, MINF_MARW1, 1, 2));
builder.add_instr(MinInfBuildInstr::new(MINF_MARF, MINF_TBB, -1, 1));
builder.add_instr(MinInfBuildInstr::newp(MINF_MAB, MINF_TBRF));
builder.add_instr(MinInfBuildInstr::newp(MINF_MARF, MINF_TBRW1));
builder.add_instr(MinInfBInstrSV::new([
(MINF_TBRW1, MINF_TBRW0, ("code1", 0, 2), ("code2", 0, 4)),
(MINF_TBRW1, MINF_TBRW0, ("code1", 1, 2), ("code2", 1, 4)),
(MINF_TBRW1, MINF_TBRW0, ("code1", 0, 2), ("code2", 2, 4)),
]));
let builder = builder.free();
let mut builder = MinInfWithStateVar::new(builder, 2);
builder.add_label("code1");
builder.add_instr(MinInfBuildInstr::newp(MINF_TBB, MINF_MRW1));
builder.add_instr(MinInfBuildInstr::newp(MINF_MARW1, MINF_TBB));
builder.add_instr(MinInfBInstrSV::from((MINF_STOP, 0isize)));
let builder = builder.free();
let mut builder = MinInfWithStateVar::new(builder, 4);
builder.add_label("code2");
builder.add_instr(MinInfBuildInstr::newp(MINF_MAB, MINF_MRW0));
builder.add_instr(MinInfBuildInstr::newp(MINF_MARW0, MINF_TBRW1));
builder.add_instr(MinInfBuildInstr::newp(MINF_MARW1, MINF_TBB));
builder.add_instr(MinInfBuildInstr::newp_01(MINF_STOP2));
let builder = builder.free();
assert_eq!(
Ok((
vec![
MinInfInstr::new(MINF_MARW0, MINF_MARW1, 3, 6),
MinInfInstr::new(MINF_MARW0, MINF_MARW1, 4, 7),
MinInfInstr::new(MINF_MARW0, MINF_MARW1, 5, 8),
MinInfInstr::new(MINF_MARF, MINF_TBB, 0, 6),
MinInfInstr::new(MINF_MARF, MINF_TBB, 1, 7),
MinInfInstr::new(MINF_MARF, MINF_TBB, 2, 8),
MinInfInstr::new_next01(MINF_MAB, MINF_TBRF, 9),
MinInfInstr::new_next01(MINF_MAB, MINF_TBRF, 10),
MinInfInstr::new_next01(MINF_MAB, MINF_TBRF, 11),
MinInfInstr::new_next01(MINF_MARF, MINF_TBRW1, 12),
MinInfInstr::new_next01(MINF_MARF, MINF_TBRW1, 13),
MinInfInstr::new_next01(MINF_MARF, MINF_TBRW1, 14),
MinInfInstr::new(MINF_TBRW1, MINF_TBRW0, 15, 21),
MinInfInstr::new(MINF_TBRW1, MINF_TBRW0, 16, 22),
MinInfInstr::new(MINF_TBRW1, MINF_TBRW0, 15, 23),
MinInfInstr::new_next01(MINF_TBB, MINF_MRW1, 17),
MinInfInstr::new_next01(MINF_TBB, MINF_MRW1, 18),
MinInfInstr::new_next01(MINF_MARW1, MINF_TBB, 19),
MinInfInstr::new_next01(MINF_MARW1, MINF_TBB, 20),
MinInfInstr::new_01(MINF_STOP, 19),
MinInfInstr::new_01(MINF_STOP, 20),
MinInfInstr::new_next01(MINF_MAB, MINF_MRW0, 25),
MinInfInstr::new_next01(MINF_MAB, MINF_MRW0, 26),
MinInfInstr::new_next01(MINF_MAB, MINF_MRW0, 27),
MinInfInstr::new_next01(MINF_MAB, MINF_MRW0, 28),
MinInfInstr::new_next01(MINF_MARW0, MINF_TBRW1, 29),
MinInfInstr::new_next01(MINF_MARW0, MINF_TBRW1, 30),
MinInfInstr::new_next01(MINF_MARW0, MINF_TBRW1, 31),
MinInfInstr::new_next01(MINF_MARW0, MINF_TBRW1, 32),
MinInfInstr::new_next01(MINF_MARW1, MINF_TBB, 33),
MinInfInstr::new_next01(MINF_MARW1, MINF_TBB, 34),
MinInfInstr::new_next01(MINF_MARW1, MINF_TBB, 35),
MinInfInstr::new_next01(MINF_MARW1, MINF_TBB, 36),
MinInfInstr::new_01(MINF_STOP2, 0),
MinInfInstr::new_01(MINF_STOP2, 0),
MinInfInstr::new_01(MINF_STOP2, 0),
MinInfInstr::new_01(MINF_STOP2, 0),
],
vec![
("code1".to_string(), 15),
("code2".to_string(), 21),
("start".to_string(), 0),
]
)),
builder.try_to_code().map_err(|x| x.to_string())
);
}
#[test]
fn test_min_inf_builder_with_var_state_snx_2() {
let builder = MinInfBuilder::<String, MinInfBInstrSingleSVInt<_>>::new();
let mut builder = MinInfWithStateVar::new(builder, 3);
builder.add_label("start");
builder.add_instr(MinInfBuildInstr::new(MINF_MARW0, MINF_MARW1, 1, 2));
builder.add_instr(MinInfBuildInstr::new(MINF_MARF, MINF_TBB, -1, 1));
builder.add_instr(MinInfBuildInstr::newp(MINF_MAB, MINF_TBRF));
builder.add_instr(MinInfBuildInstr::newp(MINF_MARF, MINF_TBRW1));
builder.add_instr(MinInfBInstrSV::new([
(MINF_TBRW1, MINF_TBRW0, ("code1", 0, 2), ("code2", 0, 4)),
(MINF_TBRW1, MINF_TBRW0, ("code1", 1, 2), ("code2", 1, 4)),
(MINF_TBRW1, MINF_TBRW0, ("code1", 0, 2), ("code2", 2, 4)),
]));
builder.switch(2);
builder.add_label("code1");
builder.add_instr(MinInfBuildInstr::newp(MINF_TBB, MINF_MRW1));
builder.add_instr(MinInfBuildInstr::newp(MINF_MARW1, MINF_TBB));
builder.add_instr(MinInfBInstrSV::from((MINF_STOP, 0isize)));
builder.switch(4);
builder.add_label("code2");
builder.add_instr(MinInfBuildInstr::newp(MINF_MAB, MINF_MRW0));
builder.add_instr(MinInfBuildInstr::newp(MINF_MARW0, MINF_TBRW1));
builder.add_instr(MinInfBuildInstr::newp(MINF_MARW1, MINF_TBB));
builder.add_instr(MinInfBuildInstr::newp_01(MINF_STOP2));
let builder = builder.free();
assert_eq!(
Ok((
vec![
MinInfInstr::new(MINF_MARW0, MINF_MARW1, 3, 6),
MinInfInstr::new(MINF_MARW0, MINF_MARW1, 4, 7),
MinInfInstr::new(MINF_MARW0, MINF_MARW1, 5, 8),
MinInfInstr::new(MINF_MARF, MINF_TBB, 0, 6),
MinInfInstr::new(MINF_MARF, MINF_TBB, 1, 7),
MinInfInstr::new(MINF_MARF, MINF_TBB, 2, 8),
MinInfInstr::new_next01(MINF_MAB, MINF_TBRF, 9),
MinInfInstr::new_next01(MINF_MAB, MINF_TBRF, 10),
MinInfInstr::new_next01(MINF_MAB, MINF_TBRF, 11),
MinInfInstr::new_next01(MINF_MARF, MINF_TBRW1, 12),
MinInfInstr::new_next01(MINF_MARF, MINF_TBRW1, 13),
MinInfInstr::new_next01(MINF_MARF, MINF_TBRW1, 14),
MinInfInstr::new(MINF_TBRW1, MINF_TBRW0, 15, 21),
MinInfInstr::new(MINF_TBRW1, MINF_TBRW0, 16, 22),
MinInfInstr::new(MINF_TBRW1, MINF_TBRW0, 15, 23),
MinInfInstr::new_next01(MINF_TBB, MINF_MRW1, 17),
MinInfInstr::new_next01(MINF_TBB, MINF_MRW1, 18),
MinInfInstr::new_next01(MINF_MARW1, MINF_TBB, 19),
MinInfInstr::new_next01(MINF_MARW1, MINF_TBB, 20),
MinInfInstr::new_01(MINF_STOP, 19),
MinInfInstr::new_01(MINF_STOP, 20),
MinInfInstr::new_next01(MINF_MAB, MINF_MRW0, 25),
MinInfInstr::new_next01(MINF_MAB, MINF_MRW0, 26),
MinInfInstr::new_next01(MINF_MAB, MINF_MRW0, 27),
MinInfInstr::new_next01(MINF_MAB, MINF_MRW0, 28),
MinInfInstr::new_next01(MINF_MARW0, MINF_TBRW1, 29),
MinInfInstr::new_next01(MINF_MARW0, MINF_TBRW1, 30),
MinInfInstr::new_next01(MINF_MARW0, MINF_TBRW1, 31),
MinInfInstr::new_next01(MINF_MARW0, MINF_TBRW1, 32),
MinInfInstr::new_next01(MINF_MARW1, MINF_TBB, 33),
MinInfInstr::new_next01(MINF_MARW1, MINF_TBB, 34),
MinInfInstr::new_next01(MINF_MARW1, MINF_TBB, 35),
MinInfInstr::new_next01(MINF_MARW1, MINF_TBB, 36),
MinInfInstr::new_01(MINF_STOP2, 0),
MinInfInstr::new_01(MINF_STOP2, 0),
MinInfInstr::new_01(MINF_STOP2, 0),
MinInfInstr::new_01(MINF_STOP2, 0),
],
vec![
("code1".to_string(), 15),
("code2".to_string(), 21),
("start".to_string(), 0),
]
)),
builder.try_to_code().map_err(|x| x.to_string())
);
}
#[test]
fn test_min_inf_builder_with_var_state_snx_mods() {
let builder = MinInfBuilder::<String, MinInfBInstrSingleSVInt<_>>::new();
let mut builder = MinInfWithStateVar::new(builder, 3);
builder.add_label("start");
builder.add_instr(MinInfBuildInstr::new(MINF_MARW0, MINF_MARW1, 1, 2));
builder.add_instr(MinInfBuildInstr::new(MINF_MARF, MINF_TBB, -1, 1));
builder.add_instr(MinInfBuildInstr::newp(MINF_MAB, MINF_TBRF));
builder.add_instr(MinInfBuildInstr::newp(MINF_MARF, MINF_TBRW1));
builder.add_instr(MinInfBInstrSV::new([
(MINF_TBRW1, MINF_TBRW0, ("code1", 0, 2), ("code2", 0, 4)),
(MINF_TBRW1, MINF_TBRW0, ("code1", 1, 2), ("code2", 1, 4)),
(MINF_TBRW1, MINF_TBRW0, ("code1", 0, 2), ("code2", 2, 4)),
]));
let builder = builder.free();
let mut builder = MinInfWithStateVar::new(builder, 2);
builder.add_label("code1");
builder.add_instr(MinInfBuildInstr::newp(MINF_TBB, MINF_MRW1));
builder.add_instr(MinInfBInstrSV::new([
MinInfBInstrSingleSV::from((
MINF_MARW1,
MINF_TBB,
MinInfRelSV {
rel: 1.into(),
value: Some(1),
next_state_num: None,
},
MinInfRelSV {
rel: (-1).into(),
value: Some(0),
next_state_num: None,
},
)),
(
MINF_MARW1,
MINF_TBB,
MinInfRelSV {
rel: (-1).into(),
value: Some(0),
next_state_num: None,
},
MinInfRelSV {
rel: 1.into(),
value: Some(1),
next_state_num: None,
},
)
.into(),
]));
builder.add_instr(MinInfBInstrSV::from((MINF_STOP, 0isize)));
let builder = builder.free();
let mut builder = MinInfWithStateVar::new(builder, 4);
builder.add_label("code2");
builder.add_instr(MinInfBInstrSV::new([
MinInfBInstrSingleSV::from((MINF_MAB, MINF_MRW0, (1, 0, 4))),
(MINF_MAB, MINF_MRW0, (1, 1, 4)).into(),
]));
builder.add_instr(MinInfBInstrSV::new([
MinInfBInstrSingleSV::from((
MINF_MARW0,
MINF_TBRW1,
MinInfRelSV {
rel: 1.into(),
value: Some(3),
next_state_num: None,
},
)),
MinInfBInstrSingleSV::from((
MINF_MARW0,
MINF_TBRW1,
MinInfRelSV {
rel: 2.into(),
value: Some(2),
next_state_num: None,
},
)),
MinInfBInstrSingleSV::from((
MINF_MARW0,
MINF_TBRW1,
MinInfRelSV {
rel: 2.into(),
value: Some(0),
next_state_num: None,
},
)),
MinInfBInstrSingleSV::from((
MINF_MARW0,
MINF_TBRW1,
MinInfRelSV {
rel: 1.into(),
value: Some(1),
next_state_num: None,
},
)),
]));
builder.add_instr((MINF_MARW1, MINF_TBB));
builder.add_instr(MINF_STOP2);
let builder = builder.free();
assert_eq!(
Ok((
vec![
MinInfInstr::new(MINF_MARW0, MINF_MARW1, 3, 6),
MinInfInstr::new(MINF_MARW0, MINF_MARW1, 4, 7),
MinInfInstr::new(MINF_MARW0, MINF_MARW1, 5, 8),
MinInfInstr::new(MINF_MARF, MINF_TBB, 0, 6),
MinInfInstr::new(MINF_MARF, MINF_TBB, 1, 7),
MinInfInstr::new(MINF_MARF, MINF_TBB, 2, 8),
MinInfInstr::new_next01(MINF_MAB, MINF_TBRF, 9),
MinInfInstr::new_next01(MINF_MAB, MINF_TBRF, 10),
MinInfInstr::new_next01(MINF_MAB, MINF_TBRF, 11),
MinInfInstr::new_next01(MINF_MARF, MINF_TBRW1, 12),
MinInfInstr::new_next01(MINF_MARF, MINF_TBRW1, 13),
MinInfInstr::new_next01(MINF_MARF, MINF_TBRW1, 14),
MinInfInstr::new(MINF_TBRW1, MINF_TBRW0, 15, 21),
MinInfInstr::new(MINF_TBRW1, MINF_TBRW0, 16, 22),
MinInfInstr::new(MINF_TBRW1, MINF_TBRW0, 15, 23),
MinInfInstr::new_next01(MINF_TBB, MINF_MRW1, 17),
MinInfInstr::new_next01(MINF_TBB, MINF_MRW1, 18),
MinInfInstr::new(MINF_MARW1, MINF_TBB, 20, 15),
MinInfInstr::new(MINF_MARW1, MINF_TBB, 15, 20),
MinInfInstr::new_01(MINF_STOP, 19),
MinInfInstr::new_01(MINF_STOP, 20),
MinInfInstr::new_next01(MINF_MAB, MINF_MRW0, 25),
MinInfInstr::new_next01(MINF_MAB, MINF_MRW0, 26),
MinInfInstr::new_next01(MINF_MAB, MINF_MRW0, 25),
MinInfInstr::new_next01(MINF_MAB, MINF_MRW0, 26),
MinInfInstr::new_next01(MINF_MARW0, MINF_TBRW1, 32),
MinInfInstr::new_next01(MINF_MARW0, MINF_TBRW1, 35),
MinInfInstr::new_next01(MINF_MARW0, MINF_TBRW1, 33),
MinInfInstr::new_next01(MINF_MARW0, MINF_TBRW1, 30),
MinInfInstr::new_next01(MINF_MARW1, MINF_TBB, 33),
MinInfInstr::new_next01(MINF_MARW1, MINF_TBB, 34),
MinInfInstr::new_next01(MINF_MARW1, MINF_TBB, 35),
MinInfInstr::new_next01(MINF_MARW1, MINF_TBB, 36),
MinInfInstr::new_01(MINF_STOP2, 0),
MinInfInstr::new_01(MINF_STOP2, 0),
MinInfInstr::new_01(MINF_STOP2, 0),
MinInfInstr::new_01(MINF_STOP2, 0),
],
vec![
("code1".to_string(), 15),
("code2".to_string(), 21),
("start".to_string(), 0),
]
)),
builder.try_to_code().map_err(|x| x.to_string())
);
}
#[test]
fn test_min_inf_builder_with_var_state_errors() {
let builder = MinInfBuilder::<String, MinInfBInstrSingleSVInt<_>>::new();
let mut builder = MinInfWithStateVar::new(builder, 3);
builder.add_label("start");
assert_eq!(
Err(concat!(
"IntoInstr: Next value out of range: 2 MinInfBInstrSingleSV ",
"{ func_fr0: TempBufferReadWrite1, func_fr1: TempBufferReadWrite0, ",
"next_fr0: MinInfRelSV { rel: MinInfRel { label: Some(\"code3\"), ",
"offset: 0 }, value: Some(1), next_state_num: Some(3) }, ",
"next_fr1: MinInfRelSV { rel: MinInfRel { label: Some(\"code2\"), ",
"offset: 0 }, value: Some(4), next_state_num: Some(4) } } 4 4"
)
.to_string()),
builder
.try_add_instr(MinInfBInstrSV::new([
(MINF_TBRW1, MINF_TBRW0, ("code1", 0, 2), ("code2", 0, 4)),
(MINF_TBRW1, MINF_TBRW0, ("code3", 1, 3), ("code2", 4, 4)),
(MINF_TBRW1, MINF_TBRW0, ("code4", 0, 4), ("code2", 2, 4)),
]))
.map_err(|e| e.to_string())
);
assert_eq!(
Err(concat!(
"IntoInstr: Next value out of range: 0 MinInfBInstrSingleSV ",
"{ func_fr0: TempBufferReadWrite1, func_fr1: TempBufferReadWrite0, ",
"next_fr0: MinInfRelSV { rel: MinInfRel { label: None, offset: 1 }, ",
"value: Some(3), next_state_num: None }, next_fr1: MinInfRelSV ",
"{ rel: MinInfRel { label: Some(\"code2\"), offset: 0 }, ",
"value: Some(0), next_state_num: Some(4) } } 3 3"
)
.to_string()),
builder
.try_add_instr(MinInfBInstrSV::new([
MinInfBInstrSingleSV::new(
MINF_TBRW1,
MINF_TBRW0,
MinInfRelSV {
rel: 1.into(),
value: Some(3), next_state_num: None,
},
("code2", 0, 4)
),
(MINF_TBRW1, MINF_TBRW0, ("code3", 1, 3), ("code2", 1, 4)).into(),
(MINF_TBRW1, MINF_TBRW0, ("code4", 0, 4), ("code2", 2, 4)).into(),
]))
.map_err(|e| e.to_string())
);
assert_eq!(
Err(concat!(
"IntoInstr: Next value out of range: 1 MinInfBInstrSingleSV ",
"{ func_fr0: TempBufferReadWrite1, func_fr1: TempBufferReadWrite0, ",
"next_fr0: MinInfRelSV { rel: MinInfRel { label: Some(\"code4\"), ",
"offset: 0 }, value: None, next_state_num: Some(2) }, ",
"next_fr1: MinInfRelSV { rel: MinInfRel { label: Some(\"code4\"), ",
"offset: 0 }, value: None, next_state_num: Some(3) } } 2 2"
)
.to_string()),
builder
.try_add_instr(MinInfBInstrSV::new([
MinInfBInstrSingleSV::new(MINF_TBRW1, MINF_TBRW0, ("code1", 0, 2), ("code2", 0, 4)),
(MINF_TBRW1, MINF_TBRW0, ("code3", 1, 3), ("code2", 2, 4)).into(),
(MINF_TBRW1, MINF_TBRW0, ("code4", 2usize), ("code4", 3usize)).into(),
]))
.map_err(|e| e.to_string())
);
assert_eq!(
Err(concat!(
"IntoInstr: Next value out of range: 3 MinInfBInstrSingleSV ",
"{ func_fr0: TempBufferReadWrite1, func_fr1: TempBufferReadWrite0, ",
"next_fr0: MinInfRelSV { rel: MinInfRel { label: Some(\"code4\"), ",
"offset: 0 }, value: None, next_state_num: Some(3) }, ",
"next_fr1: MinInfRelSV { rel: MinInfRel { label: Some(\"code4\"), ",
"offset: 0 }, value: None, next_state_num: Some(2) } } 2 2"
)
.to_string()),
builder
.try_add_instr(MinInfBInstrSV::new([
MinInfBInstrSingleSV::new(MINF_TBRW1, MINF_TBRW0, ("code1", 0, 2), ("code2", 0, 4)),
(MINF_TBRW1, MINF_TBRW0, ("code3", 1, 3), ("code2", 2, 4)).into(),
(MINF_TBRW1, MINF_TBRW0, ("code4", 3usize), ("code4", 2usize)).into(),
]))
.map_err(|e| e.to_string())
);
}
#[test]
fn test_min_inf_builder_with_var_state_snx_errors() {
let builder = MinInfBuilder::<String, MinInfBInstrSingleSVInt<_>>::new();
let mut builder = MinInfWithStateVar::new(builder, 3);
builder.add_label("start");
builder.add_instr(MinInfBuildInstr::new(MINF_MARW0, MINF_MARW1, 1, 2));
builder.add_instr(MinInfBuildInstr::new(MINF_MARF, MINF_TBB, -1, 1));
builder.add_instr(MinInfBuildInstr::newp(MINF_MAB, MINF_TBRF));
builder.add_instr(MinInfBuildInstr::newp(MINF_MARF, MINF_TBRW1));
builder.add_instr(MinInfBInstrSV::new([
(MINF_TBRW1, MINF_TBRW0, ("code1", 0, 2), ("code2", 0, 4)),
(MINF_TBRW1, MINF_TBRW0, ("code1", 1, 2), ("code2", 1, 4)),
(MINF_TBRW1, MINF_TBRW0, ("code1", 0, 2), ("code2", 2, 4)),
]));
let builder = builder.free();
let mut builder = MinInfWithStateVar::new(builder, 2);
builder.add_label("code1");
builder.add_instr(MinInfBuildInstr::newp(MINF_TBB, MINF_MRW1));
builder.add_instr(MinInfBuildInstr::new(MINF_MARW1, MINF_TBB, -2, 1));
builder.add_instr(MinInfBInstrSV::from((MINF_STOP, 0isize)));
let builder = builder.free();
let mut builder = MinInfWithStateVar::new(builder, 4);
builder.add_label("code2");
builder.add_instr(MinInfBuildInstr::newp(MINF_MAB, MINF_MRW0));
builder.add_instr(MinInfBuildInstr::newp(MINF_MARW0, MINF_TBRW1));
builder.add_instr(MinInfBuildInstr::newp(MINF_MARW1, MINF_TBB));
builder.add_instr(MinInfBuildInstr::newp_01(MINF_STOP2));
let builder = builder.free();
assert_eq!(
Err(concat!(
"Assertion error: Bad state value: MinInfBInstrSingleSVInt ",
"{ func_fr0: MemAddressReadWrite1, func_fr1: TempBufferBackward, ",
"next_fr0: MinInfRelSV { rel: MinInfRel { label: None, offset: -4 }, ",
"value: None, next_state_num: None }, next_fr1: MinInfRelSV ",
"{ rel: MinInfRel { label: None, offset: 2 }, value: None, ",
"next_state_num: None }, value: 0, state_num: 2 } ",
"MinInfBInstrSingleSVInt { func_fr0: TempBufferReadWrite1, ",
"func_fr1: TempBufferReadWrite0, next_fr0: MinInfRelSV ",
"{ rel: MinInfRel { label: Some(\"code1\"), offset: 0 }, ",
"value: Some(1), next_state_num: Some(2) }, next_fr1: MinInfRelSV ",
"{ rel: MinInfRel { label: Some(\"code2\"), offset: 0 }, ",
"value: Some(1), next_state_num: Some(4) }, value: 1, state_num: 3 }"
)
.to_string()),
builder.try_to_code().map_err(|x| x.to_string())
);
let builder = MinInfBuilder::<String, MinInfBInstrSingleSVInt<_>>::new();
let mut builder = MinInfWithStateVar::new(builder, 3);
builder.add_label("start");
builder.add_instr(MinInfBuildInstr::new(MINF_MARW0, MINF_MARW1, 1, 2));
builder.add_instr(MinInfBuildInstr::new(MINF_MARF, MINF_TBB, -1, 1));
builder.add_instr(MinInfBuildInstr::newp(MINF_MAB, MINF_TBRF));
builder.add_instr(MinInfBuildInstr::newp(MINF_MARF, MINF_TBRW1));
builder.add_instr(MinInfBInstrSV::new([
(MINF_TBRW1, MINF_TBRW0, ("code1", 0, 2), ("code2", 0, 4)),
(MINF_TBRW1, MINF_TBRW0, ("code1", 1, 2), ("code2", 1, 4)),
(MINF_TBRW1, MINF_TBRW0, ("code1", 0, 2), ("code2", 2, 4)),
]));
let builder = builder.free();
let mut builder = MinInfWithStateVar::new(builder, 2);
builder.add_label("code1");
builder.add_instr(MinInfBuildInstr::newp(MINF_TBB, MINF_MRW1));
builder.add_instr(MinInfBuildInstr::new(MINF_MARW1, MINF_TBB, -4, 1));
builder.add_instr(MinInfBInstrSV::from((MINF_STOP, 0isize)));
let builder = builder.free();
let mut builder = MinInfWithStateVar::new(builder, 4);
builder.add_label("code2");
builder.add_instr(MinInfBuildInstr::newp(MINF_MAB, MINF_MRW0));
builder.add_instr(MinInfBuildInstr::newp(MINF_MARW0, MINF_TBRW1));
builder.add_instr(MinInfBuildInstr::newp(MINF_MARW1, MINF_TBB));
builder.add_instr(MinInfBuildInstr::newp_01(MINF_STOP2));
let builder = builder.free();
assert_eq!(
Err(concat!(
"Assertion error: Next FuncRet=0 state num mismatch: ",
"MinInfBInstrSingleSVInt { func_fr0: MemAddressReadWrite1, ",
"func_fr1: TempBufferBackward, next_fr0: MinInfRelSV ",
"{ rel: MinInfRel { label: None, offset: -8 }, value: None, ",
"next_state_num: None }, next_fr1: MinInfRelSV ",
"{ rel: MinInfRel { label: None, offset: 2 }, value: None, ",
"next_state_num: None }, value: 0, state_num: 2 } ",
"MinInfBInstrSingleSVInt { func_fr0: MemAddressReadForward, ",
"func_fr1: TempBufferReadWrite1, next_fr0: MinInfRelSV ",
"{ rel: MinInfRel { label: None, offset: 3 }, value: None, ",
"next_state_num: None }, next_fr1: MinInfRelSV { rel: MinInfRel ",
"{ label: None, offset: 3 }, value: None, next_state_num: None }, ",
"value: 0, state_num: 3 }"
)
.to_string()),
builder.try_to_code().map_err(|x| x.to_string())
);
let builder = MinInfBuilder::<String, MinInfBInstrSingleSVInt<_>>::new();
let mut builder = MinInfWithStateVar::new(builder, 3);
builder.add_label("start");
builder.add_instr(MinInfBuildInstr::new(MINF_MARW0, MINF_MARW1, 1, 2));
builder.add_instr(MinInfBuildInstr::new(MINF_MARF, MINF_TBB, -1, 1));
builder.add_instr(MinInfBuildInstr::newp(MINF_MAB, MINF_TBRF));
builder.add_instr(MinInfBuildInstr::newp(MINF_MARF, MINF_TBRW1));
builder.add_instr(MinInfBInstrSV::new([
(MINF_TBRW1, MINF_TBRW0, ("code1", 0, 2), ("code2", 0, 4)),
(MINF_TBRW1, MINF_TBRW0, ("code1", 1, 2), ("code2", 1, 4)),
(MINF_TBRW1, MINF_TBRW0, ("code1", 0, 2), ("code2", 2, 4)),
]));
let builder = builder.free();
let mut builder = MinInfWithStateVar::new(builder, 2);
builder.add_label("code1");
builder.add_instr(MinInfBuildInstr::newp(MINF_TBB, MINF_MRW1));
builder.add_instr(MinInfBuildInstr::new(MINF_MARW1, MINF_TBB, 1, -4));
builder.add_instr(MinInfBInstrSV::from((MINF_STOP, 0isize)));
let builder = builder.free();
let mut builder = MinInfWithStateVar::new(builder, 4);
builder.add_label("code2");
builder.add_instr(MinInfBuildInstr::newp(MINF_MAB, MINF_MRW0));
builder.add_instr(MinInfBuildInstr::newp(MINF_MARW0, MINF_TBRW1));
builder.add_instr(MinInfBuildInstr::newp(MINF_MARW1, MINF_TBB));
builder.add_instr(MinInfBuildInstr::newp_01(MINF_STOP2));
let builder = builder.free();
assert_eq!(
Err(concat!(
"Assertion error: Next FuncRet=1 state num mismatch ",
"MinInfBInstrSingleSVInt { func_fr0: MemAddressReadWrite1, ",
"func_fr1: TempBufferBackward, next_fr0: MinInfRelSV ",
"{ rel: MinInfRel { label: None, offset: 2 }, value: None, ",
"next_state_num: None }, next_fr1: MinInfRelSV { rel: MinInfRel ",
"{ label: None, offset: -8 }, value: None, next_state_num: None }, ",
"value: 0, state_num: 2 } MinInfBInstrSingleSVInt ",
"{ func_fr0: MemAddressReadForward, func_fr1: TempBufferReadWrite1, ",
"next_fr0: MinInfRelSV { rel: MinInfRel { label: None, offset: 3 }, ",
"value: None, next_state_num: None }, next_fr1: MinInfRelSV ",
"{ rel: MinInfRel { label: None, offset: 3 }, value: None, ",
"next_state_num: None }, value: 0, state_num: 3 }"
)
.to_string()),
builder.try_to_code().map_err(|x| x.to_string())
);
}
#[test]
fn test_min_inf_builder_local_labels() {
let mut builder = MinInfBuilder::<String, MinInfBuildInstr<_>>::new();
let mut l = LocalLabels::new_with_sep(&mut builder, "myfunc", "::");
l.add_label("start".to_string());
l.b.add_instr(MinInfBuildInstr::new(MINF_MARW0, MINF_MARW1, 1, 2));
l.b.add_instr(MinInfBuildInstr::new(MINF_MARF, MINF_TBB, -1, 1));
l.b.add_instr(MinInfBuildInstr::newp(MINF_MAB, MINF_TBRF));
l.b.add_instr(MinInfBuildInstr::newp(MINF_MARF, MINF_TBRW1));
l.b.add_instr(MinInfBuildInstr::new(
MINF_TBRW1,
MINF_TBRW0,
l.t("code1"),
l.t("code2"),
));
l.add_label("code1");
l.b.add_instr(MinInfBuildInstr::newp(MINF_TBB, MINF_MRW1));
l.b.add_instr(MinInfBuildInstr::newp(MINF_MARW1, MINF_TBB));
l.b.add_instr(MinInfBuildInstr::newp_01(MINF_STOP));
l.add_label("code2");
l.b.add_instr(MinInfBuildInstr::newp(MINF_MAB, MINF_MRW0));
l.b.add_instr(MinInfBuildInstr::newp(MINF_MARW0, MINF_TBRW1));
l.b.add_instr(MinInfBuildInstr::newp(MINF_MARW1, MINF_TBB));
l.b.add_instr(MinInfBuildInstr::newp_01(MINF_STOP2));
assert_eq!(
Ok((
vec![
MinInfInstr::new(MINF_MARW0, MINF_MARW1, 1, 2),
MinInfInstr::new(MINF_MARF, MINF_TBB, 0, 2),
MinInfInstr::new_next01(MINF_MAB, MINF_TBRF, 3),
MinInfInstr::new_next01(MINF_MARF, MINF_TBRW1, 4),
MinInfInstr::new(MINF_TBRW1, MINF_TBRW0, 5, 8),
MinInfInstr::new_next01(MINF_TBB, MINF_MRW1, 6),
MinInfInstr::new_next01(MINF_MARW1, MINF_TBB, 7),
MinInfInstr::new_01(MINF_STOP, 8),
MinInfInstr::new_next01(MINF_MAB, MINF_MRW0, 9),
MinInfInstr::new_next01(MINF_MARW0, MINF_TBRW1, 10),
MinInfInstr::new_next01(MINF_MARW1, MINF_TBB, 11),
MinInfInstr::new_01(MINF_STOP2, 0),
],
vec![
("myfunc::code1".to_string(), 5),
("myfunc::code2".to_string(), 8),
("myfunc::start".to_string(), 0),
]
)),
builder.try_to_code().map_err(|x| x.to_string())
);
}
#[test]
fn test_min_inf_builder_with_var_state_snx_2_local_labels() {
let builder = MinInfBuilder::<String, MinInfBInstrSingleSVInt<_>>::new();
let mut builder = MinInfWithStateVar::new(builder, 3);
let mut l = LocalLabels::new_with_sep(&mut builder, "myfuncx", "::");
l.add_label("start");
l.b.add_instr(MinInfBuildInstr::new(MINF_MARW0, MINF_MARW1, 1, 2));
l.b.add_instr(MinInfBuildInstr::new(MINF_MARF, MINF_TBB, -1, 1));
l.b.add_instr(MinInfBuildInstr::newp(MINF_MAB, MINF_TBRF));
l.b.add_instr(MinInfBuildInstr::newp(MINF_MARF, MINF_TBRW1));
l.b.add_instr(MinInfBInstrSV::new([
(
MINF_TBRW1,
MINF_TBRW0,
(l.t("code1"), 0, 2),
(l.t("code2"), 0, 4),
),
(
MINF_TBRW1,
MINF_TBRW0,
(l.t("code1"), 1, 2),
(l.t("code2"), 1, 4),
),
(
MINF_TBRW1,
MINF_TBRW0,
(l.t("code1"), 0, 2),
(l.t("code2"), 2, 4),
),
]));
l.b.switch(2);
l.add_label("code1");
l.b.add_instr(MinInfBuildInstr::newp(MINF_TBB, MINF_MRW1));
l.b.add_instr(MinInfBuildInstr::newp(MINF_MARW1, MINF_TBB));
l.b.add_instr(MinInfBInstrSV::from((MINF_STOP, 0isize)));
l.b.switch(4);
l.add_label("code2");
l.b.add_instr(MinInfBuildInstr::newp(MINF_MAB, MINF_MRW0));
l.b.add_instr(MinInfBuildInstr::newp(MINF_MARW0, MINF_TBRW1));
l.b.add_instr(MinInfBuildInstr::newp(MINF_MARW1, MINF_TBB));
l.b.add_instr(MinInfBuildInstr::newp_01(MINF_STOP2));
let builder = builder.free();
assert_eq!(
Ok((
vec![
MinInfInstr::new(MINF_MARW0, MINF_MARW1, 3, 6),
MinInfInstr::new(MINF_MARW0, MINF_MARW1, 4, 7),
MinInfInstr::new(MINF_MARW0, MINF_MARW1, 5, 8),
MinInfInstr::new(MINF_MARF, MINF_TBB, 0, 6),
MinInfInstr::new(MINF_MARF, MINF_TBB, 1, 7),
MinInfInstr::new(MINF_MARF, MINF_TBB, 2, 8),
MinInfInstr::new_next01(MINF_MAB, MINF_TBRF, 9),
MinInfInstr::new_next01(MINF_MAB, MINF_TBRF, 10),
MinInfInstr::new_next01(MINF_MAB, MINF_TBRF, 11),
MinInfInstr::new_next01(MINF_MARF, MINF_TBRW1, 12),
MinInfInstr::new_next01(MINF_MARF, MINF_TBRW1, 13),
MinInfInstr::new_next01(MINF_MARF, MINF_TBRW1, 14),
MinInfInstr::new(MINF_TBRW1, MINF_TBRW0, 15, 21),
MinInfInstr::new(MINF_TBRW1, MINF_TBRW0, 16, 22),
MinInfInstr::new(MINF_TBRW1, MINF_TBRW0, 15, 23),
MinInfInstr::new_next01(MINF_TBB, MINF_MRW1, 17),
MinInfInstr::new_next01(MINF_TBB, MINF_MRW1, 18),
MinInfInstr::new_next01(MINF_MARW1, MINF_TBB, 19),
MinInfInstr::new_next01(MINF_MARW1, MINF_TBB, 20),
MinInfInstr::new_01(MINF_STOP, 19),
MinInfInstr::new_01(MINF_STOP, 20),
MinInfInstr::new_next01(MINF_MAB, MINF_MRW0, 25),
MinInfInstr::new_next01(MINF_MAB, MINF_MRW0, 26),
MinInfInstr::new_next01(MINF_MAB, MINF_MRW0, 27),
MinInfInstr::new_next01(MINF_MAB, MINF_MRW0, 28),
MinInfInstr::new_next01(MINF_MARW0, MINF_TBRW1, 29),
MinInfInstr::new_next01(MINF_MARW0, MINF_TBRW1, 30),
MinInfInstr::new_next01(MINF_MARW0, MINF_TBRW1, 31),
MinInfInstr::new_next01(MINF_MARW0, MINF_TBRW1, 32),
MinInfInstr::new_next01(MINF_MARW1, MINF_TBB, 33),
MinInfInstr::new_next01(MINF_MARW1, MINF_TBB, 34),
MinInfInstr::new_next01(MINF_MARW1, MINF_TBB, 35),
MinInfInstr::new_next01(MINF_MARW1, MINF_TBB, 36),
MinInfInstr::new_01(MINF_STOP2, 0),
MinInfInstr::new_01(MINF_STOP2, 0),
MinInfInstr::new_01(MINF_STOP2, 0),
MinInfInstr::new_01(MINF_STOP2, 0),
],
vec![
("myfuncx::code1".to_string(), 15),
("myfuncx::code2".to_string(), 21),
("myfuncx::start".to_string(), 0),
]
)),
builder.try_to_code().map_err(|x| x.to_string())
);
}
#[test]
fn test_min_inf_builder_multi_append() {
let mut builder = MinInfBuilder::<String, MinInfBuildInstr<_>>::new();
builder.add_label("start".to_string());
builder.add_instr(MinInfBuildInstr::new(MINF_MARW0, MINF_MARW1, 1, 2));
builder.add_instr(MinInfBuildInstr::new(MINF_MARF, MINF_TBB, -1, 1));
builder.add_instr(MinInfBuildInstr::newp(MINF_MAB, MINF_TBRF));
builder.add_instr(MinInfBuildInstr::newp(MINF_MARF, MINF_TBRW1));
builder.add_instr(MinInfBuildInstr::new(
MINF_TBRW1, MINF_TBRW0, "code1", "code2",
));
builder.add_label("code1");
builder.add_instr(MinInfBuildInstr::newp(MINF_TBB, MINF_MRW1));
builder.add_instr(MinInfBuildInstr::newp(MINF_MARW1, MINF_TBB));
builder.add_instr(MinInfBuildInstr::newp_01(MINF_STOP));
builder.add_label("code2");
builder.add_instr(MinInfBuildInstr::newp(MINF_MAB, MINF_MRW0));
builder.add_instr(MinInfBuildInstr::newp(MINF_MARW0, MINF_TBRW1));
builder.add_instr(MinInfBuildInstr::newp(MINF_MARW1, MINF_TBB));
builder.add_instr(MinInfBuildInstr::newp_01(MINF_STOP2));
let mut builder2 = MinInfBuilder::<String, MinInfBuildInstr<String>>::new();
builder2.add_instr(MinInfBuildInstr::newp(MINF_TBRW0, MINF_TBRW1));
builder2.add_label("t1");
builder2.add_instr(MinInfBuildInstr::newp(MINF_MARW0, MINF_MARW1));
let mut builder3 = MinInfBuilder::<String, MinInfBuildInstr<String>>::new();
builder3.add_instr(MinInfBuildInstr::newp(MINF_TBB, MINF_TBRF));
builder3.add_label("t2");
builder3.add_instr(MinInfBuildInstr::newp(MINF_MARF, MINF_MAB));
builder.multi_append([
(2, &builder2),
(builder.get_label_map()["code2"] + 2, &builder3),
]);
assert_eq!(
Ok((
vec![
MinInfInstr::new(MINF_MARW0, MINF_MARW1, 1, 2),
MinInfInstr::new(MINF_MARF, MINF_TBB, 0, 2),
MinInfInstr::new_next01(MINF_TBRW0, MINF_TBRW1, 3),
MinInfInstr::new_next01(MINF_MARW0, MINF_MARW1, 4),
MinInfInstr::new_next01(MINF_MAB, MINF_TBRF, 5),
MinInfInstr::new_next01(MINF_MARF, MINF_TBRW1, 6),
MinInfInstr::new(MINF_TBRW1, MINF_TBRW0, 7, 10),
MinInfInstr::new_next01(MINF_TBB, MINF_MRW1, 8),
MinInfInstr::new_next01(MINF_MARW1, MINF_TBB, 9),
MinInfInstr::new_01(MINF_STOP, 10),
MinInfInstr::new_next01(MINF_MAB, MINF_MRW0, 11),
MinInfInstr::new_next01(MINF_MARW0, MINF_TBRW1, 12),
MinInfInstr::new_next01(MINF_TBB, MINF_TBRF, 13),
MinInfInstr::new_next01(MINF_MARF, MINF_MAB, 14),
MinInfInstr::new_next01(MINF_MARW1, MINF_TBB, 15),
MinInfInstr::new_01(MINF_STOP2, 0),
],
vec![
("code1".to_string(), 7),
("code2".to_string(), 10),
("start".to_string(), 0),
("t1".to_string(), 3),
("t2".to_string(), 13),
]
)),
builder.try_to_code().map_err(|x| x.to_string())
);
let mut builder = MISimpleBuilder::new();
builder.l("start");
builder.l("l0");
builder.i(MINF_TBRF);
builder.l("l1");
builder.i(MINF_TBRF);
builder.l("l2");
builder.i(MINF_TBRF);
builder.l("l3");
builder.i(MINF_TBRF);
builder.l("l4");
builder.i(MINF_TBRF);
builder.l("l5");
builder.i(MINF_TBRF);
builder.l("l6");
builder.i((MINF_TBRF, "start"));
let mut builder2 = MISimpleBuilder::new();
builder2.l("xx1");
builder2.i(MINF_MARF);
builder2.i(MINF_MAB);
builder2.i(MINF_MARW0);
let mut builder3 = MISimpleBuilder::new();
builder3.l("xx2");
builder3.i(MINF_TBRW1);
builder3.i(MINF_TBB);
builder3.l("xx3");
builder3.i(MINF_TBRW0);
builder.multi_append([(2, &builder2), (4, &builder3)]);
assert_eq!(
Ok((
vec![
MinInfInstr::new(MINF_TBRF, MINF_TBRF, 1, 1),
(MINF_TBRF, MINF_TBRF, 2, 2).into(),
(MINF_MARF, MINF_MARF, 3, 3).into(),
(MINF_MAB, MINF_MAB, 4, 4).into(),
(MINF_MARW0, MINF_MARW0, 5, 5).into(),
(MINF_TBRF, MINF_TBRF, 6, 6).into(),
(MINF_TBRF, MINF_TBRF, 7, 7).into(),
(MINF_TBRW1, MINF_TBRW1, 8, 8).into(),
(MINF_TBB, MINF_TBB, 9, 9).into(),
(MINF_TBRW0, MINF_TBRW0, 10, 10).into(),
(MINF_TBRF, MINF_TBRF, 11, 11).into(),
(MINF_TBRF, MINF_TBRF, 12, 12).into(),
(MINF_TBRF, MINF_TBRF, 0, 0).into(),
],
vec![
("l0".to_string(), 0),
("l1".to_string(), 1),
("l2".to_string(), 2),
("l3".to_string(), 6),
("l4".to_string(), 7),
("l5".to_string(), 11),
("l6".to_string(), 12),
("start".to_string(), 0),
("xx1".to_string(), 2),
("xx2".to_string(), 7),
("xx3".to_string(), 9),
]
)),
builder.try_to_code().map_err(|x| x.to_string())
);
let mut builder = MISimpleBuilder::new();
builder.l("start");
builder.l("l6");
builder.i(MINF_TBRF);
builder.l("l5");
builder.i(MINF_TBRF);
builder.l("l4");
builder.i(MINF_TBRF);
builder.l("l3");
builder.i(MINF_TBRF);
builder.l("l2");
builder.i(MINF_TBRF);
builder.l("l1");
builder.i(MINF_TBRF);
builder.l("l0");
builder.i((MINF_TBRF, "start"));
let mut builder2 = MISimpleBuilder::new();
builder2.l("xx1");
builder2.i(MINF_MARF);
builder2.i(MINF_MAB);
builder2.i(MINF_MARW0);
let mut builder3 = MISimpleBuilder::new();
builder3.l("xx2");
builder3.i(MINF_TBRW1);
builder3.i(MINF_TBB);
builder3.l("xx3");
builder3.i(MINF_TBRW0);
builder.multi_append([(2, &builder2), (4, &builder3)]);
assert_eq!(
Ok((
vec![
MinInfInstr::new(MINF_TBRF, MINF_TBRF, 1, 1),
(MINF_TBRF, MINF_TBRF, 2, 2).into(),
(MINF_MARF, MINF_MARF, 3, 3).into(),
(MINF_MAB, MINF_MAB, 4, 4).into(),
(MINF_MARW0, MINF_MARW0, 5, 5).into(),
(MINF_TBRF, MINF_TBRF, 6, 6).into(),
(MINF_TBRF, MINF_TBRF, 7, 7).into(),
(MINF_TBRW1, MINF_TBRW1, 8, 8).into(),
(MINF_TBB, MINF_TBB, 9, 9).into(),
(MINF_TBRW0, MINF_TBRW0, 10, 10).into(),
(MINF_TBRF, MINF_TBRF, 11, 11).into(),
(MINF_TBRF, MINF_TBRF, 12, 12).into(),
(MINF_TBRF, MINF_TBRF, 0, 0).into(),
],
vec![
("l0".to_string(), 12),
("l1".to_string(), 11),
("l2".to_string(), 7),
("l3".to_string(), 6),
("l4".to_string(), 2),
("l5".to_string(), 1),
("l6".to_string(), 0),
("start".to_string(), 0),
("xx1".to_string(), 2),
("xx2".to_string(), 7),
("xx3".to_string(), 9),
]
)),
builder.try_to_code().map_err(|x| x.to_string())
);
let mut builder = MISimpleBuilder::new();
builder.i(MINF_TBRF);
builder.i(MINF_TBRF);
builder.i(MINF_TBRF);
builder.i(MINF_TBRF);
builder.i(MINF_TBRF);
builder.i(MINF_TBRF);
builder.i(MINF_STOP);
let mut builder2 = MISimpleBuilder::new();
builder2.l("xx1");
builder2.i(MINF_MARF);
builder2.i(MINF_MAB);
builder2.i(MINF_MARW0);
let mut builder3 = MISimpleBuilder::new();
builder3.l("xx2");
builder3.i(MINF_TBRW1);
builder3.i(MINF_TBB);
builder3.l("xx3");
builder3.i(MINF_TBRW0);
builder.multi_append([(2, &builder2), (4, &builder3)]);
assert_eq!(
Ok((
vec![
MinInfInstr::new(MINF_TBRF, MINF_TBRF, 1, 1),
(MINF_TBRF, MINF_TBRF, 2, 2).into(),
(MINF_MARF, MINF_MARF, 3, 3).into(),
(MINF_MAB, MINF_MAB, 4, 4).into(),
(MINF_MARW0, MINF_MARW0, 5, 5).into(),
(MINF_TBRF, MINF_TBRF, 6, 6).into(),
(MINF_TBRF, MINF_TBRF, 7, 7).into(),
(MINF_TBRW1, MINF_TBRW1, 8, 8).into(),
(MINF_TBB, MINF_TBB, 9, 9).into(),
(MINF_TBRW0, MINF_TBRW0, 10, 10).into(),
(MINF_TBRF, MINF_TBRF, 11, 11).into(),
(MINF_TBRF, MINF_TBRF, 12, 12).into(),
(MINF_STOP, MINF_STOP, 0, 0).into(),
],
vec![
("xx1".to_string(), 2),
("xx2".to_string(), 7),
("xx3".to_string(), 9),
]
)),
builder.try_to_code().map_err(|x| x.to_string())
);
let mut builder = MISimpleBuilder::new();
builder.i(MINF_TBRF);
builder.i(MINF_TBRF);
builder.i(MINF_TBRF);
builder.i(MINF_TBRF);
builder.i(MINF_TBRF);
builder.i(MINF_TBRF);
builder.i(MINF_STOP);
let mut builder2 = MISimpleBuilder::new();
builder2.l("xx1");
builder2.i(MINF_MARF);
builder2.i(MINF_MAB);
builder2.i(MINF_MARW0);
let mut builder3 = MISimpleBuilder::new();
builder3.l("xx2");
builder3.i(MINF_TBRW1);
builder3.i(MINF_TBB);
builder3.l("xx3");
builder3.i(MINF_TBRW0);
assert_eq!(
Err("Position duplicates".to_string()),
builder
.try_multi_append([(2, &builder2), (2, &builder3)])
.map_err(|x| x.to_string())
);
let mut builder = MISimpleBuilder::new();
builder.l("start");
builder.l("l0");
builder.i(MINF_TBRF);
builder.l("l1");
builder.i(MINF_TBRF);
builder.i((MINF_TBRF, "start"));
let mut builder2 = MISimpleBuilder::new();
builder2.l("l1");
builder2.i(MINF_MARF);
builder2.i(MINF_MAB);
builder2.i(MINF_MARW0);
assert_eq!(
Err("Label already exists: l1".to_string()),
builder
.try_multi_append([(2, &builder2)])
.map_err(|x| x.to_string())
);
}
#[test]
fn test_min_inf_builder_sv_multi_append() {
let mut builder = mi_std_sv_builder_new(1);
builder.l("start");
builder.l("l0");
builder.i(MINF_TBRF);
builder.l("l1");
builder.i(MINF_TBRF);
builder.l("l2");
builder.i(MINF_TBRF);
builder.l("l3");
builder.i(MINF_TBRF);
builder.l("l4");
builder.i(MINF_TBRF);
builder.l("l5");
builder.i(MINF_TBRF);
builder.l("l6");
builder.i((MINF_TBRF, "start"));
let mut builder2 = mi_std_sv_builder_new(1);
builder2.l("xx1");
builder2.i(MINF_MARF);
builder2.i(MINF_MAB);
builder2.i(MINF_MARW0);
let mut builder3 = mi_std_sv_builder_new(1);
builder3.l("xx2");
builder3.i(MINF_TBRW1);
builder3.i(MINF_TBB);
builder3.l("xx3");
builder3.i(MINF_TBRW0);
builder.multi_append([(2, &builder2), (4, &builder3)]);
assert_eq!(
Ok((
vec![
MinInfInstr::new(MINF_TBRF, MINF_TBRF, 1, 1),
(MINF_TBRF, MINF_TBRF, 2, 2).into(),
(MINF_MARF, MINF_MARF, 3, 3).into(),
(MINF_MAB, MINF_MAB, 4, 4).into(),
(MINF_MARW0, MINF_MARW0, 5, 5).into(),
(MINF_TBRF, MINF_TBRF, 6, 6).into(),
(MINF_TBRF, MINF_TBRF, 7, 7).into(),
(MINF_TBRW1, MINF_TBRW1, 8, 8).into(),
(MINF_TBB, MINF_TBB, 9, 9).into(),
(MINF_TBRW0, MINF_TBRW0, 10, 10).into(),
(MINF_TBRF, MINF_TBRF, 11, 11).into(),
(MINF_TBRF, MINF_TBRF, 12, 12).into(),
(MINF_TBRF, MINF_TBRF, 0, 0).into(),
],
vec![
("l0".to_string(), 0),
("l1".to_string(), 1),
("l2".to_string(), 2),
("l3".to_string(), 6),
("l4".to_string(), 7),
("l5".to_string(), 11),
("l6".to_string(), 12),
("start".to_string(), 0),
("xx1".to_string(), 2),
("xx2".to_string(), 7),
("xx3".to_string(), 9),
]
)),
builder.try_to_code().map_err(|x| x.to_string())
);
let mut builder = mi_std_sv_builder_new(2);
builder.l("start");
builder.l("l0");
builder.i(MINF_TBRF);
builder.l("l1");
builder.i(MINF_TBRF);
builder.l("l2");
builder.i(MINF_TBRF);
builder.l("l3");
builder.i(MINF_TBRF);
builder.l("l4");
builder.i(MINF_TBRF);
builder.l("l5");
builder.i(MINF_TBRF);
builder.l("l6");
builder.i((MINF_TBRF, "start"));
let mut builder2 = mi_std_sv_builder_new(2);
builder2.l("xx1");
builder2.i(MINF_MARF);
builder2.i(MINF_MAB);
builder2.i(MINF_MARW0);
let mut builder3 = mi_std_sv_builder_new(2);
builder3.l("xx2");
builder3.i(MINF_TBRW1);
builder3.i(MINF_TBB);
builder3.l("xx3");
builder3.i(MINF_TBRW0);
builder.multi_append([(4, &builder2), (8, &builder3)]);
assert_eq!(
Ok((
vec![
MinInfInstr::new(MINF_TBRF, MINF_TBRF, 2, 2),
(MINF_TBRF, MINF_TBRF, 3, 3).into(),
(MINF_TBRF, MINF_TBRF, 4, 4).into(),
(MINF_TBRF, MINF_TBRF, 5, 5).into(),
(MINF_MARF, MINF_MARF, 6, 6).into(),
(MINF_MARF, MINF_MARF, 7, 7).into(),
(MINF_MAB, MINF_MAB, 8, 8).into(),
(MINF_MAB, MINF_MAB, 9, 9).into(),
(MINF_MARW0, MINF_MARW0, 10, 10).into(),
(MINF_MARW0, MINF_MARW0, 11, 11).into(),
(MINF_TBRF, MINF_TBRF, 12, 12).into(),
(MINF_TBRF, MINF_TBRF, 13, 13).into(),
(MINF_TBRF, MINF_TBRF, 14, 14).into(),
(MINF_TBRF, MINF_TBRF, 15, 15).into(),
(MINF_TBRW1, MINF_TBRW1, 16, 16).into(),
(MINF_TBRW1, MINF_TBRW1, 17, 17).into(),
(MINF_TBB, MINF_TBB, 18, 18).into(),
(MINF_TBB, MINF_TBB, 19, 19).into(),
(MINF_TBRW0, MINF_TBRW0, 20, 20).into(),
(MINF_TBRW0, MINF_TBRW0, 21, 21).into(),
(MINF_TBRF, MINF_TBRF, 22, 22).into(),
(MINF_TBRF, MINF_TBRF, 23, 23).into(),
(MINF_TBRF, MINF_TBRF, 24, 24).into(),
(MINF_TBRF, MINF_TBRF, 25, 25).into(),
(MINF_TBRF, MINF_TBRF, 0, 0).into(),
(MINF_TBRF, MINF_TBRF, 1, 1).into(),
],
vec![
("l0".to_string(), 0),
("l1".to_string(), 2),
("l2".to_string(), 4),
("l3".to_string(), 12),
("l4".to_string(), 14),
("l5".to_string(), 22),
("l6".to_string(), 24),
("start".to_string(), 0),
("xx1".to_string(), 4),
("xx2".to_string(), 14),
("xx3".to_string(), 18),
]
)),
builder.try_to_code().map_err(|x| x.to_string())
);
}