Commit 7ccab1c7 by Zachary Snow

fix parsing of sized ports with implicit directions

parent 7325bd79
...@@ -17,6 +17,7 @@ ...@@ -17,6 +17,7 @@
* Support deferred immediate assertion statements * Support deferred immediate assertion statements
* Apply implicit port directions to tasks and functions * Apply implicit port directions to tasks and functions
* Support bare delay controls with real number delays * Support bare delay controls with real number delays
* Fix parsing of sized ports with implicit directions
## v0.0.8 ## v0.0.8
......
...@@ -96,8 +96,7 @@ parseDTsAsPortDecls' pieces = ...@@ -96,8 +96,7 @@ parseDTsAsPortDecls' pieces =
Just simpleIdents = maybeSimpleIdents Just simpleIdents = maybeSimpleIdents
isSimpleList = maybeSimpleIdents /= Nothing isSimpleList = maybeSimpleIdents /= Nothing
declarations = propagateDirections Input $ declarations = parseDTsAsDecls Input ModeDefault pieces'
parseDTsAsDecls ModeDefault pieces'
pieces' = filter (not . isAttr) pieces pieces' = filter (not . isAttr) pieces
...@@ -124,24 +123,6 @@ parseDTsAsPortDecls' pieces = ...@@ -124,24 +123,6 @@ parseDTsAsPortDecls' pieces =
wrapDecl :: [Attr] -> Decl -> ModuleItem wrapDecl :: [Attr] -> Decl -> ModuleItem
wrapDecl attrs decl = foldr MIAttr (MIPackageItem $ Decl decl) attrs wrapDecl attrs decl = foldr MIAttr (MIPackageItem $ Decl decl) attrs
-- internal utility for carying forward port directions in a port list
propagateDirections :: Direction -> [Decl] -> [Decl]
propagateDirections dir (decl@(Variable _ InterfaceT{} _ _ _) : decls) =
decl : propagateDirections dir decls
propagateDirections lastDir (Variable currDir t x a e : decls) =
decl : propagateDirections dir decls
where
decl = Variable dir t x a e
dir = if currDir == Local then lastDir else currDir
propagateDirections lastDir (Net currDir n s t x a e : decls) =
decl : propagateDirections dir decls
where
decl = Net dir n s t x a e
dir = if currDir == Local then lastDir else currDir
propagateDirections dir (decl : decls) =
decl : propagateDirections dir decls
propagateDirections _ [] = []
-- internal utility for a simple list of port identifiers -- internal utility for a simple list of port identifiers
parseDTsAsIdents :: [DeclToken] -> Maybe [Identifier] parseDTsAsIdents :: [DeclToken] -> Maybe [Identifier]
parseDTsAsIdents [DTIdent _ x, DTEnd _ _] = Just [x] parseDTsAsIdents [DTIdent _ x, DTEnd _ _] = Just [x]
...@@ -236,13 +217,13 @@ parseDTsAsIntantiation l0 delimTok = ...@@ -236,13 +217,13 @@ parseDTsAsIntantiation l0 delimTok =
-- [PUBLIC]: parser for comma-separated task/function port declarations -- [PUBLIC]: parser for comma-separated task/function port declarations
parseDTsAsTFDecls :: [DeclToken] -> [Decl] parseDTsAsTFDecls :: [DeclToken] -> [Decl]
parseDTsAsTFDecls = propagateDirections Input . parseDTsAsDecls ModeDefault parseDTsAsTFDecls = parseDTsAsDecls Input ModeDefault
-- [PUBLIC]; used for "single" declarations, i.e., declarations appearing -- [PUBLIC]; used for "single" declarations, i.e., declarations appearing
-- outside of a port list -- outside of a port list
parseDTsAsDecl :: [DeclToken] -> [Decl] parseDTsAsDecl :: [DeclToken] -> [Decl]
parseDTsAsDecl = parseDTsAsDecls ModeSingle parseDTsAsDecl = parseDTsAsDecls Local ModeSingle
-- [PUBLIC]: parser for single block item declarations or assign or arg-less -- [PUBLIC]: parser for single block item declarations or assign or arg-less
...@@ -259,7 +240,7 @@ declLookahead :: [DeclToken] -> Bool ...@@ -259,7 +240,7 @@ declLookahead :: [DeclToken] -> Bool
declLookahead l0 = declLookahead l0 =
length l0 /= length l6 && tripLookahead l6 length l0 /= length l6 && tripLookahead l6
where where
(_, l1) = takeDir l0 (_, l1) = takeDir l0 Local
(_, l2) = takeLifetime l1 (_, l2) = takeLifetime l1
(_, l3) = takeConst l2 (_, l3) = takeConst l2
(_, l4) = takeVarOrNet l3 (_, l4) = takeVarOrNet l3
...@@ -303,7 +284,7 @@ portsToArgs bindings = ...@@ -303,7 +284,7 @@ portsToArgs bindings =
parseDTsAsDeclsOrAsgns :: [DeclToken] -> Either [Decl] [(LHS, Expr)] parseDTsAsDeclsOrAsgns :: [DeclToken] -> Either [Decl] [(LHS, Expr)]
parseDTsAsDeclsOrAsgns tokens = parseDTsAsDeclsOrAsgns tokens =
if declLookahead tokens if declLookahead tokens
then Left $ parseDTsAsDecls ModeForLoop tokens then Left $ parseDTsAsDecls Local ModeForLoop tokens
else Right $ parseDTsAsAsgns $ shiftIncOrDec tokens else Right $ parseDTsAsAsgns $ shiftIncOrDec tokens
-- internal parser for basic assignment lists -- internal parser for basic assignment lists
...@@ -363,8 +344,8 @@ data Mode ...@@ -363,8 +344,8 @@ data Mode
deriving Eq deriving Eq
-- internal; entrypoint of the critical portion of our parser -- internal; entrypoint of the critical portion of our parser
parseDTsAsDecls :: Mode -> [DeclToken] -> [Decl] parseDTsAsDecls :: Direction -> Mode -> [DeclToken] -> [Decl]
parseDTsAsDecls mode l0 = parseDTsAsDecls backupDir mode l0 =
if l /= Nothing && l /= Just Automatic then if l /= Nothing && l /= Just Automatic then
parseError (head l1) "unexpected non-automatic lifetime" parseError (head l1) "unexpected non-automatic lifetime"
else if dir == Local && isImplicit t && not (isNet $ head l3) then else if dir == Local && isImplicit t && not (isNet $ head l3) then
...@@ -374,14 +355,14 @@ parseDTsAsDecls mode l0 = ...@@ -374,14 +355,14 @@ parseDTsAsDecls mode l0 =
else if mode == ModeSingle then else if mode == ModeSingle then
parseError (head l7) "unexpected token in declaration" parseError (head l7) "unexpected token in declaration"
else else
decls ++ parseDTsAsDecls mode l7 decls ++ parseDTsAsDecls dir mode l7
where where
initReason initReason
| hasDriveStrength (head l3) = "net with drive strength" | hasDriveStrength (head l3) = "net with drive strength"
| mode == ModeForLoop = "for loop" | mode == ModeForLoop = "for loop"
| con = "const" | con = "const"
| otherwise = "" | otherwise = ""
(dir, l1) = takeDir l0 (dir, l1) = takeDir l0 backupDir
(l , l2) = takeLifetime l1 (l , l2) = takeLifetime l1
(con, l3) = takeConst l2 (con, l3) = takeConst l2
(von, l4) = takeVarOrNet l3 (von, l4) = takeVarOrNet l3
...@@ -432,9 +413,9 @@ tripLookahead l0 = ...@@ -432,9 +413,9 @@ tripLookahead l0 =
(_, l2) = takeRanges l1 (_, l2) = takeRanges l1
(_, l3) = takeAsgn l2 "" (_, l3) = takeAsgn l2 ""
takeDir :: [DeclToken] -> (Direction, [DeclToken]) takeDir :: [DeclToken] -> Direction -> (Direction, [DeclToken])
takeDir (DTDir _ dir : rest) = (dir , rest) takeDir (DTDir _ dir : rest) _ = (dir, rest)
takeDir rest = (Local, rest) takeDir rest dir = (dir, rest)
takeLifetime :: [DeclToken] -> (Maybe Lifetime, [DeclToken]) takeLifetime :: [DeclToken] -> (Maybe Lifetime, [DeclToken])
takeLifetime (DTLifetime _ l : rest) = (Just l, rest) takeLifetime (DTLifetime _ l : rest) = (Just l, rest)
......
module top;
function automatic integer f(
input a, b, [1:0] c, d
);
f = {1'bx, a, 1'bx, b, 1'bx, c, 1'bx, d, 1'bx};
endfunction
integer x = f(0, 1, 2, 3);
initial $display("%b", x);
endmodule
module top;
function automatic integer f(
input a, b, input [1:0] c, d
);
f = {1'bx, a, 1'bx, b, 1'bx, c, 1'bx, d, 1'bx};
endfunction
integer x = f(0, 1, 2, 3);
initial $display("%b", x);
endmodule
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment