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

Safe Haskell | Safe-Inferred
Language | GHC2021

Futhark.CodeGen.Backends.SequentialWASM

Description

C code generator. This module can convert a correct ImpCode program to an equivalent C program. This C program is expected to be converted to WebAssembly, so we also produce the intended JavaScript wrapper.

Synopsis

- compileProg :: MonadFreshNames m => Text -> Prog SeqMem -> m (Warnings, (CParts, Text, [String]))
- runServer :: Text
- libraryExports :: Text
- data CParts = CParts {
  - cHeader :: Text
  - cUtils :: Text
  - cCLI :: Text
  - cServer :: Text
  - cLib :: Text
  - cJsonManifest :: Text
  }
- asLibrary :: CParts -> (Text, Text, Text)
- asExecutable :: CParts -> Text
- asServer :: CParts -> Text

# Documentation

compileProg :: MonadFreshNames m => Text -> Prog SeqMem -> m (Warnings, (CParts, Text, [String])) Source #

Compile Futhark program to wasm program (some assembly required).

The triple that is returned consists of

- Generated C code (to be passed to Emscripten).
- JavaScript wrapper code that presents a nicer interface to the Emscripten-produced code (this should be put in a `.class.js` file by itself).
- Options that should be passed to `emcc`.

runServer :: Text Source #

Javascript code that can be appended to the generated module to run a Futhark server instance on startup.

libraryExports :: Text Source #

The names exported by the generated module.

data CParts Source #

The result of compilation to C is multiple 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.

Constructors

CParts |

Fields

- cHeader :: Text
- cUtils :: Text

  Utility definitions that must be visible to both CLI and library parts.

- cCLI :: Text
- cServer :: Text
- cLib :: Text
- cJsonManifest :: Text

  The manifest, in JSON format.

asLibrary :: CParts -> (Text, Text, Text) Source #

Produce header, implementation, and manifest files.

asExecutable :: CParts -> Text Source #

As executable with command-line interface.

asServer :: CParts -> Text Source #

As server executable.