Skip to content

Commit f59ac92

Browse files
committed
genprimopcode: add --wrappers/--prim-module
1 parent 0cf3417 commit f59ac92

File tree

8 files changed

+46
-3
lines changed

8 files changed

+46
-3
lines changed

compiler/GHC/Builtin/PrimOps.hs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,9 @@ module GHC.Builtin.PrimOps (
2525

2626
getPrimOpResultInfo, isComparisonPrimOp, PrimOpResultInfo(..),
2727

28-
PrimCall(..)
28+
PrimCall(..),
29+
30+
primOpPrimModule, primOpWrappersModule
2931
) where
3032

3133
import GHC.Prelude
@@ -171,6 +173,12 @@ primOpDocs :: [(FastString, String)]
171173
primOpDeprecations :: [(OccName, FastString)]
172174
#include "primop-deprecations.hs-incl"
173175

176+
primOpPrimModule :: String
177+
#include "primop-prim-module.hs-incl"
178+
179+
primOpWrappersModule :: String
180+
#include "primop-wrappers-module.hs-incl"
181+
174182
{-
175183
************************************************************************
176184
* *

compiler/Setup.hs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,8 @@ primopIncls =
5454
, ("primop-vector-tycons.hs-incl" , "--primop-vector-tycons")
5555
, ("primop-docs.hs-incl" , "--wired-in-docs")
5656
, ("primop-deprecations.hs-incl" , "--wired-in-deprecations")
57+
, ("primop-prim-module.hs-incl" , "--prim-module")
58+
, ("primop-wrappers-module.hs-incl" , "--wrappers-module")
5759
]
5860

5961
ghcAutogen :: Verbosity -> LocalBuildInfo -> IO ()

ghc/GHC/Driver/Session/Mode.hs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,12 +32,16 @@ data PreStartupMode
3232
| ShowNumVersion -- ghc --numeric-version
3333
| ShowSupportedExtensions -- ghc --supported-extensions
3434
| ShowOptions Bool {- isInteractive -} -- ghc --show-options
35+
| PrintPrimModule -- ghc --print-prim-module
36+
| PrintPrimWrappersModule -- ghc --print-prim-wrappers-module
3537

36-
showVersionMode, showNumVersionMode, showSupportedExtensionsMode, showOptionsMode :: Mode
38+
showVersionMode, showNumVersionMode, showSupportedExtensionsMode, showOptionsMode, printPrimModule, printPrimWrappersModule :: Mode
3739
showVersionMode = mkPreStartupMode ShowVersion
3840
showNumVersionMode = mkPreStartupMode ShowNumVersion
3941
showSupportedExtensionsMode = mkPreStartupMode ShowSupportedExtensions
4042
showOptionsMode = mkPreStartupMode (ShowOptions False)
43+
printPrimModule = mkPreStartupMode PrintPrimModule
44+
printPrimWrappersModule = mkPreStartupMode PrintPrimWrappersModule
4145

4246
mkPreStartupMode :: PreStartupMode -> Mode
4347
mkPreStartupMode = Left
@@ -203,6 +207,8 @@ mode_flags =
203207
, defFlag "-numeric-version" (PassFlag (setMode showNumVersionMode))
204208
, defFlag "-info" (PassFlag (setMode showInfoMode))
205209
, defFlag "-show-options" (PassFlag (setMode showOptionsMode))
210+
, defFlag "-print-prim-module" (PassFlag (setMode printPrimModule))
211+
, defFlag "-print-prim-wrappers-module" (PassFlag (setMode printPrimWrappersModule))
206212
, defFlag "-supported-languages" (PassFlag (setMode showSupportedExtensionsMode))
207213
, defFlag "-supported-extensions" (PassFlag (setMode showSupportedExtensionsMode))
208214
, defFlag "-show-packages" (PassFlag (setMode showUnitsMode))

ghc/Main.hs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@ import GHC.Driver.Config.Diagnostic
3737
import GHC.Platform
3838
import GHC.Platform.Host
3939

40+
import GHC.Builtin.PrimOps (primOpPrimModule, primOpWrappersModule)
41+
4042
#if defined(HAVE_INTERNAL_INTERPRETER)
4143
import GHCi.UI ( interactiveUI, ghciWelcomeMsg, defaultGhciSettings )
4244
#endif
@@ -138,6 +140,8 @@ main = do
138140
ShowVersion -> showVersion
139141
ShowNumVersion -> putStrLn cProjectVersion
140142
ShowOptions isInteractive -> showOptions isInteractive
143+
PrintPrimModule -> liftIO $ putStrLn primOpPrimModule
144+
PrintPrimWrappersModule -> liftIO $ putStrLn primOpWrappersModule
141145
Right postStartupMode ->
142146
-- start our GHC session
143147
GHC.runGhc mbMinusB $ do

hadrian/src/Rules/Generate.hs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,8 @@ compilerDependencies = do
102102
, "primop-vector-uniques.hs-incl"
103103
, "primop-docs.hs-incl"
104104
, "primop-deprecations.hs-incl"
105+
, "primop-prim-module.hs-incl"
106+
, "primop-wrappers-module.hs-incl"
105107
, "GHC/Platform/Constants.hs"
106108
, "GHC/Settings/Config.hs"
107109
]

hadrian/src/Settings/Builders/GenPrimopCode.hs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,4 +24,6 @@ genPrimopCodeBuilderArgs = builder GenPrimopCode ? mconcat
2424
, output "//primop-vector-tycons.hs-incl" ? arg "--primop-vector-tycons"
2525
, output "//primop-docs.hs-incl" ? arg "--wired-in-docs"
2626
, output "//primop-deprecations.hs-incl" ? arg "--wired-in-deprecations"
27+
, output "//primop-prim-module.hs-incl" ? arg "--prim-module"
28+
, output "//primop-wrappers-module.hs-incl" ? arg "--wrappers-module"
2729
, output "//primop-usage.hs-incl" ? arg "--usage" ]

utils/genprimopcode/Main.hs

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,12 @@ main = getArgs >>= \args ->
216216
"--foundation-tests"
217217
-> putStr (gen_foundation_tests p_o_specs)
218218

219+
"--wrappers-module"
220+
-> putStr (gen_wrappers_module p_o_specs)
221+
222+
"--prim-module"
223+
-> putStr (gen_hs_source_module p_o_specs)
224+
219225
_ -> error "Should not happen, known_args out of sync?"
220226
)
221227

@@ -242,13 +248,18 @@ known_args
242248
"--make-latex-doc",
243249
"--wired-in-docs",
244250
"--wired-in-deprecations",
245-
"--foundation-tests"
251+
"--foundation-tests",
252+
"--wrappers-module",
253+
"--prim-module"
246254
]
247255

248256
------------------------------------------------------------------
249257
-- Code generators -----------------------------------------------
250258
------------------------------------------------------------------
251259

260+
gen_hs_source_module :: Info -> String
261+
gen_hs_source_module info = "primOpPrimModule = " ++ show (gen_hs_source info)
262+
252263
gen_hs_source :: Info -> String
253264
gen_hs_source (Info defaults entries) =
254265
"{-\n"
@@ -475,6 +486,9 @@ In PrimopWrappers we set some crucial GHC options
475486
a very simple module and there is no optimisation to be done
476487
-}
477488

489+
gen_wrappers_module :: Info -> String
490+
gen_wrappers_module info = "primOpWrappersModule = " ++ show (gen_wrappers info)
491+
478492
gen_wrappers :: Info -> String
479493
gen_wrappers (Info _ entries)
480494
= "-- | Users should not import this module. It is GHC internal only.\n"

utils/genprimopcode/genprimopcode.cabal

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,5 +31,10 @@ Executable genprimopcode
3131
AccessOps
3232
Build-Depends: base >= 4 && < 5,
3333
array
34+
35+
-- Happy generated unboxed sums without the necessary pragma.
36+
default-extensions:
37+
UnboxedSums
38+
3439
if flag(build-tool-depends)
3540
build-tool-depends: alex:alex >= 3.2.6, happy:happy >= 1.20.0

0 commit comments

Comments
 (0)