toolchain: banner purge + WHY-only comment sweep (rule 8)
selfhost/, cmd/, internal/ join the tree-wide sweep: every section banner dies (91 selfhost + the cmd C-style dividers -> 0); narration and stale contracts deleted (pre-#22 bundler notes, retired single-PT_LOAD and no-archive claims, superseded ABI tables); every ref/harec/qbe cite, task cite, encoding/ELF contract, and rule-10 twin pointer kept; lost lifetime/rationale lines restored where the sweep over-cut (elf_globals ownership, kwtab linear-scan). Comment- only proven: all five wwstage tool binaries byte-identical across the sweep; test-commit, test-byteid (161+1399, 0 pinned-divergent), and test-bootstrap (fixed point + 991-995 byte-id) all exit 0. The read-through banked 66 latent-bug leads (checkpoint).
This commit is contained in:
@@ -1,8 +1,4 @@
|
||||
/*
|
||||
* asm.c — encode the parsed Aprog list into amd64 machine bytes,
|
||||
* appending to Asm.text. Relocations for CALL/branch targets that
|
||||
* resolve to externals are queued in Asm.relocs.
|
||||
*
|
||||
* Encoding subset: the instructions cgen emits today. Operand shapes
|
||||
* we accept:
|
||||
* MOVQ $imm, reg — C7 /0 imm32 (REX.W) [imm fits in i32]
|
||||
@@ -95,8 +91,6 @@ a_addreloc_data(Asm *a, u64 off, int kind, Asym *s, i64 add)
|
||||
a->relocs = r;
|
||||
}
|
||||
|
||||
/* ------ register codes ------------------------------------------- */
|
||||
|
||||
/* low 3 bits of register encoding */
|
||||
static int
|
||||
rcode(int r)
|
||||
@@ -137,14 +131,12 @@ is_xmm(int r)
|
||||
return r >= D_X0 && r <= D_X15;
|
||||
}
|
||||
|
||||
/* ModR/M byte */
|
||||
static u8
|
||||
modrm(int mod, int reg, int rm)
|
||||
{
|
||||
return (u8)(((mod & 3) << 6) | ((reg & 7) << 3) | (rm & 7));
|
||||
}
|
||||
|
||||
/* emit REX with W=1 plus optional R/B for high regs */
|
||||
static void
|
||||
emit_rex(Asm *a, int regbit, int rmbit, int w)
|
||||
{
|
||||
@@ -155,9 +147,7 @@ emit_rex(Asm *a, int regbit, int rmbit, int w)
|
||||
if (b != 0x40 || w) a_emit_byte(a, b);
|
||||
}
|
||||
|
||||
/* encode mod/disp for [base+disp]; returns 0 on ok.
|
||||
* Special-cases SP (needs SIB) and BP (forces disp).
|
||||
*/
|
||||
/* Special-cases SP (needs SIB) and BP (forces disp). */
|
||||
static void
|
||||
emit_modrm_mem(Asm *a, int reg_field, int base, i64 disp)
|
||||
{
|
||||
@@ -191,7 +181,6 @@ encode_rr(Asm *a, u8 opcode, int src, int dst)
|
||||
a_emit_byte(a, modrm(3, rcode(src), rcode(dst)));
|
||||
}
|
||||
|
||||
/* MOVQ src reg → mem(base, disp). opcode = 0x89 */
|
||||
static void
|
||||
encode_rm(Asm *a, u8 opcode, int src_reg, int base, i64 disp)
|
||||
{
|
||||
@@ -200,7 +189,6 @@ encode_rm(Asm *a, u8 opcode, int src_reg, int base, i64 disp)
|
||||
emit_modrm_mem(a, rcode(src_reg), base, disp);
|
||||
}
|
||||
|
||||
/* MOVQ mem(base, disp) → reg. opcode = 0x8B */
|
||||
static void
|
||||
encode_mr(Asm *a, u8 opcode, int dst_reg, int base, i64 disp)
|
||||
{
|
||||
@@ -250,7 +238,7 @@ sse_mr_load(Asm *a, u8 prefix, u8 op2, int reg_op, int base, i64 disp)
|
||||
emit_modrm_mem(a, rcode(reg_op), base, disp);
|
||||
}
|
||||
|
||||
/* like sse_mr_load but encoded with REX.W (used by CVTTSD2SI / CVTSI2SD
|
||||
/* like sse_rr but encoded with REX.W (used by CVTTSD2SI / CVTSI2SD
|
||||
* which target/source 64-bit integer regs) */
|
||||
static void
|
||||
sse_rr_w(Asm *a, u8 prefix, u8 op2, int reg_op, int rm_op)
|
||||
@@ -262,8 +250,6 @@ sse_rr_w(Asm *a, u8 prefix, u8 op2, int reg_op, int rm_op)
|
||||
a_emit_byte(a, modrm(3, rcode(reg_op), rcode(rm_op)));
|
||||
}
|
||||
|
||||
/* ------ second-pass helper: resolve labels to addresses ---------- */
|
||||
|
||||
static u64
|
||||
resolve_label(Asm *a, const char *name)
|
||||
{
|
||||
@@ -281,8 +267,6 @@ label_defined(Asm *a, const char *name)
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* ------ first pass: encode ---------------------------------------- */
|
||||
|
||||
/* For local labels, we record a "fixup" — an offset in .text that
|
||||
* needs to be patched once the label is resolved at end of pass. */
|
||||
typedef struct Fixup Fixup;
|
||||
@@ -307,10 +291,9 @@ int
|
||||
a_encode(Asm *a)
|
||||
{
|
||||
fixups = NULL;
|
||||
const char *cur_text = NULL; /* current TEXT name */
|
||||
const char *cur_text = NULL;
|
||||
(void)cur_text;
|
||||
for (Aprog *p = a->head; p; p = p->link) {
|
||||
/* Define any pending label at the current PC */
|
||||
if (p->label) {
|
||||
Asym *s = a_intern(a, p->label);
|
||||
s->defined = 1;
|
||||
@@ -800,7 +783,6 @@ a_encode(Asm *a)
|
||||
/* R_X86_64_PLT32 (4); addend -4 */
|
||||
a_addreloc(a, reloff, 4, s, -4);
|
||||
} else if (p->to.type == D_BRANCH) {
|
||||
/* local call to a label */
|
||||
a_emit_byte(a, 0xE8);
|
||||
add_fixup(a->textlen, p->to.sym);
|
||||
a_emit_u32(a, 0);
|
||||
@@ -846,7 +828,6 @@ a_encode(Asm *a)
|
||||
}
|
||||
}
|
||||
|
||||
/* second pass: patch fixups */
|
||||
for (Fixup *f = fixups; f; f = f->next) {
|
||||
if (!label_defined(a, f->label)) {
|
||||
fprintf(stderr, "w6a: undefined label '%s'\n", f->label);
|
||||
|
||||
Reference in New Issue
Block a user