Flags --emit
Nesta página
zolo build percorre um pipeline completo por padrão:
.zolo ──parse/typeck──▶ AST ──lower──▶ ZoloIR ──Cranelift──▶ .o ──link──▶ binário
│ --emit ir │ --emit obj (padrão)
A flag --emit permite parar em qualquer estágio intermediário.
--emit ir
--emit ir imprime a representação intermediária textual (ZoloIR) no
stdout em vez de produzir um binário. Nada é gravado em disco. Útil para
entender como uma construção é baixada antes do codegen ou para depurar o
compilador:
zolo build --emit ir mostra o ZoloIR da função double e da chamada a print.
// Feature: inspect ZoloIR — `zolo build --emit ir`
// Syntax: `zolo build file.zolo --emit ir`
// When to use: see the intermediate representation the native backend
// lowers to before codegen — handy for debugging codegen or learning
// how a construct compiles.
// Run:
// zolo build 30-compilation/02-emit-ir.zolo --emit ir
//
// `--emit ir` prints the textual ZoloIR to stdout instead of producing
// a binary. Nothing is written to disk.
fn double(n: int) -> int {
return n * 2
}
print(double(21))
// Abbreviated IR for the `print(double(21))` call:
//
// ; ZoloIR Module
// ; String pool:
// ; s0 = "print"
// fn @__entry() -> val {
// entry:
// %0 = get_global "print"
// %1 = call @double(21)
// %2 = call %0(%1)
// return
// }
//
// expected (when run normally): 42
Requer a CLI/host do Zolo — abra no playground ou rode localmente.
--emit obj
--emit obj compila o código até o arquivo objeto (.o/.obj) e para
antes da etapa de linking — nenhum executável é produzido. O arquivo é
gravado ao lado do fonte. Útil para integração com toolchains externas e
experimentos de FFI:
zolo build --emit obj grava 03-emit-obj.o e encerra antes do link.
// Feature: object file without linking — `zolo build --emit obj`
// Syntax: `zolo build file.zolo --emit obj`
// When to use: produce a `.o`/`.obj` to hand to an external linker, or
// to inspect the generated machine code without a full link step.
// Run:
// zolo build 30-compilation/03-emit-obj.zolo --emit obj
// # -> Wrote 03-emit-obj.o
//
// `--emit obj` writes the compiled object file next to the source and
// stops before linking — no executable is produced. Useful for FFI
// experiments and toolchain integration.
let xs = [1, 2, 3, 4]
var total = 0
for x in xs {
total += x
}
print("sum =", total)
// expected (when run): sum = 10
Requer a CLI/host do Zolo — abra no playground ou rode localmente.
Desafio
Use --emit ir no exemplo de 03-emit-obj.zolo e observe como o laço
for aparece no IR. Como ele difere de uma chamada de função comum?
Veja também