diff options
Diffstat (limited to 'src/type')
| -rw-r--r-- | src/type/Enum.zig | 55 | ||||
| -rw-r--r-- | src/type/Struct.zig | 56 | ||||
| -rw-r--r-- | src/type/Union.zig | 56 |
3 files changed, 167 insertions, 0 deletions
diff --git a/src/type/Enum.zig b/src/type/Enum.zig new file mode 100644 index 0000000000..9b9ec5b319 --- /dev/null +++ b/src/type/Enum.zig @@ -0,0 +1,55 @@ +const std = @import("std"); +const zir = @import("../zir.zig"); +const Value = @import("../value.zig").Value; +const Type = @import("../type.zig").Type; +const Module = @import("../Module.zig"); +const Scope = Module.Scope; +const Enum = @This(); + +base: Type.Payload = .{ .tag = .@"enum" }, + +analysis: union(enum) { + queued: Zir, + in_progress, + resolved: Size, + failed, +}, +scope: Scope.Container, + +pub const Field = struct { + value: Value, +}; + +pub const Zir = struct { + body: zir.Module.Body, + inst: *zir.Inst, +}; + +pub const Size = struct { + tag_type: Type, + fields: std.StringArrayHashMapUnmanaged(Field), +}; + +pub fn resolve(self: *Enum, mod: *Module, scope: *Scope) !void { + const zir = switch (self.analysis) { + .failed => return error.AnalysisFail, + .resolved => return, + .in_progress => { + return mod.fail(scope, src, "enum '{}' depends on itself", .{enum_name}); + }, + .queued => |zir| zir, + }; + self.analysis = .in_progress; + + // TODO +} + +// TODO should this resolve the type or assert that it has already been resolved? +pub fn abiAlignment(self: *Enum, target: std.Target) u32 { + switch (self.analysis) { + .queued => unreachable, // alignment has not been resolved + .in_progress => unreachable, // alignment has not been resolved + .failed => unreachable, // type resolution failed + .resolved => |r| return r.tag_type.abiAlignment(target), + } +} diff --git a/src/type/Struct.zig b/src/type/Struct.zig new file mode 100644 index 0000000000..d6a591c95e --- /dev/null +++ b/src/type/Struct.zig @@ -0,0 +1,56 @@ +const std = @import("std"); +const zir = @import("../zir.zig"); +const Value = @import("../value.zig").Value; +const Type = @import("../type.zig").Type; +const Module = @import("../Module.zig"); +const Scope = Module.Scope; +const Struct = @This(); + +base: Type.Payload = .{ .tag = .@"struct" }, + +analysis: union(enum) { + queued: Zir, + zero_bits_in_progress, + zero_bits: Zero, + in_progress, + // alignment: Align, + resolved: Size, + failed, +}, +scope: Scope.Container, + +pub const Field = struct { + value: Value, +}; + +pub const Zir = struct { + body: zir.Module.Body, + inst: *zir.Inst, +}; + +pub const Zero = struct { + is_zero_bits: bool, + fields: std.StringArrayHashMapUnmanaged(Field), +}; + +pub const Size = struct { + is_zero_bits: bool, + alignment: u32, + size: u32, + fields: std.StringArrayHashMapUnmanaged(Field), +}; + +pub fn resolveZeroBits(self: *Struct, mod: *Module, scope: *Scope) !void { + const zir = switch (self.analysis) { + .failed => return error.AnalysisFail, + .zero_bits_in_progress => { + return mod.fail(scope, src, "struct '{}' depends on itself", .{}); + }, + .queued => |zir| zir, + else => return, + }; + + self.analysis = .zero_bits_in_progress; + + // TODO +} diff --git a/src/type/Union.zig b/src/type/Union.zig new file mode 100644 index 0000000000..26cc1796c6 --- /dev/null +++ b/src/type/Union.zig @@ -0,0 +1,56 @@ +const std = @import("std"); +const zir = @import("../zir.zig"); +const Value = @import("../value.zig").Value; +const Type = @import("../type.zig").Type; +const Module = @import("../Module.zig"); +const Scope = Module.Scope; +const Union = @This(); + +base: Type.Payload = .{ .tag = .@"struct" }, + +analysis: union(enum) { + queued: Zir, + zero_bits_in_progress, + zero_bits: Zero, + in_progress, + // alignment: Align, + resolved: Size, + failed, +}, +scope: Scope.Container, + +pub const Field = struct { + value: Value, +}; + +pub const Zir = struct { + body: zir.Module.Body, + inst: *zir.Inst, +}; + +pub const Zero = struct { + is_zero_bits: bool, + fields: std.StringArrayHashMapUnmanaged(Field), +}; + +pub const Size = struct { + is_zero_bits: bool, + alignment: u32, + size: u32, + fields: std.StringArrayHashMapUnmanaged(Field), +}; + +pub fn resolveZeroBits(self: *Union, mod: *Module, scope: *Scope) !void { + const zir = switch (self.analysis) { + .failed => return error.AnalysisFail, + .zero_bits_in_progress => { + return mod.fail(scope, src, "union '{}' depends on itself", .{}); + }, + .queued => |zir| zir, + else => return, + }; + + self.analysis = .zero_bits_in_progress; + + // TODO +} |
