summaryrefslogtreecommitdiff
path: root/compiler/GHC/Utils
diff options
context:
space:
mode:
authorSylvain Henry <sylvain@haskus.fr>2021-05-06 11:30:57 +0200
committerMarge Bot <ben+marge-bot@smart-cactus.org>2021-05-12 21:41:43 -0400
commitf78c25da05849797dab684a221923aeac244c69b (patch)
tree2be99a252aaf70a6848eb1f39ee39e13ae1578df /compiler/GHC/Utils
parenta7473e03e24878c2192958695759f5d3d415215c (diff)
downloadhaskell-f78c25da05849797dab684a221923aeac244c69b.tar.gz
Move GlobalVar macros into GHC.Utils.GlobalVars
That's the only place where they are used and they shouldn't be used elsewhere.
Diffstat (limited to 'compiler/GHC/Utils')
-rw-r--r--compiler/GHC/Utils/GlobalVars.hs35
1 files changed, 30 insertions, 5 deletions
diff --git a/compiler/GHC/Utils/GlobalVars.hs b/compiler/GHC/Utils/GlobalVars.hs
index f169d07161..19496d5d82 100644
--- a/compiler/GHC/Utils/GlobalVars.hs
+++ b/compiler/GHC/Utils/GlobalVars.hs
@@ -3,6 +3,9 @@
{-# OPTIONS_GHC -fno-cse #-}
-- -fno-cse is needed for GLOBAL_VAR's to behave properly
+-- | Do not use global variables!
+--
+-- Global variables are a hack. Do not use them if you can help it.
module GHC.Utils.GlobalVars
( v_unsafeHasPprDebug
, v_unsafeHasNoDebugOutput
@@ -19,7 +22,8 @@ module GHC.Utils.GlobalVars
)
where
-#include "HsVersions.h"
+-- For GHC_STAGE
+#include "ghcplatform.h"
import GHC.Prelude
@@ -29,11 +33,32 @@ import System.IO.Unsafe
import Data.IORef
import Foreign (Ptr)
+#define GLOBAL_VAR(name,value,ty) \
+{-# NOINLINE name #-}; \
+name :: IORef (ty); \
+name = global (value);
+
+#define GLOBAL_VAR_M(name,value,ty) \
+{-# NOINLINE name #-}; \
+name :: IORef (ty); \
+name = globalM (value);
+
+
+#define SHARED_GLOBAL_VAR(name,accessor,saccessor,value,ty) \
+{-# NOINLINE name #-}; \
+name :: IORef (ty); \
+name = sharedGlobal (value) (accessor); \
+foreign import ccall unsafe saccessor \
+ accessor :: Ptr (IORef a) -> IO (Ptr (IORef a));
+
+#define SHARED_GLOBAL_VAR_M(name,accessor,saccessor,value,ty) \
+{-# NOINLINE name #-}; \
+name :: IORef (ty); \
+name = sharedGlobalM (value) (accessor); \
+foreign import ccall unsafe saccessor \
+ accessor :: Ptr (IORef a) -> IO (Ptr (IORef a));
+
---------------------------------------------------------------------------
--- Do not use global variables!
---
--- Global variables are a hack. Do not use them if you can help it.
#if GHC_STAGE < 2