fix some silly edge cases in round-tripping output

This commit is contained in:
Zachary Snow 2019-02-22 13:55:48 -05:00
parent 546657d2c3
commit f895f4f045
2 changed files with 11 additions and 8 deletions

View File

@ -82,7 +82,7 @@ instance Show Type where
show (Reg r) = "reg" ++ (showRanges r)
show (Wire r) = "wire" ++ (showRanges r)
show (Logic r) = "logic" ++ (showRanges r)
show (Alias t r) = t ++ " " ++ (showRanges r)
show (Alias t r) = t ++ (showRanges r)
data ModuleItem
= Comment String
@ -173,8 +173,9 @@ showAssignment Nothing = ""
showAssignment (Just val) = " = " ++ show val
showRanges :: [Range] -> String
showRanges = concat . (map rangeToString)
where rangeToString d = (showRange $ Just d) ++ "\b"
showRanges [] = ""
showRanges l = " " ++ (concat $ map rangeToString l)
where rangeToString d = init $ showRange $ Just d
showRange :: Maybe Range -> String
showRange Nothing = ""

View File

@ -219,6 +219,7 @@ PortDeclsFollow :: { [ModuleItem] }
PortDecl(delim) :: { [ModuleItem] }
: "inout" opt(NetType) Dimensions Identifiers delim { portDeclToModuleItems Inout $2 $3 (zip $4 (repeat Nothing)) }
| "input" opt(NetType) Dimensions Identifiers delim { portDeclToModuleItems Input $2 $3 (zip $4 (repeat Nothing)) }
| "output" Dimensions Identifiers delim { portDeclToModuleItems Output Nothing $2 (zip $3 (repeat Nothing)) }
| "output" "wire" Dimensions Identifiers delim { portDeclToModuleItems Output (Just Wire ) $3 (zip $4 (repeat Nothing)) }
| "output" "reg" Dimensions VariablePortIdentifiers delim { portDeclToModuleItems Output (Just Reg ) $3 $4 }
| "output" "logic" Dimensions VariablePortIdentifiers delim { portDeclToModuleItems Output (Just Logic) $3 $4 }
@ -300,6 +301,7 @@ RangeOrType :: { Either Range () }
EventControl :: { Sense }
: "@" "(" Sense ")" { $3 }
| "@" "(" "*" ")" { SenseStar }
| "@" "(*)" { SenseStar }
| "@" "*" { SenseStar }
| "@*" { SenseStar }