mirror of https://github.com/zachjs/sv2v.git
performance improvements
- removed repetition in dimension query conversion - removed repetition in package item nesting conversion - packing item nesting conversion short circuit - param type conversion doesn't bother renaming non-param type instances - implement showsPrec for certain expression cases
This commit is contained in:
parent
682620b23f
commit
b71e0f5346
|
|
@ -25,11 +25,7 @@ import Convert.Traverse
|
||||||
import Language.SystemVerilog.AST
|
import Language.SystemVerilog.AST
|
||||||
|
|
||||||
convert :: [AST] -> [AST]
|
convert :: [AST] -> [AST]
|
||||||
convert files =
|
convert = map $ traverseDescriptions convertDescription
|
||||||
if files == files'
|
|
||||||
then files
|
|
||||||
else convert files'
|
|
||||||
where files' = map (traverseDescriptions convertDescription) files
|
|
||||||
|
|
||||||
convertDescription :: Description -> Description
|
convertDescription :: Description -> Description
|
||||||
convertDescription =
|
convertDescription =
|
||||||
|
|
|
||||||
|
|
@ -21,15 +21,9 @@ convert =
|
||||||
map (filter (not . isPI)) . nest
|
map (filter (not . isPI)) . nest
|
||||||
where
|
where
|
||||||
nest :: [AST] -> [AST]
|
nest :: [AST] -> [AST]
|
||||||
nest curr =
|
nest = traverseFiles
|
||||||
if next == curr
|
(collectDescriptionsM collectDescriptionM)
|
||||||
then curr
|
(traverseDescriptions . convertDescription)
|
||||||
else nest next
|
|
||||||
where
|
|
||||||
next = traverseFiles
|
|
||||||
(collectDescriptionsM collectDescriptionM)
|
|
||||||
(traverseDescriptions . convertDescription)
|
|
||||||
curr
|
|
||||||
isPI :: Description -> Bool
|
isPI :: Description -> Bool
|
||||||
isPI (PackageItem Import{}) = False
|
isPI (PackageItem Import{}) = False
|
||||||
isPI (PackageItem item) = piName item /= Nothing
|
isPI (PackageItem item) = piName item /= Nothing
|
||||||
|
|
@ -46,7 +40,9 @@ collectDescriptionM _ = return ()
|
||||||
-- nests packages items missing from modules
|
-- nests packages items missing from modules
|
||||||
convertDescription :: PIs -> Description -> Description
|
convertDescription :: PIs -> Description -> Description
|
||||||
convertDescription pis (orig @ Part{}) =
|
convertDescription pis (orig @ Part{}) =
|
||||||
Part attrs extern kw lifetime name ports items'
|
if Map.null pis
|
||||||
|
then orig
|
||||||
|
else Part attrs extern kw lifetime name ports items'
|
||||||
where
|
where
|
||||||
Part attrs extern kw lifetime name ports items = orig
|
Part attrs extern kw lifetime name ports items = orig
|
||||||
items' = addItems pis Set.empty items
|
items' = addItems pis Set.empty items
|
||||||
|
|
|
||||||
|
|
@ -233,7 +233,7 @@ convertModuleItemM info (orig @ (Instance m bindings x r p)) =
|
||||||
if Map.notMember m info then
|
if Map.notMember m info then
|
||||||
return orig
|
return orig
|
||||||
else if Map.null maybeTypeMap then
|
else if Map.null maybeTypeMap then
|
||||||
return $ Instance m bindingsNamed x r p
|
return orig
|
||||||
else if any (isLeft . snd) bindings' then
|
else if any (isLeft . snd) bindings' then
|
||||||
error $ "param type resolution left type params: " ++ show orig
|
error $ "param type resolution left type params: " ++ show orig
|
||||||
++ " converted to: " ++ show bindings'
|
++ " converted to: " ++ show bindings'
|
||||||
|
|
|
||||||
|
|
@ -80,11 +80,6 @@ instance Show Expr where
|
||||||
show (Repeat e l ) = printf "{%s {%s}}" (show e) (commas $ map show l)
|
show (Repeat e l ) = printf "{%s {%s}}" (show e) (commas $ map show l)
|
||||||
show (Concat l ) = printf "{%s}" (commas $ map show l)
|
show (Concat l ) = printf "{%s}" (commas $ map show l)
|
||||||
show (Stream o e l) = printf "{%s %s%s}" (show o) (show e) (show $ Concat l)
|
show (Stream o e l) = printf "{%s %s%s}" (show o) (show e) (show $ Concat l)
|
||||||
show (UniOp o e ) = printf "%s%s" (show o) (showUniOpPrec e)
|
|
||||||
show (BinOp o a b) = printf "%s %s %s" (showBinOpPrec a) (show o) (showBinOpPrec b)
|
|
||||||
show (Dot e n ) = printf "%s.%s" (show e) n
|
|
||||||
show (Mux c a b) = printf "(%s ? %s : %s)" (show c) (show a) (show b)
|
|
||||||
show (Call e l ) = printf "%s%s" (show e) (show l)
|
|
||||||
show (Cast tore e ) = printf "%s'(%s)" (showEither tore) (show e)
|
show (Cast tore e ) = printf "%s'(%s)" (showEither tore) (show e)
|
||||||
show (DimsFn f v ) = printf "%s(%s)" (show f) (showEither v)
|
show (DimsFn f v ) = printf "%s(%s)" (show f) (showEither v)
|
||||||
show (DimFn f v e) = printf "%s(%s, %s)" (show f) (showEither v) (show e)
|
show (DimFn f v e) = printf "%s(%s, %s)" (show f) (showEither v) (show e)
|
||||||
|
|
@ -99,6 +94,37 @@ instance Show Expr where
|
||||||
showPatternItem (':' : n, e) = showPatternItem (n, e)
|
showPatternItem (':' : n, e) = showPatternItem (n, e)
|
||||||
showPatternItem (n , e) = printf "%s: %s" n (show e)
|
showPatternItem (n , e) = printf "%s: %s" n (show e)
|
||||||
show (MinTypMax a b c) = printf "(%s : %s : %s)" (show a) (show b) (show c)
|
show (MinTypMax a b c) = printf "(%s : %s : %s)" (show a) (show b) (show c)
|
||||||
|
show (e @ UniOp{}) = showsPrec 0 e ""
|
||||||
|
show (e @ BinOp{}) = showsPrec 0 e ""
|
||||||
|
show (e @ Dot {}) = showsPrec 0 e ""
|
||||||
|
show (e @ Mux {}) = showsPrec 0 e ""
|
||||||
|
show (e @ Call {}) = showsPrec 0 e ""
|
||||||
|
|
||||||
|
showsPrec _ (UniOp o e ) =
|
||||||
|
shows o .
|
||||||
|
showUniOpPrec e
|
||||||
|
showsPrec _ (BinOp o a b) =
|
||||||
|
showBinOpPrec a .
|
||||||
|
showChar ' ' .
|
||||||
|
shows o .
|
||||||
|
showChar ' ' .
|
||||||
|
showBinOpPrec b
|
||||||
|
showsPrec _ (Dot e n ) =
|
||||||
|
shows e .
|
||||||
|
showChar '.' .
|
||||||
|
showString n
|
||||||
|
showsPrec _ (Mux c a b) =
|
||||||
|
showChar '(' .
|
||||||
|
shows c .
|
||||||
|
showString " ? " .
|
||||||
|
shows a .
|
||||||
|
showString " : " .
|
||||||
|
shows b .
|
||||||
|
showChar ')'
|
||||||
|
showsPrec _ (Call e l ) =
|
||||||
|
shows e .
|
||||||
|
shows l
|
||||||
|
showsPrec _ e = \s -> show e ++ s
|
||||||
|
|
||||||
data Args
|
data Args
|
||||||
= Args [Maybe Expr] [(Identifier, Maybe Expr)]
|
= Args [Maybe Expr] [(Identifier, Maybe Expr)]
|
||||||
|
|
@ -184,14 +210,14 @@ readNumber ('\'' : 'h' : rest) =
|
||||||
_ -> Nothing
|
_ -> Nothing
|
||||||
readNumber n = readMaybe n
|
readNumber n = readMaybe n
|
||||||
|
|
||||||
showUniOpPrec :: Expr -> String
|
showUniOpPrec :: Expr -> ShowS
|
||||||
showUniOpPrec (e @ UniOp{}) = printf "(%s)" (show e)
|
showUniOpPrec (e @ UniOp{}) = (showParen True . shows) e
|
||||||
showUniOpPrec (e @ BinOp{}) = printf "(%s)" (show e)
|
showUniOpPrec (e @ BinOp{}) = (showParen True . shows) e
|
||||||
showUniOpPrec e = show e
|
showUniOpPrec e = shows e
|
||||||
|
|
||||||
showBinOpPrec :: Expr -> String
|
showBinOpPrec :: Expr -> ShowS
|
||||||
showBinOpPrec (e @ BinOp{}) = printf "(%s)" (show e)
|
showBinOpPrec (e @ BinOp{}) = (showParen True . shows) e
|
||||||
showBinOpPrec e = show e
|
showBinOpPrec e = shows e
|
||||||
|
|
||||||
-- 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]`
|
||||||
|
|
|
||||||
|
|
@ -19,7 +19,7 @@ import Data.List (intercalate)
|
||||||
|
|
||||||
showPad :: Show t => t -> String
|
showPad :: Show t => t -> String
|
||||||
showPad x =
|
showPad x =
|
||||||
if str == ""
|
if null str
|
||||||
then ""
|
then ""
|
||||||
else str ++ " "
|
else str ++ " "
|
||||||
where str = show x
|
where str = show x
|
||||||
|
|
@ -28,14 +28,14 @@ showPadBefore :: Show t => t -> String
|
||||||
showPadBefore x =
|
showPadBefore x =
|
||||||
if str == ""
|
if str == ""
|
||||||
then ""
|
then ""
|
||||||
else " " ++ str
|
else ' ' : str
|
||||||
where str = show x
|
where str = show x
|
||||||
|
|
||||||
indent :: String -> String
|
indent :: String -> String
|
||||||
indent a = '\t' : f a
|
indent = (:) '\t' . f
|
||||||
where
|
where
|
||||||
f [] = []
|
f [] = []
|
||||||
f ('\n' : xs) = "\n\t" ++ f xs
|
f ('\n' : xs) = '\n' : '\t' : f xs
|
||||||
f (x : xs) = x : f xs
|
f (x : xs) = x : f xs
|
||||||
|
|
||||||
unlines' :: [String] -> String
|
unlines' :: [String] -> String
|
||||||
|
|
@ -46,7 +46,7 @@ commas = intercalate ", "
|
||||||
|
|
||||||
indentedParenList :: [String] -> String
|
indentedParenList :: [String] -> String
|
||||||
indentedParenList [] = "()"
|
indentedParenList [] = "()"
|
||||||
indentedParenList [x] = "(" ++ x ++ ")"
|
indentedParenList [x] = '(' : x ++ ")"
|
||||||
indentedParenList l = "(\n" ++ (indent $ intercalate ",\n" l) ++ "\n)"
|
indentedParenList l = "(\n" ++ (indent $ intercalate ",\n" l) ++ "\n)"
|
||||||
|
|
||||||
showEither :: (Show a, Show b) => Either a b -> String
|
showEither :: (Show a, Show b) => Either a b -> String
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue