Skip to content

Commit cb3e2d1

Browse files
authored
Refactor frontend Verilog compilation (#138)
1 parent 27ec13a commit cb3e2d1

File tree

5 files changed

+393
-179
lines changed

5 files changed

+393
-179
lines changed

src/bin/epak.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ fn main() -> std::io::Result<()> {
134134

135135
#[cfg(feature = "dyn_decomp")]
136136
if args.decomp || args.disassemble.is_some() {
137-
rules.append(&mut dyn_decompositions(false));
137+
rules.append(&mut dyn_decompositions(true));
138138
}
139139

140140
if !args.no_retime {
@@ -227,7 +227,7 @@ fn main() -> std::io::Result<()> {
227227

228228
eprintln!("INFO: Compiling Verilog...");
229229
let expr = f
230-
.to_single_expr()
230+
.to_single_lut_expr()
231231
.map_err(|s| std::io::Error::new(std::io::ErrorKind::Other, s))?;
232232

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

src/bin/parse-verilog.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ fn main() -> std::io::Result<()> {
7070
}
7171
} else {
7272
let expr = f
73-
.to_single_expr()
73+
.to_single_lut_expr()
7474
.map_err(|s| std::io::Error::new(std::io::ErrorKind::Other, s))?;
7575
LutLang::verify_expr(&expr)
7676
.map_err(|s| std::io::Error::new(std::io::ErrorKind::Other, s))?;

src/lib.rs

Lines changed: 43 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -282,7 +282,7 @@ endmodule\n"
282282
assert!(module.is_ok());
283283
let module = module.unwrap();
284284
assert_eq!(
285-
module.to_single_expr().unwrap().to_string(),
285+
module.to_single_lut_expr().unwrap().to_string(),
286286
"d".to_string()
287287
);
288288
}
@@ -328,7 +328,7 @@ endmodule\n"
328328
assert!(module.is_ok());
329329
let module = module.unwrap();
330330
assert_eq!(
331-
module.to_single_expr().unwrap().to_string(),
331+
module.to_single_lut_expr().unwrap().to_string(),
332332
"(LUT 17361601744336890538 true false b a c d)".to_string()
333333
);
334334
}
@@ -387,7 +387,7 @@ endmodule\n"
387387
.unwrap()
388388
.with_fname("mux_4_1".to_string());
389389
assert!(module.get_name() == "mux_4_1");
390-
let expr = module.to_expr().unwrap();
390+
let expr: RecExpr<LutLang> = module.to_expr().unwrap();
391391
assert_eq!(
392392
expr.to_string(),
393393
"(LUT 17361601744336890538 s0 s1 b a c d)".to_string()
@@ -402,7 +402,7 @@ endmodule\n"
402402
assert!(module.is_ok());
403403
let module = module.unwrap();
404404
assert_eq!(
405-
module.to_single_expr().unwrap().to_string(),
405+
module.to_single_lut_expr().unwrap().to_string(),
406406
"(REG d)".to_string()
407407
);
408408
let output = module.to_string();
@@ -456,11 +456,45 @@ endmodule\n"
456456
assert!(module.is_ok());
457457
let module = module.unwrap();
458458
assert_eq!(
459-
module.to_single_expr().unwrap().to_string(),
459+
module.to_single_lut_expr().unwrap().to_string(),
460460
"(AND a b)".to_string()
461461
);
462462
}
463463

464+
#[test]
465+
fn test_cell_parse() {
466+
let module = "module my_cell (
467+
a,
468+
b,
469+
c,
470+
y
471+
);
472+
input a;
473+
wire a;
474+
input b;
475+
wire b;
476+
input c;
477+
wire c;
478+
output y;
479+
wire y;
480+
AOI21_X1 _0_ (
481+
.A(a),
482+
.B1(b),
483+
.B2(c),
484+
.Y(y)
485+
);
486+
endmodule"
487+
.to_string();
488+
let ast = sv_parse_wrapper(&module, None).unwrap();
489+
let module = SVModule::from_ast(&ast);
490+
assert!(module.is_ok());
491+
let module = module.unwrap();
492+
assert_eq!(
493+
module.to_expr::<CellLang>().unwrap().to_string(),
494+
"(AOI21_X1 a b c)".to_string()
495+
);
496+
}
497+
464498
#[test]
465499
fn test_constant_parse() {
466500
let module = "module my_gates (
@@ -496,7 +530,7 @@ endmodule\n"
496530
assert!(module.is_ok());
497531
let module = module.unwrap();
498532
assert_eq!(
499-
module.to_single_expr().unwrap().to_string(),
533+
module.to_single_lut_expr().unwrap().to_string(),
500534
"(AND (AND true true) (AND false false))".to_string()
501535
);
502536
}
@@ -531,7 +565,7 @@ endmodule\n"
531565
assert!(module.is_ok());
532566
let module = module.unwrap();
533567
assert_eq!(
534-
module.to_single_expr().unwrap().to_string(),
568+
module.to_single_lut_expr().unwrap().to_string(),
535569
"(NOT (NOT d))".to_string()
536570
);
537571
}
@@ -901,9 +935,10 @@ endmodule\n"
901935
PrimitiveType::AOI22.get_input_list(),
902936
vec!["A1", "A2", "B1", "B2"]
903937
);
938+
// LUT input list is backwards relative to the IR
904939
assert_eq!(
905940
PrimitiveType::LUT6.get_input_list(),
906-
vec!["I0", "I1", "I2", "I3", "I4", "I5"]
941+
vec!["I5", "I4", "I3", "I2", "I1", "I0"]
907942
);
908943
}
909944

0 commit comments

Comments
 (0)