Commit 1aa30ea8 by Zachary Snow

allow genvars to be shadowed

parent e0d425d9
...@@ -18,7 +18,7 @@ traverseDescription = partScoper return traverseModuleItemM return return ...@@ -18,7 +18,7 @@ traverseDescription = partScoper return traverseModuleItemM return return
traverseModuleItemM :: ModuleItem -> Scoper () ModuleItem traverseModuleItemM :: ModuleItem -> Scoper () ModuleItem
traverseModuleItemM (Genvar x) = do traverseModuleItemM (Genvar x) = do
details <- lookupElemM x details <- lookupLocalIdentM x
if details == Nothing if details == Nothing
then insertElem x () >> return (Genvar x) then insertElem x () >> return (Genvar x)
else return $ Generate [] else return $ Generate []
......
...@@ -56,6 +56,8 @@ module Convert.Scoper ...@@ -56,6 +56,8 @@ module Convert.Scoper
, procedureLocM , procedureLocM
, isLoopVar , isLoopVar
, isLoopVarM , isLoopVarM
, loopVarDepth
, loopVarDepthM
, lookupLocalIdent , lookupLocalIdent
, lookupLocalIdentM , lookupLocalIdentM
, scopeModuleItemT , scopeModuleItemT
...@@ -65,7 +67,7 @@ module Convert.Scoper ...@@ -65,7 +67,7 @@ module Convert.Scoper
import Control.Monad.State.Strict import Control.Monad.State.Strict
import Data.Functor.Identity (runIdentity) import Data.Functor.Identity (runIdentity)
import Data.List (partition) import Data.List (findIndices, partition)
import Data.Maybe (isNothing) import Data.Maybe (isNothing)
import qualified Data.Map.Strict as Map import qualified Data.Map.Strict as Map
...@@ -357,6 +359,16 @@ isLoopVar scopes x = any matches $ sCurrent scopes ...@@ -357,6 +359,16 @@ isLoopVar scopes x = any matches $ sCurrent scopes
isLoopVarM :: Monad m => Identifier -> ScoperT a m Bool isLoopVarM :: Monad m => Identifier -> ScoperT a m Bool
isLoopVarM = embedScopes isLoopVar 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 evalScoper
:: MapperM (Scoper a) Decl :: MapperM (Scoper a) Decl
-> MapperM (Scoper a) ModuleItem -> MapperM (Scoper a) ModuleItem
......
...@@ -157,18 +157,24 @@ traverseTypeM other = ...@@ -157,18 +157,24 @@ traverseTypeM other =
-- attempts to find the given (potentially hierarchical or generate-scoped) -- attempts to find the given (potentially hierarchical or generate-scoped)
-- expression in the available scope information -- expression in the available scope information
lookupTypeOf :: Expr -> ST Type 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 lookupTypeOf expr = do
details <- lookupElemM expr details <- lookupElemM expr
case details of return $ case details of
Nothing -> case expr of Nothing -> TypeOf expr
Ident x -> do
isGenvar <- isLoopVarM x
return $ if isGenvar
then IntegerAtom TInteger Unspecified
else TypeOf expr
_ -> return $ TypeOf expr
Just (_, replacements, typ) -> Just (_, replacements, typ) ->
return $ replaceInType replacements typ replaceInType replacements typ
-- determines the type of an expression based on the available scope information -- determines the type of an expression based on the available scope information
-- according the semantics defined in IEEE 1800-2017, especially Section 11.6 -- according the semantics defined in IEEE 1800-2017, especially Section 11.6
......
`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
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
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