Batata (batata v0.1.0)

Copy Markdown View Source

An Elixir-to-native compiler built on Beaver and the Slang-defined ex dialect.

The frontend boundary lowers an expanded module snapshot to ex IR, then ex to func/arith/scf/cf and finally to LLVM via Beaver.MLIR.Conversion.Plan. Both JIT (execute/2) and AOT (build/3) execution are supported.

Summary

Functions

Compiles Elixir source to a static library and a C driver.

Parses and lowers Elixir source into a verified builtin.module of ex operations.

Parses Elixir source, lowers it to LLVM and executes main through the MLIR JIT, returning its value.

Parses Elixir source and lowers it all the way to LLVM dialect IR.

Functions

build(source, output_dir, ctx)

@spec build(String.t(), Path.t(), Beaver.MLIR.Context.t()) :: %{
  archive: Path.t(),
  driver: Path.t(),
  object: Path.t()
}

Compiles Elixir source to a static library and a C driver.

The entry function main is renamed to batata_main in the generated object so the driver can call it without colliding with the C entry point. Returns a map with the archive, driver and object paths.

Link the driver against the archive and run it:

cc driver.c libMath.a -o run_math

compile(source, ctx)

Parses and lowers Elixir source into a verified builtin.module of ex operations.

execute(source, ctx)

@spec execute(String.t(), Beaver.MLIR.Context.t()) :: term()

Parses Elixir source, lowers it to LLVM and executes main through the MLIR JIT, returning its value.

The JIT engine and module are destroyed before returning.

to_llvm(source, ctx)

Parses Elixir source and lowers it all the way to LLVM dialect IR.