mirror of https://github.com/zachjs/sv2v.git
allow genvars to be shadowed
This commit is contained in:
parent
e0d425d976
commit
1aa30ea813
|
|
@ -18,7 +18,7 @@ traverseDescription = partScoper return traverseModuleItemM return return
|
|||
|
||||
traverseModuleItemM :: ModuleItem -> Scoper () ModuleItem
|
||||
traverseModuleItemM (Genvar x) = do
|
||||
details <- lookupElemM x
|
||||
details <- lookupLocalIdentM x
|
||||
if details == Nothing
|
||||
then insertElem x () >> return (Genvar x)
|
||||
else return $ Generate []
|
||||
|
|
|
|||
|
|
@ -56,6 +56,8 @@ module Convert.Scoper
|
|||
, procedureLocM
|
||||
, isLoopVar
|
||||
, isLoopVarM
|
||||
, loopVarDepth
|
||||
, loopVarDepthM
|
||||
, lookupLocalIdent
|
||||
, lookupLocalIdentM
|
||||
, scopeModuleItemT
|
||||
|
|
@ -65,7 +67,7 @@ module Convert.Scoper
|
|||
|
||||
import Control.Monad.State.Strict
|
||||
import Data.Functor.Identity (runIdentity)
|
||||
import Data.List (partition)
|
||||
import Data.List (findIndices, partition)
|
||||
import Data.Maybe (isNothing)
|
||||
import qualified Data.Map.Strict as Map
|
||||
|
||||
|
|
@ -357,6 +359,16 @@ isLoopVar scopes x = any matches $ sCurrent scopes
|
|||
isLoopVarM :: Monad m => Identifier -> ScoperT a m Bool
|
||||
isLoopVarM = embedScopes isLoopVar
|
||||
|
||||
loopVarDepth :: Scopes a -> Identifier -> Maybe Int
|
||||
loopVarDepth scopes x =
|
||||
case findIndices matches $ sCurrent scopes of
|
||||
[] -> Nothing
|
||||
indices -> Just $ last indices
|
||||
where matches = (== x) . tierIndex
|
||||
|
||||
loopVarDepthM :: Monad m => Identifier -> ScoperT a m (Maybe Int)
|
||||
loopVarDepthM = embedScopes loopVarDepth
|
||||
|
||||
evalScoper
|
||||
:: MapperM (Scoper a) Decl
|
||||
-> MapperM (Scoper a) ModuleItem
|
||||
|
|
|
|||
|
|
@ -157,18 +157,24 @@ traverseTypeM other =
|
|||
-- attempts to find the given (potentially hierarchical or generate-scoped)
|
||||
-- expression in the available scope information
|
||||
lookupTypeOf :: Expr -> ST Type
|
||||
lookupTypeOf expr@(Ident x) = do
|
||||
details <- lookupElemM x
|
||||
loopVar <- loopVarDepthM x
|
||||
return $ case details of
|
||||
Nothing ->
|
||||
if loopVar == Nothing
|
||||
then TypeOf expr
|
||||
else IntegerAtom TInteger Unspecified
|
||||
Just (accesses, replacements, typ) ->
|
||||
if maybe True (length accesses >) loopVar
|
||||
then replaceInType replacements typ
|
||||
else IntegerAtom TInteger Unspecified
|
||||
lookupTypeOf expr = do
|
||||
details <- lookupElemM expr
|
||||
case details of
|
||||
Nothing -> case expr of
|
||||
Ident x -> do
|
||||
isGenvar <- isLoopVarM x
|
||||
return $ if isGenvar
|
||||
then IntegerAtom TInteger Unspecified
|
||||
else TypeOf expr
|
||||
_ -> return $ TypeOf expr
|
||||
return $ case details of
|
||||
Nothing -> TypeOf expr
|
||||
Just (_, replacements, typ) ->
|
||||
return $ replaceInType replacements typ
|
||||
replaceInType replacements typ
|
||||
|
||||
-- determines the type of an expression based on the available scope information
|
||||
-- according the semantics defined in IEEE 1800-2017, especially Section 11.6
|
||||
|
|
|
|||
|
|
@ -0,0 +1,26 @@
|
|||
`define DUMP(L) initial $display(`"L %0d`", $bits(i));
|
||||
module top;
|
||||
genvar i;
|
||||
for (i = 0; i < 1; i = 1) begin
|
||||
`DUMP(A)
|
||||
if (1) begin
|
||||
localparam [9:0] i = 1;
|
||||
`DUMP(B)
|
||||
if (1) begin
|
||||
genvar i;
|
||||
for (i = 0; i < 1; i = 1) begin
|
||||
`DUMP(C)
|
||||
if (1) begin
|
||||
localparam [5:0] i = 1;
|
||||
`DUMP(D)
|
||||
if (1) begin
|
||||
genvar i;
|
||||
for (i = 0; i < 1; i = 1)
|
||||
`DUMP(E)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
endmodule
|
||||
|
|
@ -0,0 +1,9 @@
|
|||
module top;
|
||||
initial begin
|
||||
$display("A %0d", 32);
|
||||
$display("B %0d", 10);
|
||||
$display("C %0d", 32);
|
||||
$display("D %0d", 6);
|
||||
$display("E %0d", 32);
|
||||
end
|
||||
endmodule
|
||||
Loading…
Reference in New Issue