summaryrefslogtreecommitdiff
path: root/testsuite/tests/codeGen/should_run/T20137/T20137.hs
blob: 2fa33b5cd97bba97dafca99fa6bf67fcfabfb652 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
{-# LANGUAGE BangPatterns #-}
{-# LANGUAGE CPP #-}
{-# LANGUAGE MagicHash #-}
{-# LANGUAGE CApiFFI #-}

module Main where

import Data.List (foldl')
import Data.Bits
import GHC.Ptr
import Foreign.Ptr
import Foreign.C.Types

type FD = CInt
type CString = Ptr CChar

foreign import ccall unsafe "runInteractiveProcess"
  c_runInteractiveProcess
        :: Ptr CString
        -> CString
        -> Ptr CString
        -> FD
        -> FD
        -> FD
        -> Ptr FD
        -> Ptr FD
        -> Ptr FD
        -> Ptr CInt
        -> Ptr CInt
        -> CInt                         -- flags
        -> Ptr CString
        -> IO CInt

main = do
  c_runInteractiveProcess
    (f 0x1)
    (f 0x2)
    (f 0x3)

    0x4 0x5 0x6

    (f 0x7)
    (f 0x8)
    (f 0x9)

    (f 0xa)
    (f 0xb)

    0xcccccccc

    (f 0xd)

-- | Fill a word with a nibble.
-- e.g. @f 1 == 0x1111111111111111@.
f :: Int -> Ptr a
f n = intPtrToPtr $ fromIntegral $ foldl' (.|.) 0 (map (n `shiftL`) [0,4..60])