summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCheng Shao <terrorjack@type.dance>2023-04-07 18:23:28 +0000
committerMarge Bot <ben+marge-bot@smart-cactus.org>2023-04-11 19:25:31 -0400
commit6c3926167dc6c2978531ecac06e1eda50874297a (patch)
treeb8c643a4619f8dcde4c7bcdaaf02923015373169
parentb7474b57830261a94903da61bb2df33022c11357 (diff)
downloadhaskell-6c3926167dc6c2978531ecac06e1eda50874297a.tar.gz
compiler: make WasmCodeGenM an instance of MonadUnique
-rw-r--r--compiler/GHC/CmmToAsm/Wasm/FromCmm.hs3
-rw-r--r--compiler/GHC/CmmToAsm/Wasm/Types.hs17
2 files changed, 14 insertions, 6 deletions
diff --git a/compiler/GHC/CmmToAsm/Wasm/FromCmm.hs b/compiler/GHC/CmmToAsm/Wasm/FromCmm.hs
index 59d183341b..db4b39f756 100644
--- a/compiler/GHC/CmmToAsm/Wasm/FromCmm.hs
+++ b/compiler/GHC/CmmToAsm/Wasm/FromCmm.hs
@@ -48,6 +48,7 @@ import GHC.Types.ForeignCall
import GHC.Types.Unique
import GHC.Types.Unique.FM
import GHC.Types.Unique.Map
+import GHC.Types.Unique.Supply
import GHC.Utils.Outputable hiding ((<>))
import GHC.Utils.Panic
import GHC.Wasm.ControlFlow.FromCmm
@@ -1328,7 +1329,7 @@ lower_CmmUnsafeForeignCall_Drop ::
[CmmActual] ->
WasmCodeGenM w (WasmStatements w)
lower_CmmUnsafeForeignCall_Drop lbl sym_callee ret_cmm_ty arg_exprs = do
- ret_uniq <- wasmUniq
+ ret_uniq <- getUniqueM
let ret_local = LocalReg ret_uniq ret_cmm_ty
lower_CmmUnsafeForeignCall
lbl
diff --git a/compiler/GHC/CmmToAsm/Wasm/Types.hs b/compiler/GHC/CmmToAsm/Wasm/Types.hs
index 50b1234f30..cef1cf6165 100644
--- a/compiler/GHC/CmmToAsm/Wasm/Types.hs
+++ b/compiler/GHC/CmmToAsm/Wasm/Types.hs
@@ -45,7 +45,6 @@ module GHC.CmmToAsm.Wasm.Types
wasmStateM,
wasmModifyM,
wasmExecM,
- wasmUniq,
)
where
@@ -466,10 +465,18 @@ wasmStateM = coerce . State
wasmModifyM :: (WasmCodeGenState w -> WasmCodeGenState w) -> WasmCodeGenM w ()
wasmModifyM = coerce . modify
+wasmEvalM :: WasmCodeGenM w a -> WasmCodeGenState w -> a
+wasmEvalM (WasmCodeGenM s) = evalState s
+
wasmExecM :: WasmCodeGenM w a -> WasmCodeGenState w -> WasmCodeGenState w
wasmExecM (WasmCodeGenM s) = execState s
-wasmUniq :: WasmCodeGenM w Unique
-wasmUniq = wasmStateM $
- \s@WasmCodeGenState {..} -> case takeUniqFromSupply wasmUniqSupply of
- (u, us) -> (# u, s {wasmUniqSupply = us} #)
+instance MonadUnique (WasmCodeGenM w) where
+ getUniqueSupplyM = wasmGetsM wasmUniqSupply
+ getUniqueM = wasmStateM $
+ \s@WasmCodeGenState {..} -> case takeUniqFromSupply wasmUniqSupply of
+ (u, us) -> (# u, s {wasmUniqSupply = us} #)
+ getUniquesM = do
+ u <- getUniqueM
+ s <- WasmCodeGenM get
+ pure $ u:(wasmEvalM getUniquesM s)