# `MaeBPFC.Codegen`
[🔗](https://github.com/cocoa-xu/MaeBPF/blob/v0.1.0/maebpf_c/lib/maebpf_c/codegen.ex#L1)

Lowers a structured `%MaeBPF.IR.Module{}` (built-in `MaeBPF.Plugs.*`,
`MaeBPFC.Plugs.TLSSNI`, `global/3`, `c_preamble/1`, and `~BPFC"""..."""`
inline C blocks) into clean, warning-free C CO-RE eBPF source.

Supports two header modes via `header_mode:`:
  * `:vmlinux` - `#include "vmlinux.h"`, `<bpf/bpf_helpers.h>`, and
    `<bpf/bpf_endian.h>` for full Linux CO-RE compilation.
  * `:standalone` - self-contained portable BPF UAPI types, map macros,
    helper declarations, and `bpf_iter_num` ksym externs so `clang -target bpf`
    compiles valid Linux `EM_BPF` ELF64 + BTF objects even on macOS or
    minimal Linux hosts without `vmlinux.h` / `libbpf-dev`.

# `generate`

```elixir
@spec generate(MaeBPF.IR.Module.t(), keyword()) :: {:ok, String.t()}
```

Generates C eBPF source code for a normalized `%MaeBPF.IR.Module{}`.

Options:
  * `:header_mode` - `:vmlinux` or `:standalone` (default `:standalone`)
  * `:includes` - extra header strings emitted as `#include "..."` or `#include <...>`
  * `:debug_trace` - emit per-plug debug RingBuf events (default `false`)

---

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