deduplicate ops, add more
This commit is contained in:
parent
cabdfea643
commit
ed3ff17c89
37
src/rtlil.rs
37
src/rtlil.rs
|
@ -41,6 +41,7 @@ impl ILWriter {
|
|||
pub enum WireOption {
|
||||
Input(i32),
|
||||
Output(i32),
|
||||
Width(i32),
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
|
@ -64,6 +65,7 @@ impl Wire {
|
|||
let option_str = match option {
|
||||
WireOption::Input(num) => format!("input {} ", num),
|
||||
WireOption::Output(num) => format!("output {} ", num),
|
||||
WireOption::Width(num) => format!("width {} ", num),
|
||||
};
|
||||
|
||||
line += &option_str;
|
||||
|
@ -161,8 +163,8 @@ impl Cell {
|
|||
}
|
||||
}
|
||||
|
||||
fn xor_cell(id: &str, a: &str, b: &str, y: &str) -> Cell {
|
||||
let mut cell = Cell::new(id, "$xor");
|
||||
fn builtin_binop_cell(celltype: &str, id: &str, a: &str, b: &str, y: &str) -> Cell {
|
||||
let mut cell = Cell::new(id, celltype);
|
||||
cell.add_param("\\A_SIGNED", "0");
|
||||
cell.add_param("\\A_WIDTH", "1");
|
||||
cell.add_param("\\B_SIGNED", "0");
|
||||
|
@ -174,15 +176,12 @@ fn xor_cell(id: &str, a: &str, b: &str, y: &str) -> Cell {
|
|||
cell
|
||||
}
|
||||
|
||||
fn adder_cell(id: &str, a: &str, b: &str, y: &str) -> Cell {
|
||||
let mut cell = Cell::new(id, "$and");
|
||||
fn builtin_unop_cell(celltype: &str, id: &str, a: &str, y: &str) -> Cell {
|
||||
let mut cell = Cell::new(id, celltype);
|
||||
cell.add_param("\\A_SIGNED", "0");
|
||||
cell.add_param("\\A_WIDTH", "1");
|
||||
cell.add_param("\\B_SIGNED", "0");
|
||||
cell.add_param("\\B_WIDTH", "1");
|
||||
cell.add_param("\\Y_WIDTH", "1");
|
||||
cell.add_connection("\\A", a);
|
||||
cell.add_connection("\\B", b);
|
||||
cell.add_connection("\\Y", y);
|
||||
cell
|
||||
}
|
||||
|
@ -202,19 +201,31 @@ fn lower_expression(module: &mut Module, expr: &parser::Expression) -> String {
|
|||
|
||||
let mut args_resolved = call.args.iter().map(|expr| lower_expression(module, expr));
|
||||
|
||||
let arg_a = args_resolved.next().unwrap();
|
||||
let arg_b = args_resolved.next().unwrap();
|
||||
|
||||
// TODO: make this sensible
|
||||
let cell = match call.name.as_str() {
|
||||
"and" => {
|
||||
let arg_a = args_resolved.next().unwrap();
|
||||
let arg_b = args_resolved.next().unwrap();
|
||||
let cell_id = module.make_genid("and");
|
||||
adder_cell(&cell_id, &arg_a, &arg_b, &output_gen_id)
|
||||
builtin_binop_cell("$and", &cell_id, &arg_a, &arg_b, &output_gen_id)
|
||||
},
|
||||
"xor" => {
|
||||
let arg_a = args_resolved.next().unwrap();
|
||||
let arg_b = args_resolved.next().unwrap();
|
||||
let cell_id = module.make_genid("xor");
|
||||
xor_cell(&cell_id, &arg_a, &arg_b, &output_gen_id)
|
||||
builtin_binop_cell("$xor", &cell_id, &arg_a, &arg_b, &output_gen_id)
|
||||
},
|
||||
_ => todo!(),
|
||||
"not" => {
|
||||
let arg_a = args_resolved.next().unwrap();
|
||||
let cell_id = module.make_genid("not");
|
||||
builtin_unop_cell("$not", &cell_id, &arg_a, &output_gen_id)
|
||||
},
|
||||
"reduce_or" => {
|
||||
let arg_a = args_resolved.next().unwrap();
|
||||
let cell_id = module.make_genid("reduce_or");
|
||||
builtin_unop_cell("$reduce_or", &cell_id, &arg_a, &output_gen_id)
|
||||
},
|
||||
_ => todo!("unknown function"),
|
||||
};
|
||||
module.cells.push(cell);
|
||||
output_gen_id
|
||||
|
|
Loading…
Reference in New Issue