Commit 407ba590 by Zachary Snow

add internal --dump-prefix utility

parent d335d2ff
...@@ -103,6 +103,8 @@ Conversion: ...@@ -103,6 +103,8 @@ Conversion:
Other: Other:
--oversized-numbers Disable standard-imposed 32-bit limit on unsized --oversized-numbers Disable standard-imposed 32-bit limit on unsized
number literals (e.g., 'h1_ffff_ffff, 4294967296) number literals (e.g., 'h1_ffff_ffff, 4294967296)
--dump-prefix=PATH Create intermediate output files with the given
path prefix; used for internal debugging
--help Display help message --help Display help message
--version Print version information --version Print version information
--numeric-version Print just the version number --numeric-version Print just the version number
......
...@@ -6,6 +6,8 @@ ...@@ -6,6 +6,8 @@
module Convert (convert) where module Convert (convert) where
import Control.Monad ((>=>))
import Language.SystemVerilog.AST import Language.SystemVerilog.AST
import qualified Job (Exclude(..)) import qualified Job (Exclude(..))
...@@ -53,6 +55,7 @@ import qualified Convert.Unsigned ...@@ -53,6 +55,7 @@ import qualified Convert.Unsigned
import qualified Convert.Wildcard import qualified Convert.Wildcard
type Phase = [AST] -> [AST] type Phase = [AST] -> [AST]
type IOPhase = [AST] -> IO [AST]
type Selector = Job.Exclude -> Phase -> Phase type Selector = Job.Exclude -> Phase -> Phase
finalPhases :: Selector -> [Phase] finalPhases :: Selector -> [Phase]
...@@ -109,22 +112,48 @@ initialPhases selectExclude = ...@@ -109,22 +112,48 @@ initialPhases selectExclude =
, Convert.UnnamedGenBlock.convert , Convert.UnnamedGenBlock.convert
] ]
convert :: [Job.Exclude] -> Phase convert :: FilePath -> [Job.Exclude] -> IOPhase
convert excludes = convert dumpPrefix excludes =
final . loopMain . initial step "parse" id >=>
step "initial" initial >=>
loop 1 "main" main >=>
step "final" final
where where
final = combine $ finalPhases selectExclude final = combine $ finalPhases selectExclude
main = combine $ mainPhases selectExclude main = combine $ mainPhases selectExclude
initial = combine $ initialPhases selectExclude initial = combine $ initialPhases selectExclude
combine = foldr1 (.) combine = foldr1 (.)
loopMain :: Phase
loopMain descriptions =
if descriptions == descriptions'
then descriptions
else loopMain descriptions'
where descriptions' = main descriptions
selectExclude :: Selector selectExclude :: Selector
selectExclude exclude phase = selectExclude exclude phase =
if elem exclude excludes if elem exclude excludes
then id then id
else phase else phase
dumper :: String -> IOPhase
dumper =
if null dumpPrefix
then const return
else fileDumper dumpPrefix
-- add debug dumping to a phase
step :: String -> Phase -> IOPhase
step key = (dumper key .)
-- add convergence and debug dumping to a phase
loop :: Int -> String -> Phase -> IOPhase
loop idx key phase files =
if files == files'
then return files
else dumper key' files' >>= loop (idx + 1) key phase
where
files' = phase files
key' = key ++ "_" ++ show idx
-- pass through dumper which writes ASTs to a file
fileDumper :: String -> String -> IOPhase
fileDumper prefix key files = do
let path = prefix ++ key ++ ".sv"
let output = show $ concat files
writeFile path output
return files
...@@ -44,6 +44,7 @@ data Job = Job ...@@ -44,6 +44,7 @@ data Job = Job
, write :: Write , write :: Write
, writeRaw :: String , writeRaw :: String
, oversizedNumbers :: Bool , oversizedNumbers :: Bool
, dumpPrefix :: FilePath
} deriving (Typeable, Data) } deriving (Typeable, Data)
version :: String version :: String
...@@ -76,6 +77,9 @@ defaultJob = Job ...@@ -76,6 +77,9 @@ defaultJob = Job
&= help ("Disable standard-imposed 32-bit limit on unsized number" &= help ("Disable standard-imposed 32-bit limit on unsized number"
++ " literals (e.g., 'h1_ffff_ffff, 4294967296)") ++ " literals (e.g., 'h1_ffff_ffff, 4294967296)")
&= groupname "Other" &= groupname "Other"
, dumpPrefix = def &= name "dump-prefix" &= explicit &= typ "PATH"
&= help ("Create intermediate output files with the given path prefix;"
++ " used for internal debugging")
} }
&= program "sv2v" &= program "sv2v"
&= summary ("sv2v " ++ version) &= summary ("sv2v " ++ version)
......
...@@ -89,9 +89,9 @@ main = do ...@@ -89,9 +89,9 @@ main = do
exitFailure exitFailure
Right asts -> do Right asts -> do
-- convert the files if requested -- convert the files if requested
let asts' = if passThrough job asts' <- if passThrough job
then asts then return asts
else convert (exclude job) asts else convert (dumpPrefix job) (exclude job) asts
emptyWarnings (concat asts) (concat asts') emptyWarnings (concat asts) (concat asts')
-- write the converted files out -- write the converted files out
writeOutput (write job) (files job) asts' writeOutput (write job) (files job) asts'
......
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