Skip to content

Commit

Permalink
Lower case type enums in bswap (#2029)
Browse files Browse the repository at this point in the history
this code is only analyzed on big-endian.
  • Loading branch information
mnemnion authored Sep 15, 2024
1 parent 961d615 commit 2464998
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions src/ZigCompileServer.zig
Original file line number Diff line number Diff line change
Expand Up @@ -119,21 +119,21 @@ fn bswap(x: anytype) @TypeOf(x) {

const T = @TypeOf(x);
switch (@typeInfo(T)) {
.Enum => return @as(T, @enumFromInt(@byteSwap(@intFromEnum(x)))),
.Int => return @byteSwap(x),
.Struct => |info| switch (info.layout) {
.Extern => {
.@"enum" => return @as(T, @enumFromInt(@byteSwap(@intFromEnum(x)))),
.int => return @byteSwap(x),
.@"struct" => |info| switch (info.layout) {
.@"extern" => {
var result: T = undefined;
inline for (info.fields) |field| {
@field(result, field.name) = bswap(@field(x, field.name));
}
return result;
},
.Packed => {
.@"packed" => {
const I = info.backing_integer.?;
return @as(T, @bitCast(@byteSwap(@as(I, @bitCast(x)))));
},
.Auto => @compileError("auto layout struct"),
.auto => @compileError("auto layout struct"),
},
else => @compileError("bswap on type " ++ @typeName(T)),
}
Expand Down

0 comments on commit 2464998

Please sign in to comment.