Commit 407ba590 by Zachary Snow

add internal --dump-prefix utility

parent d335d2ff
......@@ -103,6 +103,8 @@ Conversion:
Other:
--oversized-numbers Disable standard-imposed 32-bit limit on unsized
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
--version Print version information
--numeric-version Print just the version number
......
......@@ -6,6 +6,8 @@
module Convert (convert) where
import Control.Monad ((>=>))
import Language.SystemVerilog.AST
import qualified Job (Exclude(..))
......@@ -53,6 +55,7 @@ import qualified Convert.Unsigned
import qualified Convert.Wildcard
type Phase = [AST] -> [AST]
type IOPhase = [AST] -> IO [AST]
type Selector = Job.Exclude -> Phase -> Phase
finalPhases :: Selector -> [Phase]
......@@ -109,22 +112,48 @@ initialPhases selectExclude =
, Convert.UnnamedGenBlock.convert
]
convert :: [Job.Exclude] -> Phase
convert excludes =
final . loopMain . initial
convert :: FilePath -> [Job.Exclude] -> IOPhase
convert dumpPrefix excludes =
step "parse" id >=>
step "initial" initial >=>
loop 1 "main" main >=>
step "final" final
where
final = combine $ finalPhases selectExclude
main = combine $ mainPhases selectExclude
initial = combine $ initialPhases selectExclude
combine = foldr1 (.)
loopMain :: Phase
loopMain descriptions =
if descriptions == descriptions'
then descriptions
else loopMain descriptions'
where descriptions' = main descriptions
selectExclude :: Selector
selectExclude exclude phase =
if elem exclude excludes
then id
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
, write :: Write
, writeRaw :: String
, oversizedNumbers :: Bool
, dumpPrefix :: FilePath
} deriving (Typeable, Data)
version :: String
......@@ -76,6 +77,9 @@ defaultJob = Job
&= help ("Disable standard-imposed 32-bit limit on unsized number"
++ " literals (e.g., 'h1_ffff_ffff, 4294967296)")
&= 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"
&= summary ("sv2v " ++ version)
......
......@@ -89,9 +89,9 @@ main = do
exitFailure
Right asts -> do
-- convert the files if requested
let asts' = if passThrough job
then asts
else convert (exclude job) asts
asts' <- if passThrough job
then return asts
else convert (dumpPrefix job) (exclude job) asts
emptyWarnings (concat asts) (concat asts')
-- write the converted files out
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