/* * cat/backend/backend.h -- the pluggable backend contract. * * Naming rule: symbols here are cat_backend_* / CAT_BACKEND_*. * * A "backend" turns a compiled CAT_BYTECODE_Function into an artifact: * either printed text (its translation unit / assembly) or a built * binary. Every backend is described by a CAT_BACKEND_Backend record and * registered once in the registry (registry.c). Adding a new backend is * then: write a file that exposes one `cat_backend__backend()` * returning a static descriptor, and add a line to the registry table. * The CLI never changes. */ #ifndef CAT_BACKEND_BACKEND_H #define CAT_BACKEND_BACKEND_H #include "cat/bytecode.h" #include #include /* CAT_BACKEND_Backend -- one target, described declaratively. */ typedef struct CAT_BACKEND_Backend { const char *name; /* selector, e.g. "c" or "x86_64" */ const char *description; /* one line for `--list-backends` */ int native; /* 1 if it builds a real native binary */ /* Dump the artifact (translation unit / assembly) to `out`. */ int (*emit)(CAT_BYTECODE_Function *fn, const char *module_name, const char *module_path, FILE *out); /* Build a native executable at `outpath`. On failure returns * non-zero and fills `errbuf`. */ int (*compile)(CAT_BYTECODE_Function *fn, const char *module_name, const char *module_path, const char *outpath, char *errbuf, size_t errsz); } CAT_BACKEND_Backend; /* Look up a backend by name, or NULL when unknown. */ const CAT_BACKEND_Backend *cat_backend_find(const char *name); /* The backend used when none is named (the C backend). */ const CAT_BACKEND_Backend *cat_backend_default(void); /* Enumerate the registry. */ int cat_backend_count(void); const CAT_BACKEND_Backend *cat_backend_at(int i); #endif /* CAT_BACKEND_BACKEND_H */