diff --git a/tools/regz/build.zig.zon b/tools/regz/build.zig.zon index 3b66219..e60201d 100644 --- a/tools/regz/build.zig.zon +++ b/tools/regz/build.zig.zon @@ -3,8 +3,8 @@ .version = "0.0.0", .dependencies = .{ .clap = .{ - .url = "https://github.com/Hejsil/zig-clap/archive/3d78af4b000758abe6c6761cbf61f5a66abe4f10.tar.gz", - .hash = "1220ae43eccd3940d287e9e62bf84897040d0cc9e82c970b59c5703d7fd733d0213f", + .url = "https://github.com/Hejsil/zig-clap/archive/bdb5853b678d68f342ec65b04a6785af522ca6c9.tar.gz", + .hash = "12202af04ec78191f2018458a7be29f54e0d9118f7688e7a226857acf754d68b8473", }, }, } diff --git a/tools/regz/src/arch/arm/nvic.zig b/tools/regz/src/arch/arm/nvic.zig index 5a781da..ee5c94f 100644 --- a/tools/regz/src/arch/arm/nvic.zig +++ b/tools/regz/src/arch/arm/nvic.zig @@ -84,7 +84,7 @@ pub fn load(db: *Database, device_id: EntityId) !void { for (interrupt_registers) |register| { _ = try db.create_field(register, .{ .name = interrupt_name, - .offset = @bitCast(u32, interrupt_index), + .offset = @as(u32, @bitCast(interrupt_index)), .size = 1, }); } @@ -100,7 +100,7 @@ pub fn load(db: *Database, device_id: EntityId) !void { const reg_id = try db.get_entity_id_by_name("type.register", reg_name); _ = try db.create_field(reg_id, .{ .name = interrupt_name, - .offset = (8 * (@intCast(u8, interrupt_index) % 4)) + (8 - nvic_prio_bits), + .offset = (8 * (@as(u8, @intCast(interrupt_index)) % 4)) + (8 - nvic_prio_bits), .size = nvic_prio_bits, }); } diff --git a/tools/regz/src/atdf.zig b/tools/regz/src/atdf.zig index b550b6b..d21b44f 100644 --- a/tools/regz/src/atdf.zig +++ b/tools/regz/src/atdf.zig @@ -639,7 +639,7 @@ fn load_field(ctx: *Context, node: xml.Node, register_id: EntityId) !void { var bit_count: u32 = 0; var i = offset; while (i < 32) : (i += 1) { - if (0 != (@as(u64, 1) << @intCast(u5, i)) & mask) { + if (0 != (@as(u64, 1) << @as(u5, @intCast(i))) & mask) { const field_name = try std.fmt.allocPrint(db.arena.allocator(), "{s}_bit{}", .{ name, bit_count, diff --git a/tools/regz/src/gen.zig b/tools/regz/src/gen.zig index b7e251a..75a9c39 100644 --- a/tools/regz/src/gen.zig +++ b/tools/regz/src/gen.zig @@ -42,7 +42,7 @@ pub fn to_zig(db: Database, out_writer: anytype) !void { try writer.writeByte(0); // format the generated code - var ast = try std.zig.Ast.parse(db.gpa, @ptrCast([:0]const u8, buffer.items[0 .. buffer.items.len - 1]), .zig); + var ast = try std.zig.Ast.parse(db.gpa, @as([:0]const u8, @ptrCast(buffer.items[0 .. buffer.items.len - 1])), .zig); defer ast.deinit(db.gpa); // TODO: ast check? @@ -262,7 +262,7 @@ fn write_peripheral_instance(db: Database, instance_id: EntityId, offset: u64, o else ""; - try writer.print("pub const {s} = @intToPtr(*volatile {s}{s}, 0x{x});\n", .{ + try writer.print("pub const {s} = @as(*volatile {s}{s}, @ptrFromInt(0x{x}));\n", .{ std.zig.fmtId(name), array_prefix, type_ref, @@ -906,7 +906,7 @@ test "gen.peripheral instantiation" { \\pub const devices = struct { \\ pub const TEST_DEVICE = struct { \\ pub const peripherals = struct { - \\ pub const TEST0 = @intToPtr(*volatile types.peripherals.TEST_PERIPHERAL, 0x1000); + \\ pub const TEST0 = @as(*volatile types.peripherals.TEST_PERIPHERAL, @ptrFromInt(0x1000)); \\ }; \\ }; \\}; @@ -940,8 +940,8 @@ test "gen.peripherals with a shared type" { \\pub const devices = struct { \\ pub const TEST_DEVICE = struct { \\ pub const peripherals = struct { - \\ pub const TEST0 = @intToPtr(*volatile types.peripherals.TEST_PERIPHERAL, 0x1000); - \\ pub const TEST1 = @intToPtr(*volatile types.peripherals.TEST_PERIPHERAL, 0x2000); + \\ pub const TEST0 = @as(*volatile types.peripherals.TEST_PERIPHERAL, @ptrFromInt(0x1000)); + \\ pub const TEST1 = @as(*volatile types.peripherals.TEST_PERIPHERAL, @ptrFromInt(0x2000)); \\ }; \\ }; \\}; @@ -1160,8 +1160,8 @@ test "gen.namespaced register groups" { \\pub const devices = struct { \\ pub const ATmega328P = struct { \\ pub const peripherals = struct { - \\ pub const PORTB = @intToPtr(*volatile types.peripherals.PORT.PORTB, 0x23); - \\ pub const PORTC = @intToPtr(*volatile types.peripherals.PORT.PORTC, 0x26); + \\ pub const PORTB = @as(*volatile types.peripherals.PORT.PORTB, @ptrFromInt(0x23)); + \\ pub const PORTC = @as(*volatile types.peripherals.PORT.PORTC, @ptrFromInt(0x26)); \\ }; \\ }; \\}; @@ -1202,7 +1202,7 @@ test "gen.peripheral with reserved register" { \\pub const devices = struct { \\ pub const ATmega328P = struct { \\ pub const peripherals = struct { - \\ pub const PORTB = @intToPtr(*volatile types.peripherals.PORTB, 0x23); + \\ pub const PORTB = @as(*volatile types.peripherals.PORTB, @ptrFromInt(0x23)); \\ }; \\ }; \\}; @@ -1235,7 +1235,7 @@ test "gen.peripheral with count" { \\pub const devices = struct { \\ pub const ATmega328P = struct { \\ pub const peripherals = struct { - \\ pub const PORTB = @intToPtr(*volatile [4]types.peripherals.PORTB, 0x23); + \\ pub const PORTB = @as(*volatile [4]types.peripherals.PORTB, @ptrFromInt(0x23)); \\ }; \\ }; \\}; @@ -1268,7 +1268,7 @@ test "gen.peripheral with count, padding required" { \\pub const devices = struct { \\ pub const ATmega328P = struct { \\ pub const peripherals = struct { - \\ pub const PORTB = @intToPtr(*volatile [4]types.peripherals.PORTB, 0x23); + \\ pub const PORTB = @as(*volatile [4]types.peripherals.PORTB, @ptrFromInt(0x23)); \\ }; \\ }; \\}; @@ -1302,7 +1302,7 @@ test "gen.register with count" { \\pub const devices = struct { \\ pub const ATmega328P = struct { \\ pub const peripherals = struct { - \\ pub const PORTB = @intToPtr(*volatile types.peripherals.PORTB, 0x23); + \\ pub const PORTB = @as(*volatile types.peripherals.PORTB, @ptrFromInt(0x23)); \\ }; \\ }; \\}; @@ -1335,7 +1335,7 @@ test "gen.register with count and fields" { \\pub const devices = struct { \\ pub const ATmega328P = struct { \\ pub const peripherals = struct { - \\ pub const PORTB = @intToPtr(*volatile types.peripherals.PORTB, 0x23); + \\ pub const PORTB = @as(*volatile types.peripherals.PORTB, @ptrFromInt(0x23)); \\ }; \\ }; \\}; diff --git a/tools/regz/src/main.zig b/tools/regz/src/main.zig index 8361d0d..de4ca57 100644 --- a/tools/regz/src/main.zig +++ b/tools/regz/src/main.zig @@ -152,9 +152,9 @@ fn read_fn(ctx: ?*anyopaque, buffer: ?[*]u8, len: c_int) callconv(.C) c_int { return -1; return if (ctx) |c| blk: { - const reader = @ptrCast(*std.fs.File.Reader, @alignCast(@alignOf(*std.fs.File.Reader), c)); - const n = reader.read(buffer.?[0..@intCast(usize, len)]) catch return -1; - break :blk @intCast(c_int, n); + const reader = @as(*std.fs.File.Reader, @ptrCast(@alignCast(c))); + const n = reader.read(buffer.?[0..@as(usize, @intCast(len))]) catch return -1; + break :blk @as(c_int, @intCast(n)); } else -1; } diff --git a/tools/regz/src/mmio.zig b/tools/regz/src/mmio.zig index 4a9187a..950a55b 100644 --- a/tools/regz/src/mmio.zig +++ b/tools/regz/src/mmio.zig @@ -20,13 +20,13 @@ pub fn Mmio(comptime size: u8, comptime PackedT: type) type { pub const underlying_type = PackedT; pub inline fn read(addr: *volatile Self) PackedT { - return @bitCast(PackedT, addr.raw); + return @as(PackedT, @bitCast(addr.raw)); } pub inline fn write(addr: *volatile Self, val: PackedT) void { // This is a workaround for a compiler bug related to miscompilation // If the tmp var is not used, result location will fuck things up - var tmp = @bitCast(IntT, val); + var tmp = @as(IntT, @bitCast(val)); addr.raw = tmp; } diff --git a/tools/regz/src/regzon.zig b/tools/regz/src/regzon.zig index be2796b..166d394 100644 --- a/tools/regz/src/regzon.zig +++ b/tools/regz/src/regzon.zig @@ -48,7 +48,7 @@ fn get_array(val: Value) !Array { // TODO: handle edge cases fn get_integer_from_object(obj: ObjectMap, comptime T: type, key: []const u8) !?T { return switch (obj.get(key) orelse return null) { - .integer => |num| @intCast(T, num), + .integer => |num| @as(T, @intCast(num)), else => return error.NotJsonInteger, }; } @@ -247,7 +247,7 @@ fn load_peripheral( .description = try get_string_from_object(peripheral, "description"), .size = if (peripheral.get("size")) |size_val| switch (size_val) { - .integer => |num| @intCast(u64, num), + .integer => |num| @as(u64, @intCast(num)), else => return error.SizeNotInteger, } else @@ -633,19 +633,19 @@ fn populate_type( try typ.put("description", .{ .string = description }); if (db.attrs.offset.get(id)) |offset| - try typ.put("offset", .{ .integer = @intCast(i64, offset) }); + try typ.put("offset", .{ .integer = @as(i64, @intCast(offset)) }); if (db.attrs.size.get(id)) |size| - try typ.put("size", .{ .integer = @intCast(i64, size) }); + try typ.put("size", .{ .integer = @as(i64, @intCast(size)) }); if (db.attrs.count.get(id)) |count| - try typ.put("count", .{ .integer = @intCast(i64, count) }); + try typ.put("count", .{ .integer = @as(i64, @intCast(count)) }); if (db.attrs.reset_value.get(id)) |reset_value| - try typ.put("reset_value", .{ .integer = @intCast(i64, reset_value) }); + try typ.put("reset_value", .{ .integer = @as(i64, @intCast(reset_value)) }); if (db.attrs.reset_mask.get(id)) |reset_mask| - try typ.put("reset_mask", .{ .integer = @intCast(i64, reset_mask) }); + try typ.put("reset_mask", .{ .integer = @as(i64, @intCast(reset_mask)) }); if (db.attrs.version.get(id)) |version| try typ.put("version", .{ .string = version }); @@ -798,13 +798,13 @@ fn populate_peripheral( try peripheral.put("description", .{ .string = description }); if (db.attrs.offset.get(id)) |offset| - try peripheral.put("offset", .{ .integer = @intCast(i64, offset) }); + try peripheral.put("offset", .{ .integer = @as(i64, @intCast(offset)) }); if (db.attrs.version.get(id)) |version| try peripheral.put("version", .{ .string = version }); if (db.attrs.count.get(id)) |count| - try peripheral.put("count", .{ .integer = @intCast(i64, count) }); + try peripheral.put("count", .{ .integer = @as(i64, @intCast(count)) }); // TODO: handle collisions -- will need to inline the type const type_ref = try id_to_ref( diff --git a/tools/regz/src/xml.zig b/tools/regz/src/xml.zig index 3374f6c..71628bd 100644 --- a/tools/regz/src/xml.zig +++ b/tools/regz/src/xml.zig @@ -46,7 +46,7 @@ pub const Node = struct { pub fn next(it: *AttrIterator) ?Entry { return if (it.attr) |attr| ret: { if (attr.name) |name| - if (@ptrCast(*c.xmlNode, attr.children).content) |content| { + if (@as(*c.xmlNode, @ptrCast(attr.children)).content) |content| { defer it.attr = attr.next; break :ret Entry{ .key = std.mem.span(name), @@ -59,8 +59,8 @@ pub const Node = struct { pub fn get_attribute(node: Node, key: [:0]const u8) ?[]const u8 { if (c.xmlHasProp(node.impl, key.ptr)) |prop| { - if (@ptrCast(*c.xmlAttr, prop).children) |value_node| { - if (@ptrCast(*c.xmlNode, value_node).content) |content| { + if (@as(*c.xmlAttr, @ptrCast(prop)).children) |value_node| { + if (@as(*c.xmlNode, @ptrCast(value_node)).content) |content| { return std.mem.span(content); } } @@ -70,7 +70,7 @@ pub const Node = struct { } pub fn find_child(node: Node, key: []const u8) ?Node { - var it = @ptrCast(?*c.xmlNode, node.impl.children); + var it = @as(?*c.xmlNode, @ptrCast(node.impl.children)); return while (it != null) : (it = it.?.next) { if (it.?.type != 1) continue; @@ -107,7 +107,7 @@ pub const Node = struct { pub fn get_value(node: Node, key: []const u8) ?[:0]const u8 { return if (node.find_child(key)) |child| if (child.impl.children) |value_node| - if (@ptrCast(*c.xmlNode, value_node).content) |content| + if (@as(*c.xmlNode, @ptrCast(value_node)).content) |content| std.mem.span(content) else null @@ -135,7 +135,7 @@ pub const Doc = struct { return Doc{ .impl = c.xmlReadMemory( text.ptr, - @intCast(c_int, text.len), + @as(c_int, @intCast(text.len)), null, null, 0,