diff --git a/src/sv2v.hs b/src/sv2v.hs index fb67bbc..95da2a8 100644 --- a/src/sv2v.hs +++ b/src/sv2v.hs @@ -30,15 +30,19 @@ isPackage :: Description -> Bool isPackage Package{} = True isPackage _ = False -emptyWarnings :: [AST] -> [AST] -> IO () +isComment :: Description -> Bool +isComment (PackageItem (Decl CommentDecl{})) = True +isComment _ = False + +emptyWarnings :: AST -> AST -> IO () emptyWarnings before after = - if all null before || any (not . null) after then + if all isComment before || not (all isComment after) then return () - else if any (any isInterface) before then + else if any isInterface before then hPutStrLn stderr $ "Warning: Source includes an interface but output is" ++ " empty because there is no top-level module which has no ports" ++ " which are interfaces." - else if any (any isPackage) before then + else if any isPackage before then hPutStrLn stderr $ "Warning: Source includes packages but no modules." ++ " Please convert packages alongside the modules that use them." else @@ -82,7 +86,7 @@ main = do Right asts -> do -- convert the files let asts' = convert (exclude job) asts - emptyWarnings asts asts' + emptyWarnings (concat asts) (concat asts') -- write the converted files out writeOutput (write job) (files job) asts' exitSuccess diff --git a/test/warning/interface.sv b/test/warning/interface.sv new file mode 100644 index 0000000..d20fee8 --- /dev/null +++ b/test/warning/interface.sv @@ -0,0 +1,3 @@ +interface Interface; + logic x; +endinterface diff --git a/test/warning/module.sv b/test/warning/module.sv new file mode 100644 index 0000000..01e2db1 --- /dev/null +++ b/test/warning/module.sv @@ -0,0 +1,4 @@ +module Module; + Interface intf(); + assign intf.x = Package::X; +endmodule diff --git a/test/warning/package.sv b/test/warning/package.sv new file mode 100644 index 0000000..9af1789 --- /dev/null +++ b/test/warning/package.sv @@ -0,0 +1,3 @@ +package Package; + localparam X = 1; +endpackage diff --git a/test/warning/run.sh b/test/warning/run.sh new file mode 100755 index 0000000..f3824ff --- /dev/null +++ b/test/warning/run.sh @@ -0,0 +1,43 @@ +#!/bin/bash + +PACKAGE_WARNING="Warning: Source includes packages but no modules. Please convert packages alongside the modules that use them." +INTERFACE_WARNING="Warning: Source includes an interface but output is empty because there is no top-level module which has no ports which are interfaces." + +test_default() { + runAndCapture *.sv + assertTrue "default conversion should succeed" $result + assertNotNull "stdout should not be empty" "$stdout" + assertNull "stderr should be empty" "$stderr" +} + +test_only_package() { + runAndCapture package.sv + assertTrue "conversion should succeed" $result + assertNull "stdout should be empty" "$stdout" + assertEquals "stderr should have warning" "$PACKAGE_WARNING" "$stderr" +} + +test_only_package_verbose() { + runAndCapture -v package.sv + assertTrue "conversion should succeed" $result + assertNotNull "stdout should not be empty" "$stdout" + assertEquals "stderr should have warning" "$PACKAGE_WARNING" "$stderr" +} + +test_only_interface() { + runAndCapture interface.sv + assertTrue "conversion should succeed" $result + assertNull "stdout should be empty" "$stdout" + assertEquals "stderr should have warning" "$INTERFACE_WARNING" "$stderr" +} + +test_only_interface_verbose() { + runAndCapture -v interface.sv + assertTrue "conversion should succeed" $result + assertNotNull "stdout should not be empty" "$stdout" + assertEquals "stderr should have warning" "$INTERFACE_WARNING" "$stderr" +} + +source ../lib/functions.sh + +. shunit2