mirror of https://github.com/zachjs/sv2v.git
allow .* as element of partial port bindings
This commit is contained in:
parent
f97e069ef0
commit
b2b1c9e52c
|
|
@ -73,12 +73,12 @@ convertDescription interfaces (Part Module name ports items) =
|
||||||
mapper = \(dir, port, Just expr) ->
|
mapper = \(dir, port, Just expr) ->
|
||||||
Variable dir (lookupType interfaceItems expr)
|
Variable dir (lookupType interfaceItems expr)
|
||||||
(ident ++ "_" ++ port) [] Nothing
|
(ident ++ "_" ++ port) [] Nothing
|
||||||
mapInterface (Instance part params ident (Just instancePorts)) =
|
mapInterface (Instance part params ident instancePorts) =
|
||||||
case Map.lookup part interfaces of
|
case Map.lookup part interfaces of
|
||||||
Just interface ->
|
Just interface ->
|
||||||
Generate $ map GenModuleItem $
|
Generate $ map GenModuleItem $
|
||||||
inlineInterface interface (ident, expandedPorts)
|
inlineInterface interface (ident, expandedPorts)
|
||||||
Nothing -> Instance part params ident (Just expandedPorts)
|
Nothing -> Instance part params ident expandedPorts
|
||||||
where expandedPorts = concatMap expandPortBinding instancePorts
|
where expandedPorts = concatMap expandPortBinding instancePorts
|
||||||
mapInterface other = other
|
mapInterface other = other
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -22,11 +22,18 @@ convert descriptions =
|
||||||
getPorts _ = return ()
|
getPorts _ = return ()
|
||||||
|
|
||||||
mapInstance :: ModuleItem -> ModuleItem
|
mapInstance :: ModuleItem -> ModuleItem
|
||||||
mapInstance (Instance m p x Nothing) =
|
mapInstance (Instance m p x bindings) =
|
||||||
Instance m p x (Just portBindings)
|
Instance m p x $ concatMap expandBinding bindings
|
||||||
where
|
where
|
||||||
ports = case Map.lookup m modulePorts of
|
alreadyBound :: [Identifier]
|
||||||
Nothing -> error $ "could not convert `.*` in instantiation of " ++ m
|
alreadyBound = map fst bindings
|
||||||
Just l -> l
|
expandBinding :: PortBinding -> [PortBinding]
|
||||||
portBindings = map (\port -> (port, Just $ Ident port)) ports
|
expandBinding ("*", Nothing) =
|
||||||
|
case Map.lookup m modulePorts of
|
||||||
|
Just l ->
|
||||||
|
map (\port -> (port, Just $ Ident port)) $
|
||||||
|
filter (\s -> not $ elem s alreadyBound) $ l
|
||||||
|
-- if we can't find it, just skip :(
|
||||||
|
Nothing -> [("*", Nothing)]
|
||||||
|
expandBinding other = [other]
|
||||||
mapInstance other = other
|
mapInstance other = other
|
||||||
|
|
|
||||||
|
|
@ -45,7 +45,6 @@ module Convert.Traverse
|
||||||
, traverseNestedStmts
|
, traverseNestedStmts
|
||||||
) where
|
) where
|
||||||
|
|
||||||
import Data.Maybe (fromJust)
|
|
||||||
import Control.Monad.State
|
import Control.Monad.State
|
||||||
import Language.SystemVerilog.AST
|
import Language.SystemVerilog.AST
|
||||||
|
|
||||||
|
|
@ -302,12 +301,9 @@ traverseExprsM mapper = moduleItemMapper
|
||||||
decls' <- mapM declMapper decls
|
decls' <- mapM declMapper decls
|
||||||
stmts' <- mapM stmtMapper stmts
|
stmts' <- mapM stmtMapper stmts
|
||||||
return $ MIPackageItem $ Task lifetime f decls' stmts'
|
return $ MIPackageItem $ Task lifetime f decls' stmts'
|
||||||
moduleItemMapper (Instance m params x ml) = do
|
moduleItemMapper (Instance m params x l) = do
|
||||||
if ml == Nothing
|
l' <- mapM portBindingMapper l
|
||||||
then return $ Instance m params x Nothing
|
return $ Instance m params x l'
|
||||||
else do
|
|
||||||
l <- mapM portBindingMapper (fromJust ml)
|
|
||||||
return $ Instance m params x (Just l)
|
|
||||||
moduleItemMapper (Modport x l) =
|
moduleItemMapper (Modport x l) =
|
||||||
mapM modportDeclMapper l >>= return . Modport x
|
mapM modportDeclMapper l >>= return . Modport x
|
||||||
moduleItemMapper (Genvar x) = return $ Genvar x
|
moduleItemMapper (Genvar x) = return $ Genvar x
|
||||||
|
|
|
||||||
|
|
@ -177,7 +177,7 @@ data ModuleItem
|
||||||
= MIDecl Decl
|
= MIDecl Decl
|
||||||
| AlwaysC AlwaysKW Stmt
|
| AlwaysC AlwaysKW Stmt
|
||||||
| Assign LHS Expr
|
| Assign LHS Expr
|
||||||
| Instance Identifier [PortBinding] Identifier (Maybe [PortBinding]) -- `Nothing` represents `.*`
|
| Instance Identifier [PortBinding] Identifier [PortBinding]
|
||||||
| Genvar Identifier
|
| Genvar Identifier
|
||||||
| Generate [GenItem]
|
| Generate [GenItem]
|
||||||
| Modport Identifier [ModportDecl]
|
| Modport Identifier [ModportDecl]
|
||||||
|
|
@ -207,18 +207,18 @@ instance Show ModuleItem where
|
||||||
AlwaysC k b -> printf "%s %s" (show k) (show b)
|
AlwaysC k b -> printf "%s %s" (show k) (show b)
|
||||||
Assign a b -> printf "assign %s = %s;" (show a) (show b)
|
Assign a b -> printf "assign %s = %s;" (show a) (show b)
|
||||||
Instance m params i ports
|
Instance m params i ports
|
||||||
| null params -> printf "%s %s%s;" m i (showMaybePorts ports)
|
| null params -> printf "%s %s%s;" m i (showPorts ports)
|
||||||
| otherwise -> printf "%s #%s %s%s;" m (showPorts params) i (showMaybePorts ports)
|
| otherwise -> printf "%s #%s %s%s;" m (showPorts params) i (showPorts ports)
|
||||||
Genvar x -> printf "genvar %s;" x
|
Genvar x -> printf "genvar %s;" x
|
||||||
Generate b -> printf "generate\n%s\nendgenerate" (indent $ unlines' $ map show b)
|
Generate b -> printf "generate\n%s\nendgenerate" (indent $ unlines' $ map show b)
|
||||||
Modport x l -> printf "modport %s(\n%s\n);" x (indent $ intercalate ",\n" $ map showModportDecl l)
|
Modport x l -> printf "modport %s(\n%s\n);" x (indent $ intercalate ",\n" $ map showModportDecl l)
|
||||||
Initial s -> printf "initial %s" (show s)
|
Initial s -> printf "initial %s" (show s)
|
||||||
MIPackageItem i -> show i
|
MIPackageItem i -> show i
|
||||||
where
|
where
|
||||||
showMaybePorts = maybe "(.*)" showPorts
|
|
||||||
showPorts :: [PortBinding] -> String
|
showPorts :: [PortBinding] -> String
|
||||||
showPorts ports = indentedParenList $ map showPort ports
|
showPorts ports = indentedParenList $ map showPort ports
|
||||||
showPort :: PortBinding -> String
|
showPort :: PortBinding -> String
|
||||||
|
showPort ("*", Nothing) = ".*"
|
||||||
showPort (i, arg) =
|
showPort (i, arg) =
|
||||||
if i == ""
|
if i == ""
|
||||||
then show (fromJust arg)
|
then show (fromJust arg)
|
||||||
|
|
|
||||||
|
|
@ -344,9 +344,8 @@ Lifetime :: { Lifetime }
|
||||||
: "static" { Static }
|
: "static" { Static }
|
||||||
| "automatic" { Automatic }
|
| "automatic" { Automatic }
|
||||||
|
|
||||||
ModuleInstantiation :: { (Identifier, Maybe [PortBinding]) }
|
ModuleInstantiation :: { (Identifier, [PortBinding]) }
|
||||||
: Identifier "(" Bindings ")" { ($1, Just $3) }
|
: Identifier "(" Bindings ")" { ($1, $3) }
|
||||||
| Identifier "(" ".*" ")" { ($1, Nothing) }
|
|
||||||
|
|
||||||
TFItems :: { [Decl] }
|
TFItems :: { [Decl] }
|
||||||
: "(" DeclTokens(")") ";" { parseDTsAsDecls $2 }
|
: "(" DeclTokens(")") ";" { parseDTsAsDecls $2 }
|
||||||
|
|
@ -396,6 +395,7 @@ Binding :: { (Identifier, Maybe Expr) }
|
||||||
: "." Identifier "(" opt(Expr) ")" { ($2, $4) }
|
: "." Identifier "(" opt(Expr) ")" { ($2, $4) }
|
||||||
| "." Identifier { ($2, Just $ Ident $2) }
|
| "." Identifier { ($2, Just $ Ident $2) }
|
||||||
| Expr { ("", Just $1) }
|
| Expr { ("", Just $1) }
|
||||||
|
| ".*" { ("*", Nothing) }
|
||||||
|
|
||||||
ParameterBindings :: { [(Identifier, Maybe Expr)] }
|
ParameterBindings :: { [(Identifier, Maybe Expr)] }
|
||||||
: "#" "(" BindingsNonEmpty ")" { $3 }
|
: "#" "(" BindingsNonEmpty ")" { $3 }
|
||||||
|
|
|
||||||
|
|
@ -53,7 +53,7 @@ data DeclToken
|
||||||
| DTDir Direction
|
| DTDir Direction
|
||||||
| DTType ([Range] -> Type)
|
| DTType ([Range] -> Type)
|
||||||
| DTParams [PortBinding]
|
| DTParams [PortBinding]
|
||||||
| DTInstance (Identifier, Maybe [PortBinding])
|
| DTInstance (Identifier, [PortBinding])
|
||||||
| DTBit Expr
|
| DTBit Expr
|
||||||
| DTConcat [LHS]
|
| DTConcat [LHS]
|
||||||
deriving (Show, Eq)
|
deriving (Show, Eq)
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue