more warnings for empty output scenarios

This commit is contained in:
Zachary Snow 2023-08-20 13:56:03 -04:00
parent aa451b66a2
commit 764a11af7f
5 changed files with 69 additions and 47 deletions

View File

@ -10,37 +10,44 @@ import System.FilePath (combine, splitExtension)
import Control.Monad (when, zipWithM_) import Control.Monad (when, zipWithM_)
import Control.Monad.Except (runExceptT) import Control.Monad.Except (runExceptT)
import Data.List (nub)
import Convert (convert) import Convert (convert)
import Job (readJob, Job(..), Write(..)) import Job (readJob, Job(..), Write(..))
import Language.SystemVerilog.AST import Language.SystemVerilog.AST
import Language.SystemVerilog.Parser (parseFiles, Config(..)) import Language.SystemVerilog.Parser (parseFiles, Config(..))
isInterface :: Description -> Bool
isInterface (Part _ _ Interface _ _ _ _ ) = True
isInterface _ = False
isPackage :: Description -> Bool
isPackage Package{} = True
isPackage _ = False
isComment :: Description -> Bool isComment :: Description -> Bool
isComment (PackageItem (Decl CommentDecl{})) = True isComment (PackageItem (Decl CommentDecl{})) = True
isComment _ = False isComment _ = False
droppedKind :: Description -> Identifier
droppedKind description =
case description of
Part _ _ Interface _ _ _ _ -> "interface"
Package{} -> "package"
Class{} -> "class"
PackageItem Function{} -> "function"
PackageItem Task {} -> "task"
PackageItem (Decl Param{}) -> "localparam"
_ -> ""
emptyWarnings :: AST -> AST -> IO () emptyWarnings :: AST -> AST -> IO ()
emptyWarnings before after = emptyWarnings before after =
if all isComment before || not (all isComment after) then if all isComment before || not (all isComment after) || null kinds then
return () return ()
else if any isInterface before then else if elem "interface" kinds then
hPutStrLn stderr $ "Warning: Source includes an interface but output is" hPutStrLn stderr $ "Warning: Source includes an interface but the"
++ " empty because there is no top-level module which has no ports" ++ " output is empty because there are no modules without any"
++ " which are interfaces." ++ " interface ports. Please convert interfaces alongside the"
else if any isPackage before then ++ " modules that instantiate them."
hPutStrLn stderr $ "Warning: Source includes packages but no modules."
++ " Please convert packages alongside the modules that use them."
else else
return () hPutStrLn stderr $ "Warning: Source includes a " ++ kind ++ " but no"
++ " modules. Such elements are elaborated into the modules that"
++ " use them. Please convert all sources in one invocation."
where
kinds = nub $ filter (not . null) $ map droppedKind before
kind = head kinds
rewritePath :: FilePath -> IO FilePath rewritePath :: FilePath -> IO FilePath
rewritePath path = do rewritePath path = do

3
test/warning/class.sv Normal file
View File

@ -0,0 +1,3 @@
class Class;
localparam X = 1;
endclass

4
test/warning/function.sv Normal file
View File

@ -0,0 +1,4 @@
function Function;
input integer inp;
return inp * 2;
endfunction

View File

@ -1,12 +1,14 @@
#!/bin/bash #!/bin/bash
NO_FILES_WARNING="Warning: No input files specified (try \`sv2v --help\`)" NO_FILES_WARNING="Warning: No input files specified (try \`sv2v --help\`)"
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 the output is empty because there are no modules without any interface ports. Please convert interfaces alongside the modules that instantiate 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."
PORT_CONN_ATTR_WARNING="attr.sv:6:11: Warning: Ignored port connection attributes (* foo *)(* bar *)." PORT_CONN_ATTR_WARNING="attr.sv:6:11: Warning: Ignored port connection attributes (* foo *)(* bar *)."
test_default() { test_default() {
runAndCapture interface.sv module.sv package.sv runAndCapture \
interface.sv module.sv \
package.sv class.sv \
localparam.sv task.sv function.sv
assertTrue "default conversion should succeed" $result assertTrue "default conversion should succeed" $result
assertNotNull "stdout should not be empty" "$stdout" assertNotNull "stdout should not be empty" "$stdout"
assertNull "stderr should be empty" "$stderr" assertNull "stderr should be empty" "$stderr"
@ -26,46 +28,49 @@ test_port_conn_attr() {
assertEquals "stderr should should have warning" "$PORT_CONN_ATTR_WARNING" "$stderr" assertEquals "stderr should should have warning" "$PORT_CONN_ATTR_WARNING" "$stderr"
} }
test_only_package() { no_modules_test() {
runAndCapture package.sv file=$1
warning="$2"
runAndCapture $file
assertTrue "conversion should succeed" $result assertTrue "conversion should succeed" $result
assertNull "stdout should be empty" "$stdout" assertNull "stdout should be empty" "$stdout"
assertEquals "stderr should have warning" "$PACKAGE_WARNING" "$stderr" assertEquals "stderr should have warning" "$warning" "$stderr"
}
test_only_package_verbose() { runAndCapture -v $file
runAndCapture -v package.sv
assertTrue "conversion should succeed" $result assertTrue "conversion should succeed" $result
assertNotNull "stdout should not be empty" "$stdout" assertNotNull "stdout should not be empty" "$stdout"
assertEquals "stderr should have warning" "$PACKAGE_WARNING" "$stderr" assertEquals "stderr should have warning" "$warning" "$stderr"
} }
test_only_interface() { test_only_interface() {
runAndCapture interface.sv no_modules_test interface.sv "$INTERFACE_WARNING"
assertTrue "conversion should succeed" $result
assertNull "stdout should be empty" "$stdout"
assertEquals "stderr should have warning" "$INTERFACE_WARNING" "$stderr"
} }
test_only_interface_verbose() { basic_no_modules_test() {
runAndCapture -v interface.sv kind=$1
assertTrue "conversion should succeed" $result warning="Warning: Source includes a $kind but no modules. Such elements are elaborated into the modules that use them. Please convert all sources in one invocation."
assertNotNull "stdout should not be empty" "$stdout" no_modules_test $kind.sv "$warning"
assertEquals "stderr should have warning" "$INTERFACE_WARNING" "$stderr" }
test_only_package() {
basic_no_modules_test package
}
test_only_class() {
basic_no_modules_test class
}
test_only_function() {
basic_no_modules_test function
}
test_only_task() {
basic_no_modules_test task
} }
test_only_localparam() { test_only_localparam() {
runAndCapture localparam.sv basic_no_modules_test localparam
assertTrue "conversion should succeed" $result
assertNull "stdout should be empty" "$stdout"
assertNull "stderr should be empty" "$stderr"
}
test_only_localparam_verbose() {
runAndCapture -v localparam.sv
assertTrue "conversion should succeed" $result
assertNotNull "stdout should not be empty" "$stdout"
assertNull "stderr should be empty" "$stderr"
} }
source ../lib/functions.sh source ../lib/functions.sh

3
test/warning/task.sv Normal file
View File

@ -0,0 +1,3 @@
task Task;
$display("Hello!");
endtask