| ... | ... | @@ -6017,6 +6017,27 @@ fn ret(gz: *GenZir, scope: *Scope, node: Ast.Node.Index) InnerError!Zir.Inst.Ref |
| 6017 | 6017 | } |
| 6018 | 6018 | } |
| 6019 | 6019 | |
| 6020 | /// Parses the string `buf` as a base 10 integer of type `u16`. |
| 6021 | /// |
| 6022 | /// Unlike std.fmt.parseInt, does not allow the '_' character in `buf`. |
| 6023 | fn parseBitCount(buf: []const u8) std.fmt.ParseIntError!u16 { |
| 6024 | if (buf.len == 0) return error.InvalidCharacter; |
| 6025 | |
| 6026 | var x: u16 = 0; |
| 6027 | |
| 6028 | for (buf) |c| { |
| 6029 | const digit = switch (c) { |
| 6030 | '0'...'9' => c - '0', |
| 6031 | else => return error.InvalidCharacter, |
| 6032 | }; |
| 6033 | |
| 6034 | if (x != 0) x = try std.math.mul(u16, x, 10); |
| 6035 | x = try std.math.add(u16, x, @as(u16, digit)); |
| 6036 | } |
| 6037 | |
| 6038 | return x; |
| 6039 | } |
| 6040 | |
| 6020 | 6041 | fn identifier( |
| 6021 | 6042 | gz: *GenZir, |
| 6022 | 6043 | scope: *Scope, |
| ... | ... | @@ -6050,7 +6071,7 @@ fn identifier( |
| 6050 | 6071 | true => .signed, |
| 6051 | 6072 | false => .unsigned, |
| 6052 | 6073 | }; |
| 6053 | | const bit_count = std.fmt.parseInt(u16, ident_name_raw[1..], 10) catch |err| switch (err) { |
| 6074 | const bit_count = parseBitCount(ident_name_raw[1..]) catch |err| switch (err) { |
| 6054 | 6075 | error.Overflow => return astgen.failNode( |
| 6055 | 6076 | ident, |
| 6056 | 6077 | "primitive integer type '{s}' exceeds maximum bit width of 65535", |
| ... | ... | @@ -8864,7 +8885,7 @@ const GenZir = struct { |
| 8864 | 8885 | parent: *Scope, |
| 8865 | 8886 | /// All `GenZir` scopes for the same ZIR share this. |
| 8866 | 8887 | astgen: *AstGen, |
| 8867 | | /// Keeps track of the list of instructions in this scope. Possibly shared. |
| 8888 | /// Keeps track of the list of instructions in this scope. Possibly shared. |
| 8868 | 8889 | /// Indexes to instructions in `astgen`. |
| 8869 | 8890 | instructions: *ArrayListUnmanaged(Zir.Inst.Index), |
| 8870 | 8891 | /// A sub-block may share its instructions ArrayList with containing GenZir, |
| ... | ... | @@ -10098,7 +10119,7 @@ pub fn isPrimitive(name: []const u8) bool { |
| 10098 | 10119 | if (name.len < 2) return false; |
| 10099 | 10120 | const first_c = name[0]; |
| 10100 | 10121 | if (first_c != 'i' and first_c != 'u') return false; |
| 10101 | | if (std.fmt.parseInt(u16, name[1..], 10)) |_| { |
| 10122 | if (parseBitCount(name[1..])) |_| { |
| 10102 | 10123 | return true; |
| 10103 | 10124 | } else |err| switch (err) { |
| 10104 | 10125 | error.Overflow => return true, |