Safe Haskell | None |
---|---|
Language | Haskell2010 |
C code generator framework.
Synopsis
- compileProg :: MonadFreshNames m => Operations op () -> CompilerM op () () -> String -> [Space] -> [Option] -> Functions op -> m CParts
- data CParts = CParts {}
- asLibrary :: CParts -> (String, String)
- asExecutable :: CParts -> String
- data Operations op s = Operations {
- opsWriteScalar :: WriteScalar op s
- opsReadScalar :: ReadScalar op s
- opsAllocate :: Allocate op s
- opsDeallocate :: Deallocate op s
- opsCopy :: Copy op s
- opsStaticArray :: StaticArray op s
- opsMemoryType :: MemoryType op s
- opsCompiler :: OpCompiler op s
- opsFatMemory :: Bool
- defaultOperations :: Operations op s
- type OpCompiler op s = op -> CompilerM op s ()
- type PointerQuals op s = String -> CompilerM op s [TypeQual]
- type MemoryType op s = SpaceId -> CompilerM op s Type
- type WriteScalar op s = Exp -> Exp -> Type -> SpaceId -> Volatility -> Exp -> CompilerM op s ()
- writeScalarPointerWithQuals :: PointerQuals op s -> WriteScalar op s
- type ReadScalar op s = Exp -> Exp -> Type -> SpaceId -> Volatility -> CompilerM op s Exp
- readScalarPointerWithQuals :: PointerQuals op s -> ReadScalar op s
- type Allocate op s = Exp -> Exp -> Exp -> SpaceId -> CompilerM op s ()
- type Deallocate op s = Exp -> Exp -> SpaceId -> CompilerM op s ()
- type Copy op s = Exp -> Exp -> Space -> Exp -> Exp -> Space -> Exp -> CompilerM op s ()
- type StaticArray op s = VName -> SpaceId -> PrimType -> [PrimValue] -> CompilerM op s ()
- data CompilerM op s a
- data CompilerState s
- getUserState :: CompilerM op s s
- putUserState :: s -> CompilerM op s ()
- modifyUserState :: (s -> s) -> CompilerM op s ()
- contextContents :: CompilerM op s ([FieldGroup], [Stm])
- contextFinalInits :: CompilerM op s [Stm]
- runCompilerM :: Functions op -> Operations op s -> VNameSource -> s -> CompilerM op s a -> (a, CompilerState s)
- blockScope :: CompilerM op s () -> CompilerM op s [BlockItem]
- compileFun :: (Name, Function op) -> CompilerM op s (Definition, Func)
- compileCode :: Code op -> CompilerM op s ()
- compileExp :: Exp -> CompilerM op s Exp
- compilePrimExp :: Monad m => (v -> m Exp) -> PrimExp v -> m Exp
- compilePrimValue :: PrimValue -> Exp
- compileExpToName :: String -> PrimType -> Exp -> CompilerM op s VName
- dimSizeToExp :: DimSize -> Exp
- rawMem :: ToExp a => a -> CompilerM op s Exp
- item :: BlockItem -> CompilerM op s ()
- stm :: Stm -> CompilerM op s ()
- stms :: [Stm] -> CompilerM op s ()
- decl :: InitGroup -> CompilerM op s ()
- atInit :: Stm -> CompilerM op s ()
- headerDecl :: HeaderSection -> Definition -> CompilerM op s ()
- publicDef :: String -> HeaderSection -> (String -> (Definition, Definition)) -> CompilerM op s String
- publicDef_ :: String -> HeaderSection -> (String -> (Definition, Definition)) -> CompilerM op s ()
- debugReport :: BlockItem -> CompilerM op s ()
- data HeaderSection
- libDecl :: Definition -> CompilerM op s ()
- earlyDecls :: [Definition] -> CompilerM op s ()
- publicName :: String -> CompilerM op s String
- contextType :: CompilerM op s Type
- contextField :: String -> Type -> Maybe Exp -> CompilerM op s ()
- primTypeToCType :: PrimType -> Type
- copyMemoryDefaultSpace :: Exp -> Exp -> Exp -> Exp -> Exp -> CompilerM op s ()
Documentation
compileProg :: MonadFreshNames m => Operations op () -> CompilerM op () () -> String -> [Space] -> [Option] -> Functions op -> m CParts Source #
Compile imperative program to a C program. Always uses the function named "main" as entry point, so make sure it is defined.
The result of compilation to C is four parts, which can be put together in various ways. The obvious way is to concatenate all of them, which yields a CLI program. Another is to compile the library part by itself, and use the header file to call into it.
asExecutable :: CParts -> String Source #
As executable with command-line interface.
Pluggable compiler
data Operations op s Source #
Operations | |
|
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.
type OpCompiler op s = op -> CompilerM op s () Source #
A substitute expression compiler, tried before the main compilation function.
type PointerQuals op s = String -> CompilerM op s [TypeQual] Source #
The address space qualifiers for a pointer of the given type with the given annotation.
type MemoryType op s = SpaceId -> CompilerM op s Type Source #
The type of a memory block in the given memory space.
type WriteScalar op s = Exp -> Exp -> Type -> SpaceId -> Volatility -> Exp -> CompilerM op s () Source #
Write a scalar to the given memory block with the given index and in the given memory space.
writeScalarPointerWithQuals :: PointerQuals op s -> WriteScalar op s Source #
type ReadScalar op s = Exp -> Exp -> Type -> SpaceId -> Volatility -> CompilerM op s Exp Source #
Read a scalar from the given memory block with the given index and in the given memory space.
readScalarPointerWithQuals :: PointerQuals op s -> ReadScalar op s Source #
type Allocate op s = Exp -> Exp -> Exp -> SpaceId -> CompilerM op s () Source #
Allocate a memory block of the given size and with the given tag in the given memory space, saving a reference in the given variable name.
type Deallocate op s = Exp -> Exp -> SpaceId -> CompilerM op s () Source #
De-allocate the given memory block with the given tag, which is in the given memory space.
type Copy op s = Exp -> Exp -> Space -> Exp -> Exp -> Space -> Exp -> 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.
Monadic compiler interface
data CompilerM op s a Source #
Instances
MonadState (CompilerState s) (CompilerM op s) Source # | |
Defined in Futhark.CodeGen.Backends.GenericC 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 # | |
Functor (CompilerM op s) Source # | |
Applicative (CompilerM op s) Source # | |
Defined in Futhark.CodeGen.Backends.GenericC 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 # | |
Defined in Futhark.CodeGen.Backends.GenericC getNameSource :: CompilerM op s VNameSource Source # putNameSource :: VNameSource -> CompilerM op s () Source # |
data CompilerState s Source #
Instances
MonadState (CompilerState s) (CompilerM op s) Source # | |
Defined in Futhark.CodeGen.Backends.GenericC get :: CompilerM op s (CompilerState s) # put :: CompilerState s -> CompilerM op s () # state :: (CompilerState s -> (a, CompilerState s)) -> CompilerM op s a # |
getUserState :: CompilerM op s s Source #
putUserState :: s -> CompilerM op s () Source #
modifyUserState :: (s -> s) -> CompilerM op s () Source #
contextContents :: CompilerM op s ([FieldGroup], [Stm]) Source #
contextFinalInits :: CompilerM op s [Stm] Source #
runCompilerM :: Functions op -> Operations op s -> VNameSource -> s -> CompilerM op s a -> (a, CompilerState s) Source #
compileFun :: (Name, Function op) -> CompilerM op s (Definition, Func) Source #
compileCode :: Code op -> CompilerM op s () Source #
compilePrimExp :: Monad m => (v -> m Exp) -> PrimExp v -> m Exp Source #
Tell me how to compile a v
, and I'll Compile any PrimExp v
for you.
compilePrimValue :: PrimValue -> Exp Source #
dimSizeToExp :: DimSize -> Exp Source #
headerDecl :: HeaderSection -> Definition -> CompilerM op s () Source #
publicDef :: String -> HeaderSection -> (String -> (Definition, Definition)) -> CompilerM op s String Source #
Construct a publicly visible definition using the specified name as the template. The first returned definition is put in the header file, and the second is the implementation. Returns the public name.
publicDef_ :: String -> HeaderSection -> (String -> (Definition, Definition)) -> CompilerM op s () Source #
As publicDef
, but ignores the public name.
debugReport :: BlockItem -> CompilerM op s () Source #
data HeaderSection Source #
In which part of the header file we put the declaration. This is to ensure that the header file remains structured and readable.
Instances
Eq HeaderSection Source # | |
Defined in Futhark.CodeGen.Backends.GenericC (==) :: HeaderSection -> HeaderSection -> Bool # (/=) :: HeaderSection -> HeaderSection -> Bool # | |
Ord HeaderSection Source # | |
Defined in Futhark.CodeGen.Backends.GenericC compare :: HeaderSection -> HeaderSection -> Ordering # (<) :: HeaderSection -> HeaderSection -> Bool # (<=) :: HeaderSection -> HeaderSection -> Bool # (>) :: HeaderSection -> HeaderSection -> Bool # (>=) :: HeaderSection -> HeaderSection -> Bool # max :: HeaderSection -> HeaderSection -> HeaderSection # min :: HeaderSection -> HeaderSection -> HeaderSection # |
libDecl :: Definition -> CompilerM op s () Source #
earlyDecls :: [Definition] -> CompilerM op s () Source #
contextType :: CompilerM op s Type Source #
The generated code must define a struct with this name.
Building Blocks
primTypeToCType :: PrimType -> Type Source #
The C type corresponding to a primitive type. Integers are assumed to be unsigned.