Commit 4394dc17 by Zachary Snow

Fix PackedArray conversion after recursive Expr and LHS

parent e1799de5
...@@ -29,6 +29,7 @@ ...@@ -29,6 +29,7 @@
module Convert.PackedArray (convert) where module Convert.PackedArray (convert) where
import Text.Read (readMaybe)
import Control.Monad.State import Control.Monad.State
import Data.List (partition) import Data.List (partition)
import qualified Data.Set as Set import qualified Data.Set as Set
...@@ -90,14 +91,13 @@ recordSeqUsage i = modify $ \s -> s { sSeqUses = Set.insert i $ sSeqUses s } ...@@ -90,14 +91,13 @@ recordSeqUsage i = modify $ \s -> s { sSeqUses = Set.insert i $ sSeqUses s }
recordIdxUsage :: Identifier -> State Info () recordIdxUsage :: Identifier -> State Info ()
recordIdxUsage i = modify $ \s -> s { sIdxUses = Set.insert i $ sIdxUses s } recordIdxUsage i = modify $ \s -> s { sIdxUses = Set.insert i $ sIdxUses s }
collectExpr :: Expr -> State Info () collectExpr :: Expr -> State Info ()
collectExpr (Ident i ) = recordSeqUsage i
collectExpr (Range (Ident i) _) = recordSeqUsage i collectExpr (Range (Ident i) _) = recordSeqUsage i
collectExpr (Bit (Ident i) _) = recordIdxUsage i collectExpr (Bit (Ident i) _) = recordIdxUsage i
collectExpr _ = return () collectExpr _ = return ()
collectLHS :: LHS -> State Info () collectLHS :: LHS -> State Info ()
collectLHS (LHSIdent i) = recordSeqUsage i collectLHS (LHSRange (LHSIdent i) _) = recordSeqUsage i
collectLHS (LHSBit (LHSIdent i) _) = recordIdxUsage i collectLHS (LHSBit (LHSIdent i) _) = recordIdxUsage i
collectLHS _ = return () -- the collect recurses for us collectLHS _ = return ()
-- VCS doesn't like port declarations inside of `generate` blocks, so we hoist -- VCS doesn't like port declarations inside of `generate` blocks, so we hoist
-- them out with this function. This obviously isn't ideal, but it's a -- them out with this function. This obviously isn't ideal, but it's a
...@@ -195,6 +195,12 @@ simplify (BinOp op e1 e2) = ...@@ -195,6 +195,12 @@ simplify (BinOp op e1 e2) =
(Sub, e, Number "0") -> e (Sub, e, Number "0") -> e
(Add, BinOp Sub e (Number "1"), Number "1") -> e (Add, BinOp Sub e (Number "1"), Number "1") -> e
(Add, e, BinOp Sub (Number "0") (Number "1")) -> BinOp Sub e (Number "1") (Add, e, BinOp Sub (Number "0") (Number "1")) -> BinOp Sub e (Number "1")
(_ , Number a, Number b) ->
case (op, readMaybe a :: Maybe Int, readMaybe b :: Maybe Int) of
(Add, Just x, Just y) -> Number $ show (x + y)
(Sub, Just x, Just y) -> Number $ show (x - y)
(Mul, Just x, Just y) -> Number $ show (x * y)
_ -> BinOp op e1' e2'
_ -> BinOp op e1' e2' _ -> BinOp op e1' e2'
where where
e1' = simplify e1 e1' = simplify e1
...@@ -240,7 +246,7 @@ rewriteModuleItem info = ...@@ -240,7 +246,7 @@ rewriteModuleItem info =
rewriteAsgnIdent = rewriteIdent True rewriteAsgnIdent = rewriteIdent True
rewriteExpr :: Expr -> Expr rewriteExpr :: Expr -> Expr
rewriteExpr (Ident i)= Ident (rewriteReadIdent i) rewriteExpr (Ident i) = Ident i
rewriteExpr (Bit (Ident i) e) = Bit (Ident $ rewriteReadIdent i) e rewriteExpr (Bit (Ident i) e) = Bit (Ident $ rewriteReadIdent i) e
rewriteExpr (Range (Ident i) (r @ (s, e))) = rewriteExpr (Range (Ident i) (r @ (s, e))) =
if Map.member i typeDims if Map.member i typeDims
...@@ -256,6 +262,8 @@ rewriteModuleItem info = ...@@ -256,6 +262,8 @@ rewriteModuleItem info =
rewriteLHS :: LHS -> LHS rewriteLHS :: LHS -> LHS
rewriteLHS (LHSIdent x ) = LHSIdent (rewriteAsgnIdent x) rewriteLHS (LHSIdent x ) = LHSIdent (rewriteAsgnIdent x)
rewriteLHS (LHSBit (LHSBit (LHSIdent x) a) b) =
LHSBit (LHSBit (LHSIdent $ rewriteReadIdent x) a) b
rewriteLHS (LHSBit l e) = LHSBit (rewriteLHS l) e rewriteLHS (LHSBit l e) = LHSBit (rewriteLHS l) e
rewriteLHS (LHSRange l r) = LHSRange (rewriteLHS l) r rewriteLHS (LHSRange l r) = LHSRange (rewriteLHS l) r
rewriteLHS (LHSDot l x) = LHSDot (rewriteLHS l) x rewriteLHS (LHSDot l x) = LHSDot (rewriteLHS l) x
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment