diff --git a/src/Convert.hs b/src/Convert.hs index a1306f0..a693914 100644 --- a/src/Convert.hs +++ b/src/Convert.hs @@ -23,6 +23,7 @@ import qualified Convert.NamedBlock import qualified Convert.NestPI import qualified Convert.Package import qualified Convert.PackedArray +import qualified Convert.RemoveComments import qualified Convert.Return import qualified Convert.StarPort import qualified Convert.StmtBlock @@ -56,6 +57,7 @@ phases excludes = , Convert.Return.convert , selectExclude (Job.Interface, Convert.Interface.convert) , selectExclude (Job.Always , Convert.AlwaysKW.convert) + , selectExclude (Job.Succinct , Convert.RemoveComments.convert) ] where selectExclude :: (Job.Exclude, Phase) -> Phase diff --git a/src/Convert/RemoveComments.hs b/src/Convert/RemoveComments.hs new file mode 100644 index 0000000..61c1037 --- /dev/null +++ b/src/Convert/RemoveComments.hs @@ -0,0 +1,26 @@ +{- sv2v + - Author: Zachary Snow + - + - Conversion for removing any comments + -} + +module Convert.RemoveComments (convert) where + +import Convert.Traverse +import Language.SystemVerilog.AST + +convert :: [AST] -> [AST] +convert = map convertFile + +convertFile :: AST -> AST +convertFile = + traverseDescriptions (traverseModuleItems convertModuleItem) . + filter (not . isComment) + +isComment :: Description -> Bool +isComment (PackageItem (Comment _)) = True +isComment _ = False + +convertModuleItem :: ModuleItem -> ModuleItem +convertModuleItem (MIPackageItem (Comment _)) = Generate [] +convertModuleItem other = other diff --git a/src/Job.hs b/src/Job.hs index 53963ca..804921f 100644 --- a/src/Job.hs +++ b/src/Job.hs @@ -13,6 +13,7 @@ data Exclude = Always | Interface | Logic + | Succinct deriving (Show, Typeable, Data, Eq) data Job = Job @@ -21,6 +22,7 @@ data Job = Job , incdir :: [FilePath] , define :: [String] , oneunit :: Bool + , verbose :: Bool } deriving (Show, Typeable, Data) defaultJob :: Job @@ -33,6 +35,7 @@ defaultJob = Job ++ " preprocessing") , oneunit = False &= help ("put all files in one compilation unit, so" ++ " macros from earlier files remain defined in later files") + , verbose = False &= help "retain certain conversion artifacts" } &= program "sv2v" &= summary "sv2v v0.0.1, (C) 2019 Zachary Snow, 2011-2015 Tom Hawkins" @@ -40,4 +43,8 @@ defaultJob = Job , "More info: https://github.com/zachjs/sv2v" ] readJob :: IO Job -readJob = cmdArgs defaultJob +readJob = do + job <- cmdArgs defaultJob + return $ if verbose job + then job { exclude = Succinct : exclude job } + else job diff --git a/sv2v.cabal b/sv2v.cabal index e5042e5..9f15850 100644 --- a/sv2v.cabal +++ b/sv2v.cabal @@ -67,6 +67,7 @@ executable sv2v Convert.NestPI Convert.Package Convert.PackedArray + Convert.RemoveComments Convert.Return Convert.StarPort Convert.StmtBlock