authorgravatar for alex@alexrp.comAlex Rønne Petersen <alex@alexrp.com> 2024-07-26 02:51:03+02:00
committergravatar for alex@alexrp.comAlex Rønne Petersen <alex@alexrp.com> 2024-07-30 01:32:47+02:00
logc9664cb657e8bd30fefdd2eb4249e89d75edc91a
treed42ccb37ebd3d4357a44ba9f04f8eb2c0a3c1851
parent38e0f049c531e83ec2eec80d50b624e6c3b8c486
signaturebadge-check Signed by SSH key SHA256:7B/LJ7bpR1eX8aCXSr4mtd5M45VMPKcx9zY8e95b5QM

generate_linux_syscalls: Bring loongarch64 generation code in line with other newer ports.


1 files changed, 14 insertions(+), 23 deletions(-)

tools/generate_linux_syscalls.zig+14-23
...@@ -427,16 +427,11 @@ pub fn main() !void {...@@ -427,16 +427,11 @@ pub fn main() !void {
427 try writer.writeAll("};\n\n");427 try writer.writeAll("};\n\n");
428 }428 }
429 {429 {
430 try writer.writeAll(430 try writer.writeAll("pub const LoongArch64 = enum(usize) {\n");
431 \\
432 \\pub const LoongArch64 = enum(usize) {
433 \\
434 );
435431
436 const child_args = [_][]const u8{432 const child_args = [_][]const u8{
437 zig_exe,433 zig_exe,
438 "cc",434 "cc",
439 "-march=loongarch64",
440 "-target",435 "-target",
441 "loongarch64-linux-gnu",436 "loongarch64-linux-gnu",
442 "-E",437 "-E",
...@@ -445,6 +440,8 @@ pub fn main() !void {...@@ -445,6 +440,8 @@ pub fn main() !void {
445 "-nostdinc",440 "-nostdinc",
446 "-Iinclude",441 "-Iinclude",
447 "-Iinclude/uapi",442 "-Iinclude/uapi",
443 "-Iarch/loongarch/include/uapi",
444 "-D __SYSCALL(nr, nm)=zigsyscall nm nr",
448 "arch/loongarch/include/uapi/asm/unistd.h",445 "arch/loongarch/include/uapi/asm/unistd.h",
449 };446 };
450447
...@@ -468,27 +465,21 @@ pub fn main() !void {...@@ -468,27 +465,21 @@ pub fn main() !void {
468 };465 };
469466
470 var lines = mem.tokenizeScalar(u8, defines, '\n');467 var lines = mem.tokenizeScalar(u8, defines, '\n');
471 loop: while (lines.next()) |line| {468 while (lines.next()) |line| {
472 var fields = mem.tokenizeAny(u8, line, " \t");469 var fields = mem.tokenizeAny(u8, line, " ");
473 const cmd = fields.next() orelse return error.Incomplete;470 const prefix = fields.next() orelse return error.Incomplete;
474 if (!mem.eql(u8, cmd, "#define")) continue;
475 const define = fields.next() orelse return error.Incomplete;
476 const number = fields.next() orelse continue;
477471
478 if (!std.ascii.isDigit(number[0])) continue;472 if (!mem.eql(u8, prefix, "zigsyscall")) continue;
479 if (!mem.startsWith(u8, define, "__NR")) continue;
480 const name = mem.trimLeft(u8, mem.trimLeft(u8, define, "__NR3264_"), "__NR_");
481 if (mem.eql(u8, name, "arch_specific_syscall")) continue;
482 if (mem.eql(u8, name, "syscalls")) break :loop;
483473
484 const fixed_name = if (stdlib_renames.get(name)) |fixed| fixed else name;474 const sys_name = fields.next() orelse return error.Incomplete;
485 try writer.print(" {p} = {s},\n", .{ zig.fmtId(fixed_name), number });475 const value = fields.rest();
476 const name = (getOverridenNameNew(value) orelse sys_name)["sys_".len..];
477 const fixed_name = if (stdlib_renames_new.get(name)) |f| f else if (stdlib_renames.get(name)) |f| f else name;
478
479 try writer.print(" {p} = {s},\n", .{ zig.fmtId(fixed_name), value });
486 }480 }
487481
488 try writer.writeAll(482 try writer.writeAll("};\n\n");
489 \\};
490 \\
491 );
492 }483 }
493484
494 try buf_out.flush();485 try buf_out.flush();