- cat/backend/backend.h: the CAT_BACKEND_Backend contract (name, description, native flag, emit(), compile()). - cat/backend/registry.c: the single table of targets; cat_backend_find/ default/count/at. Adding a backend = one file + one line here. - cat/backend/c.c: exposes cat_backend_c_backend(); body unchanged. - cat/backend/x86_64.c: the native x86-64 backend descriptor (lowering stubbed for now). - main.c: --backend <name> --emit/--build, --list-backends; --emit-c and --build stay as shortcuts for the default (c) backend. - Makefile: build the new files. Suite 151 -> 155.
48 lines
1.8 KiB
C
48 lines
1.8 KiB
C
/*
|
|
* 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_<name>_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 <stddef.h>
|
|
#include <stdio.h>
|
|
|
|
/* 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 */
|