    {-# LANGUAGE QuasiQuotes #-}

    -- | Boilerplate for multicore C code.
    module Futhark.CodeGen.Backends.MulticoreC.Boilerplate (generateBoilerplate) where

    import Data.Text qualified as T
    import Futhark.CodeGen.Backends.GenericC qualified as GC
    import Futhark.CodeGen.RTS.C (backendsMulticoreH, schedulerH)
    import Language.C.Quote.OpenCL qualified as C

    -- | Generate the necessary boilerplate.
    generateBoilerplate :: GC.CompilerM op s ()
    generateBoilerplate :: forall op s. CompilerM op s ()
    generateBoilerplate = do
      (Definition -> CompilerM op s ())
    -> [Definition] -> CompilerM op s ()
    forall (t :: * -> *) (m :: * -> *) a b.
    (Foldable t, Monad m) =>
    (a -> m b) -> t a -> m ()
    mapM_ Definition -> CompilerM op s ()
    forall op s. Definition -> CompilerM op s ()
    GC.earlyDecl [C.cunit|$esc:(T.unpack schedulerH)|]
      (Definition -> CompilerM op s ())
    -> [Definition] -> CompilerM op s ()
    forall (t :: * -> *) (m :: * -> *) a b.
    (Foldable t, Monad m) =>
    (a -> m b) -> t a -> m ()
    mapM_ Definition -> CompilerM op s ()
    forall op s. Definition -> CompilerM op s ()
    GC.earlyDecl [C.cunit|$esc:(T.unpack backendsMulticoreH)|]
      HeaderSection -> Definition -> CompilerM op s ()
    forall op s. HeaderSection -> Definition -> CompilerM op s ()
    GC.headerDecl HeaderSection
    GC.InitDecl [C.cedecl|void futhark_context_config_set_num_threads(struct futhark_context_config *cfg, int n);|]
      CompilerM op s ()
    forall op s. CompilerM op s ()
    GC.generateProgramStruct
    {-# NOINLINE generateBoilerplate #-}