Commit a6cd3626 by Zachary Snow

small pre-refactor PackedArray fixes

parent e1d6da00
...@@ -6,9 +6,12 @@ ...@@ -6,9 +6,12 @@
- This removes one dimension per identifier at a time. This works fine because - This removes one dimension per identifier at a time. This works fine because
- the conversions are repeatedly applied. - the conversions are repeatedly applied.
- -
- TODO FIXME XXX: The Parser/AST don't yet support indexing into an identifier
- twice, or indexing into an identifier, and then selecting a range.
-
- TODO: This assumes that the first range index is the upper bound. We could - TODO: This assumes that the first range index is the upper bound. We could
- probably get arround this with some cleverness in the generate block. I don't - probably get around this with some cleverness in the generate block. I don't
- think it's urgent to have support for "backwards" ragnes. - think it's urgent to have support for "backwards" ranges.
-} -}
module Convert.PackedArray (convert) where module Convert.PackedArray (convert) where
...@@ -40,7 +43,7 @@ convertDescription description = ...@@ -40,7 +43,7 @@ convertDescription description =
collectDecl :: ModuleItem -> State (DimMap, DirMap) () collectDecl :: ModuleItem -> State (DimMap, DirMap) ()
collectDecl (MIDecl (Variable dir t ident _ _)) = do collectDecl (MIDecl (Variable dir t ident _ _)) = do
let (tf, rs) = typeDims t let (tf, rs) = typeDims t
if length rs > 1 if not (typeIsImplicit t) && length rs > 1
then modify $ \(m, r) -> (Map.insert ident (tf $ tail rs, head rs) m, r) then modify $ \(m, r) -> (Map.insert ident (tf $ tail rs, head rs) m, r)
else return () else return ()
if dir /= Local if dir /= Local
...@@ -93,9 +96,6 @@ flattenModuleItem (dimMap, dirMap) (orig @ (MIDecl (Variable dir t ident a me))) ...@@ -93,9 +96,6 @@ flattenModuleItem (dimMap, dirMap) (orig @ (MIDecl (Variable dir t ident a me)))
flipGen = Map.lookup ident dirMap == Just Input flipGen = Map.lookup ident dirMap == Just Input
genItems = unflattener flipGen ident (dimMap Map.! ident) genItems = unflattener flipGen ident (dimMap Map.! ident)
newDecl = MIDecl $ Variable dir t' ident a me newDecl = MIDecl $ Variable dir t' ident a me
typeIsImplicit :: Type -> Bool
typeIsImplicit (Implicit _) = True
typeIsImplicit _ = False
flattenModuleItem _ other = other flattenModuleItem _ other = other
-- produces a generate block for creating a local unflattened copy of the given -- produces a generate block for creating a local unflattened copy of the given
...@@ -132,6 +132,10 @@ unflattener shouldFlip arr (t, (majorHi, majorLo)) = ...@@ -132,6 +132,10 @@ unflattener shouldFlip arr (t, (majorHi, majorLo)) =
(BinOp Sub size (Number "1"))) (BinOp Sub size (Number "1")))
, Ident startBit ) , Ident startBit )
typeIsImplicit :: Type -> Bool
typeIsImplicit (Implicit _) = True
typeIsImplicit _ = False
-- basic expression simplfication utility to help us generate nicer code in the -- basic expression simplfication utility to help us generate nicer code in the
-- common case of ranges like `[FOO-1:0]` -- common case of ranges like `[FOO-1:0]`
simplify :: Expr -> Expr simplify :: Expr -> Expr
...@@ -190,6 +194,12 @@ rewriteModuleItem dimMap = ...@@ -190,6 +194,12 @@ rewriteModuleItem dimMap =
e' = BinOp Mul size e e' = BinOp Mul size e
rewriteExpr other = other rewriteExpr other = other
rewriteLHS :: LHS -> LHS
rewriteLHS (LHS x ) = LHS (rewriteIdent x)
rewriteLHS (LHSBit x e) = LHSBit (rewriteIdent x) e
rewriteLHS (LHSRange x r) = LHSRange (rewriteIdent x) r
rewriteLHS (LHSConcat ls) = LHSConcat $ map rewriteLHS ls
rewriteStmt :: Stmt -> Stmt rewriteStmt :: Stmt -> Stmt
rewriteStmt (AsgnBlk lhs expr) = convertAssignment AsgnBlk lhs expr rewriteStmt (AsgnBlk lhs expr) = convertAssignment AsgnBlk lhs expr
rewriteStmt (Asgn lhs expr) = convertAssignment Asgn lhs expr rewriteStmt (Asgn lhs expr) = convertAssignment Asgn lhs expr
...@@ -197,7 +207,7 @@ rewriteModuleItem dimMap = ...@@ -197,7 +207,7 @@ rewriteModuleItem dimMap =
convertAssignment :: (LHS -> Expr -> Stmt) -> LHS -> Expr -> Stmt convertAssignment :: (LHS -> Expr -> Stmt) -> LHS -> Expr -> Stmt
convertAssignment constructor (lhs @ (LHS ident)) (expr @ (Repeat _ exprs)) = convertAssignment constructor (lhs @ (LHS ident)) (expr @ (Repeat _ exprs)) =
case Map.lookup ident dimMap of case Map.lookup ident dimMap of
Nothing -> constructor lhs expr Nothing -> constructor (rewriteLHS lhs) expr
Just (_, (a, b)) -> Just (_, (a, b)) ->
For inir chkr incr assign For inir chkr incr assign
where where
...@@ -209,4 +219,4 @@ rewriteModuleItem dimMap = ...@@ -209,4 +219,4 @@ rewriteModuleItem dimMap =
chkr = BinOp Le (Ident index) a chkr = BinOp Le (Ident index) a
incr = (index, BinOp Add (Ident index) (Number "1")) incr = (index, BinOp Add (Ident index) (Number "1"))
convertAssignment constructor lhs expr = convertAssignment constructor lhs expr =
constructor lhs expr constructor (rewriteLHS lhs) expr
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