Commit e006e36d by Zachary Snow

preliminary support for tasks

parent 0f4a60be
......@@ -110,6 +110,9 @@ traverseStmtsM mapper = moduleItemMapper
moduleItemMapper (MIPackageItem (Function lifetime ret name decls stmts)) = do
stmts' <- mapM fullMapper stmts
return $ MIPackageItem $ Function lifetime ret name decls stmts'
moduleItemMapper (MIPackageItem (Task lifetime name decls stmts)) = do
stmts' <- mapM fullMapper stmts
return $ MIPackageItem $ Task lifetime name decls stmts'
moduleItemMapper (Initial stmt) =
fullMapper stmt >>= return . Initial
moduleItemMapper other = return $ other
......@@ -298,6 +301,10 @@ traverseExprsM mapper = moduleItemMapper
decls' <- mapM declMapper decls
stmts' <- mapM stmtMapper stmts
return $ MIPackageItem $ Function lifetime ret f decls' stmts'
moduleItemMapper (MIPackageItem (Task lifetime f decls stmts)) = do
decls' <- mapM declMapper decls
stmts' <- mapM stmtMapper stmts
return $ MIPackageItem $ Task lifetime f decls' stmts'
moduleItemMapper (Instance m params x ml) = do
if ml == Nothing
then return $ Instance m params x Nothing
......@@ -357,6 +364,9 @@ traverseDeclsM mapper item = do
miMapperA (MIPackageItem (Function l t x decls s)) = do
decls' <- mapM mapper decls
return $ MIPackageItem $ Function l t x decls' s
miMapperA (MIPackageItem (Task l x decls s)) = do
decls' <- mapM mapper decls
return $ MIPackageItem $ Task l x decls' s
miMapperA other = return other
miMapperB (Block (Just (name, decls)) stmts) = do
decls' <- mapM mapper decls
......@@ -400,6 +410,8 @@ traverseTypesM mapper item =
fullMapper t >>= \t' -> return $ Variable d t' x a me
miMapper (MIPackageItem (Function l t x d s)) =
fullMapper t >>= \t' -> return $ MIPackageItem $ Function l t' x d s
miMapper (MIPackageItem (other @ (Task _ _ _ _))) =
return $ MIPackageItem other
miMapper other = return other
traverseTypes :: Mapper Type -> Mapper ModuleItem
......
......@@ -53,6 +53,7 @@ type AST = [Description]
data PackageItem
= Typedef Type Identifier
| Function (Maybe Lifetime) Type Identifier [Decl] [Stmt]
| Task (Maybe Lifetime) Identifier [Decl] [Stmt]
| Comment String
deriving Eq
......@@ -62,6 +63,10 @@ instance Show PackageItem where
printf "function %s%s%s;\n%s\n%s\nendfunction"
(showLifetime ml) (showPad t) x (indent $ show i)
(indent $ unlines' $ map show b)
show (Task ml x i b) =
printf "task %s%s;\n%s\n%s\nendtask"
(showLifetime ml) x (indent $ show i)
(indent $ unlines' $ map show b)
show (Comment c) = "// " ++ c
data Description
......
......@@ -71,6 +71,7 @@ tokens :-
"endgenerate" { tok KW_endgenerate }
"endinterface" { tok KW_endinterface }
"endmodule" { tok KW_endmodule }
"endtask" { tok KW_endtask }
"enum" { tok KW_enum }
"for" { tok KW_for }
"forever" { tok KW_forever }
......@@ -98,6 +99,7 @@ tokens :-
"return" { tok KW_return }
"static" { tok KW_static }
"struct" { tok KW_struct }
"task" { tok KW_task }
"typedef" { tok KW_typedef }
"unique" { tok KW_unique }
"while" { tok KW_while }
......
......@@ -36,6 +36,7 @@ import Language.SystemVerilog.Parser.Tokens
"endgenerate" { Token KW_endgenerate _ _ }
"endinterface" { Token KW_endinterface _ _ }
"endmodule" { Token KW_endmodule _ _ }
"endtask" { Token KW_endtask _ _ }
"enum" { Token KW_enum _ _ }
"for" { Token KW_for _ _ }
"forever" { Token KW_forever _ _ }
......@@ -63,6 +64,7 @@ import Language.SystemVerilog.Parser.Tokens
"return" { Token KW_return _ _ }
"static" { Token KW_static _ _ }
"struct" { Token KW_struct _ _ }
"task" { Token KW_task _ _ }
"typedef" { Token KW_typedef _ _ }
"unique" { Token KW_unique _ _ }
"while" { Token KW_while _ _ }
......@@ -324,7 +326,8 @@ ModuleItem :: { [ModuleItem] }
PackageItem :: { PackageItem }
: "typedef" Type Identifier ";" { Typedef $2 $3 }
| "function" opt(Lifetime) FuncRetAndName FunctionItems DeclsAndStmts "endfunction" opt(Tag) { Function $2 (fst $3) (snd $3) (map defaultFuncInput $ $4 ++ fst $5) (snd $5) }
| "function" opt(Lifetime) FuncRetAndName TFItems DeclsAndStmts "endfunction" opt(Tag) { Function $2 (fst $3) (snd $3) (map defaultFuncInput $ (map makeInput $4) ++ fst $5) (snd $5) }
| "task" opt(Lifetime) Identifier TFItems DeclsAndStmts "endtask" opt(Tag) { Task $2 $3 (map defaultFuncInput $ $4 ++ fst $5) (snd $5) }
FuncRetAndName :: { (Type, Identifier) }
: {- empty -} Identifier { (Implicit [], $1) }
......@@ -345,8 +348,8 @@ ModuleInstantiation :: { (Identifier, Maybe [PortBinding]) }
: Identifier "(" Bindings ")" { ($1, Just $3) }
| Identifier "(" ".*" ")" { ($1, Nothing) }
FunctionItems :: { [Decl] }
: "(" DeclTokens(")") ";" { map makeInput $ parseDTsAsDecls $2 }
TFItems :: { [Decl] }
: "(" DeclTokens(")") ";" { parseDTsAsDecls $2 }
| ";" { [] }
ParamType :: { Type }
......
......@@ -183,6 +183,8 @@ finalize (dir, typ, trips) =
-- internal; entrypoint of the critical portion of our parser
parseDTsAsComponents :: [DeclToken] -> [Component]
parseDTsAsComponents [] = []
parseDTsAsComponents [DTDir dir, DTIdent ident] =
[(dir, Implicit [], [(ident, [], Nothing)])]
parseDTsAsComponents l0 =
component : parseDTsAsComponents l4
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