{-# LANGUAGE ViewPatterns #-}
{-# OPTIOnS_GHC -Wall -fno-warn-tabs #-}

module Shaderc.Middle where

import Foreign.Storable
import Control.Monad.Trans
import Control.Monad.Cont

import qualified Data.ByteString as BS

import Language.SpirV.ShaderKind.Core

import qualified Shaderc.Core as C
import qualified Language.SpirV.Shaderc.CompileOptions.Internal as CompileOptions
import qualified Shaderc.CompilationResult.Core as CompilationResult

compileIntoSpv :: Storable ud =>
	C.CompilerT -> BS.ByteString -> ShaderKind ->
	BS.ByteString -> BS.ByteString -> CompileOptions.C ud ->
	ContT r IO CompilationResult.T
compileIntoSpv :: forall ud r.
Storable ud =>
CompilerT
-> ByteString
-> ShaderKind
-> ByteString
-> ByteString
-> C ud
-> ContT r IO T
compileIntoSpv CompilerT
cmp ByteString
src ShaderKind
knd ByteString
ifnm ByteString
epnm C ud
opts = do
	(csrc, fromIntegral -> csrcln) <- (((Ptr CChar, Int) -> IO r) -> IO r) -> ContT r IO (Ptr CChar, Int)
forall {k} (r :: k) (m :: k -> *) a.
((a -> m r) -> m r) -> ContT r m a
ContT ((((Ptr CChar, Int) -> IO r) -> IO r)
 -> ContT r IO (Ptr CChar, Int))
-> (((Ptr CChar, Int) -> IO r) -> IO r)
-> ContT r IO (Ptr CChar, Int)
forall a b. (a -> b) -> a -> b
$ ByteString -> ((Ptr CChar, Int) -> IO r) -> IO r
forall a. ByteString -> ((Ptr CChar, Int) -> IO a) -> IO a
BS.useAsCStringLen ByteString
src
	cifnm <- ContT $ BS.useAsCString ifnm
	cepnm <- ContT $ BS.useAsCString epnm
	copts <- CompileOptions.tToCore opts
	lift $ C.compileIntoSpv cmp csrc csrcln knd cifnm cepnm copts