diff options
Diffstat (limited to 'src/Compile/Exec.hs')
-rw-r--r-- | src/Compile/Exec.hs | 14 |
1 files changed, 11 insertions, 3 deletions
diff --git a/src/Compile/Exec.hs b/src/Compile/Exec.hs index 487ed8a..83ce4ff 100644 --- a/src/Compile/Exec.hs +++ b/src/Compile/Exec.hs @@ -6,6 +6,7 @@ module Compile.Exec ( callKernelFun, ) where +import Control.Monad (when) import Data.IORef import qualified Data.Map.Strict as Map import Data.Map.Strict (Map) @@ -20,6 +21,9 @@ import System.Posix.Temp (mkdtemp) import System.Process (readProcess) +debug :: Bool +debug = False + -- The IORef wrapper is required for the finalizer to attach properly (see the 'Weak' docs) data KernelLib = KernelLib !(IORef (Map String (FunPtr (Ptr () -> IO ())))) @@ -29,11 +33,15 @@ buildKernel csource funnames = do path <- mkdtemp template let outso = path ++ "/out.so" - let args = ["-O3", "-march=native", "-shared", "-fPIC", "-std=c99", "-x", "c", "-o", outso, "-", "-Wall", "-Wextra", "-Wno-unused-parameter"] + let args = ["-O3", "-march=native" + ,"-shared", "-fPIC" + ,"-std=c99", "-x", "c" + ,"-o", outso, "-" + ,"-Wall", "-Wextra", "-Wno-unused-variable", "-Wno-unused-parameter"] _ <- readProcess "gcc" args csource numLoaded <- atomicModifyIORef' numLoadedCounter (\n -> (n+1, n+1)) - hPutStrLn stderr $ "[chad] loading kernel " ++ path ++ " (" ++ show numLoaded ++ " total)" + when debug $ hPutStrLn stderr $ "[chad] loading kernel " ++ path ++ " (" ++ show numLoaded ++ " total)" dl <- dlopen outso [RTLD_LAZY, RTLD_LOCAL] removeDirectoryRecursive path -- we keep a reference anyway because we have the file open now @@ -41,7 +49,7 @@ buildKernel csource funnames = do ptrs <- Map.fromList <$> sequence [(name,) <$> dlsym dl name | name <- funnames] ref <- newIORef ptrs _ <- mkWeakIORef ref (do numLeft <- atomicModifyIORef' numLoadedCounter (\n -> (n-1, n-1)) - hPutStrLn stderr $ "[chad] unloading kernel " ++ path ++ " (" ++ show numLeft ++ " left)" + when debug $ hPutStrLn stderr $ "[chad] unloading kernel " ++ path ++ " (" ++ show numLeft ++ " left)" dlclose dl) return (KernelLib ref) |