diff options
| author | Andrew Kelley <andrew@ziglang.org> | 2020-04-21 17:11:42 -0400 |
|---|---|---|
| committer | Andrew Kelley <andrew@ziglang.org> | 2020-04-21 17:11:42 -0400 |
| commit | 25679b63eb01b7f4b1fb031afb9e355b90b2ea86 (patch) | |
| tree | f16c7263e4732c4bc6c4cac66f67332ab8804035 | |
| parent | 8671e8d6d4e570b104014859eaa66d70a0991217 (diff) | |
| download | zig-25679b63eb01b7f4b1fb031afb9e355b90b2ea86.tar.gz zig-25679b63eb01b7f4b1fb031afb9e355b90b2ea86.zip | |
ir: analyze primitive instruction
| -rw-r--r-- | src-self-hosted/ir.zig | 6 | ||||
| -rw-r--r-- | src-self-hosted/ir/text.zig | 33 |
2 files changed, 34 insertions, 5 deletions
diff --git a/src-self-hosted/ir.zig b/src-self-hosted/ir.zig index ca68e64bd5..593dc2b65f 100644 --- a/src-self-hosted/ir.zig +++ b/src-self-hosted/ir.zig @@ -280,7 +280,7 @@ const Analyze = struct { .@"unreachable" => return self.fail(old_inst.src, "TODO implement analyzing {}", .{@tagName(old_inst.tag)}), .@"fn" => return self.analyzeInstFn(func, old_inst.cast(text.Inst.Fn).?), .@"export" => return self.fail(old_inst.src, "TODO implement analyzing {}", .{@tagName(old_inst.tag)}), - .primitive => return self.fail(old_inst.src, "TODO implement analyzing {}", .{@tagName(old_inst.tag)}), + .primitive => return self.analyzeInstPrimitive(func, old_inst.cast(text.Inst.Primitive).?), .fntype => return self.analyzeInstFnType(func, old_inst.cast(text.Inst.FnType).?), } } @@ -337,6 +337,10 @@ const Analyze = struct { return self.fail(fntype.base.src, "TODO implement fntype instruction more", .{}); } + fn analyzeInstPrimitive(self: *Analyze, opt_func: ?*Fn, primitive: *text.Inst.Primitive) InnerError!*Inst { + return self.constType(primitive.base.src, primitive.positionals.tag.toType()); + } + fn coerce(self: *Analyze, dest_type: Type, inst: *Inst) !*Inst { const in_memory_result = coerceInMemoryAllowed(dest_type, inst.ty); if (in_memory_result == .ok) { diff --git a/src-self-hosted/ir/text.zig b/src-self-hosted/ir/text.zig index d00966cdce..cf63ee2a17 100644 --- a/src-self-hosted/ir/text.zig +++ b/src-self-hosted/ir/text.zig @@ -3,10 +3,9 @@ const std = @import("std"); const mem = std.mem; const Allocator = std.mem.Allocator; -const Value = @import("../value.zig").Value; const assert = std.debug.assert; -const ir = @import("../ir.zig"); const BigInt = std.math.big.Int; +const Type = @import("../type.zig").Type; /// These are instructions that correspond to the ZIR text format. See `ir.Inst` for /// in-memory, analyzed instructions with types and values. @@ -201,6 +200,34 @@ pub const Inst = struct { @"anyerror", @"comptime_int", @"comptime_float", + + fn toType(self: BuiltinType) Type { + return switch (self) { + .@"isize" => Type.initTag(.@"isize"), + .@"usize" => Type.initTag(.@"usize"), + .@"c_short" => Type.initTag(.@"c_short"), + .@"c_ushort" => Type.initTag(.@"c_ushort"), + .@"c_int" => Type.initTag(.@"c_int"), + .@"c_uint" => Type.initTag(.@"c_uint"), + .@"c_long" => Type.initTag(.@"c_long"), + .@"c_ulong" => Type.initTag(.@"c_ulong"), + .@"c_longlong" => Type.initTag(.@"c_longlong"), + .@"c_ulonglong" => Type.initTag(.@"c_ulonglong"), + .@"c_longdouble" => Type.initTag(.@"c_longdouble"), + .@"c_void" => Type.initTag(.@"c_void"), + .@"f16" => Type.initTag(.@"f16"), + .@"f32" => Type.initTag(.@"f32"), + .@"f64" => Type.initTag(.@"f64"), + .@"f128" => Type.initTag(.@"f128"), + .@"bool" => Type.initTag(.@"bool"), + .@"void" => Type.initTag(.@"void"), + .@"noreturn" => Type.initTag(.@"noreturn"), + .@"type" => Type.initTag(.@"type"), + .@"anyerror" => Type.initTag(.@"anyerror"), + .@"comptime_int" => Type.initTag(.@"comptime_int"), + .@"comptime_float" => Type.initTag(.@"comptime_float"), + }; + } }; }; @@ -337,7 +364,6 @@ pub const Module = struct { return stream.writeAll(@tagName(param)); } switch (@TypeOf(param)) { - Value => return stream.print("{}", .{param}), *Inst => return self.writeInstParamToStream(stream, param, inst_table), []*Inst => { try stream.writeByte('['); @@ -693,7 +719,6 @@ const Parser = struct { return instructions.toOwnedSlice(); }, *Inst => return parseParameterInst(self, body_ctx), - Value => return self.fail("TODO implement parseParameterGeneric for type Value", .{}), []u8 => return self.parseStringLiteral(), BigInt => return self.parseIntegerLiteral(), else => @compileError("Unimplemented: ir parseParameterGeneric for type " ++ @typeName(T)), |
