Plan 9-style w-prefix on the per-arch tools, disambiguating from the
real Plan 9 6c/6a/6l in ref/plan9front/:
cmd/wwc/ → cmd/wcc/ libwwc.a → libwcc.a
cmd/6{c,a,l} → cmd/w6{c,a,l} binary names too
test/wwc/ → test/wcc/ 6 test files w/ w6 prefix
selfhost/cmd mirror in lockstep
bootstrap/amd64/{w6c,w6a,w6l} snapshot binaries (gitignored)
WW_6{C,A,L} → WW_W6{C,A,L} env-var overrides
Plan 9 source-tree refs ("Plan 9 6c shape", ref/plan9front/, etc.)
preserved. Hare-style driver, both C and ww sides:
ww test [path] discover *_test.ww in a directory module, run
each; single-file mode for `ww test foo.ww`
Module-by-name `ww build foo` resolves to foo.ww or foo/foo.ww
via search path (cwd : -I dirs : $WW_LIB)
Default-to-cwd `ww build` / `ww test` build the cwd module
Run pass-through `ww run path arg1 arg2` reaches the program
lib/os: getcwd (79) and getdents64 (217) syscalls power `.` resolution
and directory enumeration on the ww side.
Makefile: wwstage tool deps now include lib/os/os.ww (+ lib/strconv
for wwdump_ww) so lib/* edits force their rebuild instead of leaving
stale binaries — surfaced when test 995 first failed against a stale
w6c_ww built before the lib/os additions.
Test 993 byte-identical parity gate (C-side ww vs ww-side ww_ww on a
build corpus) stays green; all 19 tests pass.
60 lines
1.4 KiB
C
60 lines
1.4 KiB
C
/*
|
|
* w6a — amd64 assembler driver. Read .s, parse, encode, emit ELF .o.
|
|
*/
|
|
#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;
|
|
}
|