|
|
@ -99,7 +99,7 @@ pub fn route(module: Module) -> Result<(Vec<lw::Component>, Vec<lw::Wire>), Erro
|
|
|
|
for (i, cell) in module.cells.iter().enumerate() {
|
|
|
|
for (i, cell) in module.cells.iter().enumerate() {
|
|
|
|
println!("{}: {:?}", i, cell);
|
|
|
|
println!("{}: {:?}", i, cell);
|
|
|
|
let components = match cell.cell_type.as_str() {
|
|
|
|
let components = match cell.cell_type.as_str() {
|
|
|
|
"$and" => basic_gate(
|
|
|
|
"$and" => binary_op(
|
|
|
|
cell,
|
|
|
|
cell,
|
|
|
|
"MHG.AndGate",
|
|
|
|
"MHG.AndGate",
|
|
|
|
board_address,
|
|
|
|
board_address,
|
|
|
@ -107,7 +107,7 @@ pub fn route(module: Module) -> Result<(Vec<lw::Component>, Vec<lw::Wire>), Erro
|
|
|
|
&mut next_position,
|
|
|
|
&mut next_position,
|
|
|
|
&mut connection_map,
|
|
|
|
&mut connection_map,
|
|
|
|
),
|
|
|
|
),
|
|
|
|
"$xor" => basic_gate(
|
|
|
|
"$xor" => binary_op(
|
|
|
|
cell,
|
|
|
|
cell,
|
|
|
|
"MHG.XorGate",
|
|
|
|
"MHG.XorGate",
|
|
|
|
board_address,
|
|
|
|
board_address,
|
|
|
@ -123,6 +123,14 @@ pub fn route(module: Module) -> Result<(Vec<lw::Component>, Vec<lw::Wire>), Erro
|
|
|
|
&mut wires,
|
|
|
|
&mut wires,
|
|
|
|
&mut connection_map,
|
|
|
|
&mut connection_map,
|
|
|
|
),
|
|
|
|
),
|
|
|
|
|
|
|
|
"$not" => unary_op(
|
|
|
|
|
|
|
|
cell,
|
|
|
|
|
|
|
|
"MHG.Inverter",
|
|
|
|
|
|
|
|
board_address,
|
|
|
|
|
|
|
|
&mut next_address,
|
|
|
|
|
|
|
|
&mut next_position,
|
|
|
|
|
|
|
|
&mut connection_map,
|
|
|
|
|
|
|
|
),
|
|
|
|
_ => return Err(Error::UnsupportedCell),
|
|
|
|
_ => return Err(Error::UnsupportedCell),
|
|
|
|
};
|
|
|
|
};
|
|
|
|
cells.extend(components);
|
|
|
|
cells.extend(components);
|
|
|
@ -277,7 +285,7 @@ fn output_port(
|
|
|
|
return vec![peg, label];
|
|
|
|
return vec![peg, label];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
fn basic_gate(
|
|
|
|
fn binary_op(
|
|
|
|
cell: &Cell,
|
|
|
|
cell: &Cell,
|
|
|
|
text_id: &str,
|
|
|
|
text_id: &str,
|
|
|
|
parent_address: u32,
|
|
|
|
parent_address: u32,
|
|
|
@ -318,6 +326,42 @@ fn basic_gate(
|
|
|
|
return vec![component];
|
|
|
|
return vec![component];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
fn unary_op(
|
|
|
|
|
|
|
|
cell: &Cell,
|
|
|
|
|
|
|
|
text_id: &str,
|
|
|
|
|
|
|
|
parent_address: u32,
|
|
|
|
|
|
|
|
next_address: &mut u32,
|
|
|
|
|
|
|
|
next_position: &mut Vector3<i32>,
|
|
|
|
|
|
|
|
connection_map: &mut HashMap<(usize, &str), lw::PegAddress>,
|
|
|
|
|
|
|
|
) -> Vec<lw::Component> {
|
|
|
|
|
|
|
|
let input = lw::Input::new(cell.inputs["A"][0] as i32);
|
|
|
|
|
|
|
|
let output = lw::Output::new(cell.outputs["Y"][0] as i32);
|
|
|
|
|
|
|
|
let component = lw::Component {
|
|
|
|
|
|
|
|
address: *next_address,
|
|
|
|
|
|
|
|
parent: parent_address,
|
|
|
|
|
|
|
|
numeric_id: COMPONENT_MAP[text_id],
|
|
|
|
|
|
|
|
position: *next_position,
|
|
|
|
|
|
|
|
rotation: quaternion::id(),
|
|
|
|
|
|
|
|
inputs: vec![input],
|
|
|
|
|
|
|
|
outputs: vec![output],
|
|
|
|
|
|
|
|
custom_data: vec![],
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
connection_map.insert(
|
|
|
|
|
|
|
|
(cell.index, "A"),
|
|
|
|
|
|
|
|
lw::PegAddress::input(component.address, 0),
|
|
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
connection_map.insert(
|
|
|
|
|
|
|
|
(cell.index, "Y"),
|
|
|
|
|
|
|
|
lw::PegAddress::output(component.address, 0),
|
|
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
*next_address += 1;
|
|
|
|
|
|
|
|
next_position[2] += 3 * SQUARE;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return vec![component];
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
fn or_gate(
|
|
|
|
fn or_gate(
|
|
|
|
cell: &Cell,
|
|
|
|
cell: &Cell,
|
|
|
|
parent_address: u32,
|
|
|
|
parent_address: u32,
|
|
|
|