From 67cf264d094c5887d05707b6687ddaf83ef4db79 Mon Sep 17 00:00:00 2001 From: Rachit Nigam Date: Fri, 13 Oct 2023 11:50:03 -0400 Subject: [PATCH] fix checking for large constants (#1743) --- calyx-ir/src/builder.rs | 9 +++++++-- tests/errors/insufficient-params.expect | 2 +- tests/parsing/comb-component.expect | 1 + 3 files changed, 9 insertions(+), 3 deletions(-) diff --git a/calyx-ir/src/builder.rs b/calyx-ir/src/builder.rs index 78aa369685..547533e538 100644 --- a/calyx-ir/src/builder.rs +++ b/calyx-ir/src/builder.rs @@ -2,7 +2,7 @@ //! representation. use crate::{self as ir, LibrarySignatures, Nothing, RRC, WRC}; use calyx_frontend::BoolAttr; -use std::rc::Rc; +use std::{cmp, rc::Rc}; use super::{CellType, PortDef}; @@ -162,7 +162,12 @@ impl<'a> Builder<'a> { pub fn add_constant(&mut self, val: u64, width: u64) -> RRC { // Ensure that the value can fit within the width assert!( - val < (1 << width), + val < match width.cmp(&64) { + cmp::Ordering::Less => 1 << width, + cmp::Ordering::Equal => u64::MAX, + cmp::Ordering::Greater => + panic!("Widths greater than 64 are not supported."), + }, "Constant value {} cannot fit in {} bits", val, width diff --git a/tests/errors/insufficient-params.expect b/tests/errors/insufficient-params.expect index 25f8b07e8a..09ebb3bff7 100644 --- a/tests/errors/insufficient-params.expect +++ b/tests/errors/insufficient-params.expect @@ -1,5 +1,5 @@ ---CODE--- 101 ---STDERR--- -thread 'main' panicked at 'Failed to add primitive.: Malformed Structure: Invalid parameter binding for primitive `std_fp_div_pipe`. Requires 3 parameters but provided with 1.', calyx-ir/src/builder.rs:219:14 +thread 'main' panicked at 'Failed to add primitive.: Malformed Structure: Invalid parameter binding for primitive `std_fp_div_pipe`. Requires 3 parameters but provided with 1.', calyx-ir/src/builder.rs:224:14 note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace diff --git a/tests/parsing/comb-component.expect b/tests/parsing/comb-component.expect index c7551bf46b..ec96480a00 100644 --- a/tests/parsing/comb-component.expect +++ b/tests/parsing/comb-component.expect @@ -2,6 +2,7 @@ import "primitives/core.futil"; comb component custom_lt(left: 4, right: 4) -> (out: 1) { cells { lt = std_lt(4); + c0 = std_const(64, 1000); } wires { lt.left = left;