Skip to content

Commit 058b560

Browse files
authored
Allow 'Don't Care' to be parsed into LutLang (#105)
1 parent bc99916 commit 058b560

File tree

3 files changed

+13
-6
lines changed

3 files changed

+13
-6
lines changed

src/bin/parse-verilog.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,10 @@ use std::{
44
};
55

66
use clap::Parser;
7-
use lut_synth::verilog::{sv_parse_wrapper, SVModule};
7+
use lut_synth::{
8+
lut::verify_expr,
9+
verilog::{sv_parse_wrapper, SVModule},
10+
};
811
/// Parse structural verilog into a LutLang Expression
912
#[derive(Parser, Debug)]
1013
#[command(version, about, long_about = None)]
@@ -62,13 +65,16 @@ fn main() -> std::io::Result<()> {
6265
.get_exprs()
6366
.map_err(|s| std::io::Error::new(std::io::ErrorKind::Other, s))?;
6467
for (y, expr) in exprs {
68+
verify_expr(&expr)
69+
.map_err(|s| std::io::Error::new(std::io::ErrorKind::Other, s))?;
6570
eprintln!("{}: {}", y, expr);
6671
println!("{}", expr);
6772
}
6873
} else {
6974
let expr = f
7075
.to_single_expr()
7176
.map_err(|s| std::io::Error::new(std::io::ErrorKind::Other, s))?;
77+
verify_expr(&expr).map_err(|s| std::io::Error::new(std::io::ErrorKind::Other, s))?;
7278
eprintln!("{:?}", f.get_outputs());
7379
println!("{}", expr);
7480
}

src/lut.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@ define_language! {
2222
pub enum LutLang {
2323
Const(bool),
2424
Program(u64), // The only node type that is not a net
25-
Var(Symbol),
2625
"x" = DC,
26+
Var(Symbol),
2727
"NOR" = Nor([Id; 2]),
2828
"MUX" = Mux([Id; 3]), // s, a, b
2929
"AND" = And([Id; 2]),
@@ -61,9 +61,10 @@ impl LutLang {
6161
}
6262
LutLang::Var(f) => match f.as_str() {
6363
"NOR" | "LUT" | "MUX" | "AND" | "XOR" | "NOT" | "BUS" | "DC" | "x" | "REG"
64-
| "CYCLE" | "ARG" => Err(
65-
"Variable name is already reserved. Check for missing parentheses.".to_string(),
66-
),
64+
| "CYCLE" | "ARG" => Err(format!(
65+
"Variable name '{}' is already reserved. Check for missing parentheses.",
66+
f.as_str()
67+
)),
6768
_ => Ok(()),
6869
},
6970
_ => Ok(()),

src/rewrite.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -524,7 +524,7 @@ impl Applier<lut::LutLang, LutAnalysis> for ShannonCondense {
524524
}
525525
let k = operands.len();
526526
assert!(k <= 5);
527-
let new_prog = p << (1 << k) | q;
527+
let new_prog = (p << (1 << k)) | q;
528528
let new_prog_id = egraph.add(lut::LutLang::Program(new_prog));
529529
let sel = subst[self.sel];
530530
let mut c = Vec::from(&[new_prog_id, sel]);

0 commit comments

Comments
 (0)