authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2025-08-11 13:52:52-07:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2025-09-24 20:01:19-07:00
log0f88f9c66444406879bf133895f3c21ab3b85418
tree7a17c0f8f4ef439bbf0fdf071201c7ca6bd81656
parent21f5f06f1f66c9f849ae39d868c2d4548078231f

aro: avoid BoundedArray


3 files changed, 16 insertions(+), 15 deletions(-)

lib/compiler/aro/aro/Driver/Multilib.zig+8-8
...@@ -1,12 +1,12 @@...@@ -1,12 +1,12 @@
1const std = @import("std");1const std = @import("std");
2const Filesystem = @import("Filesystem.zig").Filesystem;2const Filesystem = @import("Filesystem.zig").Filesystem;
33
4pub const Flags = std.BoundedArray([]const u8, 6);4pub const Flags = std.ArrayListUnmanaged([]const u8);
55
6/// Large enough for GCCDetector for Linux; may need to be increased to support other toolchains.6/// Large enough for GCCDetector for Linux; may need to be increased to support other toolchains.
7const max_multilibs = 4;7const max_multilibs = 4;
88
9const MultilibArray = std.BoundedArray(Multilib, max_multilibs);9const MultilibArray = std.ArrayListUnmanaged(Multilib);
1010
11pub const Detected = struct {11pub const Detected = struct {
12 multilibs: MultilibArray = .{},12 multilibs: MultilibArray = .{},
...@@ -15,20 +15,20 @@ pub const Detected = struct {...@@ -15,20 +15,20 @@ pub const Detected = struct {
1515
16 pub fn filter(self: *Detected, multilib_filter: Filter, fs: Filesystem) void {16 pub fn filter(self: *Detected, multilib_filter: Filter, fs: Filesystem) void {
17 var found_count: usize = 0;17 var found_count: usize = 0;
18 for (self.multilibs.constSlice()) |multilib| {18 for (self.multilibs.items) |multilib| {
19 if (multilib_filter.exists(multilib, fs)) {19 if (multilib_filter.exists(multilib, fs)) {
20 self.multilibs.set(found_count, multilib);20 self.multilibs.items[found_count] = multilib;
21 found_count += 1;21 found_count += 1;
22 }22 }
23 }23 }
24 self.multilibs.resize(found_count) catch unreachable;24 self.multilibs.resize(found_count) catch unreachable;
25 }25 }
2626
27 pub fn select(self: *Detected, flags: Flags) !bool {27 pub fn select(self: *Detected, flags: []const []const Flags) !bool {
28 var filtered: MultilibArray = .{};28 var filtered: MultilibArray = .{};
29 for (self.multilibs.constSlice()) |multilib| {29 for (self.multilibs.items) |multilib| {
30 for (multilib.flags.constSlice()) |multilib_flag| {30 for (flags) |multilib_flag| {
31 const matched = for (flags.constSlice()) |arg_flag| {31 const matched = for (flags) |arg_flag| {
32 if (std.mem.eql(u8, arg_flag[1..], multilib_flag[1..])) break arg_flag;32 if (std.mem.eql(u8, arg_flag[1..], multilib_flag[1..])) break arg_flag;
33 } else multilib_flag;33 } else multilib_flag;
34 if (matched[0] != multilib_flag[0]) break;34 if (matched[0] != multilib_flag[0]) break;
lib/compiler/aro/aro/Toolchain.zig+5-4
...@@ -171,8 +171,7 @@ pub fn getLinkerPath(tc: *const Toolchain, buf: []u8) ![]const u8 {...@@ -171,8 +171,7 @@ pub fn getLinkerPath(tc: *const Toolchain, buf: []u8) ![]const u8 {
171/// TODO: this isn't exactly right since our target names don't necessarily match up171/// TODO: this isn't exactly right since our target names don't necessarily match up
172/// with GCC's.172/// with GCC's.
173/// For example the Zig target `arm-freestanding-eabi` would need the `arm-none-eabi` tools173/// For example the Zig target `arm-freestanding-eabi` would need the `arm-none-eabi` tools
174fn possibleProgramNames(raw_triple: ?[]const u8, name: []const u8, buf: *[64]u8) std.BoundedArray([]const u8, 2) {174fn possibleProgramNames(raw_triple: ?[]const u8, name: []const u8, buf: *[64]u8, possible_names: *std.ArrayListUnmanaged([]const u8)) void {
175 var possible_names: std.BoundedArray([]const u8, 2) = .{};
176 if (raw_triple) |triple| {175 if (raw_triple) |triple| {
177 if (std.fmt.bufPrint(buf, "{s}-{s}", .{ triple, name })) |res| {176 if (std.fmt.bufPrint(buf, "{s}-{s}", .{ triple, name })) |res| {
178 possible_names.appendAssumeCapacity(res);177 possible_names.appendAssumeCapacity(res);
...@@ -209,9 +208,11 @@ fn getProgramPath(tc: *const Toolchain, name: []const u8, buf: []u8) []const u8...@@ -209,9 +208,11 @@ fn getProgramPath(tc: *const Toolchain, name: []const u8, buf: []u8) []const u8
209 var fib = std.heap.FixedBufferAllocator.init(&path_buf);208 var fib = std.heap.FixedBufferAllocator.init(&path_buf);
210209
211 var tool_specific_buf: [64]u8 = undefined;210 var tool_specific_buf: [64]u8 = undefined;
212 const possible_names = possibleProgramNames(tc.driver.raw_target_triple, name, &tool_specific_buf);211 var possible_names_buffer: [2][]const u8 = undefined;
212 var possible_names = std.ArrayListUnmanaged.initBuffer(&possible_names_buffer);
213 possibleProgramNames(tc.driver.raw_target_triple, name, &tool_specific_buf, &possible_names);
213214
214 for (possible_names.constSlice()) |tool_name| {215 for (possible_names.items) |tool_name| {
215 for (tc.program_paths.items) |program_path| {216 for (tc.program_paths.items) |program_path| {
216 defer fib.reset();217 defer fib.reset();
217218
lib/compiler/translate-c/Translator.zig+3-3
...@@ -3439,8 +3439,8 @@ fn transStringLiteralInitializer(...@@ -3439,8 +3439,8 @@ fn transStringLiteralInitializer(
3439 const init_list = try t.arena.alloc(ZigNode, @intCast(num_inits));3439 const init_list = try t.arena.alloc(ZigNode, @intCast(num_inits));
3440 for (init_list, 0..) |*item, i| {3440 for (init_list, 0..) |*item, i| {
3441 const codepoint = switch (size) {3441 const codepoint = switch (size) {
3442 2 => @as(*const u16, @alignCast(@ptrCast(bytes.ptr + i * 2))).*,3442 2 => @as(*const u16, @ptrCast(@alignCast(bytes.ptr + i * 2))).*,
3443 4 => @as(*const u32, @alignCast(@ptrCast(bytes.ptr + i * 4))).*,3443 4 => @as(*const u32, @ptrCast(@alignCast(bytes.ptr + i * 4))).*,
3444 else => unreachable,3444 else => unreachable,
3445 };3445 };
3446 item.* = try t.createCharLiteralNode(false, codepoint);3446 item.* = try t.createCharLiteralNode(false, codepoint);
...@@ -3873,7 +3873,7 @@ fn createNumberNode(t: *Translator, num: anytype, num_kind: enum { int, float })...@@ -3873,7 +3873,7 @@ fn createNumberNode(t: *Translator, num: anytype, num_kind: enum { int, float })
38733873
3874fn createCharLiteralNode(t: *Translator, narrow: bool, val: u32) TransError!ZigNode {3874fn createCharLiteralNode(t: *Translator, narrow: bool, val: u32) TransError!ZigNode {
3875 return ZigTag.char_literal.create(t.arena, if (narrow)3875 return ZigTag.char_literal.create(t.arena, if (narrow)
3876 try std.fmt.allocPrint(t.arena, "'{f}'", .{std.zig.fmtChar(&.{@as(u8, @intCast(val))})})3876 try std.fmt.allocPrint(t.arena, "'{f}'", .{std.zig.fmtChar(@intCast(val))})
3877 else3877 else
3878 try std.fmt.allocPrint(t.arena, "'\\u{{{x}}}'", .{val}));3878 try std.fmt.allocPrint(t.arena, "'\\u{{{x}}}'", .{val}));
3879}3879}