Skip to content

Commit

Permalink
fix checking for large constants (#1743)
Browse files Browse the repository at this point in the history
  • Loading branch information
rachitnigam authored Oct 13, 2023
1 parent 41b24bd commit 67cf264
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 3 deletions.
9 changes: 7 additions & 2 deletions calyx-ir/src/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};

Expand Down Expand Up @@ -162,7 +162,12 @@ impl<'a> Builder<'a> {
pub fn add_constant(&mut self, val: u64, width: u64) -> RRC<ir::Cell> {
// 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
Expand Down
2 changes: 1 addition & 1 deletion tests/errors/insufficient-params.expect
Original file line number Diff line number Diff line change
@@ -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
1 change: 1 addition & 0 deletions tests/parsing/comb-component.expect
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 67cf264

Please sign in to comment.