Skip to content

Instantly share code, notes, and snippets.

@takenobu-hs
Last active March 4, 2019 14:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save takenobu-hs/751aed055481d3594cf439a40790119b to your computer and use it in GitHub Desktop.
Save takenobu-hs/751aed055481d3594cf439a40790119b to your computer and use it in GitHub Desktop.
Object representation (in slack-jp)
import Unsafe.Coerce
{-# NOINLINE bool_var1 #-}
bool_var1 :: Bool
bool_var1 = True
main :: IO ()
main = print $ (unsafeCoerce bool_var1 :: Int)
------------------------------------------------------------------------
$ ./Coerce2
4611686018427405893
(0x4000_0000_0000_4645)
------------------------------------------------------------------------
$ ghc -O -fforce-recomp -ddump-stg Coerce2.hs > z.stg
Main.bool_var1 [InlPrag=NOINLINE] :: GHC.Types.Bool
[GblId, Caf=NoCafRefs, Unf=OtherCon []] =
CCS_DONT_CARE GHC.Types.True! [];
------------------------------------------------------------------------
$ ghc -O -fforce-recomp -ddump-opt-cmm Coerce2.hs > z.opt-cmm
section ""data" . Main.bool_var1_closure" {
Main.bool_var1_closure:
const GHC.Types.True_con_info;
}
------------------------------------------------------------------------
$ ghc -O -fforce-recomp -ddump-asm Coerce2.hs > z.asm
.section .data
.align 8
.align 1
.globl Main.bool_var1_closure
.type Main.bool_var1_closure, @object
Main.bool_var1_closure:
.quad GHC.Types.True_con_info
------------------------------------------------------------------------
$ objdump -D Coerce2 > z.disas
00000000004a4300 <Main_boolzuvar1_closure>: <----- closure(info ptr) of "Main.bool_var1"
4a4300: 38 44 46 00 cmp %al,0x0(%rsi,%rax,2)
4a4304: 00 00 add %al,(%rax)
...
00000000004a4308 <Main_zdtrModule3_closure>:
4a4308: 98 cwtl
4a4309: 45 rex.RB <----- +9 (little endian)
4a430a: 46 00 00 rex.RX add %r8b,(%rax)
4a430d: 00 00 add %al,(%rax)
4a430f: 00 40 ba add %al,-0x46(%rax)
4a4312: 48 00 00 rex.W add %al,(%rax)
4a4315: 00 00 add %al,(%rax)
0000000000464438 <ghczmprim_GHCziTypes_True_con_info>:
464438: 48 83 c3 02 add $0x2,%rbx
46443c: ff 65 00 jmpq *0x0(%rbp)
46443f: 90 nop
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment