2019-09-04 05:36:29 +02:00
|
|
|
{- sv2v
|
|
|
|
|
- Author: Zachary Snow <zach@zachjs.com>
|
|
|
|
|
-
|
|
|
|
|
- Conversion of streaming concatenations.
|
|
|
|
|
-}
|
|
|
|
|
|
|
|
|
|
module Convert.Stream (convert) where
|
|
|
|
|
|
|
|
|
|
import Convert.Traverse
|
|
|
|
|
import Language.SystemVerilog.AST
|
|
|
|
|
|
|
|
|
|
convert :: [AST] -> [AST]
|
|
|
|
|
convert = map $ traverseDescriptions convertDescription
|
|
|
|
|
|
|
|
|
|
convertDescription :: Description -> Description
|
2019-09-16 05:17:14 +02:00
|
|
|
convertDescription (description @ Part{}) =
|
2020-04-05 19:09:52 +02:00
|
|
|
traverseModuleItems (traverseStmts traverseStmt) description
|
2019-09-04 05:36:29 +02:00
|
|
|
convertDescription other = other
|
|
|
|
|
|
|
|
|
|
streamerBlock :: Expr -> Expr -> (LHS -> Expr -> Stmt) -> LHS -> Expr -> Stmt
|
|
|
|
|
streamerBlock chunk size asgn output input =
|
2019-10-01 05:03:55 +02:00
|
|
|
Block Seq ""
|
2020-06-14 21:56:09 +02:00
|
|
|
[ Variable Local t inp [] input
|
|
|
|
|
, Variable Local t out [] Nil
|
|
|
|
|
, Variable Local (IntegerAtom TInteger Unspecified) idx [] Nil
|
2019-09-04 05:36:29 +02:00
|
|
|
]
|
|
|
|
|
[ For inits cmp incr stmt
|
2020-05-06 00:42:45 +02:00
|
|
|
, If NoCheck cmp2 stmt2 Null
|
2019-09-04 05:36:29 +02:00
|
|
|
, asgn output (Ident out)
|
|
|
|
|
]
|
|
|
|
|
where
|
|
|
|
|
lo = Number "0"
|
|
|
|
|
hi = BinOp Sub size (Number "1")
|
|
|
|
|
t = IntegerVector TLogic Unspecified [(hi, lo)]
|
|
|
|
|
name = streamerBlockName chunk size
|
|
|
|
|
inp = name ++ "_inp"
|
|
|
|
|
out = name ++ "_out"
|
|
|
|
|
idx = name ++ "_idx"
|
|
|
|
|
-- main chunk loop
|
2019-10-01 05:03:55 +02:00
|
|
|
inits = Right [(LHSIdent idx, lo)]
|
2020-05-06 00:42:45 +02:00
|
|
|
cmp = BinOp Lt (Ident idx) base
|
2019-09-04 05:36:29 +02:00
|
|
|
incr = [(LHSIdent idx, AsgnOp Add, chunk)]
|
|
|
|
|
lhs = LHSRange (LHSIdent out) IndexedMinus (BinOp Sub hi (Ident idx), chunk)
|
|
|
|
|
expr = Range (Ident inp) IndexedPlus (Ident idx, chunk)
|
2020-02-01 21:52:52 +01:00
|
|
|
stmt = Asgn AsgnOpEq Nothing lhs expr
|
2020-05-06 00:42:45 +02:00
|
|
|
base = BinOp Mul (BinOp Div size chunk) chunk
|
2019-09-04 05:36:29 +02:00
|
|
|
-- final chunk loop
|
2020-05-06 00:42:45 +02:00
|
|
|
left = BinOp Sub size base
|
|
|
|
|
lhs2 = LHSRange (LHSIdent out) IndexedMinus (BinOp Sub hi base, left)
|
|
|
|
|
expr2 = Range (Ident inp) IndexedPlus (base, left)
|
2020-02-01 21:52:52 +01:00
|
|
|
stmt2 = Asgn AsgnOpEq Nothing lhs2 expr2
|
2020-05-06 00:42:45 +02:00
|
|
|
cmp2 = BinOp Gt left (Number "0")
|
2019-09-04 05:36:29 +02:00
|
|
|
|
|
|
|
|
streamerBlockName :: Expr -> Expr -> Identifier
|
|
|
|
|
streamerBlockName chunk size =
|
2019-09-04 05:52:22 +02:00
|
|
|
"_sv2v_strm_" ++ shortHash (chunk, size)
|
2019-09-04 05:36:29 +02:00
|
|
|
|
2020-04-05 19:09:52 +02:00
|
|
|
traverseStmt :: Stmt -> Stmt
|
|
|
|
|
traverseStmt (Asgn op mt lhs expr) =
|
|
|
|
|
traverseAsgn (lhs, expr) (Asgn op mt)
|
|
|
|
|
traverseStmt other = other
|
2019-09-04 05:36:29 +02:00
|
|
|
|
2020-04-05 19:09:52 +02:00
|
|
|
traverseAsgn :: (LHS, Expr) -> (LHS -> Expr -> Stmt) -> Stmt
|
|
|
|
|
traverseAsgn (lhs, Stream StreamR _ exprs) constructor =
|
|
|
|
|
constructor lhs expr
|
2019-09-04 05:36:29 +02:00
|
|
|
where
|
|
|
|
|
expr = Concat $ exprs ++ [Repeat delta [Number "1'b0"]]
|
2019-09-14 18:31:44 +02:00
|
|
|
size = DimsFn FnBits $ Right $ lhsToExpr lhs
|
|
|
|
|
exprSize = DimsFn FnBits $ Right (Concat exprs)
|
2019-09-04 05:36:29 +02:00
|
|
|
delta = BinOp Sub size exprSize
|
2020-04-05 19:09:52 +02:00
|
|
|
traverseAsgn (LHSStream StreamR _ lhss, expr) constructor =
|
|
|
|
|
constructor (LHSConcat lhss) expr
|
|
|
|
|
traverseAsgn (lhs, Stream StreamL chunk exprs) constructor = do
|
|
|
|
|
streamerBlock chunk size constructor lhs expr
|
2019-09-04 05:36:29 +02:00
|
|
|
where
|
|
|
|
|
expr = Concat $ Repeat delta [Number "1'b0"] : exprs
|
2019-09-14 18:31:44 +02:00
|
|
|
size = DimsFn FnBits $ Right $ lhsToExpr lhs
|
|
|
|
|
exprSize = DimsFn FnBits $ Right (Concat exprs)
|
2019-09-04 05:36:29 +02:00
|
|
|
delta = BinOp Sub size exprSize
|
2020-04-05 19:09:52 +02:00
|
|
|
traverseAsgn (LHSStream StreamL chunk lhss, expr) constructor = do
|
|
|
|
|
streamerBlock chunk size constructor lhs expr
|
2019-09-04 05:36:29 +02:00
|
|
|
where
|
|
|
|
|
lhs = LHSConcat lhss
|
2019-09-14 18:31:44 +02:00
|
|
|
size = DimsFn FnBits $ Right expr
|
2020-04-05 19:09:52 +02:00
|
|
|
traverseAsgn (lhs, expr) constructor =
|
|
|
|
|
constructor lhs expr
|