55 lines
1.6 KiB
Rust
55 lines
1.6 KiB
Rust
|
use crate::frontend::{Callable, CallArgument, Type};
|
||
|
use crate::rtlil;
|
||
|
|
||
|
fn builtin_unop_cell(celltype: &str, id: &str, a: &str, y: &str) -> rtlil::Cell {
|
||
|
let mut cell = rtlil::Cell::new(id, celltype);
|
||
|
cell.add_param("\\A_SIGNED", "0");
|
||
|
cell.add_param("\\A_WIDTH", "1");
|
||
|
cell.add_param("\\Y_WIDTH", "1");
|
||
|
cell.add_connection("\\A", a);
|
||
|
cell.add_connection("\\Y", y);
|
||
|
cell
|
||
|
}
|
||
|
|
||
|
fn instantiate_binop(celltype: &str, id: &str, args: &[String], ret: &str) -> rtlil::Cell {
|
||
|
let a = args.get(0).expect("wrong argcount slipped through type check");
|
||
|
let b = args.get(1).expect("wrong argcount slipped through type check");
|
||
|
|
||
|
let mut cell = rtlil::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", ret);
|
||
|
cell
|
||
|
}
|
||
|
|
||
|
fn make_binop_callable(name: &str, celltype: &'static str) -> Callable {
|
||
|
let args = vec![
|
||
|
CallArgument {
|
||
|
name: "A".to_owned(),
|
||
|
atype: Type::wire(),
|
||
|
},
|
||
|
CallArgument {
|
||
|
name: "B".to_owned(),
|
||
|
atype: Type::wire(),
|
||
|
},
|
||
|
];
|
||
|
Callable {
|
||
|
name: name.to_owned(),
|
||
|
args,
|
||
|
ret: Type::wire(),
|
||
|
instantiate: Box::new(move |id, args, ret| instantiate_binop(celltype, id, args, ret))
|
||
|
}
|
||
|
}
|
||
|
|
||
|
pub fn get_builtins() -> Vec<Callable> {
|
||
|
vec![
|
||
|
make_binop_callable("and", "$and"),
|
||
|
make_binop_callable("xor", "$xor"),
|
||
|
]
|
||
|
}
|