Commit 2d003c6d by Zachary Snow

conversion for package-scoped tasks, functions, and typenames

parent bc23aebc
......@@ -81,9 +81,9 @@ Common flags:
## Supported Features
sv2v supports most synthesizable SystemVerilog features. Current notable
exceptions include `package`/`import`/`export`, interfaces _with parameter
bindings_, and complex (non-identifier) `modport` expressions. Assertions are
also supported, but are simply dropped during conversion.
exceptions include `export`, interfaces _with parameter bindings_, and complex
(non-identifier) `modport` expressions. Assertions are also supported, but are
simply dropped during conversion.
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.
......
......@@ -46,12 +46,12 @@ phases excludes =
, Convert.StarPort.convert
, Convert.StmtBlock.convert
, Convert.Struct.convert
, Convert.Return.convert
, Convert.Typedef.convert
, Convert.UnbasedUnsized.convert
, Convert.Unique.convert
, Convert.Package.convert
, Convert.NestPI.convert
, Convert.Return.convert
, selectExclude (Job.Interface, Convert.Interface.convert)
, selectExclude (Job.Always , Convert.AlwaysKW.convert)
]
......
......@@ -2,10 +2,6 @@
- Author: Zachary Snow <zach@zachjs.com>
-
- 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
......@@ -64,8 +60,11 @@ prefixPackageItem packageName idents item =
other -> other
convertExpr (Ident x) = Ident $ prefix x
convertExpr other = other
convertLHS (LHSIdent x) = LHSIdent $ prefix x
convertLHS other = other
converter =
(traverseExprs $ traverseNestedExprs convertExpr)
(traverseExprs $ traverseNestedExprs convertExpr) .
(traverseLHSs $ traverseNestedLHSs convertLHS )
MIPackageItem item'' = converter $ MIPackageItem item'
collectDescriptionM :: Description -> Writer Packages ()
......@@ -102,11 +101,26 @@ traverseModuleItem packages (MIPackageItem (Import x y)) =
items = map snd $ filter (filterer . fst) $ Map.toList packageItems
traverseModuleItem _ item =
(traverseExprs $ traverseNestedExprs traverseExpr) $
(traverseStmts traverseStmt) $
(traverseTypes traverseType) $
item
where
traverseExpr :: Expr -> Expr
traverseExpr (PSIdent x y) = Ident $ x ++ "_" ++ y
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
traverseExpr :: Expr -> Expr
traverseExpr (PSIdent x y) = Ident $ x ++ "_" ++ y
traverseExpr 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
piName :: PackageItem -> Maybe Identifier
......
......@@ -6,6 +6,18 @@ package B;
localparam FOO = -37;
localparam BAR = -97;
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;
import A::FOO;
import B::BAR;
......@@ -16,5 +28,9 @@ module top;
$display(B::BAR);
$display(FOO);
$display(BAR);
$display("%d", D::pack(0));
$display("%d", D::pack(1));
$display("%d", E::pack(0));
$display("%d", E::pack(1));
end
endmodule
......@@ -5,6 +5,14 @@ module top;
localparam B_BAR = -97;
localparam FOO = 37;
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
$display(A_FOO);
$display(A_BAR);
......@@ -12,5 +20,9 @@ module top;
$display(B_BAR);
$display(FOO);
$display(BAR);
$display("%d", D_pack(0));
$display("%d", D_pack(1));
$display("%d", E_pack(0));
$display("%d", E_pack(1));
end
endmodule
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