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 {
|
pub enum WireOption {
|
||||||
Input(i32),
|
Input(i32),
|
||||||
Output(i32),
|
Output(i32),
|
||||||
|
Width(i32),
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
|
@ -64,6 +65,7 @@ impl Wire {
|
||||||
let option_str = match option {
|
let option_str = match option {
|
||||||
WireOption::Input(num) => format!("input {} ", num),
|
WireOption::Input(num) => format!("input {} ", num),
|
||||||
WireOption::Output(num) => format!("output {} ", num),
|
WireOption::Output(num) => format!("output {} ", num),
|
||||||
|
WireOption::Width(num) => format!("width {} ", num),
|
||||||
};
|
};
|
||||||
|
|
||||||
line += &option_str;
|
line += &option_str;
|
||||||
|
@ -161,8 +163,8 @@ impl Cell {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn xor_cell(id: &str, a: &str, b: &str, y: &str) -> Cell {
|
fn builtin_binop_cell(celltype: &str, id: &str, a: &str, b: &str, y: &str) -> Cell {
|
||||||
let mut cell = Cell::new(id, "$xor");
|
let mut cell = Cell::new(id, celltype);
|
||||||
cell.add_param("\\A_SIGNED", "0");
|
cell.add_param("\\A_SIGNED", "0");
|
||||||
cell.add_param("\\A_WIDTH", "1");
|
cell.add_param("\\A_WIDTH", "1");
|
||||||
cell.add_param("\\B_SIGNED", "0");
|
cell.add_param("\\B_SIGNED", "0");
|
||||||
|
@ -174,15 +176,12 @@ fn xor_cell(id: &str, a: &str, b: &str, y: &str) -> Cell {
|
||||||
cell
|
cell
|
||||||
}
|
}
|
||||||
|
|
||||||
fn adder_cell(id: &str, a: &str, b: &str, y: &str) -> Cell {
|
fn builtin_unop_cell(celltype: &str, id: &str, a: &str, y: &str) -> Cell {
|
||||||
let mut cell = Cell::new(id, "$and");
|
let mut cell = Cell::new(id, celltype);
|
||||||
cell.add_param("\\A_SIGNED", "0");
|
cell.add_param("\\A_SIGNED", "0");
|
||||||
cell.add_param("\\A_WIDTH", "1");
|
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_param("\\Y_WIDTH", "1");
|
||||||
cell.add_connection("\\A", a);
|
cell.add_connection("\\A", a);
|
||||||
cell.add_connection("\\B", b);
|
|
||||||
cell.add_connection("\\Y", y);
|
cell.add_connection("\\Y", y);
|
||||||
cell
|
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 mut args_resolved = call.args.iter().map(|expr| lower_expression(module, expr));
|
||||||
|
|
||||||
let arg_a = args_resolved.next().unwrap();
|
// TODO: make this sensible
|
||||||
let arg_b = args_resolved.next().unwrap();
|
|
||||||
|
|
||||||
let cell = match call.name.as_str() {
|
let cell = match call.name.as_str() {
|
||||||
"and" => {
|
"and" => {
|
||||||
|
let arg_a = args_resolved.next().unwrap();
|
||||||
|
let arg_b = args_resolved.next().unwrap();
|
||||||
let cell_id = module.make_genid("and");
|
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" => {
|
"xor" => {
|
||||||
|
let arg_a = args_resolved.next().unwrap();
|
||||||
|
let arg_b = args_resolved.next().unwrap();
|
||||||
let cell_id = module.make_genid("xor");
|
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);
|
module.cells.push(cell);
|
||||||
output_gen_id
|
output_gen_id
|
||||||
|
|
Loading…
Reference in New Issue