diff --git a/src/Convert/Stream.hs b/src/Convert/Stream.hs index ff5b14e..461714d 100644 --- a/src/Convert/Stream.hs +++ b/src/Convert/Stream.hs @@ -70,10 +70,7 @@ streamerBlock chunk size asgn output input = streamerBlockName :: Expr -> Expr -> Identifier streamerBlockName chunk size = - "_sv2v_strm_" ++ take 5 str - where - val = hash $ show (chunk, size) - str = tail $ show val + "_sv2v_strm_" ++ shortHash (chunk, size) traverseStmtM :: Stmt -> Writer Funcs Stmt traverseStmtM (AsgnBlk op lhs expr) = diff --git a/src/Convert/Struct.hs b/src/Convert/Struct.hs index 4348bc5..89bc976 100644 --- a/src/Convert/Struct.hs +++ b/src/Convert/Struct.hs @@ -8,7 +8,6 @@ module Convert.Struct (convert) where import Control.Monad.State import Control.Monad.Writer -import Data.Hashable (hash) import Data.List (elemIndex, sortOn) import Data.Maybe (fromJust, isJust) import Data.Tuple (swap) @@ -207,10 +206,7 @@ packerFn structTf = -- returns a "unique" name for the packer for a given struct type packerFnName :: TypeFunc -> Identifier packerFnName structTf = - "sv2v_pack_struct_" ++ str - where - val = hash $ show structTf - str = tail $ show val + "sv2v_struct_" ++ shortHash structTf -- This is where the magic happens. This is responsible for converting struct -- accesses, assignments, and literals, given appropriate information about the diff --git a/src/Language/SystemVerilog/AST.hs b/src/Language/SystemVerilog/AST.hs index 46864f3..ee22105 100644 --- a/src/Language/SystemVerilog/AST.hs +++ b/src/Language/SystemVerilog/AST.hs @@ -27,8 +27,12 @@ module Language.SystemVerilog.AST , module Type , exprToLHS , lhsToExpr + , shortHash ) where +import Text.Printf (printf) +import Data.Hashable (hash) + import Language.SystemVerilog.AST.Attr as Attr import Language.SystemVerilog.AST.Decl as Decl import Language.SystemVerilog.AST.Description as Description @@ -68,3 +72,8 @@ 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 + +shortHash :: (Show a) => a -> String +shortHash x = + take 5 $ printf "%05X" val + where val = hash $ show x