mirror of https://github.com/zachjs/sv2v.git
defer elaboration of void functions
This commit is contained in:
parent
b7a2327668
commit
9eceb55673
|
|
@ -30,14 +30,16 @@ convertDescription description@Part{} =
|
||||||
convertDescription other = other
|
convertDescription other = other
|
||||||
|
|
||||||
traverseFunctionsM :: ModuleItem -> Writer Idents ModuleItem
|
traverseFunctionsM :: ModuleItem -> Writer Idents ModuleItem
|
||||||
traverseFunctionsM (MIPackageItem (Function ml t f decls stmts)) = do
|
traverseFunctionsM item@(MIPackageItem (Function _ Void _ _ _)) =
|
||||||
|
return item
|
||||||
|
traverseFunctionsM (MIPackageItem (Function l t f decls stmts)) = do
|
||||||
decls' <-
|
decls' <-
|
||||||
if any isInput decls
|
if any isInput decls
|
||||||
then return decls
|
then return decls
|
||||||
else do
|
else do
|
||||||
tell $ Set.singleton f
|
tell $ Set.singleton f
|
||||||
return $ dummyDecl : decls
|
return $ dummyDecl : decls
|
||||||
return $ MIPackageItem $ Function ml t f decls' stmts
|
return $ MIPackageItem $ Function l t f decls' stmts
|
||||||
where
|
where
|
||||||
dummyType = IntegerVector TReg Unspecified []
|
dummyType = IntegerVector TReg Unspecified []
|
||||||
dummyDecl = Variable Input dummyType "_sv2v_unused" [] Nil
|
dummyDecl = Variable Input dummyType "_sv2v_unused" [] Nil
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,8 @@
|
||||||
{- sv2v
|
{- sv2v
|
||||||
- Author: Zachary Snow <zach@zachjs.com>
|
- Author: Zachary Snow <zach@zachjs.com>
|
||||||
-
|
-
|
||||||
- Conversion which makes function `logic` and `reg` return types implicit
|
- Conversion which makes function `logic` and `reg` return types implicit and
|
||||||
|
- converts `void` functions to tasks
|
||||||
-
|
-
|
||||||
- Verilog-2005 restricts function return types to `integer`, `real`,
|
- Verilog-2005 restricts function return types to `integer`, `real`,
|
||||||
- `realtime`, `time`, and implicit signed/dimensioned types.
|
- `realtime`, `time`, and implicit signed/dimensioned types.
|
||||||
|
|
@ -16,6 +17,8 @@ convert :: [AST] -> [AST]
|
||||||
convert = map $ traverseDescriptions $ traverseModuleItems convertFunction
|
convert = map $ traverseDescriptions $ traverseModuleItems convertFunction
|
||||||
|
|
||||||
convertFunction :: ModuleItem -> ModuleItem
|
convertFunction :: ModuleItem -> ModuleItem
|
||||||
|
convertFunction (MIPackageItem (Function ml Void f decls stmts)) =
|
||||||
|
MIPackageItem $ Task ml f decls stmts
|
||||||
convertFunction (MIPackageItem (Function ml t f decls stmts)) =
|
convertFunction (MIPackageItem (Function ml t f decls stmts)) =
|
||||||
MIPackageItem $ Function ml t' f decls stmts
|
MIPackageItem $ Function ml t' f decls stmts
|
||||||
where
|
where
|
||||||
|
|
|
||||||
|
|
@ -32,6 +32,7 @@ convertDescription description@Part{} =
|
||||||
convertDescription other = other
|
convertDescription other = other
|
||||||
|
|
||||||
collectFunctionsM :: ModuleItem -> Writer Idents ()
|
collectFunctionsM :: ModuleItem -> Writer Idents ()
|
||||||
|
collectFunctionsM (MIPackageItem (Function _ Void _ _ _)) = return ()
|
||||||
collectFunctionsM (MIPackageItem (Function _ _ f _ _)) =
|
collectFunctionsM (MIPackageItem (Function _ _ f _ _)) =
|
||||||
tell $ Set.singleton f
|
tell $ Set.singleton f
|
||||||
collectFunctionsM _ = return ()
|
collectFunctionsM _ = return ()
|
||||||
|
|
|
||||||
|
|
@ -834,6 +834,7 @@ traverseSinglyNestedTypesM mapper = tm
|
||||||
tm (UnpackedType t r) = do
|
tm (UnpackedType t r) = do
|
||||||
t' <- mapper t
|
t' <- mapper t
|
||||||
return $ UnpackedType t' r
|
return $ UnpackedType t' r
|
||||||
|
tm Void = return Void
|
||||||
|
|
||||||
traverseSinglyNestedTypes :: Mapper Type -> Mapper Type
|
traverseSinglyNestedTypes :: Mapper Type -> Mapper Type
|
||||||
traverseSinglyNestedTypes = unmonad traverseSinglyNestedTypesM
|
traverseSinglyNestedTypes = unmonad traverseSinglyNestedTypesM
|
||||||
|
|
|
||||||
|
|
@ -52,6 +52,7 @@ data Type
|
||||||
| TypeOf Expr
|
| TypeOf Expr
|
||||||
| TypedefRef Expr
|
| TypedefRef Expr
|
||||||
| UnpackedType Type [Range] -- used internally
|
| UnpackedType Type [Range] -- used internally
|
||||||
|
| Void
|
||||||
deriving Eq
|
deriving Eq
|
||||||
|
|
||||||
instance Show Type where
|
instance Show Type where
|
||||||
|
|
@ -74,6 +75,7 @@ instance Show Type where
|
||||||
show (TypeOf expr) = printf "type(%s)" (show expr)
|
show (TypeOf expr) = printf "type(%s)" (show expr)
|
||||||
show (UnpackedType t rs) = printf "UnpackedType(%s, %s)" (show t) (showRanges rs)
|
show (UnpackedType t rs) = printf "UnpackedType(%s, %s)" (show t) (showRanges rs)
|
||||||
show (TypedefRef e) = show e
|
show (TypedefRef e) = show e
|
||||||
|
show Void = "void"
|
||||||
|
|
||||||
showFields :: [Field] -> String
|
showFields :: [Field] -> String
|
||||||
showFields items = itemsStr
|
showFields items = itemsStr
|
||||||
|
|
@ -102,6 +104,7 @@ typeRanges typ =
|
||||||
NonInteger kw -> (nullRange $ NonInteger kw , [])
|
NonInteger kw -> (nullRange $ NonInteger kw , [])
|
||||||
TypeOf expr -> (nullRange $ TypeOf expr, [])
|
TypeOf expr -> (nullRange $ TypeOf expr, [])
|
||||||
TypedefRef expr -> (nullRange $ TypedefRef expr, [])
|
TypedefRef expr -> (nullRange $ TypedefRef expr, [])
|
||||||
|
Void -> (nullRange Void , [])
|
||||||
|
|
||||||
nullRange :: Type -> ([Range] -> Type)
|
nullRange :: Type -> ([Range] -> Type)
|
||||||
nullRange t [] = t
|
nullRange t [] = t
|
||||||
|
|
|
||||||
|
|
@ -924,7 +924,6 @@ ImportOrExport :: { [PackageItem] }
|
||||||
| "export" "*" "::" "*" ";" { [Export "" ""] }
|
| "export" "*" "::" "*" ";" { [Export "" ""] }
|
||||||
TaskOrFunction :: { PackageItem }
|
TaskOrFunction :: { PackageItem }
|
||||||
: "function" Lifetime FuncRetAndName TFItems DeclsAndStmts endfunction StrTag {% checkTag (snd $3) $7 $ Function $2 (fst $3) (snd $3) (map makeInput $4 ++ fst $5) (snd $5) }
|
: "function" Lifetime FuncRetAndName TFItems DeclsAndStmts endfunction StrTag {% checkTag (snd $3) $7 $ Function $2 (fst $3) (snd $3) (map makeInput $4 ++ fst $5) (snd $5) }
|
||||||
| "function" Lifetime "void" Identifier TFItems DeclsAndStmts endfunction StrTag {% checkTag $4 $8 $ Task $2 $4 ($5 ++ fst $6) (snd $6) }
|
|
||||||
| "task" Lifetime Identifier TFItems DeclsAndStmts endtask StrTag {% checkTag $3 $7 $ Task $2 $3 ($4 ++ fst $5) (snd $5) }
|
| "task" Lifetime Identifier TFItems DeclsAndStmts endtask StrTag {% checkTag $3 $7 $ Task $2 $3 ($4 ++ fst $5) (snd $5) }
|
||||||
Typedef :: { Decl }
|
Typedef :: { Decl }
|
||||||
: "typedef" Type Identifier ";" { ParamType Localparam $3 $2 }
|
: "typedef" Type Identifier ";" { ParamType Localparam $3 $2 }
|
||||||
|
|
@ -965,7 +964,6 @@ OptDPIImportProperty :: { DPIImportProperty }
|
||||||
|
|
||||||
DPITFProto :: { (Type, Identifier, [Decl]) }
|
DPITFProto :: { (Type, Identifier, [Decl]) }
|
||||||
: "function" FuncRetAndName TFItems { (fst $2 , snd $2, $3) }
|
: "function" FuncRetAndName TFItems { (fst $2 , snd $2, $3) }
|
||||||
| "function" "void" Identifier TFItems { (UnknownType, $3, $4) }
|
|
||||||
| "task" Identifier TFItems { (UnknownType, $2, $3) }
|
| "task" Identifier TFItems { (UnknownType, $2, $3) }
|
||||||
|
|
||||||
Directive :: { String }
|
Directive :: { String }
|
||||||
|
|
@ -995,6 +993,7 @@ FuncRetAndName :: { (Type, Identifier) }
|
||||||
| Signing Identifier { (Implicit $1 [], $2) }
|
| Signing Identifier { (Implicit $1 [], $2) }
|
||||||
| DimensionsNonEmpty Identifier { (Implicit Unspecified $1, $2) }
|
| DimensionsNonEmpty Identifier { (Implicit Unspecified $1, $2) }
|
||||||
| Signing DimensionsNonEmpty Identifier { (Implicit $1 $2, $3) }
|
| Signing DimensionsNonEmpty Identifier { (Implicit $1 $2, $3) }
|
||||||
|
| "void" Identifier { (Void , $2) }
|
||||||
|
|
||||||
AlwaysKW :: { AlwaysKW }
|
AlwaysKW :: { AlwaysKW }
|
||||||
: "always" { Always }
|
: "always" { Always }
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue