Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update gen.zig to produce just enums #242

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 8 additions & 21 deletions tools/regz/src/gen.zig
Original file line number Diff line number Diff line change
Expand Up @@ -824,29 +824,22 @@ fn write_fields(
} else if (db.attrs.@"enum".get(fields[i].id)) |enum_id| {
if (db.attrs.name.get(enum_id)) |enum_name| {
try writer.print(
\\{}: packed union {{
\\ raw: u{},
\\ value: {},
\\}},
\\{}: {},
taylorh140 marked this conversation as resolved.
Show resolved Hide resolved
\\
, .{
std.zig.fmtId(name),
next.size,
std.zig.fmtId(enum_name),
});
} else {
try writer.print(
\\{}: packed union {{
\\ raw: u{},
\\ value: enum(u{}) {{
\\{}: enum(u{}) {{
taylorh140 marked this conversation as resolved.
Show resolved Hide resolved
\\
, .{
std.zig.fmtId(name),
next.size,
next.size,
});
try write_enum_fields(db, enum_id, writer);
try writer.writeAll("},\n},\n");
try writer.writeAll("},\n");
}
} else {
try writer.print("{}: u{},\n", .{ std.zig.fmtId(name), next.size });
Expand Down Expand Up @@ -1120,10 +1113,7 @@ test "gen.field with named enum" {
\\ };
\\
\\ TEST_REGISTER: mmio.Mmio(packed struct(u8) {
\\ TEST_FIELD: packed union {
\\ raw: u4,
\\ value: TEST_ENUM,
\\ },
\\ TEST_FIELD: TEST_ENUM,
\\ padding: u4,
\\ }),
\\ };
Expand All @@ -1149,13 +1139,10 @@ test "gen.field with anonymous enum" {
\\ pub const peripherals = struct {
\\ pub const TEST_PERIPHERAL = extern struct {
\\ TEST_REGISTER: mmio.Mmio(packed struct(u8) {
\\ TEST_FIELD: packed union {
\\ raw: u4,
\\ value: enum(u4) {
\\ TEST_ENUM_FIELD1 = 0x0,
\\ TEST_ENUM_FIELD2 = 0x1,
\\ _,
\\ },
\\ TEST_FIELD: enum(u4) {
\\ TEST_ENUM_FIELD1 = 0x0,
\\ TEST_ENUM_FIELD2 = 0x1,
\\ _,
\\ },
\\ padding: u4,
\\ }),
Expand Down
Loading