| ... | @@ -532,6 +532,60 @@ pub fn main() !void { | ... | @@ -532,6 +532,60 @@ pub fn main() !void { |
| 532 | | 532 | |
| 533 | try writer.writeAll("};\n\n"); | 533 | try writer.writeAll("};\n\n"); |
| 534 | } | 534 | } |
| | 535 | { |
| | 536 | try writer.writeAll("pub const CSky = enum(usize) {\n"); |
| | 537 | |
| | 538 | const child_args = [_][]const u8{ |
| | 539 | zig_exe, |
| | 540 | "cc", |
| | 541 | "-target", |
| | 542 | "csky-freestanding-none", |
| | 543 | "-E", |
| | 544 | "-dD", |
| | 545 | "-P", |
| | 546 | "-nostdinc", |
| | 547 | "-Itools/include", |
| | 548 | "-Itools/include/uapi", |
| | 549 | "-D __SYSCALL(nr, nm)=zigsyscall nm nr", |
| | 550 | "arch/csky/include/uapi/asm/unistd.h", |
| | 551 | }; |
| | 552 | |
| | 553 | const child_result = try std.process.Child.run(.{ |
| | 554 | .allocator = allocator, |
| | 555 | .argv = &child_args, |
| | 556 | .cwd = linux_path, |
| | 557 | .cwd_dir = linux_dir, |
| | 558 | }); |
| | 559 | if (child_result.stderr.len > 0) std.debug.print("{s}\n", .{child_result.stderr}); |
| | 560 | |
| | 561 | const defines = switch (child_result.term) { |
| | 562 | .Exited => |code| if (code == 0) child_result.stdout else { |
| | 563 | std.debug.print("zig cc exited with code {d}\n", .{code}); |
| | 564 | std.process.exit(1); |
| | 565 | }, |
| | 566 | else => { |
| | 567 | std.debug.print("zig cc crashed\n", .{}); |
| | 568 | std.process.exit(1); |
| | 569 | }, |
| | 570 | }; |
| | 571 | |
| | 572 | var lines = mem.tokenizeScalar(u8, defines, '\n'); |
| | 573 | while (lines.next()) |line| { |
| | 574 | var fields = mem.tokenizeAny(u8, line, " "); |
| | 575 | const prefix = fields.next() orelse return error.Incomplete; |
| | 576 | |
| | 577 | if (!mem.eql(u8, prefix, "zigsyscall")) continue; |
| | 578 | |
| | 579 | const sys_name = fields.next() orelse return error.Incomplete; |
| | 580 | const value = fields.rest(); |
| | 581 | const name = (getOverridenNameNew(value) orelse sys_name)["sys_".len..]; |
| | 582 | const fixed_name = if (stdlib_renames_new.get(name)) |f| f else if (stdlib_renames.get(name)) |f| f else name; |
| | 583 | |
| | 584 | try writer.print(" {p} = {s},\n", .{ zig.fmtId(fixed_name), value }); |
| | 585 | } |
| | 586 | |
| | 587 | try writer.writeAll("};\n\n"); |
| | 588 | } |
| 535 | | 589 | |
| 536 | try buf_out.flush(); | 590 | try buf_out.flush(); |
| 537 | } | 591 | } |