struct conversion attempts to size unsized constants when packing patterns

This commit is contained in:
Zachary Snow 2019-04-10 13:42:56 -04:00
parent 006e0e0830
commit 377600078a
2 changed files with 18 additions and 3 deletions

View File

@ -10,6 +10,7 @@ import Data.Maybe (fromJust, isJust)
import Data.List (elemIndex, sortOn)
import Data.Tuple (swap)
import Control.Monad.Writer
import Text.Read (readMaybe)
import qualified Data.Map.Strict as Map
import Convert.Traverse
@ -231,7 +232,21 @@ convertAsgn structs types (lhs, expr) =
items'' = map subMap items'
fieldNames = map snd fields
itemPosition = \(Just x, _) -> fromJust $ elemIndex x fieldNames
exprs = map snd $ sortOn itemPosition items''
packItem (Just x, Number n) =
Number $
case readMaybe unticked :: Maybe Int of
Nothing ->
if unticked == n
then n
else size ++ n
Just num -> size ++ "'d" ++ show num
where
Number size = rangeSize $ lookupUnstructRange structTf x
unticked = case n of
'\'' : rest -> rest
rest -> rest
packItem (_, itemExpr) = itemExpr
exprs = map packItem $ sortOn itemPosition items''
convertExpr _ other = other
-- try expression conversion by looking at the *innermost* type first

View File

@ -50,7 +50,7 @@ module CacheHelper (
writeData: `WORD_POISON,
requestType: CACHE_READ,
isValid: 1'b1,
writeEnable: 4'b0,
writeEnable: 0,
// This is effectively 32-bits wide which is sufficient, but not technically correct. The "compiler" will truncate the bits to the width of 'writeSet'
writeSet: '0
};