{-# LANGUAGE CPP #-}
{-# LANGUAGE RecordWildCards #-}
{-# LANGUAGE TemplateHaskell #-}
{-# LANGUAGE TupleSections #-}
module Data.Array.Accelerate.LLVM.Native.Compile.Link
where
import LLVM.AST
import LLVM.AST.Global
import LLVM.ExecutionEngine
import Data.Array.Accelerate.Error
import Data.Maybe
getGlobalFunctions
:: ExecutionEngine e f
=> Module
-> ExecutableModule e
-> IO [(String, f)]
getGlobalFunctions ast exe
= mapM (\f -> (f,) `fmap` link f)
$ globalFunctions (moduleDefinitions ast)
where
link f = fromMaybe ($internalError "link" "function not found") `fmap` getFunction exe (Name f)
globalFunctions :: [Definition] -> [String]
globalFunctions defs =
[ n | GlobalDefinition Function{..} <- defs
, not (null basicBlocks)
, let Name n = name
]