Commit 1f7c70df by Zachary Snow

language support for LHS streaming operators

parent d6c932d0
......@@ -37,8 +37,9 @@ convertStmt (AsgnBlk (AsgnOp op) lhs expr) =
convertStmt other = other
lhsToExpr :: LHS -> Expr
lhsToExpr (LHSIdent x ) = Ident x
lhsToExpr (LHSBit l e ) = Bit (lhsToExpr l) e
lhsToExpr (LHSRange l m r) = Range (lhsToExpr l) m r
lhsToExpr (LHSDot l x ) = Dot (lhsToExpr l) x
lhsToExpr (LHSConcat ls ) = Concat $ map lhsToExpr ls
lhsToExpr (LHSIdent x ) = Ident x
lhsToExpr (LHSBit l e ) = Bit (lhsToExpr l) e
lhsToExpr (LHSRange l m r ) = Range (lhsToExpr l) m r
lhsToExpr (LHSDot l x ) = Dot (lhsToExpr l) x
lhsToExpr (LHSConcat ls) = Concat $ map lhsToExpr ls
lhsToExpr (LHSStream o e ls) = Stream o e $ map lhsToExpr ls
......@@ -288,6 +288,8 @@ convertAsgn structs types (lhs, expr) =
fieldType = lookupFieldType fields x
convertLHS (LHSConcat lhss) =
(Implicit Unspecified [], LHSConcat $ map (snd . convertLHS) lhss)
convertLHS (LHSStream o e lhss) =
(Implicit Unspecified [], LHSStream o e $ map (snd . convertLHS) lhss)
-- try expression conversion by looking at the *outermost* type first
convertExpr :: Type -> Expr -> Expr
......
......@@ -504,6 +504,9 @@ exprMapperHelpers exprMapper =
rangeMapper r >>= return . LHSRange l m
lhsMapper (LHSBit l e) =
exprMapper e >>= return . LHSBit l
lhsMapper (LHSStream o e ls) = do
e' <- exprMapper e
return $ LHSStream o e' ls
lhsMapper other = return other
traverseExprsM' :: Monad m => TFStrategy -> MapperM m Expr -> MapperM m ModuleItem
......@@ -730,11 +733,12 @@ traverseNestedLHSsM :: Monad m => MapperM m LHS -> MapperM m LHS
traverseNestedLHSsM mapper = fullMapper
where
fullMapper lhs = mapper lhs >>= tl
tl (LHSIdent x ) = return $ LHSIdent x
tl (LHSBit l e ) = fullMapper l >>= \l' -> return $ LHSBit l' e
tl (LHSRange l m r) = fullMapper l >>= \l' -> return $ LHSRange l' m r
tl (LHSDot l x ) = fullMapper l >>= \l' -> return $ LHSDot l' x
tl (LHSConcat lhss ) = mapM fullMapper lhss >>= return . LHSConcat
tl (LHSIdent x ) = return $ LHSIdent x
tl (LHSBit l e ) = fullMapper l >>= \l' -> return $ LHSBit l' e
tl (LHSRange l m r ) = fullMapper l >>= \l' -> return $ LHSRange l' m r
tl (LHSDot l x ) = fullMapper l >>= \l' -> return $ LHSDot l' x
tl (LHSConcat lhss) = mapM fullMapper lhss >>= return . LHSConcat
tl (LHSStream o e lhss) = mapM fullMapper lhss >>= return . LHSStream o e
traverseNestedLHSs :: Mapper LHS -> Mapper LHS
traverseNestedLHSs = unmonad traverseNestedLHSsM
......
......@@ -55,4 +55,7 @@ exprToLHS (Dot l x ) = do
exprToLHS (Concat ls ) = do
ls' <- mapM exprToLHS ls
Just $ LHSConcat ls'
exprToLHS (Stream o e ls) = do
ls' <- mapM exprToLHS ls
Just $ LHSStream o e ls'
exprToLHS _ = Nothing
......@@ -14,6 +14,7 @@ import Text.Printf (printf)
import Language.SystemVerilog.AST.ShowHelp (commas)
import Language.SystemVerilog.AST.Type (Identifier)
import Language.SystemVerilog.AST.Expr (Expr, PartSelectMode, Range)
import Language.SystemVerilog.AST.Op (StreamOp)
data LHS
= LHSIdent Identifier
......@@ -21,6 +22,7 @@ data LHS
| LHSRange LHS PartSelectMode Range
| LHSDot LHS Identifier
| LHSConcat [LHS]
| LHSStream StreamOp Expr [LHS]
deriving Eq
instance Show LHS where
......@@ -28,4 +30,5 @@ instance Show LHS where
show (LHSBit l e ) = printf "%s[%s]" (show l) (show e)
show (LHSRange l m (a, b)) = printf "%s[%s%s%s]" (show l) (show a) (show m) (show b)
show (LHSDot l x ) = printf "%s.%s" (show l) x
show (LHSConcat lhss ) = printf "{%s}" (commas $ map show lhss)
show (LHSConcat lhss) = printf "{%s}" (commas $ map show lhss)
show (LHSStream o e lhss) = printf "{%s %s%s}" (show o) (show e) (show $ LHSConcat lhss)
......@@ -423,12 +423,14 @@ DeclOrStmtToken :: { DeclToken }
| Identifier { DTIdent $1 }
| Direction { DTDir $1 }
| "[" Expr "]" { DTBit $2 }
| "{" LHSs "}" { DTConcat $2 }
| LHSConcat { DTConcat $1 }
| PartialType { DTType $1 }
| "." Identifier { DTDot $2 }
| Signing { DTSigning $1 }
| Lifetime { DTLifetime $1 }
| Identifier "::" Identifier { DTPSIdent $1 $3 }
| "{" StreamOp StreamSize Concat "}" { DTStream $2 $3 (map toLHS $4) }
| "{" StreamOp Concat "}" { DTStream $2 (Number "1") (map toLHS $3) }
VariablePortIdentifiers :: { [(Identifier, Maybe Expr)] }
: VariablePortIdentifier { [$1] }
......@@ -654,8 +656,12 @@ LHS :: { LHS }
| LHS PartSelect { LHSRange $1 (fst $2) (snd $2) }
| LHS "[" Expr "]" { LHSBit $1 $3 }
| LHS "." Identifier { LHSDot $1 $3 }
| "{" LHSs "}" { LHSConcat $2 }
| LHSConcat { LHSConcat $1 }
| "{" StreamOp StreamSize Concat "}" { LHSStream $2 $3 (map toLHS $4) }
| "{" StreamOp Concat "}" { LHSStream $2 (Number "1") (map toLHS $3) }
LHSConcat :: { [LHS] }
: "{" LHSs "}" { $2 }
LHSs :: { [LHS] }
: LHS { [$1] }
| LHSs "," LHS { $1 ++ [$3] }
......
......@@ -57,6 +57,7 @@ data DeclToken
| DTInstance [PortBinding]
| DTBit Expr
| DTConcat [LHS]
| DTStream StreamOp Expr [LHS]
| DTDot Identifier
| DTSigning Signing
| DTLifetime Lifetime
......@@ -229,6 +230,7 @@ parseDTsAsDeclsAndAsgns tokens =
isAsgnToken :: DeclToken -> Bool
isAsgnToken (DTBit _) = True
isAsgnToken (DTConcat _) = True
isAsgnToken (DTStream _ _ _) = True
isAsgnToken (DTDot _) = True
isAsgnToken (DTAsgnNBlk _ _) = True
isAsgnToken (DTAsgn (AsgnOp _) _) = True
......@@ -240,8 +242,9 @@ takeLHS (t : ts) =
foldl takeLHSStep (takeLHSStart t) ts
takeLHSStart :: DeclToken -> Maybe LHS
takeLHSStart (DTConcat lhss) = Just $ LHSConcat lhss
takeLHSStart (DTIdent x ) = Just $ LHSIdent x
takeLHSStart (DTConcat lhss) = Just $ LHSConcat lhss
takeLHSStart (DTStream o e lhss) = Just $ LHSStream o e lhss
takeLHSStart (DTIdent x ) = Just $ LHSIdent x
takeLHSStart _ = Nothing
takeLHSStep :: Maybe LHS -> DeclToken -> Maybe LHS
......
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