# `EHLS.Runtime.AtomVM`
[🔗](https://github.com/elixir-hls/elixir-hls/blob/v0.1.0/lib/ehls/backend/atomvm.ex#L1)

The AtomVM runtime backend (`priv/backend/atomvm`): the generated functions call the
`:hwstream` NIFs, which drive the LiteX backend's CSRs and DMA.

`generate/1` writes `<out>/gen/hw_kernels.erl` (kernel / pipeline / param / state
indices). A target builds into AtomVM and the application:

  * `src/hwstream_nif.c` (the NIFs; needs `hwstream_csr.h`) and `src/hwstream_pack.c` (a
    list of elements to the packed format of a CPU end and back; no hardware),
  * `gen_csr_header.py <csr.json> <out dir> [package root]...` (that header from the SoC's
    csr.json, and the headers the block packages' csr_headers.json ask for),
  * `lib/hwstream.erl` (the NIF stubs) and `lib/hls_check.ex` (`EHLS.Check`: a kernel on
    the FPGA against the CPU, on the board).

With `mix ehls.compile --target cpu` (`generate_nif/1`) the `defhls` functions run on the CPU as C
instead of Elixir: `gen/ehls_nif_kernels.c` and `gen/hw_nif.erl` with `src/ehls_nif.c`
(`hwnif:info/1`, `init/1`, `run/4`; `src/ehls_nif.h`), `lib/hwnif.erl` and `lib/nif_run.ex`
(`EHLS.NIFRun`, which cuts a long input into chunks so that the VM is not held).

The generated CPU code stays within what AtomVM runs (immediate terms, no
`Enum.map_reduce/3`).

# `generate_nif`

For `mix ehls.compile --target cpu`: `<out>/gen/ehls_nif_kernels.c` (the kernels' C and their table,
`ehls_nif.h`) and `<out>/gen/hw_nif.erl` (their numbers and layouts). A target builds
`src/ehls_nif.c` with them and `lib/hwnif.erl` and `lib/nif_run.ex` (`EHLS.NIFRun`)
into AtomVM and the application.

---

*Consult [api-reference.md](api-reference.md) for complete listing*
