Skip to content
Merged
Show file tree
Hide file tree
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
35 changes: 35 additions & 0 deletions tools/regz/src/Database.zig
Original file line number Diff line number Diff line change
Expand Up @@ -1347,7 +1347,42 @@ pub fn get_enum_by_name(
return db.one_alloc(Enum, allocator, query, .{
.struct_id = struct_id,
.name = name,
}) catch |err| switch (err) {
error.MissingEntity => {
// lookup the enum among the parents
var parent_id = struct_id;
var i: u8 = 0;
const max_depth = 10;
while (i <= max_depth) : (i += 1) {
parent_id = db.get_parent_struct_id(parent_id) catch {
return err;
};

log.debug("get_enum_by_name: parent_id={} name='{s}'", .{ parent_id, name });
return db.one_alloc(Enum, allocator, query, .{
.struct_id = parent_id,
.name = name,
}) catch {
continue;
};
}
return err;
},
else => {
return err;
},
};
}

fn get_parent_struct_id(db: *Database, struct_id: StructID) !StructID {
var stmt = try db.sql.prepare("SELECT parent_id FROM struct_decls WHERE struct_id = ?");
defer stmt.deinit();

const row = try stmt.one(StructID, .{}, .{
.struct_id = struct_id,
});

return if (row) |parent_id| parent_id else error.MissingEntity;
}

fn one_alloc(
Expand Down
10 changes: 8 additions & 2 deletions tools/regz/src/atdf.zig
Original file line number Diff line number Diff line change
Expand Up @@ -676,7 +676,10 @@ fn load_field(ctx: *Context, node: xml.Node, peripheral_struct_id: StructID, par
.size_bits = 1,
.offset_bits = i,
.enum_id = if (node.get_attribute("values")) |values| blk: {
const e = try db.get_enum_by_name(arena, peripheral_struct_id, values);
const e = db.get_enum_by_name(arena, peripheral_struct_id, values) catch |err| {
log.warn("{s} failed to get_enum_by_name: {s}", .{ name, values });
return err;
};
break :blk e.id;
} else null,
});
Expand Down Expand Up @@ -722,7 +725,10 @@ fn load_field(ctx: *Context, node: xml.Node, peripheral_struct_id: StructID, par
.size_bits = width,
.offset_bits = offset,
.enum_id = if (node.get_attribute("values")) |values| blk: {
const e = try db.get_enum_by_name(arena, peripheral_struct_id, values);
const e = db.get_enum_by_name(arena, peripheral_struct_id, values) catch |err| {
log.warn("{s} failed to get_enum_by_name: {s}", .{ name, values });
return err;
};
break :blk e.id;
} else null,
});
Expand Down
Loading