restore positive Decimal invariant

This commit is contained in:
Zachary Snow 2024-04-20 13:39:54 -04:00
parent 52575560ef
commit 57d6d2e9e8
2 changed files with 5 additions and 3 deletions

View File

@ -23,7 +23,7 @@ convert = map $ traverseDescriptions traverseDescription
elaborationFatalIdent :: Identifier
elaborationFatalIdent = "_sv2v_elaboration_fatal"
elaborationFatalCancelCode :: Expr
elaborationFatalCancelCode = RawNum (-1)
elaborationFatalCancelCode = UniOp UniSub $ RawNum 1
-- Checker for fatal elaboration
elaborationFatalDecl :: ModuleItem

View File

@ -322,7 +322,7 @@ numberBitLength (Based size _ _ _ _) =
then max 32 $ negate size
else size
-- get whether or not a number is sized
-- get whether or not a number is signed
numberIsSized :: Number -> Bool
numberIsSized UnbasedUnsized{} = False
numberIsSized (Decimal size _ _) = size > 0
@ -359,7 +359,9 @@ instance Show Number where
show (UnbasedUnsized bit) =
'\'' : show bit
show (Decimal (-32) True value) =
show value
if value < 0
then error $ "illegal decimal: " ++ show value
else show value
show (Decimal size signed value) =
if size == 0
then error $ "illegal decimal literal: "