Commit 80d75d2a by Zachary Snow

confine genvar local typing to loops

parent f84dd701
...@@ -46,6 +46,8 @@ module Convert.Scoper ...@@ -46,6 +46,8 @@ module Convert.Scoper
, embedScopes , embedScopes
, withinProcedure , withinProcedure
, withinProcedureM , withinProcedureM
, isLoopVar
, isLoopVarM
, lookupLocalIdent , lookupLocalIdent
, lookupLocalIdentM , lookupLocalIdentM
, scopeModuleItemT , scopeModuleItemT
...@@ -296,6 +298,13 @@ withinProcedureM = gets sProcedure ...@@ -296,6 +298,13 @@ withinProcedureM = gets sProcedure
withinProcedure :: Scopes a -> Bool withinProcedure :: Scopes a -> Bool
withinProcedure = sProcedure withinProcedure = sProcedure
isLoopVar :: Scopes a -> Identifier -> Bool
isLoopVar scopes x = any matches $ sCurrent scopes
where matches = (== x) . tierIndex
isLoopVarM :: Monad m => Identifier -> ScoperT a m Bool
isLoopVarM = embedScopes isLoopVar
evalScoper evalScoper
:: MapperM (Scoper a) Decl :: MapperM (Scoper a) Decl
-> MapperM (Scoper a) ModuleItem -> MapperM (Scoper a) ModuleItem
......
...@@ -37,7 +37,7 @@ convert = map $ traverseDescriptions $ partScoper ...@@ -37,7 +37,7 @@ convert = map $ traverseDescriptions $ partScoper
pattern UnitType :: Type pattern UnitType :: Type
pattern UnitType = IntegerVector TLogic Unspecified [] pattern UnitType = IntegerVector TLogic Unspecified []
type ST = Scoper (Type, Bool) type ST = Scoper Type
-- insert the given declaration into the scope, and convert an TypeOfs within -- insert the given declaration into the scope, and convert an TypeOfs within
traverseDeclM :: Decl -> ST Decl traverseDeclM :: Decl -> ST Decl
...@@ -72,7 +72,7 @@ traverseDeclM decl = do ...@@ -72,7 +72,7 @@ traverseDeclM decl = do
insertType :: Identifier -> Type -> ST () insertType :: Identifier -> Type -> ST ()
insertType ident typ = do insertType ident typ = do
typ' <- scopeType typ typ' <- scopeType typ
insertElem ident (typ', False) insertElem ident typ'
-- rewrite an expression so that any identifiers it contains unambiguously refer -- rewrite an expression so that any identifiers it contains unambiguously refer
-- refer to currently visible declarations so it can be substituted elsewhere -- refer to currently visible declarations so it can be substituted elsewhere
...@@ -82,18 +82,15 @@ scopeExpr expr = do ...@@ -82,18 +82,15 @@ scopeExpr expr = do
>>= traverseExprTypesM scopeType >>= traverseExprTypesM scopeType
details <- lookupElemM expr' details <- lookupElemM expr'
case details of case details of
Just (accesses, _, (_, False)) -> return $ accessesToExpr accesses Just (accesses, _, _) -> return $ accessesToExpr accesses
_ -> return expr' _ -> return expr'
scopeType :: Type -> ST Type scopeType :: Type -> ST Type
scopeType = traverseNestedTypesM $ traverseTypeExprsM scopeExpr scopeType = traverseNestedTypesM $ traverseTypeExprsM scopeExpr
-- convert TypeOf in a ModuleItem -- convert TypeOf in a ModuleItem
traverseModuleItemM :: ModuleItem -> ST ModuleItem traverseModuleItemM :: ModuleItem -> ST ModuleItem
traverseModuleItemM (Genvar x) = traverseModuleItemM =
insertElem x (t, True) >> return (Genvar x) traverseNodesM traverseExprM return traverseTypeM traverseLHSM return
where t = IntegerAtom TInteger Unspecified
traverseModuleItemM item =
traverseNodesM traverseExprM return traverseTypeM traverseLHSM return item
where traverseLHSM = traverseLHSExprsM traverseExprM where traverseLHSM = traverseLHSExprsM traverseExprM
-- convert TypeOf in a GenItem -- convert TypeOf in a GenItem
...@@ -130,7 +127,8 @@ traverseExprM (Cast (Left t1) expr) = do ...@@ -130,7 +127,8 @@ traverseExprM (Cast (Left t1) expr) = do
traverseExprM (Cast (Right (Ident x)) expr) = do traverseExprM (Cast (Right (Ident x)) expr) = do
expr' <- traverseExprM expr expr' <- traverseExprM expr
details <- lookupElemM x details <- lookupElemM x
if details == Nothing isGenvar <- isLoopVarM x
if details == Nothing && not isGenvar
then return $ Cast (Left $ Alias x []) expr' then return $ Cast (Left $ Alias x []) expr'
else elaborateSizeCast (Ident x) expr' else elaborateSizeCast (Ident x) expr'
traverseExprM (Cast (Right size) expr) = do traverseExprM (Cast (Right size) expr) = do
...@@ -163,8 +161,14 @@ lookupTypeOf :: Expr -> ST Type ...@@ -163,8 +161,14 @@ lookupTypeOf :: Expr -> ST Type
lookupTypeOf expr = do lookupTypeOf expr = do
details <- lookupElemM expr details <- lookupElemM expr
case details of case details of
Nothing -> return $ TypeOf expr Nothing -> case expr of
Just (_, replacements, (typ, _)) -> do Ident x -> do
isGenvar <- isLoopVarM x
return $ if isGenvar
then IntegerAtom TInteger Unspecified
else TypeOf expr
_ -> return $ TypeOf expr
Just (_, replacements, typ) -> do
let typ' = toVarType typ let typ' = toVarType typ
return $ replaceInType replacements typ' return $ replaceInType replacements typ'
where where
......
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