Skip to content

Commit d633677

Browse files
authored
Merge pull request haskell-mafia#184 from ambiata/topic/asm
Add --dump-asm build option
2 parents dd6865c + 52fa9cf commit d633677

File tree

1 file changed

+29
-7
lines changed

1 file changed

+29
-7
lines changed

main/mafia.hs

+29-7
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ data MafiaCommand =
8080
| MafiaHash
8181
| MafiaDepends DependsUI (Maybe PackageName) [Flag]
8282
| MafiaClean
83-
| MafiaBuild Profiling Warnings CoreDump [Flag] [Argument]
83+
| MafiaBuild Profiling Warnings CoreDump AsmDump [Flag] [Argument]
8484
| MafiaTest [Flag] [Argument]
8585
| MafiaTestCI [Flag] [Argument]
8686
| MafiaRepl [Flag] [Argument]
@@ -108,6 +108,11 @@ data CoreDump =
108108
| EnableCoreDump
109109
deriving (Eq, Show)
110110

111+
data AsmDump =
112+
DisableAsmDump
113+
| EnableAsmDump
114+
deriving (Eq, Show)
115+
111116
data GhciInclude =
112117
Directory Directory
113118
| ProjectLibraries
@@ -129,8 +134,8 @@ run = \case
129134
mafiaDepends tree pkg flags
130135
MafiaClean ->
131136
mafiaClean
132-
MafiaBuild p w dump flags args ->
133-
mafiaBuild p w dump flags args
137+
MafiaBuild p w dumpc dumpa flags args ->
138+
mafiaBuild p w dumpc dumpa flags args
134139
MafiaTest flags args ->
135140
mafiaTest flags args
136141
MafiaTestCI flags args ->
@@ -192,7 +197,7 @@ commands =
192197
(pure MafiaClean)
193198

194199
, command' "build" "Build this package, including all executables and test suites."
195-
(MafiaBuild <$> pProfiling <*> pWarnings <*> pCoreDump <*> many pFlag <*> many pCabalArgs)
200+
(MafiaBuild <$> pProfiling <*> pWarnings <*> pCoreDump <*> pAsmDump <*> many pFlag <*> many pCabalArgs)
196201

197202
, command' "test" "Test this package, by default this runs all test suites."
198203
(MafiaTest <$> many pFlag <*> many pCabalArgs)
@@ -283,6 +288,12 @@ pCoreDump =
283288
long "dump-core"
284289
<> help "Dump the optimised Core output to dist/build/*. This is simply a shorthand for other GHC options."
285290

291+
pAsmDump :: Parser AsmDump
292+
pAsmDump =
293+
flag DisableAsmDump EnableAsmDump $
294+
long "dump-asm"
295+
<> help "Dump the assembly-language output to dist/build/*. This is simply a shorthand for other GHC options."
296+
286297
pDependsUI :: Parser DependsUI
287298
pDependsUI =
288299
flag List Tree $
@@ -462,8 +473,8 @@ mafiaClean = do
462473
Out (_ :: ByteString) <- liftCabal $ cabal "clean" []
463474
liftCabal removeSandbox
464475

465-
mafiaBuild :: Profiling -> Warnings -> CoreDump -> [Flag] -> [Argument] -> EitherT MafiaError IO ()
466-
mafiaBuild p w dump flags args = do
476+
mafiaBuild :: Profiling -> Warnings -> CoreDump -> AsmDump -> [Flag] -> [Argument] -> EitherT MafiaError IO ()
477+
mafiaBuild p w dumpc dumpa flags args = do
467478
initMafia LatestSources p flags
468479

469480
let
@@ -475,7 +486,10 @@ mafiaBuild p w dump flags args = do
475486
["--ghc-options=-Werror"]
476487

477488
dumpargs =
478-
case dump of
489+
ordNub $ coredump <> asmdump
490+
491+
coredump =
492+
case dumpc of
479493
DisableCoreDump ->
480494
[]
481495
EnableCoreDump -> fmap ("--ghc-options="<>)
@@ -489,6 +503,14 @@ mafiaBuild p w dump flags args = do
489503
,"-dsuppress-module-prefixes"
490504
]
491505

506+
asmdump =
507+
case dumpa of
508+
DisableAsmDump ->
509+
[]
510+
EnableAsmDump -> fmap ("--ghc-options="<>)
511+
["-ddump-asm"
512+
,"-ddump-to-file"
513+
]
492514

493515
liftCabal . cabal_ "build" $ ["-j"] <> wargs <> dumpargs <> args
494516

0 commit comments

Comments
 (0)