Skip to content

Commit e4c62de

Browse files
authored
CellLang support multiple module outputs (#140)
1 parent ebda942 commit e4c62de

File tree

4 files changed

+30
-6
lines changed

4 files changed

+30
-6
lines changed

src/asic.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,8 @@ define_language! {
2323
"AND" = And([Id; 2]),
2424
"OR" = Or([Id; 2]),
2525
"INV" = Inv([Id; 1]),
26-
Cell(Symbol, Vec<Id>), // or Box<[Id]>?
26+
Cell(Symbol, Vec<Id>),
27+
"BUS" = Bus(Box<[Id]>),
2728
}
2829
}
2930

src/bin/cellmap.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ fn main() -> std::io::Result<()> {
161161

162162
eprintln!("INFO: Compiling Verilog...");
163163
let expr = f
164-
.to_expr()
164+
.to_single_cell_expr()
165165
.map_err(|s| std::io::Error::new(std::io::ErrorKind::Other, s))?;
166166

167167
eprintln!("INFO: Building e-graph...");

src/verilog.rs

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -776,7 +776,11 @@ impl VerilogEmission for CellLang {
776776
if expr.is_empty() {
777777
return vec![];
778778
}
779-
vec![(expr.len() - 1).into()]
779+
780+
match expr.last().unwrap() {
781+
CellLang::Bus(l) => l.to_vec(),
782+
_ => vec![(expr.len() - 1).into()],
783+
}
780784
}
781785

782786
fn get_var(&self) -> Option<String> {
@@ -1606,8 +1610,6 @@ impl SVModule {
16061610
module.signals.push(SVSignal::new(1, output));
16071611
}
16081612
mapping.insert(id.into(), sname);
1609-
} else {
1610-
return Err(format!("Unsupported node type: {:?}", node));
16111613
}
16121614
}
16131615

@@ -1753,6 +1755,27 @@ impl SVModule {
17531755
Ok(expr)
17541756
}
17551757

1758+
/// Get a single [CellLang] expression for the module as a bus
1759+
pub fn to_single_cell_expr(&self) -> Result<RecExpr<CellLang>, String> {
1760+
if let Err(s) = self.contains_cycles() {
1761+
return Err(format!(
1762+
"Cannot convert module with feedback on signal {}",
1763+
s
1764+
));
1765+
}
1766+
1767+
let mut expr: RecExpr<CellLang> = RecExpr::default();
1768+
let mut map = HashMap::new();
1769+
let mut outputs: Vec<Id> = vec![];
1770+
for output in self.outputs.iter() {
1771+
outputs.push(CellLang::get_expr(&output.name, self, &mut expr, &mut map)?);
1772+
}
1773+
if outputs.len() > 1 {
1774+
expr.add(CellLang::Bus(outputs.into()));
1775+
}
1776+
Ok(expr)
1777+
}
1778+
17561779
/// Convert the module to a [Language] expression
17571780
pub fn to_expr<L>(&self) -> Result<RecExpr<L>, String>
17581781
where

tests/lutlang/bus.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// RUN: opt %s -k 4 -n 24 2>>/dev/null | FileCheck %s
1+
// RUN: opt %s -k 4 -n 5 2>>/dev/null | FileCheck %s
22

33
// MUX with exact inputs
44
(BUS (MUX s1 (MUX s0 a b) (MUX s0 c d)) (MUX s1 (MUX s0 a b) (MUX s0 a b)))

0 commit comments

Comments
 (0)