mirror of
https://codeberg.org/ziglang/zig.git
synced 2025-12-06 05:44:20 +00:00
progress towards compiler building again
This commit is contained in:
parent
3b34622368
commit
d40803284e
4 changed files with 41 additions and 41 deletions
|
|
@ -6,12 +6,13 @@
|
|||
//! There is one special encoding for this data structure. If both arrays are
|
||||
//! empty, it means there are no errors. This special encoding exists so that
|
||||
//! heap allocation is not needed in the common case of no errors.
|
||||
const ErrorBundle = @This();
|
||||
|
||||
const std = @import("std");
|
||||
const ErrorBundle = @This();
|
||||
const Io = std.Io;
|
||||
const Writer = std.Io.Writer;
|
||||
const Allocator = std.mem.Allocator;
|
||||
const assert = std.debug.assert;
|
||||
const Writer = std.Io.Writer;
|
||||
|
||||
string_bytes: []const u8,
|
||||
/// The first thing in this array is an `ErrorMessageList`.
|
||||
|
|
@ -156,7 +157,7 @@ pub fn nullTerminatedString(eb: ErrorBundle, index: String) [:0]const u8 {
|
|||
}
|
||||
|
||||
pub const RenderOptions = struct {
|
||||
ttyconf: std.Io.tty.Config,
|
||||
ttyconf: Io.tty.Config,
|
||||
include_reference_trace: bool = true,
|
||||
include_source_line: bool = true,
|
||||
include_log_text: bool = true,
|
||||
|
|
@ -190,7 +191,7 @@ fn renderErrorMessageToWriter(
|
|||
err_msg_index: MessageIndex,
|
||||
w: *Writer,
|
||||
kind: []const u8,
|
||||
color: std.Io.tty.Color,
|
||||
color: Io.tty.Color,
|
||||
indent: usize,
|
||||
) (Writer.Error || std.posix.UnexpectedError)!void {
|
||||
const ttyconf = options.ttyconf;
|
||||
|
|
@ -320,6 +321,7 @@ fn writeMsg(eb: ErrorBundle, err_msg: ErrorMessage, w: *Writer, indent: usize) !
|
|||
|
||||
pub const Wip = struct {
|
||||
gpa: Allocator,
|
||||
io: Io,
|
||||
string_bytes: std.ArrayListUnmanaged(u8),
|
||||
/// The first thing in this array is a ErrorMessageList.
|
||||
extra: std.ArrayListUnmanaged(u32),
|
||||
|
|
@ -806,7 +808,7 @@ pub const Wip = struct {
|
|||
};
|
||||
defer bundle.deinit(std.testing.allocator);
|
||||
|
||||
const ttyconf: std.Io.tty.Config = .no_color;
|
||||
const ttyconf: Io.tty.Config = .no_color;
|
||||
|
||||
var bundle_buf: Writer.Allocating = .init(std.testing.allocator);
|
||||
const bundle_bw = &bundle_buf.interface;
|
||||
|
|
|
|||
|
|
@ -1,7 +1,9 @@
|
|||
const Compilation = @This();
|
||||
const builtin = @import("builtin");
|
||||
|
||||
const std = @import("std");
|
||||
const builtin = @import("builtin");
|
||||
const Io = std.Io;
|
||||
const Writer = std.Io.Writer;
|
||||
const fs = std.fs;
|
||||
const mem = std.mem;
|
||||
const Allocator = std.mem.Allocator;
|
||||
|
|
@ -12,7 +14,6 @@ const ThreadPool = std.Thread.Pool;
|
|||
const WaitGroup = std.Thread.WaitGroup;
|
||||
const ErrorBundle = std.zig.ErrorBundle;
|
||||
const fatal = std.process.fatal;
|
||||
const Writer = std.Io.Writer;
|
||||
|
||||
const Value = @import("Value.zig");
|
||||
const Type = @import("Type.zig");
|
||||
|
|
@ -1095,6 +1096,7 @@ pub const CObject = struct {
|
|||
bundle: Bundle,
|
||||
notes_len: u32,
|
||||
) !ErrorBundle.ErrorMessage {
|
||||
const io = eb.io;
|
||||
var start = diag.src_loc.offset;
|
||||
var end = diag.src_loc.offset;
|
||||
for (diag.src_ranges) |src_range| {
|
||||
|
|
@ -1117,7 +1119,7 @@ pub const CObject = struct {
|
|||
const file = fs.cwd().openFile(file_name, .{}) catch break :source_line 0;
|
||||
defer file.close();
|
||||
var buffer: [1024]u8 = undefined;
|
||||
var file_reader = file.reader(&buffer);
|
||||
var file_reader = file.reader(io, &buffer);
|
||||
file_reader.seekTo(diag.src_loc.offset + 1 - diag.src_loc.column) catch break :source_line 0;
|
||||
var aw: Writer.Allocating = .init(eb.gpa);
|
||||
defer aw.deinit();
|
||||
|
|
@ -1155,7 +1157,7 @@ pub const CObject = struct {
|
|||
gpa.destroy(bundle);
|
||||
}
|
||||
|
||||
pub fn parse(gpa: Allocator, path: []const u8) !*Bundle {
|
||||
pub fn parse(gpa: Allocator, io: Io, path: []const u8) !*Bundle {
|
||||
const BlockId = enum(u32) {
|
||||
Meta = 8,
|
||||
Diag,
|
||||
|
|
@ -1191,7 +1193,7 @@ pub const CObject = struct {
|
|||
var buffer: [1024]u8 = undefined;
|
||||
const file = try fs.cwd().openFile(path, .{});
|
||||
defer file.close();
|
||||
var file_reader = file.reader(&buffer);
|
||||
var file_reader = file.reader(io, &buffer);
|
||||
var bc = std.zig.llvm.BitcodeReader.init(gpa, .{ .reader = &file_reader.interface });
|
||||
defer bc.deinit();
|
||||
|
||||
|
|
|
|||
55
src/main.zig
55
src/main.zig
|
|
@ -319,7 +319,7 @@ fn mainArgs(gpa: Allocator, arena: Allocator, args: []const []const u8) !void {
|
|||
.root_src_path = "objcopy.zig",
|
||||
});
|
||||
} else if (mem.eql(u8, cmd, "fetch")) {
|
||||
return cmdFetch(gpa, arena, cmd_args);
|
||||
return cmdFetch(gpa, arena, io, cmd_args);
|
||||
} else if (mem.eql(u8, cmd, "libc")) {
|
||||
return jitCmd(gpa, arena, io, cmd_args, .{
|
||||
.cmd_name = "libc",
|
||||
|
|
@ -348,12 +348,14 @@ fn mainArgs(gpa: Allocator, arena: Allocator, args: []const []const u8) !void {
|
|||
return;
|
||||
} else if (mem.eql(u8, cmd, "env")) {
|
||||
dev.check(.env_command);
|
||||
const host = std.zig.resolveTargetQueryOrFatal(io, .{});
|
||||
var stdout_writer = fs.File.stdout().writer(&stdout_buffer);
|
||||
try @import("print_env.zig").cmdEnv(
|
||||
arena,
|
||||
&stdout_writer.interface,
|
||||
args,
|
||||
if (native_os == .wasi) wasi_preopens,
|
||||
&host,
|
||||
);
|
||||
return stdout_writer.interface.flush();
|
||||
} else if (mem.eql(u8, cmd, "reduce")) {
|
||||
|
|
@ -368,11 +370,11 @@ fn mainArgs(gpa: Allocator, arena: Allocator, args: []const []const u8) !void {
|
|||
dev.check(.help_command);
|
||||
return fs.File.stdout().writeAll(usage);
|
||||
} else if (mem.eql(u8, cmd, "ast-check")) {
|
||||
return cmdAstCheck(arena, cmd_args);
|
||||
return cmdAstCheck(arena, io, cmd_args);
|
||||
} else if (mem.eql(u8, cmd, "detect-cpu")) {
|
||||
return cmdDetectCpu(io, cmd_args);
|
||||
} else if (build_options.enable_debug_extensions and mem.eql(u8, cmd, "changelist")) {
|
||||
return cmdChangelist(arena, cmd_args);
|
||||
return cmdChangelist(arena, io, cmd_args);
|
||||
} else if (build_options.enable_debug_extensions and mem.eql(u8, cmd, "dump-zir")) {
|
||||
return cmdDumpZir(arena, cmd_args);
|
||||
} else if (build_options.enable_debug_extensions and mem.eql(u8, cmd, "llvm-ints")) {
|
||||
|
|
@ -741,7 +743,7 @@ const ArgMode = union(enum) {
|
|||
const Listen = union(enum) {
|
||||
none,
|
||||
stdio: if (dev.env.supports(.stdio_listen)) void else noreturn,
|
||||
ip4: if (dev.env.supports(.network_listen)) std.net.Ip4Address else noreturn,
|
||||
ip4: if (dev.env.supports(.network_listen)) Io.net.Ip4Address else noreturn,
|
||||
};
|
||||
|
||||
const ArgsIterator = struct {
|
||||
|
|
@ -1335,7 +1337,7 @@ fn buildOutputType(
|
|||
const host, const port_text = mem.cutScalar(u8, next_arg, ':') orelse .{ next_arg, "14735" };
|
||||
const port = std.fmt.parseInt(u16, port_text, 10) catch |err|
|
||||
fatal("invalid port number: '{s}': {s}", .{ port_text, @errorName(err) });
|
||||
listen = .{ .ip4 = std.net.Ip4Address.parse(host, port) catch |err|
|
||||
listen = .{ .ip4 = Io.net.Ip4Address.parse(host, port) catch |err|
|
||||
fatal("invalid host: '{s}': {s}", .{ host, @errorName(err) }) };
|
||||
}
|
||||
} else if (mem.eql(u8, arg, "--listen=-")) {
|
||||
|
|
@ -3318,7 +3320,7 @@ fn buildOutputType(
|
|||
var file_writer = f.writer(&.{});
|
||||
var buffer: [1000]u8 = undefined;
|
||||
var hasher = file_writer.interface.hashed(Cache.Hasher.init("0123456789abcdef"), &buffer);
|
||||
var stdin_reader = fs.File.stdin().readerStreaming(&.{});
|
||||
var stdin_reader = fs.File.stdin().readerStreaming(io, &.{});
|
||||
_ = hasher.writer.sendFileAll(&stdin_reader, .unlimited) catch |err| switch (err) {
|
||||
error.WriteFailed => fatal("failed to write {s}: {t}", .{ dump_path, file_writer.err.? }),
|
||||
else => fatal("failed to pipe stdin to {s}: {t}", .{ dump_path, err }),
|
||||
|
|
@ -3549,7 +3551,7 @@ fn buildOutputType(
|
|||
switch (listen) {
|
||||
.none => {},
|
||||
.stdio => {
|
||||
var stdin_reader = fs.File.stdin().reader(&stdin_buffer);
|
||||
var stdin_reader = fs.File.stdin().reader(io, &stdin_buffer);
|
||||
var stdout_writer = fs.File.stdout().writer(&stdout_buffer);
|
||||
try serve(
|
||||
io,
|
||||
|
|
@ -3565,23 +3567,23 @@ fn buildOutputType(
|
|||
return cleanExit();
|
||||
},
|
||||
.ip4 => |ip4_addr| {
|
||||
const addr: std.net.Address = .{ .in = ip4_addr };
|
||||
const addr: Io.net.IpAddress = .{ .ip4 = ip4_addr };
|
||||
|
||||
var server = try addr.listen(.{
|
||||
var server = try addr.listen(io, .{
|
||||
.reuse_address = true,
|
||||
});
|
||||
defer server.deinit();
|
||||
defer server.deinit(io);
|
||||
|
||||
const conn = try server.accept();
|
||||
defer conn.stream.close();
|
||||
var stream = try server.accept(io);
|
||||
defer stream.close(io);
|
||||
|
||||
var input = conn.stream.reader(&stdin_buffer);
|
||||
var output = conn.stream.writer(&stdout_buffer);
|
||||
var input = stream.reader(io, &stdin_buffer);
|
||||
var output = stream.writer(io, &stdout_buffer);
|
||||
|
||||
try serve(
|
||||
io,
|
||||
comp,
|
||||
input.interface(),
|
||||
&input.interface,
|
||||
&output.interface,
|
||||
test_exec_args.items,
|
||||
self_exe_path,
|
||||
|
|
@ -5062,7 +5064,7 @@ fn cmdBuild(gpa: Allocator, arena: Allocator, io: Io, args: []const []const u8)
|
|||
var http_client: if (dev.env.supports(.fetch_command)) std.http.Client else struct {
|
||||
allocator: Allocator,
|
||||
fn deinit(_: @This()) void {}
|
||||
} = .{ .allocator = gpa };
|
||||
} = .{ .allocator = gpa, .io = io };
|
||||
defer http_client.deinit();
|
||||
|
||||
var unlazy_set: Package.Fetch.JobQueue.UnlazySet = .{};
|
||||
|
|
@ -5600,7 +5602,7 @@ fn jitCmd(
|
|||
try child.spawn();
|
||||
|
||||
if (options.capture) |ptr| {
|
||||
var stdout_reader = child.stdout.?.readerStreaming(&.{});
|
||||
var stdout_reader = child.stdout.?.readerStreaming(io, &.{});
|
||||
ptr.* = try stdout_reader.interface.allocRemaining(arena, .limited(std.math.maxInt(u32)));
|
||||
}
|
||||
|
||||
|
|
@ -6055,10 +6057,7 @@ const usage_ast_check =
|
|||
\\
|
||||
;
|
||||
|
||||
fn cmdAstCheck(
|
||||
arena: Allocator,
|
||||
args: []const []const u8,
|
||||
) !void {
|
||||
fn cmdAstCheck(arena: Allocator, io: Io, args: []const []const u8) !void {
|
||||
dev.check(.ast_check_command);
|
||||
|
||||
const Zir = std.zig.Zir;
|
||||
|
|
@ -6106,7 +6105,7 @@ fn cmdAstCheck(
|
|||
};
|
||||
} else fs.File.stdin();
|
||||
defer if (zig_source_path != null) f.close();
|
||||
var file_reader: fs.File.Reader = f.reader(&stdin_buffer);
|
||||
var file_reader: fs.File.Reader = f.reader(io, &stdin_buffer);
|
||||
break :s std.zig.readSourceFileToEndAlloc(arena, &file_reader) catch |err| {
|
||||
fatal("unable to load file '{s}' for ast-check: {s}", .{ display_path, @errorName(err) });
|
||||
};
|
||||
|
|
@ -6448,10 +6447,7 @@ fn cmdDumpZir(
|
|||
}
|
||||
|
||||
/// This is only enabled for debug builds.
|
||||
fn cmdChangelist(
|
||||
arena: Allocator,
|
||||
args: []const []const u8,
|
||||
) !void {
|
||||
fn cmdChangelist(arena: Allocator, io: Io, args: []const []const u8) !void {
|
||||
dev.check(.changelist_command);
|
||||
|
||||
const color: Color = .auto;
|
||||
|
|
@ -6464,7 +6460,7 @@ fn cmdChangelist(
|
|||
var f = fs.cwd().openFile(old_source_path, .{}) catch |err|
|
||||
fatal("unable to open old source file '{s}': {s}", .{ old_source_path, @errorName(err) });
|
||||
defer f.close();
|
||||
var file_reader: fs.File.Reader = f.reader(&stdin_buffer);
|
||||
var file_reader: fs.File.Reader = f.reader(io, &stdin_buffer);
|
||||
break :source std.zig.readSourceFileToEndAlloc(arena, &file_reader) catch |err|
|
||||
fatal("unable to read old source file '{s}': {s}", .{ old_source_path, @errorName(err) });
|
||||
};
|
||||
|
|
@ -6472,7 +6468,7 @@ fn cmdChangelist(
|
|||
var f = fs.cwd().openFile(new_source_path, .{}) catch |err|
|
||||
fatal("unable to open new source file '{s}': {s}", .{ new_source_path, @errorName(err) });
|
||||
defer f.close();
|
||||
var file_reader: fs.File.Reader = f.reader(&stdin_buffer);
|
||||
var file_reader: fs.File.Reader = f.reader(io, &stdin_buffer);
|
||||
break :source std.zig.readSourceFileToEndAlloc(arena, &file_reader) catch |err|
|
||||
fatal("unable to read new source file '{s}': {s}", .{ new_source_path, @errorName(err) });
|
||||
};
|
||||
|
|
@ -6829,6 +6825,7 @@ const usage_fetch =
|
|||
fn cmdFetch(
|
||||
gpa: Allocator,
|
||||
arena: Allocator,
|
||||
io: Io,
|
||||
args: []const []const u8,
|
||||
) !void {
|
||||
dev.check(.fetch_command);
|
||||
|
|
@ -6884,7 +6881,7 @@ fn cmdFetch(
|
|||
try thread_pool.init(.{ .allocator = gpa });
|
||||
defer thread_pool.deinit();
|
||||
|
||||
var http_client: std.http.Client = .{ .allocator = gpa };
|
||||
var http_client: std.http.Client = .{ .allocator = gpa, .io = io };
|
||||
defer http_client.deinit();
|
||||
|
||||
try http_client.initDefaultProxies(arena);
|
||||
|
|
|
|||
|
|
@ -14,6 +14,7 @@ pub fn cmdEnv(
|
|||
.wasi => std.fs.wasi.Preopens,
|
||||
else => void,
|
||||
},
|
||||
host: *const std.Target,
|
||||
) !void {
|
||||
const override_lib_dir: ?[]const u8 = try EnvVar.ZIG_LIB_DIR.get(arena);
|
||||
const override_global_cache_dir: ?[]const u8 = try EnvVar.ZIG_GLOBAL_CACHE_DIR.get(arena);
|
||||
|
|
@ -38,8 +39,6 @@ pub fn cmdEnv(
|
|||
const zig_lib_dir = dirs.zig_lib.path orelse "";
|
||||
const zig_std_dir = try dirs.zig_lib.join(arena, &.{"std"});
|
||||
const global_cache_dir = dirs.global_cache.path orelse "";
|
||||
|
||||
const host = try std.zig.system.resolveTargetQuery(.{});
|
||||
const triple = try host.zigTriple(arena);
|
||||
|
||||
var serializer: std.zon.Serializer = .{ .writer = out };
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue