New `w6c -I <out.wwi>` flag (both stages) writes a re-parseable ww-prototype rendering of a package's EXPORTED surface. M2 dead-code: nothing consumes .wwi yet (combined.ww stays the live path); the flag is off on every existing invocation, so the 990-997 byte-id gates and all prior tests are unperturbed. The unparse walks the AST type-expr subtree (N_T* nodes), not the tinfo Type* (which collapses nominal pkg.Name identity). Deterministic output: package line, byte-sorted imports, byte-sorted decls — a pure function of the exported API. cmd/w6c/wwi.c + selfhost/cmd/wcc/wwi.ww emit byte-identical .wwi (new cross-stage byte-id substrate, rule 10). check_exported_type (drew) rides the producer entry, flag-gated: an exported signature naming a non-exported nominal is loud-rejected before any byte is written, identically on both stages. Ports harec check.c:4092-4168, recursing the type-AST and gating on the resolved SK_TYPE sym's decl export flag (Sym.exported is vestigial in both stages; the predeclared synthetic `nomem` decl carries no source position and is treated as a builtin leaf — cstage parity). Two wwstage checker AST-mutations are normalized to cstage's pristine view for byte-id: the N_TPARAM tuple-element wrapper (unwrapped) and the variadic `T...`→`[]T` param desugar (peeled). Gate 989_m2wwi_run: ascii/strings/getopt each produce a .wwi that re-parses (wwdump -a) and is cs==ww byte-identical; a private-type-leak fixture is rejected identically by both stages (non-vacuous check).
69 lines
1.9 KiB
C
69 lines
1.9 KiB
C
/*
|
|
* gc.h — w6c-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;
|
|
const char *cur_mod; /* current fn's `// MODULE: foo` directive,
|
|
* NULL when the fn lives in the primary
|
|
* file (no MODULE: stamp). Drives bare-IDENT
|
|
* call mangling — `frob()` from within
|
|
* lib/foo binds to `foo.frob` regardless
|
|
* of which other modules also export `frob`.
|
|
* Set by cgfn before walking the body. */
|
|
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);
|
|
|
|
/* wwi.c — `.wwi` export-data producer (w6c -I). M2 dead-code: writes a
|
|
* re-parseable ww-prototype rendering of the package's exported surface.
|
|
* Returns non-zero if check_exported_type rejects a dangling export. */
|
|
int wwi_emit(Checker *c, FILE *of, Node *file);
|
|
|
|
/* swt.c, peep.c, reg.c — placeholders for now */
|
|
void peephole(Cg*);
|
|
void regalloc_init(Cg*);
|
|
|
|
#endif
|