futilehdl/src/builtin_cells.rs

77 lines
2.4 KiB
Rust
Raw Normal View History

2022-02-02 00:03:03 +00:00
use crate::frontend::types::TypeStruct;
2022-01-23 21:52:06 +00:00
use crate::frontend::Callable;
2022-01-05 01:08:25 +00:00
use crate::rtlil;
use crate::rtlil::SigSpec;
fn instantiate_unop(celltype: &str, id: &str, args: &[SigSpec], ret: &SigSpec) -> rtlil::Cell {
let a = args
.get(0)
.expect("wrong argcount slipped through type check");
assert_eq!(args.len(), 1);
2022-01-05 01:08:25 +00:00
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", ret);
2022-01-05 01:08:25 +00:00
cell
}
fn instantiate_binop(celltype: &str, id: &str, args: &[SigSpec], ret: &SigSpec) -> rtlil::Cell {
2022-01-05 01:09:08 +00:00
let a = args
.get(0)
.expect("wrong argcount slipped through type check");
let b = args
.get(1)
.expect("wrong argcount slipped through type check");
assert_eq!(args.len(), 2);
2022-01-05 01:08:25 +00:00
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
}
2022-02-02 00:03:03 +00:00
fn make_binop_callable<'ctx>(name: &str, _celltype: &'static str) -> Callable<'ctx> {
// FIXME: CRIMES CRIMES CRIMES
let logic_type: &'static TypeStruct = Box::leak(Box::new(TypeStruct::logic_infer()));
2022-01-05 01:08:25 +00:00
let args = vec![
2022-01-23 21:52:06 +00:00
(Some("a".to_owned()), logic_type),
(Some("b".to_owned()), logic_type),
2022-01-05 01:08:25 +00:00
];
Callable {
name: name.to_owned(),
args,
ret_type: Some(logic_type),
2022-01-05 01:08:25 +00:00
}
}
2022-02-02 00:03:03 +00:00
fn make_unnop_callable<'ctx>(name: &str, _celltype: &'static str) -> Callable<'ctx> {
// FIXME: CRIMES CRIMES CRIMES
let logic_type: &'static TypeStruct = Box::leak(Box::new(TypeStruct::logic_infer()));
2022-01-23 21:52:06 +00:00
let args = vec![(Some("A".to_owned()), logic_type)];
Callable {
name: name.to_owned(),
args,
ret_type: Some(logic_type),
}
}
pub fn get_builtins<'ctx>() -> Vec<Callable<'ctx>> {
2022-01-05 01:08:25 +00:00
vec![
make_binop_callable("and", "$and"),
2022-01-14 14:28:39 +00:00
make_binop_callable("or", "$or"),
2022-01-05 01:08:25 +00:00
make_binop_callable("xor", "$xor"),
2022-01-14 14:28:39 +00:00
make_binop_callable("xnor", "$xnor"),
make_unnop_callable("not", "$not"),
2022-01-17 18:20:51 +00:00
make_unnop_callable("reduce_or", "$reduce_or"),
2022-01-05 01:08:25 +00:00
]
}