Skip to content

Commit

Permalink
testsuite: Add test for dynamic linking of cmm-sources objects
Browse files Browse the repository at this point in the history
Essentially just copying the existing CmmSources test but building with
`--enable-executable-dynamic`
  • Loading branch information
bgamari authored and hololeap committed Apr 24, 2022
1 parent 5f7445e commit 8badf64
Show file tree
Hide file tree
Showing 9 changed files with 108 additions and 0 deletions.
13 changes: 13 additions & 0 deletions cabal-testsuite/PackageTests/CmmSourcesDyn/cabal.out
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# cabal v2-run
Resolving dependencies...
Build profile: -w ghc-<GHCVER> -O1
In order, the following will be built:
- cmmexperiment-0 (lib) (first run)
- cmmexperiment-0 (exe:demo) (first run)
Configuring library for cmmexperiment-0..
Preprocessing library for cmmexperiment-0..
Building library for cmmexperiment-0..
Configuring executable 'demo' for cmmexperiment-0..
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.
Preprocessing executable 'demo' for cmmexperiment-0..
Building executable 'demo' for cmmexperiment-0..
2 changes: 2 additions & 0 deletions cabal-testsuite/PackageTests/CmmSourcesDyn/cabal.project
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
packages: .
executable-dynamic: True
7 changes: 7 additions & 0 deletions cabal-testsuite/PackageTests/CmmSourcesDyn/cabal.test.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import Test.Cabal.Prelude

main = cabalTest $ do
skipIfWindows
res <- cabal' "v2-run" ["demo"]
assertOutputContains "= Post common block elimination =" res
assertOutputContains "In Box we have 0x" res
6 changes: 6 additions & 0 deletions cabal-testsuite/PackageTests/CmmSourcesDyn/cbits/HeapPrim.cmm
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#include "Cmm.h"

aToMyWordzh (P_ clos)
{
return (clos);
}
27 changes: 27 additions & 0 deletions cabal-testsuite/PackageTests/CmmSourcesDyn/cmmexperiment.cabal
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
cabal-version: 3.0
name: cmmexperiment
version: 0
build-type: Simple

-- This code is extracted form ghc-heap
-- Copyright (c) 2012-2013, Joachim Breitner
-- (and probably -2020 GHC Team)
-- Under BSD-3-Clause

library
default-language: Haskell2010
hs-source-dirs: src
build-depends: base
exposed-modules: Demo

cmm-sources: cbits/HeapPrim.cmm
if impl(ghc >=8.2)
cmm-options: -ddump-cmm-verbose
else
cmm-options: -ddump-cmm

executable demo
default-language: Haskell2010
main-is: Main.hs
hs-source-dirs: demo
build-depends: base, cmmexperiment
2 changes: 2 additions & 0 deletions cabal-testsuite/PackageTests/CmmSourcesDyn/demo/Main.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
module Main (main) where
import Demo (main)
7 changes: 7 additions & 0 deletions cabal-testsuite/PackageTests/CmmSourcesDyn/setup.out
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# Setup configure
Configuring cmmexperiment-0...
# Setup build
Preprocessing library for cmmexperiment-0..
Building library for cmmexperiment-0..
Preprocessing executable 'demo' for cmmexperiment-0..
Building executable 'demo' for cmmexperiment-0..
7 changes: 7 additions & 0 deletions cabal-testsuite/PackageTests/CmmSourcesDyn/setup.test.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import Test.Cabal.Prelude

main = setupTest $ do
skipIf "ghc < 7.8" =<< ghcVersionIs (< mkVersion [7,8])
setup "configure" []
res <- setup' "build" []
assertOutputContains "= Post common block elimination =" res
37 changes: 37 additions & 0 deletions cabal-testsuite/PackageTests/CmmSourcesDyn/src/Demo.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
{-# LANGUAGE CPP #-}
{-# LANGUAGE ForeignFunctionInterface #-}
{-# LANGUAGE GHCForeignImportPrim #-}
{-# LANGUAGE MagicHash #-}
{-# LANGUAGE UnliftedFFITypes #-}
module Demo (main) where

#include "MachDeps.h"

import Data.Bits
import GHC.Exts
import Numeric (showHex)

foreign import prim "aToMyWordzh" aToWord# :: Any -> Word#

tAG_MASK :: Int
tAG_MASK = (1 `shift` TAG_BITS) - 1

data Box = Box Any

instance Show Box where
showsPrec _ (Box a) rs =
-- unsafePerformIO (print "↓" >> pClosure a) `seq`
pad_out (showHex addr "") ++ (if tag>0 then "/" ++ show tag else "") ++ rs
where
ptr = W# (aToWord# a)
tag = ptr .&. fromIntegral tAG_MASK -- ((1 `shiftL` TAG_BITS) -1)
addr = ptr - tag
pad_out ls = '0':'x':ls

asBox :: a -> Box
asBox x = Box (unsafeCoerce# x)

main :: IO ()
main = do
let box = asBox "foobar"
putStrLn $ "In Box we have " ++ show box

0 comments on commit 8badf64

Please sign in to comment.