diff --git a/README.md b/README.md index 93ab5c3..e9bb771 100644 --- a/README.md +++ b/README.md @@ -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. diff --git a/src/Convert.hs b/src/Convert.hs index d42cec1..a1abbdc 100644 --- a/src/Convert.hs +++ b/src/Convert.hs @@ -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) ] diff --git a/src/Convert/Package.hs b/src/Convert/Package.hs index 772fe33..d148abf 100644 --- a/src/Convert/Package.hs +++ b/src/Convert/Package.hs @@ -2,10 +2,6 @@ - Author: Zachary Snow - - 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 other = other + 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 + + 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 diff --git a/test/basic/package.sv b/test/basic/package.sv index 896ccb8..d21201f 100644 --- a/test/basic/package.sv +++ b/test/basic/package.sv @@ -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 diff --git a/test/basic/package.v b/test/basic/package.v index 7b2938a..87dfdb5 100644 --- a/test/basic/package.v +++ b/test/basic/package.v @@ -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