| ... | @@ -478,6 +478,60 @@ pub fn main() !void { | ... | @@ -478,6 +478,60 @@ pub fn main() !void { |
| 478 | | 478 | |
| 479 | try writer.writeAll("};\n\n"); | 479 | try writer.writeAll("};\n\n"); |
| 480 | } | 480 | } |
| | 481 | { |
| | 482 | try writer.writeAll("pub const Arc = enum(usize) {\n"); |
| | 483 | |
| | 484 | const child_args = [_][]const u8{ |
| | 485 | zig_exe, |
| | 486 | "cc", |
| | 487 | "-target", |
| | 488 | "arc-freestanding-none", |
| | 489 | "-E", |
| | 490 | "-dD", |
| | 491 | "-P", |
| | 492 | "-nostdinc", |
| | 493 | "-Itools/include", |
| | 494 | "-Itools/include/uapi", |
| | 495 | "-D __SYSCALL(nr, nm)=zigsyscall nm nr", |
| | 496 | "arch/arc/include/uapi/asm/unistd.h", |
| | 497 | }; |
| | 498 | |
| | 499 | const child_result = try std.process.Child.run(.{ |
| | 500 | .allocator = allocator, |
| | 501 | .argv = &child_args, |
| | 502 | .cwd = linux_path, |
| | 503 | .cwd_dir = linux_dir, |
| | 504 | }); |
| | 505 | if (child_result.stderr.len > 0) std.debug.print("{s}\n", .{child_result.stderr}); |
| | 506 | |
| | 507 | const defines = switch (child_result.term) { |
| | 508 | .Exited => |code| if (code == 0) child_result.stdout else { |
| | 509 | std.debug.print("zig cc exited with code {d}\n", .{code}); |
| | 510 | std.process.exit(1); |
| | 511 | }, |
| | 512 | else => { |
| | 513 | std.debug.print("zig cc crashed\n", .{}); |
| | 514 | std.process.exit(1); |
| | 515 | }, |
| | 516 | }; |
| | 517 | |
| | 518 | var lines = mem.tokenizeScalar(u8, defines, '\n'); |
| | 519 | while (lines.next()) |line| { |
| | 520 | var fields = mem.tokenizeAny(u8, line, " "); |
| | 521 | const prefix = fields.next() orelse return error.Incomplete; |
| | 522 | |
| | 523 | if (!mem.eql(u8, prefix, "zigsyscall")) continue; |
| | 524 | |
| | 525 | const sys_name = fields.next() orelse return error.Incomplete; |
| | 526 | const value = fields.rest(); |
| | 527 | const name = (getOverridenNameNew(value) orelse sys_name)["sys_".len..]; |
| | 528 | const fixed_name = if (stdlib_renames_new.get(name)) |f| f else if (stdlib_renames.get(name)) |f| f else name; |
| | 529 | |
| | 530 | try writer.print(" {p} = {s},\n", .{ zig.fmtId(fixed_name), value }); |
| | 531 | } |
| | 532 | |
| | 533 | try writer.writeAll("};\n\n"); |
| | 534 | } |
| 481 | | 535 | |
| 482 | try buf_out.flush(); | 536 | try buf_out.flush(); |
| 483 | } | 537 | } |