| author | |
| committer | |
| log | be673e67937bbc3e2c74591f8f447f848b2a566a |
| tree | a6784230d35bbb35ea0374984d475228313ac265 |
| parent | aa46a705ad998636443e744b63471bf0864e90c9 |
also add i128 and u128 to const inst list5 files changed, 94 insertions(+), 9 deletions(-)
src/Module.zig+5-2| ... | ... | @@ -3599,11 +3599,14 @@ pub fn lookupDeclName(mod: *Module, scope: *Scope, ident_name: []const u8) ?*Dec |
| 3599 | 3599 | return mod.decl_table.get(name_hash); |
| 3600 | 3600 | } |
| 3601 | 3601 | |
| 3602 | pub fn makeIntType(arena: *Allocator, signed: bool, bits: u16) !Type { | |
| 3602 | pub fn makeIntType(arena: *Allocator, signedness: std.builtin.Signedness, bits: u16) !Type { | |
| 3603 | 3603 | const int_payload = try arena.create(Type.Payload.Bits); |
| 3604 | 3604 | int_payload.* = .{ |
| 3605 | 3605 | .base = .{ |
| 3606 | .tag = if (signed) .int_signed else .int_unsigned, | |
| 3606 | .tag = switch (signedness) { | |
| 3607 | .signed => .int_signed, | |
| 3608 | .unsigned => .int_unsigned, | |
| 3609 | }, | |
| 3607 | 3610 | }, |
| 3608 | 3611 | .data = bits, |
| 3609 | 3612 | }; |
src/Sema.zig+7-2| ... | ... | @@ -1226,7 +1226,11 @@ fn zirIntType(sema: *Sema, block: *Scope.Block, inst: zir.Inst.Index) InnerError |
| 1226 | 1226 | const tracy = trace(@src()); |
| 1227 | 1227 | defer tracy.end(); |
| 1228 | 1228 | |
| 1229 | return sema.mod.fail(&block.base, sema.src, "TODO implement inttype", .{}); | |
| 1229 | const int_type = sema.code.instructions.items(.data)[inst].int_type; | |
| 1230 | const src = int_type.src(); | |
| 1231 | const ty = try Module.makeIntType(sema.arena, int_type.signedness, int_type.bit_count); | |
| 1232 | ||
| 1233 | return sema.mod.constType(sema.arena, src, ty); | |
| 1230 | 1234 | } |
| 1231 | 1235 | |
| 1232 | 1236 | fn zirOptionalType(sema: *Sema, block: *Scope.Block, inst: zir.Inst.Index) InnerError!*Inst { |
| ... | ... | @@ -3967,7 +3971,8 @@ fn cmpNumeric( |
| 3967 | 3971 | const casted_bits = std.math.cast(u16, max_bits) catch |err| switch (err) { |
| 3968 | 3972 | error.Overflow => return sema.mod.fail(&block.base, src, "{d} exceeds maximum integer bit count", .{max_bits}), |
| 3969 | 3973 | }; |
| 3970 | break :blk try Module.makeIntType(sema.arena, dest_int_is_signed, casted_bits); | |
| 3974 | const signedness: std.builtin.Signedness = if (dest_int_is_signed) .signed else .unsigned; | |
| 3975 | break :blk try Module.makeIntType(sema.arena, signedness, casted_bits); | |
| 3971 | 3976 | }; |
| 3972 | 3977 | const casted_lhs = try sema.coerce(block, dest_type, lhs, lhs.src); |
| 3973 | 3978 | const casted_rhs = try sema.coerce(block, dest_type, rhs, rhs.src); |
src/astgen.zig+13-2| ... | ... | @@ -2888,7 +2888,10 @@ fn identifier( |
| 2888 | 2888 | if (ident_name.len >= 2) integer: { |
| 2889 | 2889 | const first_c = ident_name[0]; |
| 2890 | 2890 | if (first_c == 'i' or first_c == 'u') { |
| 2891 | const is_signed = first_c == 'i'; | |
| 2891 | const signedness: std.builtin.Signedness = switch (first_c == 'i') { | |
| 2892 | true => .signed, | |
| 2893 | false => .unsigned, | |
| 2894 | }; | |
| 2892 | 2895 | const bit_count = std.fmt.parseInt(u16, ident_name[1..], 10) catch |err| switch (err) { |
| 2893 | 2896 | error.Overflow => return mod.failNode( |
| 2894 | 2897 | scope, |
| ... | ... | @@ -2898,7 +2901,15 @@ fn identifier( |
| 2898 | 2901 | ), |
| 2899 | 2902 | error.InvalidCharacter => break :integer, |
| 2900 | 2903 | }; |
| 2901 | return rvalue(mod, scope, rl, try gz.addBin(.int_type, @boolToInt(is_signed), bit_count), ident); | |
| 2904 | const result = try gz.add(.{ | |
| 2905 | .tag = .int_type, | |
| 2906 | .data = .{ .int_type = .{ | |
| 2907 | .src_node = gz.zir_code.decl.nodeIndexToRelative(ident), | |
| 2908 | .signedness = signedness, | |
| 2909 | .bit_count = bit_count, | |
| 2910 | } }, | |
| 2911 | }); | |
| 2912 | return rvalue(mod, scope, rl, result, ident); | |
| 2902 | 2913 | } |
| 2903 | 2914 | } |
| 2904 | 2915 |
src/value.zig+36| ... | ... | @@ -30,6 +30,8 @@ pub const Value = extern union { |
| 30 | 30 | i32_type, |
| 31 | 31 | u64_type, |
| 32 | 32 | i64_type, |
| 33 | u128_type, | |
| 34 | i128_type, | |
| 33 | 35 | usize_type, |
| 34 | 36 | isize_type, |
| 35 | 37 | c_short_type, |
| ... | ... | @@ -120,6 +122,8 @@ pub const Value = extern union { |
| 120 | 122 | .i32_type, |
| 121 | 123 | .u64_type, |
| 122 | 124 | .i64_type, |
| 125 | .u128_type, | |
| 126 | .i128_type, | |
| 123 | 127 | .usize_type, |
| 124 | 128 | .isize_type, |
| 125 | 129 | .c_short_type, |
| ... | ... | @@ -274,6 +278,8 @@ pub const Value = extern union { |
| 274 | 278 | .i32_type, |
| 275 | 279 | .u64_type, |
| 276 | 280 | .i64_type, |
| 281 | .u128_type, | |
| 282 | .i128_type, | |
| 277 | 283 | .usize_type, |
| 278 | 284 | .isize_type, |
| 279 | 285 | .c_short_type, |
| ... | ... | @@ -427,6 +433,8 @@ pub const Value = extern union { |
| 427 | 433 | .i32_type => return out_stream.writeAll("i32"), |
| 428 | 434 | .u64_type => return out_stream.writeAll("u64"), |
| 429 | 435 | .i64_type => return out_stream.writeAll("i64"), |
| 436 | .u128_type => return out_stream.writeAll("u128"), | |
| 437 | .i128_type => return out_stream.writeAll("i128"), | |
| 430 | 438 | .isize_type => return out_stream.writeAll("isize"), |
| 431 | 439 | .usize_type => return out_stream.writeAll("usize"), |
| 432 | 440 | .c_short_type => return out_stream.writeAll("c_short"), |
| ... | ... | @@ -554,6 +562,8 @@ pub const Value = extern union { |
| 554 | 562 | .i32_type => Type.initTag(.i32), |
| 555 | 563 | .u64_type => Type.initTag(.u64), |
| 556 | 564 | .i64_type => Type.initTag(.i64), |
| 565 | .u128_type => Type.initTag(.u128), | |
| 566 | .i128_type => Type.initTag(.i128), | |
| 557 | 567 | .usize_type => Type.initTag(.usize), |
| 558 | 568 | .isize_type => Type.initTag(.isize), |
| 559 | 569 | .c_short_type => Type.initTag(.c_short), |
| ... | ... | @@ -650,6 +660,8 @@ pub const Value = extern union { |
| 650 | 660 | .i32_type, |
| 651 | 661 | .u64_type, |
| 652 | 662 | .i64_type, |
| 663 | .u128_type, | |
| 664 | .i128_type, | |
| 653 | 665 | .usize_type, |
| 654 | 666 | .isize_type, |
| 655 | 667 | .c_short_type, |
| ... | ... | @@ -736,6 +748,8 @@ pub const Value = extern union { |
| 736 | 748 | .i32_type, |
| 737 | 749 | .u64_type, |
| 738 | 750 | .i64_type, |
| 751 | .u128_type, | |
| 752 | .i128_type, | |
| 739 | 753 | .usize_type, |
| 740 | 754 | .isize_type, |
| 741 | 755 | .c_short_type, |
| ... | ... | @@ -822,6 +836,8 @@ pub const Value = extern union { |
| 822 | 836 | .i32_type, |
| 823 | 837 | .u64_type, |
| 824 | 838 | .i64_type, |
| 839 | .u128_type, | |
| 840 | .i128_type, | |
| 825 | 841 | .usize_type, |
| 826 | 842 | .isize_type, |
| 827 | 843 | .c_short_type, |
| ... | ... | @@ -935,6 +951,8 @@ pub const Value = extern union { |
| 935 | 951 | .i32_type, |
| 936 | 952 | .u64_type, |
| 937 | 953 | .i64_type, |
| 954 | .u128_type, | |
| 955 | .i128_type, | |
| 938 | 956 | .usize_type, |
| 939 | 957 | .isize_type, |
| 940 | 958 | .c_short_type, |
| ... | ... | @@ -1026,6 +1044,8 @@ pub const Value = extern union { |
| 1026 | 1044 | .i32_type, |
| 1027 | 1045 | .u64_type, |
| 1028 | 1046 | .i64_type, |
| 1047 | .u128_type, | |
| 1048 | .i128_type, | |
| 1029 | 1049 | .usize_type, |
| 1030 | 1050 | .isize_type, |
| 1031 | 1051 | .c_short_type, |
| ... | ... | @@ -1182,6 +1202,8 @@ pub const Value = extern union { |
| 1182 | 1202 | .i32_type, |
| 1183 | 1203 | .u64_type, |
| 1184 | 1204 | .i64_type, |
| 1205 | .u128_type, | |
| 1206 | .i128_type, | |
| 1185 | 1207 | .usize_type, |
| 1186 | 1208 | .isize_type, |
| 1187 | 1209 | .c_short_type, |
| ... | ... | @@ -1265,6 +1287,8 @@ pub const Value = extern union { |
| 1265 | 1287 | .i32_type, |
| 1266 | 1288 | .u64_type, |
| 1267 | 1289 | .i64_type, |
| 1290 | .u128_type, | |
| 1291 | .i128_type, | |
| 1268 | 1292 | .usize_type, |
| 1269 | 1293 | .isize_type, |
| 1270 | 1294 | .c_short_type, |
| ... | ... | @@ -1416,6 +1440,8 @@ pub const Value = extern union { |
| 1416 | 1440 | .i32_type, |
| 1417 | 1441 | .u64_type, |
| 1418 | 1442 | .i64_type, |
| 1443 | .u128_type, | |
| 1444 | .i128_type, | |
| 1419 | 1445 | .usize_type, |
| 1420 | 1446 | .isize_type, |
| 1421 | 1447 | .c_short_type, |
| ... | ... | @@ -1573,6 +1599,8 @@ pub const Value = extern union { |
| 1573 | 1599 | .i32_type, |
| 1574 | 1600 | .u64_type, |
| 1575 | 1601 | .i64_type, |
| 1602 | .u128_type, | |
| 1603 | .i128_type, | |
| 1576 | 1604 | .usize_type, |
| 1577 | 1605 | .isize_type, |
| 1578 | 1606 | .c_short_type, |
| ... | ... | @@ -1659,6 +1687,8 @@ pub const Value = extern union { |
| 1659 | 1687 | .i32_type, |
| 1660 | 1688 | .u64_type, |
| 1661 | 1689 | .i64_type, |
| 1690 | .u128_type, | |
| 1691 | .i128_type, | |
| 1662 | 1692 | .usize_type, |
| 1663 | 1693 | .isize_type, |
| 1664 | 1694 | .c_short_type, |
| ... | ... | @@ -1762,6 +1792,8 @@ pub const Value = extern union { |
| 1762 | 1792 | .i32_type, |
| 1763 | 1793 | .u64_type, |
| 1764 | 1794 | .i64_type, |
| 1795 | .u128_type, | |
| 1796 | .i128_type, | |
| 1765 | 1797 | .usize_type, |
| 1766 | 1798 | .isize_type, |
| 1767 | 1799 | .c_short_type, |
| ... | ... | @@ -1843,6 +1875,8 @@ pub const Value = extern union { |
| 1843 | 1875 | .i32_type, |
| 1844 | 1876 | .u64_type, |
| 1845 | 1877 | .i64_type, |
| 1878 | .u128_type, | |
| 1879 | .i128_type, | |
| 1846 | 1880 | .usize_type, |
| 1847 | 1881 | .isize_type, |
| 1848 | 1882 | .c_short_type, |
| ... | ... | @@ -1944,6 +1978,8 @@ pub const Value = extern union { |
| 1944 | 1978 | .i32_type, |
| 1945 | 1979 | .u64_type, |
| 1946 | 1980 | .i64_type, |
| 1981 | .u128_type, | |
| 1982 | .i128_type, | |
| 1947 | 1983 | .usize_type, |
| 1948 | 1984 | .isize_type, |
| 1949 | 1985 | .c_short_type, |
src/zir.zig+33-3| ... | ... | @@ -125,6 +125,8 @@ pub const Const = enum { |
| 125 | 125 | i32_type, |
| 126 | 126 | u64_type, |
| 127 | 127 | i64_type, |
| 128 | u128_type, | |
| 129 | i128_type, | |
| 128 | 130 | usize_type, |
| 129 | 131 | isize_type, |
| 130 | 132 | c_short_type, |
| ... | ... | @@ -210,6 +212,14 @@ pub const const_inst_list = std.enums.directEnumArray(Const, TypedValue, 0, .{ |
| 210 | 212 | .ty = Type.initTag(.type), |
| 211 | 213 | .val = Value.initTag(.i64_type), |
| 212 | 214 | }, |
| 215 | .u128_type = .{ | |
| 216 | .ty = Type.initTag(.type), | |
| 217 | .val = Value.initTag(.u128_type), | |
| 218 | }, | |
| 219 | .i128_type = .{ | |
| 220 | .ty = Type.initTag(.type), | |
| 221 | .val = Value.initTag(.i128_type), | |
| 222 | }, | |
| 213 | 223 | .usize_type = .{ |
| 214 | 224 | .ty = Type.initTag(.type), |
| 215 | 225 | .val = Value.initTag(.usize_type), |
| ... | ... | @@ -619,8 +629,7 @@ pub const Inst = struct { |
| 619 | 629 | /// Payload is `Bin` with lhs as the dest type, rhs the operand. |
| 620 | 630 | intcast, |
| 621 | 631 | /// Make an integer type out of signedness and bit count. |
| 622 | /// lhs is signedness, rhs is bit count. | |
| 623 | /// Payload is `Bin` | |
| 632 | /// Payload is `int_type` | |
| 624 | 633 | int_type, |
| 625 | 634 | /// Return a boolean false if an optional is null. `x != null` |
| 626 | 635 | /// Uses the `un_tok` field. |
| ... | ... | @@ -1135,6 +1144,17 @@ pub const Inst = struct { |
| 1135 | 1144 | /// For `fn_type_cc` this points to `FnTypeCc` in `extra`. |
| 1136 | 1145 | payload_index: u32, |
| 1137 | 1146 | }, |
| 1147 | int_type: struct { | |
| 1148 | /// Offset from Decl AST node index. | |
| 1149 | /// `Tag` determines which kind of AST node this points to. | |
| 1150 | src_node: i32, | |
| 1151 | signedness: std.builtin.Signedness, | |
| 1152 | bit_count: u16, | |
| 1153 | ||
| 1154 | pub fn src(self: @This()) LazySrcLoc { | |
| 1155 | return .{ .node_offset = self.src_node }; | |
| 1156 | } | |
| 1157 | }, | |
| 1138 | 1158 | bool_br: struct { |
| 1139 | 1159 | lhs: Ref, |
| 1140 | 1160 | /// Points to a `Block`. |
| ... | ... | @@ -1340,7 +1360,6 @@ const Writer = struct { |
| 1340 | 1360 | .elem_ptr, |
| 1341 | 1361 | .elem_val, |
| 1342 | 1362 | .intcast, |
| 1343 | .int_type, | |
| 1344 | 1363 | .merge_error_sets, |
| 1345 | 1364 | => try self.writeBin(stream, inst), |
| 1346 | 1365 | |
| ... | ... | @@ -1405,6 +1424,7 @@ const Writer = struct { |
| 1405 | 1424 | .str => try self.writeStr(stream, inst), |
| 1406 | 1425 | .elided => try stream.writeAll(")"), |
| 1407 | 1426 | .break_void_node => try self.writeBreakVoidNode(stream, inst), |
| 1427 | .int_type => try self.writeIntType(stream, inst), | |
| 1408 | 1428 | |
| 1409 | 1429 | .@"asm", |
| 1410 | 1430 | .asm_volatile, |
| ... | ... | @@ -1742,6 +1762,16 @@ const Writer = struct { |
| 1742 | 1762 | try self.writeSrc(stream, inst_data.src()); |
| 1743 | 1763 | } |
| 1744 | 1764 | |
| 1765 | fn writeIntType(self: *Writer, stream: anytype, inst: Inst.Index) !void { | |
| 1766 | const int_type = self.code.instructions.items(.data)[inst].int_type; | |
| 1767 | const prefix: u8 = switch (int_type.signedness) { | |
| 1768 | .signed => 'i', | |
| 1769 | .unsigned => 'u', | |
| 1770 | }; | |
| 1771 | try stream.print("{c}{d}) ", .{ prefix, int_type.bit_count }); | |
| 1772 | try self.writeSrc(stream, int_type.src()); | |
| 1773 | } | |
| 1774 | ||
| 1745 | 1775 | fn writeUnreachable(self: *Writer, stream: anytype, inst: Inst.Index) !void { |
| 1746 | 1776 | const inst_data = self.code.instructions.items(.data)[inst].@"unreachable"; |
| 1747 | 1777 | const safety_str = if (inst_data.safety) "safe" else "unsafe"; |