futhark-0.9.1: An optimising compiler for a functional, array-oriented language.

Safe HaskellNone
LanguageHaskell2010

Futhark.CodeGen.Backends.GenericCSharp

Description

A generic C# code generator which is polymorphic in the type of the operations. Concretely, we use this to handle both sequential and OpenCL C# code.

Synopsis

Documentation

compileProg :: MonadFreshNames m => Maybe String -> Constructor -> [CSStmt] -> [CSStmt] -> Operations op s -> s -> CompilerM op s () -> [CSStmt] -> [Space] -> [Option] -> Functions op -> m String Source #

data Constructor Source #

The class generated by the code generator must have a constructor, although it can be vacuous.

Constructors

Constructor [CSFunDefArg] [CSStmt] 

emptyConstructor :: Constructor Source #

A constructor that takes no arguments and does nothing.

compileCode :: Code op -> CompilerM op s () Source #

compilePrimValue :: PrimValue -> CSExp Source #

The ctypes type corresponding to a PrimType.

compilePrimType :: PrimType -> String Source #

The ctypes type corresponding to a PrimType.

compilePrimTypeExt :: PrimType -> Signedness -> String Source #

The ctypes type corresponding to a PrimType, taking sign into account.

defaultOperations :: Operations op s Source #

A set of operations that fail for every operation involving non-default memory spaces. Uses plain pointers and malloc for memory management.

newtype CompilerM op s a Source #

Constructors

CompilerM (RWS (CompilerEnv op s) (CompilerAcc op s) (CompilerState s) a) 
Instances
MonadState (CompilerState s) (CompilerM op s) Source # 
Instance details

Defined in Futhark.CodeGen.Backends.GenericCSharp

Methods

get :: CompilerM op s (CompilerState s) #

put :: CompilerState s -> CompilerM op s () #

state :: (CompilerState s -> (a, CompilerState s)) -> CompilerM op s a #

Monad (CompilerM op s) Source # 
Instance details

Defined in Futhark.CodeGen.Backends.GenericCSharp

Methods

(>>=) :: CompilerM op s a -> (a -> CompilerM op s b) -> CompilerM op s b #

(>>) :: CompilerM op s a -> CompilerM op s b -> CompilerM op s b #

return :: a -> CompilerM op s a #

fail :: String -> CompilerM op s a #

Functor (CompilerM op s) Source # 
Instance details

Defined in Futhark.CodeGen.Backends.GenericCSharp

Methods

fmap :: (a -> b) -> CompilerM op s a -> CompilerM op s b #

(<$) :: a -> CompilerM op s b -> CompilerM op s a #

Applicative (CompilerM op s) Source # 
Instance details

Defined in Futhark.CodeGen.Backends.GenericCSharp

Methods

pure :: a -> CompilerM op s a #

(<*>) :: CompilerM op s (a -> b) -> CompilerM op s a -> CompilerM op s b #

liftA2 :: (a -> b -> c) -> CompilerM op s a -> CompilerM op s b -> CompilerM op s c #

(*>) :: CompilerM op s a -> CompilerM op s b -> CompilerM op s b #

(<*) :: CompilerM op s a -> CompilerM op s b -> CompilerM op s a #

MonadFreshNames (CompilerM op s) Source # 
Instance details

Defined in Futhark.CodeGen.Backends.GenericCSharp

MonadReader (CompilerEnv op s) (CompilerM op s) Source # 
Instance details

Defined in Futhark.CodeGen.Backends.GenericCSharp

Methods

ask :: CompilerM op s (CompilerEnv op s) #

local :: (CompilerEnv op s -> CompilerEnv op s) -> CompilerM op s a -> CompilerM op s a #

reader :: (CompilerEnv op s -> a) -> CompilerM op s a #

type OpCompiler op s = op -> CompilerM op s () Source #

A substitute expression compiler, tried before the main compilation function.

type WriteScalar op s = VName -> CSExp -> PrimType -> SpaceId -> CSExp -> CompilerM op s () Source #

Write a scalar to the given memory block with the given index and in the given memory space.

type ReadScalar op s = VName -> CSExp -> PrimType -> SpaceId -> CompilerM op s CSExp Source #

Read a scalar from the given memory block with the given index and in the given memory space.

type Allocate op s = VName -> CSExp -> SpaceId -> CompilerM op s () Source #

Allocate a memory block of the given size in the given memory space, saving a reference in the given variable name.

type Copy op s = VName -> CSExp -> Space -> VName -> CSExp -> Space -> CSExp -> PrimType -> CompilerM op s () Source #

Copy from one memory block to another.

type StaticArray op s = VName -> SpaceId -> PrimType -> [PrimValue] -> CompilerM op s () Source #

Create a static array of values - initialised at load time.

type EntryOutput op s = VName -> SpaceId -> PrimType -> Signedness -> [DimSize] -> CompilerM op s CSExp Source #

Construct the C# array being returned from an entry point.

type EntryInput op s = VName -> MemSize -> SpaceId -> PrimType -> Signedness -> [DimSize] -> CSExp -> CompilerM op s () Source #

Unpack the array being passed to an entry point.

data CompilerEnv op s Source #

Constructors

CompilerEnv 
Instances
MonadReader (CompilerEnv op s) (CompilerM op s) Source # 
Instance details

Defined in Futhark.CodeGen.Backends.GenericCSharp

Methods

ask :: CompilerM op s (CompilerEnv op s) #

local :: (CompilerEnv op s -> CompilerEnv op s) -> CompilerM op s a -> CompilerM op s a #

reader :: (CompilerEnv op s -> a) -> CompilerM op s a #

stm :: CSStmt -> CompilerM op s () Source #

stms :: [CSStmt] -> CompilerM op s () Source #

collect' :: CompilerM op s a -> CompilerM op s (a, [CSStmt]) Source #

collect :: CompilerM op s () -> CompilerM op s [CSStmt] Source #

simpleCall :: String -> [CSExp] -> CSExp Source #

A Call where the function is a variable and every argument is a simple Arg.

callMethod :: CSExp -> String -> [CSExp] -> CSExp Source #

A CallMethod

parametrizedCall :: String -> String -> [CSExp] -> CSExp Source #

A Call where the function is a variable and every argument is a simple Arg.

publicName :: String -> String Source #

Public names must have a consistent prefix.