diff --git a/src/Convert/SizeCast.hs b/src/Convert/SizeCast.hs index b5566de..a4457df 100644 --- a/src/Convert/SizeCast.hs +++ b/src/Convert/SizeCast.hs @@ -73,7 +73,7 @@ traverseExprM = castFn :: Expr -> Signing -> Description castFn e sg = PackageItem $ - Function (Just Automatic) t fnName [decl] [Return $ Ident inp] + Function Automatic t fnName [decl] [Return $ Ident inp] where inp = "inp" r = (simplify $ BinOp Sub e (Number "1"), Number "0") diff --git a/src/Convert/Struct.hs b/src/Convert/Struct.hs index 08bba5f..661d76d 100644 --- a/src/Convert/Struct.hs +++ b/src/Convert/Struct.hs @@ -211,7 +211,7 @@ traverseDeclM structs origDecl = do packerFn :: TypeFunc -> ModuleItem packerFn structTf = MIPackageItem $ - Function Nothing (structTf []) fnName decls [retStmt] + Function Automatic (structTf []) fnName decls [retStmt] where Struct _ fields [] = structTf [] toInput (t, x) = Variable Input t x [] Nothing diff --git a/src/Convert/Traverse.hs b/src/Convert/Traverse.hs index f348570..b6d0235 100644 --- a/src/Convert/Traverse.hs +++ b/src/Convert/Traverse.hs @@ -153,9 +153,9 @@ traverseModuleItemsM mapper (Part attrs extern kw lifetime name ports items) = d traverseModuleItemsM mapper (PackageItem packageItem) = do let item = MIPackageItem packageItem converted <- - traverseModuleItemsM mapper (Part [] False Module Nothing "DNE" [] [item]) + traverseModuleItemsM mapper (Part [] False Module Inherit "DNE" [] [item]) let item' = case converted of - Part [] False Module Nothing "DNE" [] [newItem] -> newItem + Part [] False Module Inherit "DNE" [] [newItem] -> newItem _ -> error $ "redirected PackageItem traverse failed: " ++ show converted return $ case item' of @@ -164,9 +164,9 @@ traverseModuleItemsM mapper (PackageItem packageItem) = do traverseModuleItemsM mapper (Package lifetime name packageItems) = do let items = map MIPackageItem packageItems converted <- - traverseModuleItemsM mapper (Part [] False Module Nothing "DNE" [] items) + traverseModuleItemsM mapper (Part [] False Module Inherit "DNE" [] items) let items' = case converted of - Part [] False Module Nothing "DNE" [] newItems -> newItems + Part [] False Module Inherit "DNE" [] newItems -> newItems _ -> error $ "redirected Package traverse failed: " ++ show converted return $ Package lifetime name $ map (\(MIPackageItem item) -> item) items' @@ -1017,9 +1017,9 @@ collectStmtAsgnsM = collectify traverseStmtAsgnsM traverseNestedModuleItemsM :: Monad m => MapperM m ModuleItem -> MapperM m ModuleItem traverseNestedModuleItemsM mapper item = do converted <- - traverseModuleItemsM mapper (Part [] False Module Nothing "DNE" [] [item]) + traverseModuleItemsM mapper (Part [] False Module Inherit "DNE" [] [item]) let items' = case converted of - Part [] False Module Nothing "DNE" [] newItems -> newItems + Part [] False Module Inherit "DNE" [] newItems -> newItems _ -> error $ "redirected NestedModuleItems traverse failed: " ++ show converted return $ case items' of diff --git a/src/Language/SystemVerilog/AST/Description.hs b/src/Language/SystemVerilog/AST/Description.hs index e0d4458..2ce162b 100644 --- a/src/Language/SystemVerilog/AST/Description.hs +++ b/src/Language/SystemVerilog/AST/Description.hs @@ -25,9 +25,9 @@ import Language.SystemVerilog.AST.Type (Type, Identifier) import {-# SOURCE #-} Language.SystemVerilog.AST.ModuleItem (ModuleItem) data Description - = Part [Attr] Bool PartKW (Maybe Lifetime) Identifier [Identifier] [ModuleItem] + = Part [Attr] Bool PartKW Lifetime Identifier [Identifier] [ModuleItem] | PackageItem PackageItem - | Package (Maybe Lifetime) Identifier [PackageItem] + | Package Lifetime Identifier [PackageItem] deriving Eq instance Show Description where @@ -35,12 +35,12 @@ instance Show Description where show (Part attrs True kw lifetime name _ items) = printf "%sextern %s %s%s %s;" (concatMap showPad attrs) - (show kw) (showLifetime lifetime) name (indentedParenList itemStrs) + (show kw) (showPad lifetime) name (indentedParenList itemStrs) where itemStrs = map (init . show) items show (Part attrs False kw lifetime name ports items) = printf "%s%s %s%s%s;\n%s\nend%s" (concatMap showPad attrs) - (show kw) (showLifetime lifetime) name portsStr bodyStr (show kw) + (show kw) (showPad lifetime) name portsStr bodyStr (show kw) where portsStr = if null ports then "" @@ -48,15 +48,15 @@ instance Show Description where bodyStr = indent $ unlines' $ map show items show (Package lifetime name items) = printf "package %s%s;\n%s\nendpackage" - (showLifetime lifetime) name bodyStr + (showPad lifetime) name bodyStr where bodyStr = indent $ unlines' $ map show items show (PackageItem i) = show i data PackageItem = Typedef Type Identifier - | Function (Maybe Lifetime) Type Identifier [Decl] [Stmt] - | Task (Maybe Lifetime) Identifier [Decl] [Stmt] + | Function Lifetime Type Identifier [Decl] [Stmt] + | Task Lifetime Identifier [Decl] [Stmt] | Import Identifier (Maybe Identifier) | Export (Maybe (Identifier, Maybe Identifier)) | Decl Decl @@ -68,11 +68,11 @@ instance Show PackageItem where show (Typedef t x) = printf "typedef %s %s;" (show t) x show (Function ml t x i b) = printf "function %s%s%s;\n%s\n%s\nendfunction" - (showLifetime ml) (showPad t) x (indent $ show i) + (showPad ml) (showPad t) x (indent $ show i) (indent $ unlines' $ map show b) show (Task ml x i b) = printf "task %s%s;\n%s\n%s\nendtask" - (showLifetime ml) x (indent $ show i) + (showPad ml) x (indent $ show i) (indent $ unlines' $ map show b) show (Import x y) = printf "import %s::%s;" x (fromMaybe "*" y) show (Export Nothing) = "export *::*"; @@ -96,12 +96,10 @@ instance Show PartKW where data Lifetime = Static | Automatic + | Inherit deriving (Eq, Ord) instance Show Lifetime where show Static = "static" show Automatic = "automatic" - -showLifetime :: Maybe Lifetime -> String -showLifetime Nothing = "" -showLifetime (Just l) = show l ++ " " + show Inherit = "" diff --git a/src/Language/SystemVerilog/Parser/Parse.y b/src/Language/SystemVerilog/Parser/Parse.y index b50e0cd..f924e9b 100644 --- a/src/Language/SystemVerilog/Parser/Parse.y +++ b/src/Language/SystemVerilog/Parser/Parse.y @@ -513,7 +513,7 @@ Part(begin, end) :: { Description } | AttributeInstances "extern" begin PartHeader { $4 $1 True $3 [] } PartHeader :: { [Attr] -> Bool -> PartKW -> [ModuleItem] -> Description } - : opt(Lifetime) Identifier PackageImportDeclarations Params PortDecls ";" { \attrs extern kw items -> Part attrs extern kw $1 $2 (fst $5) ($3 ++ $4 ++ (snd $5) ++ items) } + : Lifetime Identifier PackageImportDeclarations Params PortDecls ";" { \attrs extern kw items -> Part attrs extern kw $1 $2 (fst $5) ($3 ++ $4 ++ (snd $5) ++ items) } ModuleKW :: { PartKW } : "module" { Module } @@ -521,7 +521,7 @@ InterfaceKW :: { PartKW } : "interface" { Interface } PackageDeclaration :: { Description } - : "package" opt(Lifetime) Identifier ";" PackageItems "endpackage" opt(Tag) { Package $2 $3 $5 } + : "package" Lifetime Identifier ";" PackageItems "endpackage" opt(Tag) { Package $2 $3 $5 } Tag :: { Identifier } : ":" Identifier { $2 } @@ -613,7 +613,7 @@ DeclOrStmtToken :: { DeclToken } | "." Identifier { DTDot $2 } | PortBindings { DTInstance $1 } | Signing { DTSigning $1 } - | Lifetime { DTLifetime $1 } + | ExplicitLifetime { DTLifetime $1 } | Identifier "::" Identifier { DTPSIdent $1 $3 } | "const" PartialType { DTType $2 } | "{" StreamOp StreamSize Concat "}" { DTStream $2 $3 (map toLHS $4) } @@ -775,9 +775,9 @@ PackageItem :: { [PackageItem] } | NonDeclPackageItem { $1 } NonDeclPackageItem :: { [PackageItem] } : "typedef" Type Identifier ";" { [Typedef $2 $3] } - | "function" opt(Lifetime) FuncRetAndName TFItems DeclsAndStmts "endfunction" opt(Tag) { [Function $2 (fst $3) (snd $3) (map defaultFuncInput $ (map makeInput $4) ++ fst $5) (snd $5)] } - | "function" opt(Lifetime) "void" Identifier TFItems DeclsAndStmts "endfunction" opt(Tag) { [Task $2 $4 (map defaultFuncInput $ $5 ++ fst $6) (snd $6)] } - | "task" opt(Lifetime) Identifier TFItems DeclsAndStmts "endtask" opt(Tag) { [Task $2 $3 (map defaultFuncInput $ $4 ++ fst $5) (snd $5)] } + | "function" Lifetime FuncRetAndName TFItems DeclsAndStmts "endfunction" opt(Tag) { [Function $2 (fst $3) (snd $3) (map defaultFuncInput $ (map makeInput $4) ++ fst $5) (snd $5)] } + | "function" Lifetime "void" Identifier TFItems DeclsAndStmts "endfunction" opt(Tag) { [Task $2 $4 (map defaultFuncInput $ $5 ++ fst $6) (snd $6)] } + | "task" Lifetime Identifier TFItems DeclsAndStmts "endtask" opt(Tag) { [Task $2 $3 (map defaultFuncInput $ $4 ++ fst $5) (snd $5)] } | "import" PackageImportItems ";" { map (uncurry Import) $2 } | "export" PackageImportItems ";" { map (Export . Just) $2 } | "export" "*" "::" "*" ";" { [Export Nothing] } -- "Nothing" being no restrictions @@ -818,6 +818,9 @@ AlwaysKW :: { AlwaysKW } | "always_latch" { AlwaysLatch } Lifetime :: { Lifetime } + : {- empty -} { Inherit } + | ExplicitLifetime { $1 } +ExplicitLifetime :: { Lifetime } : "static" { Static } | "automatic" { Automatic }