C bootstrap (phases 0-9):
cmd/wwc, cmd/6c, cmd/6a, cmd/6l, cmd/ww, rt, lib/*.
ww-side self-host (phase 10):
selfhost/cmd/wwc — ww-cgen frontend; bootstrap fixed point.
selfhost/cmd/6a — assembler; byte-identical to C 6a (test 991).
selfhost/cmd/6l — linker w/ archive (.a) support; byte-identical
to C 6l (test 992).
selfhost/cmd/ww — driver (build/run/version); byte-identical to
C ww (test 993).
make test: 15/15. make bootstrap: ww2.s == ww3.s, ww2.o == ww3.o,
ww2 == ww3 byte-identical, with the full ww-tooled chain.
57 lines
1.3 KiB
C
57 lines
1.3 KiB
C
/*
|
|
* gc.h — 6c-private header: Prog/Adr structs, scratch register set,
|
|
* stack-frame state. Plan 9 cmd/6c/gc.h shape, trimmed.
|
|
*/
|
|
#ifndef SIX_GC_H
|
|
#define SIX_GC_H
|
|
|
|
#include "ww.h"
|
|
#include "6.out.h"
|
|
|
|
typedef struct Prog Prog;
|
|
typedef struct Adr Adr;
|
|
|
|
/* one operand: register, immediate, indirect, or symbolic. */
|
|
struct Adr {
|
|
int type; /* D_AX, D_CONST, D_INDIR, ... */
|
|
int reg; /* base register for D_INDIR */
|
|
long long offset; /* immediate value or memory displacement */
|
|
const char *sym; /* symbol name for D_EXTERN/D_BRANCH */
|
|
};
|
|
|
|
struct Prog {
|
|
int as; /* opcode (A_MOVQ, ...) */
|
|
Adr from; /* source operand */
|
|
Adr to; /* destination operand (Plan 9 order) */
|
|
int line;
|
|
const char *label; /* if non-NULL, this prog is preceded by label: */
|
|
Prog *link;
|
|
};
|
|
|
|
/* per-fn codegen state */
|
|
typedef struct Cg Cg;
|
|
struct Cg {
|
|
Arena *a;
|
|
Prog *head, *tail;
|
|
const char *fnname;
|
|
int framesize; /* bytes of locals; 16-byte aligned */
|
|
int curoff; /* current top of locals */
|
|
Scope *locals; /* (name → offset) tracked via Sym */
|
|
int labelseq;
|
|
};
|
|
|
|
/* cgen.c */
|
|
void cg_init(Cg*, Arena*);
|
|
void cg_file(Cg*, FILE *out, Node *file);
|
|
Prog *newprog(Cg*, int op);
|
|
void emit(Cg*, Prog*);
|
|
|
|
/* txt.c */
|
|
void txt_emit(FILE*, Prog *head);
|
|
|
|
/* swt.c, peep.c, reg.c — placeholders for now */
|
|
void peephole(Cg*);
|
|
void regalloc_init(Cg*);
|
|
|
|
#endif
|