summaryrefslogtreecommitdiff
path: root/compiler/GHC/ByteCode/Instr.hs
diff options
context:
space:
mode:
authorLuite Stegeman <stegeman@gmail.com>2023-01-10 14:48:01 +0900
committerLuite Stegeman <stegeman@gmail.com>2023-01-18 16:17:17 +0900
commite48eb9761e78695d2d072dfb78c76120a5a27ae8 (patch)
tree2656e717d197e5415830f9f166d1f38f8c43d997 /compiler/GHC/ByteCode/Instr.hs
parent4efee43db5090aac4dde1293357bdb548ae71c24 (diff)
downloadhaskell-wip/ghci-primcall.tar.gz
Add PrimCallConv support to GHCiwip/ghci-primcall
This adds support for calling Cmm code from bytecode using the native calling convention, allowing modules that use `foreign import prim` to be loaded and debugged in GHCi. This patch introduces a new `PRIMCALL` bytecode instruction and a helper stack frame `stg_primcall`. The code is based on the existing functionality for dealing with unboxed tuples in bytecode, which has been generalised to handle arbitrary calls. Fixes #22051
Diffstat (limited to 'compiler/GHC/ByteCode/Instr.hs')
-rw-r--r--compiler/GHC/ByteCode/Instr.hs16
1 files changed, 10 insertions, 6 deletions
diff --git a/compiler/GHC/ByteCode/Instr.hs b/compiler/GHC/ByteCode/Instr.hs
index 498152c471..34baa57d40 100644
--- a/compiler/GHC/ByteCode/Instr.hs
+++ b/compiler/GHC/ByteCode/Instr.hs
@@ -90,7 +90,7 @@ data BCInstr
| PUSH_ALTS (ProtoBCO Name)
| PUSH_ALTS_UNLIFTED (ProtoBCO Name) ArgRep
| PUSH_ALTS_TUPLE (ProtoBCO Name) -- continuation
- !TupleInfo
+ !NativeCallInfo
(ProtoBCO Name) -- tuple return BCO
-- Pushing 8, 16 and 32 bits of padding (for constructors).
@@ -184,6 +184,8 @@ data BCInstr
-- (XXX: inefficient, but I don't know
-- what the alignment constraints are.)
+ | PRIMCALL
+
-- For doing magic ByteArray passing to foreign calls
| SWIZZLE Word16 -- to the ptr N words down the stack,
Word16 -- add M (interpreted as a signed 16-bit entity)
@@ -269,8 +271,8 @@ instance Outputable BCInstr where
ppr (PUSH_ALTS bco) = hang (text "PUSH_ALTS") 2 (ppr bco)
ppr (PUSH_ALTS_UNLIFTED bco pk) = hang (text "PUSH_ALTS_UNLIFTED" <+> ppr pk) 2 (ppr bco)
- ppr (PUSH_ALTS_TUPLE bco tuple_info tuple_bco) =
- hang (text "PUSH_ALTS_TUPLE" <+> ppr tuple_info)
+ ppr (PUSH_ALTS_TUPLE bco call_info tuple_bco) =
+ hang (text "PUSH_ALTS_TUPLE" <+> ppr call_info)
2
(ppr tuple_bco $+$ ppr bco)
@@ -340,6 +342,7 @@ instance Outputable BCInstr where
0x1 -> text "(interruptible)"
0x2 -> text "(unsafe)"
_ -> empty)
+ ppr PRIMCALL = text "PRIMCALL"
ppr (SWIZZLE stkoff n) = text "SWIZZLE " <+> text "stkoff" <+> ppr stkoff
<+> text "by" <+> ppr n
ppr ENTER = text "ENTER"
@@ -382,11 +385,11 @@ bciStackUse (PUSH_ALTS bco) = 2 {- profiling only, restore CCCS -} +
bciStackUse (PUSH_ALTS_UNLIFTED bco _) = 2 {- profiling only, restore CCCS -} +
4 + protoBCOStackUse bco
bciStackUse (PUSH_ALTS_TUPLE bco info _) =
- -- (tuple_bco, tuple_info word, cont_bco, stg_ctoi_t)
+ -- (tuple_bco, call_info word, cont_bco, stg_ctoi_t)
-- tuple
- -- (tuple_info, tuple_bco, stg_ret_t)
+ -- (call_info, tuple_bco, stg_ret_t)
1 {- profiling only -} +
- 7 + fromIntegral (tupleSize info) + protoBCOStackUse bco
+ 7 + fromIntegral (nativeCallSize info) + protoBCOStackUse bco
bciStackUse (PUSH_PAD8) = 1 -- overapproximation
bciStackUse (PUSH_PAD16) = 1 -- overapproximation
bciStackUse (PUSH_PAD32) = 1 -- overapproximation on 64bit arch
@@ -443,6 +446,7 @@ bciStackUse RETURN{} = 0
bciStackUse RETURN_UNLIFTED{} = 1 -- pushes stg_ret_X for some X
bciStackUse RETURN_TUPLE{} = 1 -- pushes stg_ret_t header
bciStackUse CCALL{} = 0
+bciStackUse PRIMCALL{} = 1 -- pushes stg_primcall
bciStackUse SWIZZLE{} = 0
bciStackUse BRK_FUN{} = 0