From 8a8b089a92dbf736a6bddd1c4b5bbd3d478d87dc Mon Sep 17 00:00:00 2001 From: Zachary Snow Date: Sun, 16 Aug 2020 13:44:40 -0400 Subject: [PATCH] assume 0-based sized ranges are non-negative --- src/Convert/ExprUtils.hs | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/Convert/ExprUtils.hs b/src/Convert/ExprUtils.hs index c93219d..465de8c 100644 --- a/src/Convert/ExprUtils.hs +++ b/src/Convert/ExprUtils.hs @@ -178,6 +178,7 @@ rangeSizeHiLo (hi, lo) = -- chooses one or the other expression based on the endianness of the given -- range; [hi:lo] chooses the first expression endianCondExpr :: Range -> Expr -> Expr -> Expr +endianCondExpr SizedRange{} e _ = e endianCondExpr r e1 e2 = simplify $ Mux (uncurry (BinOp Ge) r) e1 e2 -- chooses one or the other range based on the endianness of the given range, @@ -197,3 +198,8 @@ dimensionsSize ranges = foldl (BinOp Mul) (RawNum 1) $ map rangeSize $ ranges + +-- "sized ranges" are of the form [E-1:0], where E is any expression; in most +-- designs, we can safely assume that E >= 1, allowing for more succinct output +pattern SizedRange :: Expr -> Range +pattern SizedRange expr = (BinOp Sub expr (RawNum 1), RawNum 0)