Commit b28a3cac by Zachary Snow

represent typedefs as localparam types

parent 378ede9e
...@@ -267,12 +267,6 @@ processItems topName packageName moduleItems = do ...@@ -267,12 +267,6 @@ processItems topName packageName moduleItems = do
++ intercalate ", " rootPkgs ++ intercalate ", " rootPkgs
traversePackageItemM :: PackageItem -> Scope PackageItem traversePackageItemM :: PackageItem -> Scope PackageItem
-- TODO: fold this in with type parameters
traversePackageItemM (Typedef t x) = do
t' <- traverseTypeM t
x' <- prefixIdent x
t'' <- traverseNestedTypesM (traverseTypeExprsM traverseExprM) t'
return $ Typedef t'' x'
traversePackageItemM (orig @ (Import pkg ident)) = do traversePackageItemM (orig @ (Import pkg ident)) = do
if null ident if null ident
then wildcardImports pkg then wildcardImports pkg
...@@ -516,6 +510,8 @@ traverseDeclIdentsM identMapper = ...@@ -516,6 +510,8 @@ traverseDeclIdentsM identMapper =
-- returns any names defined by a package item -- returns any names defined by a package item
piNames :: PackageItem -> [Identifier] piNames :: PackageItem -> [Identifier]
piNames (Decl (ParamType _ ident (Enum _ enumItems _))) =
ident : map fst enumItems
piNames (Function _ _ ident _ _) = [ident] piNames (Function _ _ ident _ _) = [ident]
piNames (Task _ ident _ _) = [ident] piNames (Task _ ident _ _) = [ident]
piNames (Decl (Variable _ _ ident _ _)) = [ident] piNames (Decl (Variable _ _ ident _ _)) = [ident]
...@@ -525,6 +521,3 @@ piNames (Decl (CommentDecl _)) = [] ...@@ -525,6 +521,3 @@ piNames (Decl (CommentDecl _)) = []
piNames (Import x y) = [show $ Import x y] piNames (Import x y) = [show $ Import x y]
piNames (Export x y) = [show $ Export x y] piNames (Export x y) = [show $ Export x y]
piNames (Directive _) = [] piNames (Directive _) = []
piNames (Typedef (Enum _ enumItems _) ident) =
ident : map fst enumItems
piNames (Typedef _ ident) = [ident]
...@@ -555,9 +555,6 @@ traverseNodesM exprMapper declMapper typeMapper lhsMapper stmtMapper = ...@@ -555,9 +555,6 @@ traverseNodesM exprMapper declMapper typeMapper lhsMapper stmtMapper =
moduleItemMapper (MIAttr attr mi) = moduleItemMapper (MIAttr attr mi) =
-- note: we exclude expressions in attributes from conversion -- note: we exclude expressions in attributes from conversion
return $ MIAttr attr mi return $ MIAttr attr mi
moduleItemMapper (MIPackageItem (Typedef t x)) = do
t' <- typeMapper t
return $ MIPackageItem $ Typedef t' x
moduleItemMapper (MIPackageItem (Decl decl)) = moduleItemMapper (MIPackageItem (Decl decl)) =
declMapper decl >>= return . MIPackageItem . Decl declMapper decl >>= return . MIPackageItem . Decl
moduleItemMapper (Defparam lhs expr) = do moduleItemMapper (Defparam lhs expr) = do
...@@ -951,8 +948,6 @@ traverseTypesM' strategy mapper = ...@@ -951,8 +948,6 @@ traverseTypesM' strategy mapper =
where where
exprMapper = traverseExprTypesM mapper exprMapper = traverseExprTypesM mapper
declMapper = traverseDeclTypesM mapper declMapper = traverseDeclTypesM mapper
miMapper (MIPackageItem (Typedef t x)) =
mapper t >>= \t' -> return $ MIPackageItem $ Typedef t' x
miMapper (MIPackageItem (Function l t x d s)) = miMapper (MIPackageItem (Function l t x d s)) =
mapper t >>= \t' -> return $ MIPackageItem $ Function l t' x d s mapper t >>= \t' -> return $ MIPackageItem $ Function l t' x d s
miMapper (MIPackageItem (other @ (Task _ _ _ _))) = miMapper (MIPackageItem (other @ (Task _ _ _ _))) =
......
...@@ -45,10 +45,6 @@ traverseExprM (DimFn f v e) = do ...@@ -45,10 +45,6 @@ traverseExprM (DimFn f v e) = do
traverseExprM other = return other traverseExprM other = return other
traverseModuleItemM :: ModuleItem -> Scoper Type ModuleItem traverseModuleItemM :: ModuleItem -> Scoper Type ModuleItem
traverseModuleItemM (MIPackageItem (Typedef t x)) = do
t' <- traverseNestedTypesM traverseTypeM t
insertElem x t'
return $ Generate []
traverseModuleItemM (Instance m params x rs p) = do traverseModuleItemM (Instance m params x rs p) = do
let mapParam (i, v) = traverseTypeOrExprM v >>= \v' -> return (i, v') let mapParam (i, v) = traverseTypeOrExprM v >>= \v' -> return (i, v')
params' <- mapM mapParam params params' <- mapM mapParam params
......
...@@ -52,8 +52,7 @@ instance Show Description where ...@@ -52,8 +52,7 @@ instance Show Description where
show (PackageItem i) = show i show (PackageItem i) = show i
data PackageItem data PackageItem
= Typedef Type Identifier = Function Lifetime Type Identifier [Decl] [Stmt]
| Function Lifetime Type Identifier [Decl] [Stmt]
| Task Lifetime Identifier [Decl] [Stmt] | Task Lifetime Identifier [Decl] [Stmt]
| Import Identifier Identifier | Import Identifier Identifier
| Export Identifier Identifier | Export Identifier Identifier
...@@ -62,7 +61,6 @@ data PackageItem ...@@ -62,7 +61,6 @@ data PackageItem
deriving Eq deriving Eq
instance Show PackageItem where instance Show PackageItem where
show (Typedef t x) = printf "typedef %s %s;" (show t) x
show (Function ml t x i b) = show (Function ml t x i b) =
printf "function %s%s%s;\n%s\nendfunction" (showPad ml) (showPad t) x printf "function %s%s%s;\n%s\nendfunction" (showPad ml) (showPad t) x
(showBlock i b) (showBlock i b)
......
...@@ -837,8 +837,8 @@ PackageItem :: { [PackageItem] } ...@@ -837,8 +837,8 @@ PackageItem :: { [PackageItem] }
| ParameterDecl(";") { map (Decl . makeLocalparam) $1 } | ParameterDecl(";") { map (Decl . makeLocalparam) $1 }
| NonDeclPackageItem { $1 } | NonDeclPackageItem { $1 }
NonDeclPackageItem :: { [PackageItem] } NonDeclPackageItem :: { [PackageItem] }
: "typedef" Type Identifier ";" { [Typedef $2 $3] } : "typedef" Type Identifier ";" { [Decl $ ParamType Localparam $3 $2] }
| "typedef" Type Identifier DimensionsNonEmpty ";" { [Typedef (UnpackedType $2 $4) $3] } | "typedef" Type Identifier DimensionsNonEmpty ";" { [Decl $ ParamType Localparam $3 (UnpackedType $2 $4)] }
| "function" Lifetime FuncRetAndName TFItems DeclsAndStmts "endfunction" opt(Tag) { [Function $2 (fst $3) (snd $3) (map defaultFuncInput $ (map makeInput $4) ++ fst $5) (snd $5)] } | "function" Lifetime FuncRetAndName TFItems DeclsAndStmts "endfunction" opt(Tag) { [Function $2 (fst $3) (snd $3) (map defaultFuncInput $ (map makeInput $4) ++ fst $5) (snd $5)] }
| "function" Lifetime "void" Identifier TFItems DeclsAndStmts "endfunction" opt(Tag) { [Task $2 $4 (map defaultFuncInput $ $5 ++ fst $6) (snd $6)] } | "function" Lifetime "void" Identifier TFItems DeclsAndStmts "endfunction" opt(Tag) { [Task $2 $4 (map defaultFuncInput $ $5 ++ fst $6) (snd $6)] }
| "task" Lifetime Identifier TFItems DeclsAndStmts "endtask" opt(Tag) { [Task $2 $3 (map defaultFuncInput $ $4 ++ fst $5) (snd $5)] } | "task" Lifetime Identifier TFItems DeclsAndStmts "endtask" opt(Tag) { [Task $2 $3 (map defaultFuncInput $ $4 ++ fst $5) (snd $5)] }
......
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