mirror of
https://codeberg.org/ziglang/zig.git
synced 2026-03-08 02:44:43 +01:00
aro: avoid BoundedArray
This commit is contained in:
parent
21f5f06f1f
commit
0f88f9c664
3 changed files with 16 additions and 15 deletions
16
lib/compiler/aro/aro/Driver/Multilib.zig
vendored
16
lib/compiler/aro/aro/Driver/Multilib.zig
vendored
|
|
@ -1,12 +1,12 @@
|
|||
const std = @import("std");
|
||||
const Filesystem = @import("Filesystem.zig").Filesystem;
|
||||
|
||||
pub const Flags = std.BoundedArray([]const u8, 6);
|
||||
pub const Flags = std.ArrayListUnmanaged([]const u8);
|
||||
|
||||
/// Large enough for GCCDetector for Linux; may need to be increased to support other toolchains.
|
||||
const max_multilibs = 4;
|
||||
|
||||
const MultilibArray = std.BoundedArray(Multilib, max_multilibs);
|
||||
const MultilibArray = std.ArrayListUnmanaged(Multilib);
|
||||
|
||||
pub const Detected = struct {
|
||||
multilibs: MultilibArray = .{},
|
||||
|
|
@ -15,20 +15,20 @@ pub const Detected = struct {
|
|||
|
||||
pub fn filter(self: *Detected, multilib_filter: Filter, fs: Filesystem) void {
|
||||
var found_count: usize = 0;
|
||||
for (self.multilibs.constSlice()) |multilib| {
|
||||
for (self.multilibs.items) |multilib| {
|
||||
if (multilib_filter.exists(multilib, fs)) {
|
||||
self.multilibs.set(found_count, multilib);
|
||||
self.multilibs.items[found_count] = multilib;
|
||||
found_count += 1;
|
||||
}
|
||||
}
|
||||
self.multilibs.resize(found_count) catch unreachable;
|
||||
}
|
||||
|
||||
pub fn select(self: *Detected, flags: Flags) !bool {
|
||||
pub fn select(self: *Detected, flags: []const []const Flags) !bool {
|
||||
var filtered: MultilibArray = .{};
|
||||
for (self.multilibs.constSlice()) |multilib| {
|
||||
for (multilib.flags.constSlice()) |multilib_flag| {
|
||||
const matched = for (flags.constSlice()) |arg_flag| {
|
||||
for (self.multilibs.items) |multilib| {
|
||||
for (flags) |multilib_flag| {
|
||||
const matched = for (flags) |arg_flag| {
|
||||
if (std.mem.eql(u8, arg_flag[1..], multilib_flag[1..])) break arg_flag;
|
||||
} else multilib_flag;
|
||||
if (matched[0] != multilib_flag[0]) break;
|
||||
|
|
|
|||
9
lib/compiler/aro/aro/Toolchain.zig
vendored
9
lib/compiler/aro/aro/Toolchain.zig
vendored
|
|
@ -171,8 +171,7 @@ pub fn getLinkerPath(tc: *const Toolchain, buf: []u8) ![]const u8 {
|
|||
/// TODO: this isn't exactly right since our target names don't necessarily match up
|
||||
/// with GCC's.
|
||||
/// For example the Zig target `arm-freestanding-eabi` would need the `arm-none-eabi` tools
|
||||
fn possibleProgramNames(raw_triple: ?[]const u8, name: []const u8, buf: *[64]u8) std.BoundedArray([]const u8, 2) {
|
||||
var possible_names: std.BoundedArray([]const u8, 2) = .{};
|
||||
fn possibleProgramNames(raw_triple: ?[]const u8, name: []const u8, buf: *[64]u8, possible_names: *std.ArrayListUnmanaged([]const u8)) void {
|
||||
if (raw_triple) |triple| {
|
||||
if (std.fmt.bufPrint(buf, "{s}-{s}", .{ triple, name })) |res| {
|
||||
possible_names.appendAssumeCapacity(res);
|
||||
|
|
@ -209,9 +208,11 @@ fn getProgramPath(tc: *const Toolchain, name: []const u8, buf: []u8) []const u8
|
|||
var fib = std.heap.FixedBufferAllocator.init(&path_buf);
|
||||
|
||||
var tool_specific_buf: [64]u8 = undefined;
|
||||
const possible_names = possibleProgramNames(tc.driver.raw_target_triple, name, &tool_specific_buf);
|
||||
var possible_names_buffer: [2][]const u8 = undefined;
|
||||
var possible_names = std.ArrayListUnmanaged.initBuffer(&possible_names_buffer);
|
||||
possibleProgramNames(tc.driver.raw_target_triple, name, &tool_specific_buf, &possible_names);
|
||||
|
||||
for (possible_names.constSlice()) |tool_name| {
|
||||
for (possible_names.items) |tool_name| {
|
||||
for (tc.program_paths.items) |program_path| {
|
||||
defer fib.reset();
|
||||
|
||||
|
|
|
|||
|
|
@ -3439,8 +3439,8 @@ fn transStringLiteralInitializer(
|
|||
const init_list = try t.arena.alloc(ZigNode, @intCast(num_inits));
|
||||
for (init_list, 0..) |*item, i| {
|
||||
const codepoint = switch (size) {
|
||||
2 => @as(*const u16, @alignCast(@ptrCast(bytes.ptr + i * 2))).*,
|
||||
4 => @as(*const u32, @alignCast(@ptrCast(bytes.ptr + i * 4))).*,
|
||||
2 => @as(*const u16, @ptrCast(@alignCast(bytes.ptr + i * 2))).*,
|
||||
4 => @as(*const u32, @ptrCast(@alignCast(bytes.ptr + i * 4))).*,
|
||||
else => unreachable,
|
||||
};
|
||||
item.* = try t.createCharLiteralNode(false, codepoint);
|
||||
|
|
@ -3873,7 +3873,7 @@ fn createNumberNode(t: *Translator, num: anytype, num_kind: enum { int, float })
|
|||
|
||||
fn createCharLiteralNode(t: *Translator, narrow: bool, val: u32) TransError!ZigNode {
|
||||
return ZigTag.char_literal.create(t.arena, if (narrow)
|
||||
try std.fmt.allocPrint(t.arena, "'{f}'", .{std.zig.fmtChar(&.{@as(u8, @intCast(val))})})
|
||||
try std.fmt.allocPrint(t.arena, "'{f}'", .{std.zig.fmtChar(@intCast(val))})
|
||||
else
|
||||
try std.fmt.allocPrint(t.arena, "'\\u{{{x}}}'", .{val}));
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue