From 63fd038729900ee2069b8cad503610fb985ce79a Mon Sep 17 00:00:00 2001 From: Jacob Lifshay Date: Tue, 16 Jul 2024 19:45:12 -0700 Subject: [PATCH] correctly handle hdl byte literal suffixes --- .../src/module/transform_body.rs | 17 ++++++++++------- crates/fayalite/tests/module.rs | 2 +- 2 files changed, 11 insertions(+), 8 deletions(-) diff --git a/crates/fayalite-proc-macros-impl/src/module/transform_body.rs b/crates/fayalite-proc-macros-impl/src/module/transform_body.rs index 4dc18d9..13a7362 100644 --- a/crates/fayalite-proc-macros-impl/src/module/transform_body.rs +++ b/crates/fayalite-proc-macros-impl/src/module/transform_body.rs @@ -1392,13 +1392,16 @@ impl Visitor { fn process_literal(&mut self, literal: ExprLit) -> Expr { let ExprLit { attrs, lit } = literal; match &lit { - Lit::Byte(lit_byte) if lit_byte.suffix() == "hdl" => { - if let Some(retval) = self.process_int_literal( - lit_byte.span(), - &lit_byte.value().to_string(), - "hdl_u8", - ) { - return retval; + Lit::Byte(lit_byte) => { + let trimmed_suffix = lit_byte.suffix().trim_start_matches('_'); + if trimmed_suffix == "hdl" || trimmed_suffix == "hdl_u8" { + if let Some(retval) = self.process_int_literal( + lit_byte.span(), + &lit_byte.value().to_string(), + "hdl_u8", + ) { + return retval; + } } } Lit::Int(lit_int) => { diff --git a/crates/fayalite/tests/module.rs b/crates/fayalite/tests/module.rs index 9ee28ca..2fb6927 100644 --- a/crates/fayalite/tests/module.rs +++ b/crates/fayalite/tests/module.rs @@ -57,7 +57,7 @@ pub fn my_module(width: usize) { m.connect( o, #[hdl] - [r, r, 13_hdl_u8], + [r, r, b'\r'_hdl], ); m.connect(o[1], 30_hdl_u8); m.connect(o2, i2);