# `MaeBPF.Compiler`
[🔗](https://github.com/cocoa-xu/MaeBPF/blob/v0.1.0/maebpf/lib/maebpf/compiler.ex#L1)

Behaviour for eBPF compiler backends invoked by `use MaeBPF, compiler: Module`.

    defmodule MyCustomCompiler do
      @behaviour MaeBPF.Compiler

      @impl true
      def compile_ir(ir_module, opts) do
        MaeBPF.Compiler.Pure.compile_ir(ir_module, opts)
      end
    end

    defmodule MyPolicy do
      use MaeBPF, compiler: MyCustomCompiler

      xdp :ingress do
        default :pass
      end
    end

Defaults to `MaeBPF.Compiler.Pure` when `:compiler` is omitted.

# `compile_result`

```elixir
@type compile_result() :: %{
  :elf =&gt; binary(),
  :ir =&gt; MaeBPF.IR.Module.t(),
  optional(:c_source) =&gt; String.t(),
  optional(:source_map) =&gt; map(),
  optional(:insn_counts) =&gt; map(),
  optional(:stack_bytes) =&gt; map(),
  optional(:elapsed_us) =&gt; non_neg_integer()
}
```

# `compile_ir`

```elixir
@callback compile_ir(MaeBPF.IR.Module.t(), keyword()) ::
  {:ok, compile_result()} | {:error, term()}
```

Compiles a `%MaeBPF.IR.Module{}` into an ELF64 `bpfel` binary and metadata map.

---

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