Commit 8f7968bf by Zachary Snow

support data declarations with automatic lifetime (closes #20)

parent 243f7736
...@@ -427,6 +427,7 @@ DeclOrStmtToken :: { DeclToken } ...@@ -427,6 +427,7 @@ DeclOrStmtToken :: { DeclToken }
| PartialType { DTType $1 } | PartialType { DTType $1 }
| "." Identifier { DTDot $2 } | "." Identifier { DTDot $2 }
| Signing { DTSigning $1 } | Signing { DTSigning $1 }
| Lifetime { DTLifetime $1 }
| Identifier "::" Identifier { DTPSIdent $1 $3 } | Identifier "::" Identifier { DTPSIdent $1 $3 }
VariablePortIdentifiers :: { [(Identifier, Maybe Expr)] } VariablePortIdentifiers :: { [(Identifier, Maybe Expr)] }
......
...@@ -22,11 +22,10 @@ ...@@ -22,11 +22,10 @@
- increasingly convoluted grammars, this became more and more untenable as I - increasingly convoluted grammars, this became more and more untenable as I
- added support for more SystemVerilog constructs. - added support for more SystemVerilog constructs.
- -
- Because of how liberal this parser is, the parser will accept some - This parser is very liberal, and so accepts some syntactically invalid files.
- syntactically invalid files. In the future, we may add some basic - In the future, we may add some basic type-checking to complain about
- type-checking to complain about malformed input files. However, we generally - malformed input files. However, we generally assume that users have tested
- assume that users have tested their code with commercial simulator before - their code with a commercial simulator before running it through our tool.
- running it through our tool.
-} -}
module Language.SystemVerilog.Parser.ParseDecl module Language.SystemVerilog.Parser.ParseDecl
...@@ -60,6 +59,7 @@ data DeclToken ...@@ -60,6 +59,7 @@ data DeclToken
| DTConcat [LHS] | DTConcat [LHS]
| DTDot Identifier | DTDot Identifier
| DTSigning Signing | DTSigning Signing
| DTLifetime Lifetime
deriving (Show, Eq) deriving (Show, Eq)
...@@ -263,12 +263,15 @@ parseDTsAsComponents tokens = ...@@ -263,12 +263,15 @@ parseDTsAsComponents tokens =
parseDTsAsComponent :: [DeclToken] -> (Component, [DeclToken]) parseDTsAsComponent :: [DeclToken] -> (Component, [DeclToken])
parseDTsAsComponent [] = error "parseDTsAsComponent unexpected end of tokens" parseDTsAsComponent [] = error "parseDTsAsComponent unexpected end of tokens"
parseDTsAsComponent l0 = parseDTsAsComponent l0 =
(component, l4) if l /= Nothing && l /= Just Automatic
then error $ "unexpected non-automatic lifetime: " ++ show l0
else (component, l5)
where where
(dir, l1) = takeDir l0 (dir, l1) = takeDir l0
(tf , l2) = takeType l1 (l , l2) = takeLifetime l1
(rs , l3) = takeRanges l2 (tf , l3) = takeType l2
(tps, l4) = takeTrips l3 True (rs , l4) = takeRanges l3
(tps, l5) = takeTrips l4 True
component = (dir, tf rs, tps) component = (dir, tf rs, tps)
...@@ -312,6 +315,10 @@ takeDir :: [DeclToken] -> (Direction, [DeclToken]) ...@@ -312,6 +315,10 @@ takeDir :: [DeclToken] -> (Direction, [DeclToken])
takeDir (DTDir dir : rest) = (dir , rest) takeDir (DTDir dir : rest) = (dir , rest)
takeDir rest = (Local, rest) takeDir rest = (Local, rest)
takeLifetime :: [DeclToken] -> (Maybe Lifetime, [DeclToken])
takeLifetime (DTLifetime l : rest) = (Just l, rest)
takeLifetime rest = (Nothing, rest)
takeType :: [DeclToken] -> ([Range] -> Type, [DeclToken]) takeType :: [DeclToken] -> ([Range] -> Type, [DeclToken])
takeType (DTIdent a : DTDot b : rest) = (InterfaceT a (Just b), rest) takeType (DTIdent a : DTDot b : rest) = (InterfaceT a (Just b), rest)
takeType (DTType tf : DTSigning sg : rest) = (tf sg , rest) takeType (DTType tf : DTSigning sg : rest) = (tf sg , rest)
......
module top;
function automatic logic [31:0] lcg(input logic [31:0] x);
automatic logic [3:0] temp;
lcg = x;
for (temp = 0; temp < 3; temp++) begin
lcg *= 1664525;
lcg += 1013904223;
end
endfunction
initial $display(lcg(0));
initial $display(lcg(1));
initial $display(lcg(2));
initial $display(lcg(3));
initial $display(lcg(4));
initial $display(lcg(5));
endmodule
module top;
function automatic [31:0] lcg(input [31:0] x);
begin : foo
reg [3:0] temp;
lcg = x;
for (temp = 0; temp < 3; temp++) begin
lcg *= 1664525;
lcg += 1013904223;
end
end
endfunction
initial $display(lcg(0));
initial $display(lcg(1));
initial $display(lcg(2));
initial $display(lcg(3));
initial $display(lcg(4));
initial $display(lcg(5));
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