selfhost/cmd/{w6c,w6a,w6l}: drop snake_case from main.ww drivers
This commit is contained in:
@@ -21,7 +21,7 @@ use sym;
|
||||
use check;
|
||||
use cgen;
|
||||
|
||||
fn streq_cs(a: *u8, lit: str) bool = {
|
||||
fn cstreq(a: *u8, lit: str) bool = {
|
||||
let n: u64 = lit.len: u64;
|
||||
let i: u64 = 0u64;
|
||||
for (i < n) {
|
||||
@@ -39,8 +39,8 @@ fn cstrlen(p: *u8) u64 = {
|
||||
return n;
|
||||
};
|
||||
|
||||
fn slurp(path_cs: *u8) (*u8, u64) = {
|
||||
let fd: i32 = os.open(path_cs, os.O_RDONLY, 0i32);
|
||||
fn slurp(path: *u8) (*u8, u64) = {
|
||||
let fd: i32 = os.open(path, os.O_RDONLY, 0i32);
|
||||
if (fd < 0) { return nil, 0u64; };
|
||||
let n: i64 = os.filesize(fd);
|
||||
if (n < 0i64) { os.close(fd); return nil, 0u64; };
|
||||
@@ -54,40 +54,40 @@ fn slurp(path_cs: *u8) (*u8, u64) = {
|
||||
};
|
||||
|
||||
export fn main(argc: i32, argv: **u8) i32 = {
|
||||
let src_cs: *u8 = nil;
|
||||
let out_cs: *u8 = nil;
|
||||
let src: *u8 = nil;
|
||||
let out: *u8 = nil;
|
||||
|
||||
let i: i32 = 1;
|
||||
for (i < argc) {
|
||||
let a: *u8 = argv[i];
|
||||
if (streq_cs(a, "-o")) {
|
||||
if (cstreq(a, "-o")) {
|
||||
i += 1;
|
||||
if (i >= argc) {
|
||||
os.write(2, "w6c: -o requires arg\n".ptr, 20u64);
|
||||
return 2;
|
||||
};
|
||||
out_cs = argv[i];
|
||||
out = argv[i];
|
||||
} else { if (a[0u64] == 45u8) {
|
||||
os.write(2, "w6c: unknown flag\n".ptr, 17u64);
|
||||
return 2;
|
||||
} else {
|
||||
if (src_cs != nil) {
|
||||
if (src != nil) {
|
||||
os.write(2, "w6c: only one input\n".ptr, 19u64);
|
||||
return 2;
|
||||
};
|
||||
src_cs = a;
|
||||
src = a;
|
||||
}; };
|
||||
i += 1;
|
||||
};
|
||||
|
||||
if (src_cs == nil) {
|
||||
if (src == nil) {
|
||||
os.write(2, "usage: w6c_ww [-o out.s] file.ww\n".ptr, 32u64);
|
||||
return 2;
|
||||
};
|
||||
|
||||
let buf: *u8;
|
||||
let blen: u64;
|
||||
buf, blen = slurp(src_cs);
|
||||
buf, blen = slurp(src);
|
||||
if (buf == nil) {
|
||||
os.write(2, "w6c: cannot read input\n".ptr, 22u64);
|
||||
return 1;
|
||||
@@ -96,8 +96,8 @@ export fn main(argc: i32, argv: **u8) i32 = {
|
||||
// Redirect fd 1 to the output file before any cgen emit runs.
|
||||
// cgen.ww writes directly to fd 1; dup2 lets us reuse it without
|
||||
// threading a file descriptor through the emit helpers.
|
||||
if (out_cs != nil) {
|
||||
let ofd: i32 = os.open(out_cs,
|
||||
if (out != nil) {
|
||||
let ofd: i32 = os.open(out,
|
||||
os.O_WRONLY | os.O_CREAT | os.O_TRUNC, 420i32); // 0o644
|
||||
if (ofd < 0) {
|
||||
os.write(2, "w6c: cannot open output\n".ptr, 23u64);
|
||||
@@ -112,8 +112,8 @@ export fn main(argc: i32, argv: **u8) i32 = {
|
||||
};
|
||||
|
||||
let ar: *arena = newarena();
|
||||
let nlen: u64 = cstrlen(src_cs);
|
||||
let fname: str = astrndup(ar, src_cs, nlen);
|
||||
let nlen: u64 = cstrlen(src);
|
||||
let fname: str = astrndup(ar, src, nlen);
|
||||
|
||||
let l: lex;
|
||||
lexinit(&l, ar, fname, buf, blen);
|
||||
|
||||
Reference in New Issue
Block a user