Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Generate region standard compliance fixes #239

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions src/Language/SystemVerilog/AST/GenItem.hs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import Language.SystemVerilog.AST.ShowHelp
import Language.SystemVerilog.AST.Expr (Expr)
import Language.SystemVerilog.AST.Op (AsgnOp)
import Language.SystemVerilog.AST.Type (Identifier)
import {-# SOURCE #-} Language.SystemVerilog.AST.ModuleItem (ModuleItem)
import {-# SOURCE #-} Language.SystemVerilog.AST.ModuleItem (ModuleItem, showGenModuleItem)

data GenItem
= GenBlock Identifier [GenItem]
Expand All @@ -36,21 +36,23 @@ instance Show GenItem where
printf "case (%s)\n%s\nendcase" (show e) bodyStr
where bodyStr = indent $ unlines' $ map showGenCase cs
show (GenIf e a GenNull) = printf "if (%s) %s" (show e) (showBareBlock a)
-- showBlockedBranch avoids dangling else ambiguity
show (GenIf e a b ) = printf "if (%s) %s\nelse %s" (show e) (showBlockedBranch a) (showBareBlock b)
show (GenFor (x1, e1) c (x2, o2, e2) s) =
printf "for (%s = %s; %s; %s %s %s) %s"
x1 (show e1)
(show c)
x2 (show o2) (show e2)
(showBareBlock s)
show (GenNull) = ";"
show (GenModuleItem item) = show item
(showBlockedBranch s) -- Verilog 2001 requires this to be a block
show (GenNull) = ""
show (GenModuleItem item) = showGenModuleItem item

showBareBlock :: GenItem -> String
showBareBlock (GenBlock x i) =
printf "begin%s\n%s\nend"
(if null x then "" else " : " ++ x)
(indent $ show i)
showBareBlock (GenNull) = ";"
showBareBlock item = show item

showBlockedBranch :: GenItem -> String
Expand Down
5 changes: 5 additions & 0 deletions src/Language/SystemVerilog/AST/ModuleItem.hs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ module Language.SystemVerilog.AST.ModuleItem
, AssignOption (..)
, Severity (..)
, AssertionItem (..)
, showGenModuleItem
) where

import Data.List (intercalate)
Expand Down Expand Up @@ -96,6 +97,10 @@ showModportDecl (dir, ident, e) =
then printf "%s %s" (show dir) ident
else printf "%s .%s(%s)" (show dir) ident (show e)

showGenModuleItem :: ModuleItem -> String
showGenModuleItem (Generate genItems) = show genItems
showGenModuleItem item = show item

type PortBinding = (Identifier, Expr)

type ModportDecl = (Direction, Identifier, Expr)
Expand Down
3 changes: 3 additions & 0 deletions src/Language/SystemVerilog/AST/ModuleItem.hs-boot
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
module Language.SystemVerilog.AST.ModuleItem
( ModuleItem
, showGenModuleItem
) where

data ModuleItem
instance Eq ModuleItem
instance Show ModuleItem

showGenModuleItem :: ModuleItem -> String
8 changes: 5 additions & 3 deletions src/Language/SystemVerilog/Parser/Parse.y
Original file line number Diff line number Diff line change
Expand Up @@ -699,7 +699,11 @@ ModuleItem :: { [ModuleItem] }
: NonGenerateModuleItem { $1 }
| ConditionalGenerateConstruct { [Generate [$1]] }
| LoopGenerateConstruct { [Generate [$1]] }
| AttributeInstance ModuleItem { map (addMIAttr $1) $2 }
| "generate" GenItems endgenerate { [Generate $2] }
NonGenerateModuleItemA :: { [ModuleItem] }
: NonGenerateModuleItem { $1 }
| AttributeInstance NonGenerateModuleItemA { map (addMIAttr $1) $2 }
NonGenerateModuleItem :: { [ModuleItem] }
-- This item covers module instantiations and all declarations
: ModuleDeclTokens(";") {% mapM recordPartUsed $ parseDTsAsModuleItems $1 }
Expand All @@ -715,7 +719,6 @@ NonGenerateModuleItem :: { [ModuleItem] }
| TaskOrFunction { [MIPackageItem $1] }
| NInputGateKW NInputGates ";" { map (\(a, b, c, d) -> NInputGate $1 a b c d) $2 }
| NOutputGateKW NOutputGates ";" { map (\(a, b, c, d) -> NOutputGate $1 a b c d) $2 }
| AttributeInstance ModuleItem { map (addMIAttr $1) $2 }
| AssertionItem { [AssertionItem $1] }

AssignOption :: { AssignOption }
Expand Down Expand Up @@ -1449,8 +1452,7 @@ GenItems :: { [GenItem] }

GenItem :: { GenItem }
: MITrace GenBlock { uncurry GenBlock $2 }
| MITrace NonGenerateModuleItem { genItemsToGenItem $ map GenModuleItem $ addMITrace $1 $2 }
| MITrace "generate" GenItems "endgenerate" { genItemsToGenItem $3 }
| MITrace NonGenerateModuleItemA { genItemsToGenItem $ map GenModuleItem $ addMITrace $1 $2 }
| MITrace ConditionalGenerateConstruct { $2 }
| MITrace LoopGenerateConstruct { $2 }
ConditionalGenerateConstruct :: { GenItem }
Expand Down