| ... | ... | @@ -6065,6 +6065,27 @@ fn ret(gz: *GenZir, scope: *Scope, node: Ast.Node.Index) InnerError!Zir.Inst.Ref |
| 6065 | 6065 | } |
| 6066 | 6066 | } |
| 6067 | 6067 | |
| 6068 | /// Parses the string `buf` as a base 10 integer of type `u16`. |
| 6069 | /// |
| 6070 | /// Unlike std.fmt.parseInt, does not allow the '_' character in `buf`. |
| 6071 | fn parseBitCount(buf: []const u8) std.fmt.ParseIntError!u16 { |
| 6072 | if (buf.len == 0) return error.InvalidCharacter; |
| 6073 | |
| 6074 | var x: u16 = 0; |
| 6075 | |
| 6076 | for (buf) |c| { |
| 6077 | const digit = switch (c) { |
| 6078 | '0'...'9' => c - '0', |
| 6079 | else => return error.InvalidCharacter, |
| 6080 | }; |
| 6081 | |
| 6082 | if (x != 0) x = try std.math.mul(u16, x, 10); |
| 6083 | x = try std.math.add(u16, x, @as(u16, digit)); |
| 6084 | } |
| 6085 | |
| 6086 | return x; |
| 6087 | } |
| 6088 | |
| 6068 | 6089 | fn identifier( |
| 6069 | 6090 | gz: *GenZir, |
| 6070 | 6091 | scope: *Scope, |
| ... | ... | @@ -6098,7 +6119,7 @@ fn identifier( |
| 6098 | 6119 | true => .signed, |
| 6099 | 6120 | false => .unsigned, |
| 6100 | 6121 | }; |
| 6101 | | const bit_count = std.fmt.parseInt(u16, ident_name_raw[1..], 10) catch |err| switch (err) { |
| 6122 | const bit_count = parseBitCount(ident_name_raw[1..]) catch |err| switch (err) { |
| 6102 | 6123 | error.Overflow => return astgen.failNode( |
| 6103 | 6124 | ident, |
| 6104 | 6125 | "primitive integer type '{s}' exceeds maximum bit width of 65535", |
| ... | ... | @@ -8985,7 +9006,7 @@ const GenZir = struct { |
| 8985 | 9006 | parent: *Scope, |
| 8986 | 9007 | /// All `GenZir` scopes for the same ZIR share this. |
| 8987 | 9008 | astgen: *AstGen, |
| 8988 | | /// Keeps track of the list of instructions in this scope. Possibly shared. |
| 9009 | /// Keeps track of the list of instructions in this scope. Possibly shared. |
| 8989 | 9010 | /// Indexes to instructions in `astgen`. |
| 8990 | 9011 | instructions: *ArrayListUnmanaged(Zir.Inst.Index), |
| 8991 | 9012 | /// A sub-block may share its instructions ArrayList with containing GenZir, |
| ... | ... | @@ -10231,7 +10252,7 @@ pub fn isPrimitive(name: []const u8) bool { |
| 10231 | 10252 | if (name.len < 2) return false; |
| 10232 | 10253 | const first_c = name[0]; |
| 10233 | 10254 | if (first_c != 'i' and first_c != 'u') return false; |
| 10234 | | if (std.fmt.parseInt(u16, name[1..], 10)) |_| { |
| 10255 | if (parseBitCount(name[1..])) |_| { |
| 10235 | 10256 | return true; |
| 10236 | 10257 | } else |err| switch (err) { |
| 10237 | 10258 | error.Overflow => return true, |