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).
57 lines
1.3 KiB
C
57 lines
1.3 KiB
C
#include "a.h"
|
|
#include <stdio.h>
|
|
#include <stdlib.h>
|
|
#include <string.h>
|
|
|
|
static int
|
|
slurp(const char *path, char **buf, u64 *len)
|
|
{
|
|
FILE *f = fopen(path, "rb");
|
|
if (f == NULL) return -1;
|
|
fseek(f, 0, SEEK_END);
|
|
long n = ftell(f);
|
|
fseek(f, 0, SEEK_SET);
|
|
if (n < 0) { fclose(f); return -1; }
|
|
char *b = malloc((size_t)n + 1);
|
|
if (fread(b, 1, (size_t)n, f) != (size_t)n) { free(b); fclose(f); return -1; }
|
|
b[n] = 0;
|
|
fclose(f);
|
|
*buf = b;
|
|
*len = (u64)n;
|
|
return 0;
|
|
}
|
|
|
|
int
|
|
main(int argc, char **argv)
|
|
{
|
|
const char *src = NULL;
|
|
const char *out = NULL;
|
|
for (int i = 1; i < argc; i++) {
|
|
if (strcmp(argv[i], "-o") == 0 && i + 1 < argc) out = argv[++i];
|
|
else if (argv[i][0] == '-') {
|
|
fprintf(stderr, "w6a: unknown flag %s\n", argv[i]); return 2;
|
|
} else if (src == NULL) src = argv[i];
|
|
else { fprintf(stderr, "w6a: only one input\n"); return 2; }
|
|
}
|
|
if (src == NULL || out == NULL) {
|
|
fputs("usage: w6a -o file.o file.s\n", stderr);
|
|
return 2;
|
|
}
|
|
char *buf;
|
|
u64 len;
|
|
if (slurp(src, &buf, &len) < 0) {
|
|
fprintf(stderr, "w6a: cannot read %s\n", src);
|
|
return 1;
|
|
}
|
|
Asm a;
|
|
a_init(&a, src, buf, len);
|
|
if (a_parse(&a) != 0) return 1;
|
|
if (a_encode(&a) != 0) return 1;
|
|
FILE *f = fopen(out, "wb");
|
|
if (f == NULL) { fprintf(stderr, "w6a: cannot open %s\n", out); return 1; }
|
|
int rc = a_emit_elf(&a, f);
|
|
fclose(f);
|
|
free(buf);
|
|
return rc;
|
|
}
|