File tree Expand file tree Collapse file tree 9 files changed +106
-0
lines changed
cabal-testsuite/PackageTests/CmmSources Expand file tree Collapse file tree 9 files changed +106
-0
lines changed Original file line number Diff line number Diff line change
1
+ # cabal v2-run
2
+ Resolving dependencies...
3
+ Build profile: -w ghc-<GHCVER> -O1
4
+ In order, the following will be built:
5
+ - cmmexperiment-0 (lib) (first run)
6
+ - cmmexperiment-0 (exe:demo) (first run)
7
+ Configuring library for cmmexperiment-0..
8
+ Preprocessing library for cmmexperiment-0..
9
+ Building library for cmmexperiment-0..
10
+ Configuring executable 'demo' for cmmexperiment-0..
11
+ Warning: The package has an extraneous version range for a dependency on an internal library: cmmexperiment >=0 && ==0. This version range includes the current package but isn't needed as the current package's library will always be used.
12
+ Preprocessing executable 'demo' for cmmexperiment-0..
13
+ Building executable 'demo' for cmmexperiment-0..
Original file line number Diff line number Diff line change
1
+ packages : .
Original file line number Diff line number Diff line change
1
+ import Test.Cabal.Prelude
2
+
3
+ main = cabalTest $ do
4
+ res <- cabal' " v2-run" [" demo" ]
5
+ assertOutputContains " = Post common block elimination =" res
6
+ assertOutputContains " In Box we have 0x" res
Original file line number Diff line number Diff line change
1
+ #include "Cmm.h"
2
+
3
+ aToMyWordzh (P_ clos)
4
+ {
5
+ return clos;
6
+ }
Original file line number Diff line number Diff line change
1
+ cabal-version : 3.0
2
+ name : cmmexperiment
3
+ version : 0
4
+ build-type : Simple
5
+
6
+ -- This code is extracted form ghc-heap
7
+ -- Copyright (c) 2012-2013, Joachim Breitner
8
+ -- (and probably -2020 GHC Team)
9
+ -- Under BSD-3-Clause
10
+
11
+ library
12
+ default-language : Haskell2010
13
+ hs-source-dirs : src
14
+ build-depends : base
15
+ exposed-modules : Demo
16
+
17
+ cmm-sources : cbits/HeapPrim.cmm
18
+ if impl(ghc >= 8.2 )
19
+ cmm-options : -ddump-cmm-verbose
20
+ else
21
+ cmm-options : -ddump-cmm
22
+
23
+ executable demo
24
+ default-language : Haskell2010
25
+ main-is : Main.hs
26
+ hs-source-dirs : demo
27
+ build-depends : base, cmmexperiment
Original file line number Diff line number Diff line change
1
+ module Main (main ) where
2
+ import Demo (main )
Original file line number Diff line number Diff line change
1
+ # Setup configure
2
+ Configuring cmmexperiment-0...
3
+ # Setup build
4
+ Preprocessing library for cmmexperiment-0..
5
+ Building library for cmmexperiment-0..
6
+ Preprocessing executable 'demo' for cmmexperiment-0..
7
+ Building executable 'demo' for cmmexperiment-0..
Original file line number Diff line number Diff line change
1
+ import Test.Cabal.Prelude
2
+
3
+ main = setupTest $ do
4
+ skipIf =<< ghcVersionIs (< mkVersion [7 ,8 ])
5
+ setup " configure" []
6
+ res <- setup' " build" []
7
+ assertOutputContains " = Parsed Cmm =" res
Original file line number Diff line number Diff line change
1
+ {-# LANGUAGE CPP #-}
2
+ {-# LANGUAGE ForeignFunctionInterface #-}
3
+ {-# LANGUAGE GHCForeignImportPrim #-}
4
+ {-# LANGUAGE MagicHash #-}
5
+ {-# LANGUAGE UnliftedFFITypes #-}
6
+ module Demo (main ) where
7
+
8
+ #include "MachDeps.h"
9
+
10
+ import Data.Bits
11
+ import GHC.Exts
12
+ import Numeric (showHex )
13
+
14
+ foreign import prim " aToMyWordzh" aToWord# :: Any -> Word #
15
+
16
+ tAG_MASK :: Int
17
+ tAG_MASK = (1 `shift` TAG_BITS ) - 1
18
+
19
+ data Box = Box Any
20
+
21
+ instance Show Box where
22
+ showsPrec _ (Box a) rs =
23
+ -- unsafePerformIO (print "↓" >> pClosure a) `seq`
24
+ pad_out (showHex addr " " ) ++ (if tag> 0 then " /" ++ show tag else " " ) ++ rs
25
+ where
26
+ ptr = W # (aToWord# a)
27
+ tag = ptr .&. fromIntegral tAG_MASK -- ((1 `shiftL` TAG_BITS) -1)
28
+ addr = ptr - tag
29
+ pad_out ls = ' 0' : ' x' : ls
30
+
31
+ asBox :: a -> Box
32
+ asBox x = Box (unsafeCoerce# x)
33
+
34
+ main :: IO ()
35
+ main = do
36
+ let box = asBox " foobar"
37
+ putStrLn $ " In Box we have " ++ show box
You can’t perform that action at this time.
0 commit comments