summaryrefslogtreecommitdiff
path: root/compiler/GHC
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
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')
-rw-r--r--compiler/GHC/Data/FastString.hs3
-rw-r--r--compiler/GHC/Utils/GlobalVars.hs35
2 files changed, 32 insertions, 6 deletions
diff --git a/compiler/GHC/Data/FastString.hs b/compiler/GHC/Data/FastString.hs
index 590f043d4b..ac44a68d54 100644
--- a/compiler/GHC/Data/FastString.hs
+++ b/compiler/GHC/Data/FastString.hs
@@ -112,7 +112,8 @@ module GHC.Data.FastString
lengthPS
) where
-#include "HsVersions.h"
+-- For GHC_STAGE
+#include "ghcplatform.h"
import GHC.Prelude as Prelude
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