generate loongarch64 Linux syscalls

This commit is contained in:
YANG Xudong
2024-02-01 14:31:13 +08:00
committed by Andrew Kelley
parent 95f0dce7da
commit 87150468fc
2 changed files with 373 additions and 0 deletions

View File

@@ -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();
}