diff options
| author | YANG Xudong <yangxudong@ymatrix.cn> | 2024-02-01 14:31:13 +0800 |
|---|---|---|
| committer | Andrew Kelley <andrew@ziglang.org> | 2024-06-05 18:54:14 -0400 |
| commit | 87150468fc25f2ad70abcc1428112bfb8d31843a (patch) | |
| tree | bd972036fc484318721ddbd2d9016ab066ceca4e /tools/generate_linux_syscalls.zig | |
| parent | 95f0dce7dae258fc2cf9947fdaad26d768902373 (diff) | |
| download | zig-87150468fc25f2ad70abcc1428112bfb8d31843a.tar.gz zig-87150468fc25f2ad70abcc1428112bfb8d31843a.zip | |
generate loongarch64 Linux syscalls
Diffstat (limited to 'tools/generate_linux_syscalls.zig')
| -rw-r--r-- | tools/generate_linux_syscalls.zig | 64 |
1 files changed, 64 insertions, 0 deletions
diff --git a/tools/generate_linux_syscalls.zig b/tools/generate_linux_syscalls.zig index 3e09875e4d..a356cbdd03 100644 --- a/tools/generate_linux_syscalls.zig +++ b/tools/generate_linux_syscalls.zig @@ -362,6 +362,70 @@ pub fn main() !void { \\ ); } + { + try writer.writeAll( + \\ + \\pub const LoongArch64 = enum(usize) { + \\ + ); + + const child_args = [_][]const u8{ + zig_exe, + "cc", + "-march=loongarch64", + "-target", + "loongarch64-linux-gnu", + "-E", + "-dD", + "-P", + "-nostdinc", + "-Iinclude", + "-Iinclude/uapi", + "arch/loongarch/include/uapi/asm/unistd.h", + }; + + const child_result = try std.process.Child.run(.{ + .allocator = allocator, + .argv = &child_args, + .cwd = linux_path, + .cwd_dir = linux_dir, + }); + if (child_result.stderr.len > 0) std.debug.print("{s}\n", .{child_result.stderr}); + + const defines = switch (child_result.term) { + .Exited => |code| if (code == 0) child_result.stdout else { + std.debug.print("zig cc exited with code {d}\n", .{code}); + std.process.exit(1); + }, + else => { + std.debug.print("zig cc crashed\n", .{}); + std.process.exit(1); + }, + }; + + var lines = mem.tokenizeScalar(u8, defines, '\n'); + loop: while (lines.next()) |line| { + var fields = mem.tokenizeAny(u8, line, " \t"); + const cmd = fields.next() orelse return error.Incomplete; + if (!mem.eql(u8, cmd, "#define")) continue; + const define = fields.next() orelse return error.Incomplete; + const number = fields.next() orelse continue; + + if (!std.ascii.isDigit(number[0])) continue; + if (!mem.startsWith(u8, define, "__NR")) continue; + const name = mem.trimLeft(u8, mem.trimLeft(u8, define, "__NR3264_"), "__NR_"); + if (mem.eql(u8, name, "arch_specific_syscall")) continue; + if (mem.eql(u8, name, "syscalls")) break :loop; + + const fixed_name = if (stdlib_renames.get(name)) |fixed| fixed else name; + try writer.print(" {p} = {s},\n", .{ zig.fmtId(fixed_name), number }); + } + + try writer.writeAll( + \\}; + \\ + ); + } try buf_out.flush(); } |
