imperative-edsl-0.5: Deep embedding of imperative programs with code generation

Safe HaskellNone
LanguageHaskell2010

Language.Embedded.Backend.C

Contents

Description

C code generation for Program

Synopsis

Documentation

Utilities

namedType :: String -> Type Source

Create a named type

viewNotExp :: Exp -> Maybe Exp Source

Return the argument of a boolean negation expression

Code generation user interface

compile :: (Interp instr CGen (Param2 exp pred), HFunctor instr) => Program instr (Param2 exp pred) a -> String Source

Compile a program to C code represented as a string

This function returns only the first (main) module. To get every C translation units, use compileAll.

For programs that make use of the primitives in Language.Embedded.Concurrent, the resulting C code can be compiled as follows:

gcc -Iinclude csrc/chan.c -lpthread YOURPROGRAM.c

compileAll :: (Interp instr CGen (Param2 exp pred), HFunctor instr) => Program instr (Param2 exp pred) a -> [(String, String)] Source

icompile :: (Interp instr CGen (Param2 exp pred), HFunctor instr) => Program instr (Param2 exp pred) a -> IO () Source

Compile a program to C code and print it on the screen

This function returns only the first (main) module. To get every C translation units, use icompileAll.

For programs that make use of the primitives in Language.Embedded.Concurrent, the resulting C code can be compiled as follows:

gcc -Iinclude csrc/chan.c -lpthread YOURPROGRAM.c

icompileAll :: (Interp instr CGen (Param2 exp pred), HFunctor instr) => Program instr (Param2 exp pred) a -> IO () Source

data ExternalCompilerOpts Source

Constructors

ExternalCompilerOpts 

Fields

externalKeepFiles :: Bool

Keep generated files?

externalFlagsPre :: [String]

External compiler flags (e.g. ["-Ipath"])

externalFlagsPost :: [String]

External compiler flags after C source (e.g. ["-lm","-lpthread"])

externalSilent :: Bool

Don't print anything besides what the program prints

compileC Source

Arguments

:: (Interp instr CGen (Param2 exp pred), HFunctor instr) 
=> ExternalCompilerOpts 
-> Program instr (Param2 exp pred) a

Program to compile

-> IO FilePath

Path to the generated executable

Generate C code and use GCC to compile it

compileAndCheck' :: (Interp instr CGen (Param2 exp pred), HFunctor instr) => ExternalCompilerOpts -> Program instr (Param2 exp pred) a -> IO () Source

Generate C code and use GCC to check that it compiles (no linking)

compileAndCheck :: (Interp instr CGen (Param2 exp pred), HFunctor instr) => Program instr (Param2 exp pred) a -> IO () Source

Generate C code and use GCC to check that it compiles (no linking)

runCompiled' :: (Interp instr CGen (Param2 exp pred), HFunctor instr) => ExternalCompilerOpts -> Program instr (Param2 exp pred) a -> IO () Source

Generate C code, use GCC to compile it, and run the resulting executable

runCompiled :: (Interp instr CGen (Param2 exp pred), HFunctor instr) => Program instr (Param2 exp pred) a -> IO () Source

Generate C code, use GCC to compile it, and run the resulting executable

captureCompiled' Source

Arguments

:: (Interp instr CGen (Param2 exp pred), HFunctor instr) 
=> ExternalCompilerOpts 
-> Program instr (Param2 exp pred) a

Program to run

-> String

Input to send to stdin

-> IO String

Result from stdout

Like runCompiled' but with explicit input/output connected to stdin/stdout

captureCompiled Source

Arguments

:: (Interp instr CGen (Param2 exp pred), HFunctor instr) 
=> Program instr (Param2 exp pred) a

Program to run

-> String

Input to send to stdin

-> IO String

Result from stdout

Like runCompiled but with explicit input/output connected to stdin/stdout

compareCompiled' Source

Arguments

:: (Interp instr CGen (Param2 exp pred), HFunctor instr) 
=> ExternalCompilerOpts 
-> Program instr (Param2 exp pred) a

Program to run

-> IO a

Reference program

-> String

Input to send to stdin

-> IO () 

Compare the content written to stdout from the reference program and from running the compiled C code

compareCompiled Source

Arguments

:: (Interp instr CGen (Param2 exp pred), HFunctor instr) 
=> Program instr (Param2 exp pred) a

Program to run

-> IO a

Reference program

-> String

Input to send to stdin

-> IO () 

Compare the content written to stdout from the reference program and from running the compiled C code