Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Provisional API: This reference documents current compiler behavior. Compatibility is not yet promised.

src/generate.x

Generate C headers and source files.

Functions

FunctionSummary
generate_codeWrites the generated C header and source for one lowered translation unit.

Functions

generate_code

void generate_code(Compiler c, List ast, String dir)

Writes the generated C header and source for one lowered translation unit. ast must be the normalized result of transform_ast for this compiler; its filename, symbols, binding facts, cache keys, and initialization state must still describe that same unit. dir must already exist. Generation partitions the AST, materializes caches and once-only initialization, and writes or replaces <dir>/<source-stem>.h, .c, and the .xi interface of a collected unit through one file_publish, so a failed write replaces none of them. It appends generated bindings and initialization work to the compiler and is not idempotent. Failures are reported as emit diagnostics.

Source: src/generate.x:973

Design notes

Turns a normalized AST into formatted header and source files. It splits the header from the source, adds once-only translation-unit initialization and include guards, and writes the files. Filesystem failures retain their target and host error as compiler diagnostic notes.