Skip to content

Commit 3ff9d09

Browse files
committed
Resolve #6377: Add test for package with cmm-sources/options
1 parent 61378b0 commit 3ff9d09

File tree

9 files changed

+106
-0
lines changed

9 files changed

+106
-0
lines changed
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
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..
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
packages: .
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
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
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#include "Cmm.h"
2+
3+
aToMyWordzh (P_ clos)
4+
{
5+
return clos;
6+
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
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
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
module Main (main) where
2+
import Demo (main)
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
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..
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
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
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
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

0 commit comments

Comments
 (0)