conversion for package-scoped tasks, functions, and typenames

This commit is contained in:
Zachary Snow 2019-04-24 04:01:33 -04:00
parent bc23aebc55
commit 2d003c6ded
5 changed files with 54 additions and 12 deletions

View File

@ -81,9 +81,9 @@ Common flags:
## Supported Features ## Supported Features
sv2v supports most synthesizable SystemVerilog features. Current notable sv2v supports most synthesizable SystemVerilog features. Current notable
exceptions include `package`/`import`/`export`, interfaces _with parameter exceptions include `export`, interfaces _with parameter bindings_, and complex
bindings_, and complex (non-identifier) `modport` expressions. Assertions are (non-identifier) `modport` expressions. Assertions are also supported, but are
also supported, but are simply dropped during conversion. simply dropped during conversion.
If you find a bug or have a feature request, please create an issue. Preference If you find a bug or have a feature request, please create an issue. Preference
will be given to issues which include examples or test cases. will be given to issues which include examples or test cases.

View File

@ -46,12 +46,12 @@ phases excludes =
, Convert.StarPort.convert , Convert.StarPort.convert
, Convert.StmtBlock.convert , Convert.StmtBlock.convert
, Convert.Struct.convert , Convert.Struct.convert
, Convert.Return.convert
, Convert.Typedef.convert , Convert.Typedef.convert
, Convert.UnbasedUnsized.convert , Convert.UnbasedUnsized.convert
, Convert.Unique.convert , Convert.Unique.convert
, Convert.Package.convert , Convert.Package.convert
, Convert.NestPI.convert , Convert.NestPI.convert
, Convert.Return.convert
, selectExclude (Job.Interface, Convert.Interface.convert) , selectExclude (Job.Interface, Convert.Interface.convert)
, selectExclude (Job.Always , Convert.AlwaysKW.convert) , selectExclude (Job.Always , Convert.AlwaysKW.convert)
] ]

View File

@ -2,10 +2,6 @@
- Author: Zachary Snow <zach@zachjs.com> - Author: Zachary Snow <zach@zachjs.com>
- -
- Conversion for packages and imports - Conversion for packages and imports
-
- TODO FIXME: This package conversion does not yet handle package-scoped
- identifiers for task/function names or type names, as the AST and parser
- doesn't support them yet. This won't be too difficult.
-} -}
module Convert.Package (convert) where module Convert.Package (convert) where
@ -64,8 +60,11 @@ prefixPackageItem packageName idents item =
other -> other other -> other
convertExpr (Ident x) = Ident $ prefix x convertExpr (Ident x) = Ident $ prefix x
convertExpr other = other convertExpr other = other
convertLHS (LHSIdent x) = LHSIdent $ prefix x
convertLHS other = other
converter = converter =
(traverseExprs $ traverseNestedExprs convertExpr) (traverseExprs $ traverseNestedExprs convertExpr) .
(traverseLHSs $ traverseNestedLHSs convertLHS )
MIPackageItem item'' = converter $ MIPackageItem item' MIPackageItem item'' = converter $ MIPackageItem item'
collectDescriptionM :: Description -> Writer Packages () collectDescriptionM :: Description -> Writer Packages ()
@ -102,11 +101,26 @@ traverseModuleItem packages (MIPackageItem (Import x y)) =
items = map snd $ filter (filterer . fst) $ Map.toList packageItems items = map snd $ filter (filterer . fst) $ Map.toList packageItems
traverseModuleItem _ item = traverseModuleItem _ item =
(traverseExprs $ traverseNestedExprs traverseExpr) $ (traverseExprs $ traverseNestedExprs traverseExpr) $
(traverseStmts traverseStmt) $
(traverseTypes traverseType) $
item item
where
traverseExpr :: Expr -> Expr traverseExpr :: Expr -> Expr
traverseExpr (PSIdent x y) = Ident $ x ++ "_" ++ y traverseExpr (PSIdent x y) = Ident $ x ++ "_" ++ y
traverseExpr other = other traverseExpr (Call (Just ps) f args) =
Call Nothing (ps ++ "_" ++ f) args
traverseExpr other = other
traverseStmt :: Stmt -> Stmt
traverseStmt (Subroutine (Just ps) f args) =
Subroutine Nothing (ps ++ "_" ++ f) args
traverseStmt other = other
traverseType :: Type -> Type
traverseType (Alias (Just ps) xx rs) =
Alias Nothing (ps ++ "_" ++ xx) rs
traverseType other = other
-- returns the "name" of a package item, if it has one -- returns the "name" of a package item, if it has one
piName :: PackageItem -> Maybe Identifier piName :: PackageItem -> Maybe Identifier

View File

@ -6,6 +6,18 @@ package B;
localparam FOO = -37; localparam FOO = -37;
localparam BAR = -97; localparam BAR = -97;
endpackage endpackage
package C;
typedef logic [3:0] pack_t;
endpackage
package D;
function C::pack_t pack;
input logic x;
pack = {$bits(C::pack_t){x}};
endfunction
endpackage
package E;
import D::*;
endpackage
module top; module top;
import A::FOO; import A::FOO;
import B::BAR; import B::BAR;
@ -16,5 +28,9 @@ module top;
$display(B::BAR); $display(B::BAR);
$display(FOO); $display(FOO);
$display(BAR); $display(BAR);
$display("%d", D::pack(0));
$display("%d", D::pack(1));
$display("%d", E::pack(0));
$display("%d", E::pack(1));
end end
endmodule endmodule

View File

@ -5,6 +5,14 @@ module top;
localparam B_BAR = -97; localparam B_BAR = -97;
localparam FOO = 37; localparam FOO = 37;
localparam BAR = -97; localparam BAR = -97;
function [3:0] D_pack;
input reg x;
D_pack = {4{x}};
endfunction
function [3:0] E_pack;
input reg x;
E_pack = {4{x}};
endfunction
initial begin initial begin
$display(A_FOO); $display(A_FOO);
$display(A_BAR); $display(A_BAR);
@ -12,5 +20,9 @@ module top;
$display(B_BAR); $display(B_BAR);
$display(FOO); $display(FOO);
$display(BAR); $display(BAR);
$display("%d", D_pack(0));
$display("%d", D_pack(1));
$display("%d", E_pack(0));
$display("%d", E_pack(1));
end end
endmodule endmodule