| author | |
| committer | |
| log | 51a904677c9c9264f4856aaff270b18483205443 |
| tree | cfd47da9310c79116e32c455cb7a9c3934971ace |
| parent | 4128eea00c86f2f62d6d9e987c51929f1722be24 |
| signature |
* `zig env`:
* fix depreciated interface, update outStream -> writer
* make code more readable by updating `anytype` -> `std.fs.File.Writer`5 files changed, 29 insertions(+), 29 deletions(-)
doc/docgen.zig+6-6| ... | @@ -42,7 +42,7 @@ pub fn main() !void { | ... | @@ -42,7 +42,7 @@ pub fn main() !void { |
| 42 | 42 | ||
| 43 | const input_file_bytes = try in_file.inStream().readAllAlloc(allocator, max_doc_file_size); | 43 | const input_file_bytes = try in_file.inStream().readAllAlloc(allocator, max_doc_file_size); |
| 44 | 44 | ||
| 45 | var buffered_out_stream = io.bufferedOutStream(out_file.outStream()); | 45 | var buffered_out_stream = io.bufferedOutStream(out_file.writer()); |
| 46 | 46 | ||
| 47 | var tokenizer = Tokenizer.init(in_file_name, input_file_bytes); | 47 | var tokenizer = Tokenizer.init(in_file_name, input_file_bytes); |
| 48 | var toc = try genToc(allocator, &tokenizer); | 48 | var toc = try genToc(allocator, &tokenizer); |
| ... | @@ -50,7 +50,7 @@ pub fn main() !void { | ... | @@ -50,7 +50,7 @@ pub fn main() !void { |
| 50 | try fs.cwd().makePath(tmp_dir_name); | 50 | try fs.cwd().makePath(tmp_dir_name); |
| 51 | defer fs.cwd().deleteTree(tmp_dir_name) catch {}; | 51 | defer fs.cwd().deleteTree(tmp_dir_name) catch {}; |
| 52 | 52 | ||
| 53 | try genHtml(allocator, &tokenizer, &toc, buffered_out_stream.outStream(), zig_exe); | 53 | try genHtml(allocator, &tokenizer, &toc, buffered_out_stream.writer(), zig_exe); |
| 54 | try buffered_out_stream.flush(); | 54 | try buffered_out_stream.flush(); |
| 55 | } | 55 | } |
| 56 | 56 | ||
| ... | @@ -325,7 +325,7 @@ fn genToc(allocator: *mem.Allocator, tokenizer: *Tokenizer) !Toc { | ... | @@ -325,7 +325,7 @@ fn genToc(allocator: *mem.Allocator, tokenizer: *Tokenizer) !Toc { |
| 325 | var toc_buf = std.ArrayList(u8).init(allocator); | 325 | var toc_buf = std.ArrayList(u8).init(allocator); |
| 326 | defer toc_buf.deinit(); | 326 | defer toc_buf.deinit(); |
| 327 | 327 | ||
| 328 | var toc = toc_buf.outStream(); | 328 | var toc = toc_buf.writer(); |
| 329 | 329 | ||
| 330 | var nodes = std.ArrayList(Node).init(allocator); | 330 | var nodes = std.ArrayList(Node).init(allocator); |
| 331 | defer nodes.deinit(); | 331 | defer nodes.deinit(); |
| ... | @@ -615,7 +615,7 @@ fn urlize(allocator: *mem.Allocator, input: []const u8) ![]u8 { | ... | @@ -615,7 +615,7 @@ fn urlize(allocator: *mem.Allocator, input: []const u8) ![]u8 { |
| 615 | var buf = std.ArrayList(u8).init(allocator); | 615 | var buf = std.ArrayList(u8).init(allocator); |
| 616 | defer buf.deinit(); | 616 | defer buf.deinit(); |
| 617 | 617 | ||
| 618 | const out = buf.outStream(); | 618 | const out = buf.writer(); |
| 619 | for (input) |c| { | 619 | for (input) |c| { |
| 620 | switch (c) { | 620 | switch (c) { |
| 621 | 'a'...'z', 'A'...'Z', '_', '-', '0'...'9' => { | 621 | 'a'...'z', 'A'...'Z', '_', '-', '0'...'9' => { |
| ... | @@ -634,7 +634,7 @@ fn escapeHtml(allocator: *mem.Allocator, input: []const u8) ![]u8 { | ... | @@ -634,7 +634,7 @@ fn escapeHtml(allocator: *mem.Allocator, input: []const u8) ![]u8 { |
| 634 | var buf = std.ArrayList(u8).init(allocator); | 634 | var buf = std.ArrayList(u8).init(allocator); |
| 635 | defer buf.deinit(); | 635 | defer buf.deinit(); |
| 636 | 636 | ||
| 637 | const out = buf.outStream(); | 637 | const out = buf.writer(); |
| 638 | try writeEscaped(out, input); | 638 | try writeEscaped(out, input); |
| 639 | return buf.toOwnedSlice(); | 639 | return buf.toOwnedSlice(); |
| 640 | } | 640 | } |
| ... | @@ -680,7 +680,7 @@ fn termColor(allocator: *mem.Allocator, input: []const u8) ![]u8 { | ... | @@ -680,7 +680,7 @@ fn termColor(allocator: *mem.Allocator, input: []const u8) ![]u8 { |
| 680 | var buf = std.ArrayList(u8).init(allocator); | 680 | var buf = std.ArrayList(u8).init(allocator); |
| 681 | defer buf.deinit(); | 681 | defer buf.deinit(); |
| 682 | 682 | ||
| 683 | var out = buf.outStream(); | 683 | var out = buf.writer(); |
| 684 | var number_start_index: usize = undefined; | 684 | var number_start_index: usize = undefined; |
| 685 | var first_number: usize = undefined; | 685 | var first_number: usize = undefined; |
| 686 | var second_number: usize = undefined; | 686 | var second_number: usize = undefined; |
src/main.zig+1-1| ... | @@ -200,7 +200,7 @@ pub fn mainArgs(gpa: *Allocator, arena: *Allocator, args: []const []const u8) !v | ... | @@ -200,7 +200,7 @@ pub fn mainArgs(gpa: *Allocator, arena: *Allocator, args: []const []const u8) !v |
| 200 | } else if (mem.eql(u8, cmd, "version")) { | 200 | } else if (mem.eql(u8, cmd, "version")) { |
| 201 | try std.io.getStdOut().writeAll(build_options.version ++ "\n"); | 201 | try std.io.getStdOut().writeAll(build_options.version ++ "\n"); |
| 202 | } else if (mem.eql(u8, cmd, "env")) { | 202 | } else if (mem.eql(u8, cmd, "env")) { |
| 203 | try @import("print_env.zig").cmdEnv(arena, cmd_args, io.getStdOut().outStream()); | 203 | try @import("print_env.zig").cmdEnv(arena, cmd_args, io.getStdOut().writer()); |
| 204 | } else if (mem.eql(u8, cmd, "zen")) { | 204 | } else if (mem.eql(u8, cmd, "zen")) { |
| 205 | try io.getStdOut().writeAll(info_zen); | 205 | try io.getStdOut().writeAll(info_zen); |
| 206 | } else if (mem.eql(u8, cmd, "help") or mem.eql(u8, cmd, "-h") or mem.eql(u8, cmd, "--help")) { | 206 | } else if (mem.eql(u8, cmd, "help") or mem.eql(u8, cmd, "-h") or mem.eql(u8, cmd, "--help")) { |
src/print_env.zig+1-1| ... | @@ -4,7 +4,7 @@ const introspect = @import("introspect.zig"); | ... | @@ -4,7 +4,7 @@ const introspect = @import("introspect.zig"); |
| 4 | const Allocator = std.mem.Allocator; | 4 | const Allocator = std.mem.Allocator; |
| 5 | const fatal = @import("main.zig").fatal; | 5 | const fatal = @import("main.zig").fatal; |
| 6 | 6 | ||
| 7 | pub fn cmdEnv(gpa: *Allocator, args: []const []const u8, stdout: anytype) !void { | 7 | pub fn cmdEnv(gpa: *Allocator, args: []const []const u8, stdout: std.fs.File.Writer) !void { |
| 8 | const self_exe_path = try std.fs.selfExePathAlloc(gpa); | 8 | const self_exe_path = try std.fs.selfExePathAlloc(gpa); |
| 9 | defer gpa.free(self_exe_path); | 9 | defer gpa.free(self_exe_path); |
| 10 | 10 |
tools/merge_anal_dumps.zig+15-15| ... | @@ -17,13 +17,13 @@ pub fn main() anyerror!void { | ... | @@ -17,13 +17,13 @@ pub fn main() anyerror!void { |
| 17 | var dump = Dump.init(allocator); | 17 | var dump = Dump.init(allocator); |
| 18 | for (args[1..]) |arg| { | 18 | for (args[1..]) |arg| { |
| 19 | parser = json.Parser.init(allocator, false); | 19 | parser = json.Parser.init(allocator, false); |
| 20 | const json_text = try std.io.readFileAlloc(allocator, arg); | 20 | const json_text = try std.fs.cwd().readFileAlloc(allocator, arg, std.math.maxInt(usize)); |
| 21 | const tree = try parser.parse(json_text); | 21 | const tree = try parser.parse(json_text); |
| 22 | try dump.mergeJson(tree.root); | 22 | try dump.mergeJson(tree.root); |
| 23 | } | 23 | } |
| 24 | 24 | ||
| 25 | const stdout = try std.io.getStdOut(); | 25 | const stdout = try std.io.getStdOut(); |
| 26 | try dump.render(stdout.outStream()); | 26 | try dump.render(stdout.writer()); |
| 27 | } | 27 | } |
| 28 | 28 | ||
| 29 | /// AST source node | 29 | /// AST source node |
| ... | @@ -33,12 +33,12 @@ const Node = struct { | ... | @@ -33,12 +33,12 @@ const Node = struct { |
| 33 | col: usize, | 33 | col: usize, |
| 34 | fields: []usize, | 34 | fields: []usize, |
| 35 | 35 | ||
| 36 | fn hash(n: Node) u32 { | 36 | fn hash(n: Node) u64 { |
| 37 | var hasher = std.hash.Wyhash.init(0); | 37 | var hasher = std.hash.Wyhash.init(0); |
| 38 | std.hash.autoHash(&hasher, n.file); | 38 | std.hash.autoHash(&hasher, n.file); |
| 39 | std.hash.autoHash(&hasher, n.line); | 39 | std.hash.autoHash(&hasher, n.line); |
| 40 | std.hash.autoHash(&hasher, n.col); | 40 | std.hash.autoHash(&hasher, n.col); |
| 41 | return @truncate(u32, hasher.final()); | 41 | return hasher.final(); |
| 42 | } | 42 | } |
| 43 | 43 | ||
| 44 | fn eql(a: Node, b: Node) bool { | 44 | fn eql(a: Node, b: Node) bool { |
| ... | @@ -52,10 +52,10 @@ const Error = struct { | ... | @@ -52,10 +52,10 @@ const Error = struct { |
| 52 | src: usize, | 52 | src: usize, |
| 53 | name: []const u8, | 53 | name: []const u8, |
| 54 | 54 | ||
| 55 | fn hash(n: Error) u32 { | 55 | fn hash(n: Error) u64 { |
| 56 | var hasher = std.hash.Wyhash.init(0); | 56 | var hasher = std.hash.Wyhash.init(0); |
| 57 | std.hash.autoHash(&hasher, n.src); | 57 | std.hash.autoHash(&hasher, n.src); |
| 58 | return @truncate(u32, hasher.final()); | 58 | return hasher.final(); |
| 59 | } | 59 | } |
| 60 | 60 | ||
| 61 | fn eql(a: Error, b: Error) bool { | 61 | fn eql(a: Error, b: Error) bool { |
| ... | @@ -103,7 +103,6 @@ const Type = union(builtin.TypeId) { | ... | @@ -103,7 +103,6 @@ const Type = union(builtin.TypeId) { |
| 103 | Union, // TODO | 103 | Union, // TODO |
| 104 | Fn, // TODO | 104 | Fn, // TODO |
| 105 | BoundFn, // TODO | 105 | BoundFn, // TODO |
| 106 | ArgTuple, // TODO | ||
| 107 | Opaque, // TODO | 106 | Opaque, // TODO |
| 108 | Frame, // TODO | 107 | Frame, // TODO |
| 109 | 108 | ||
| ... | @@ -127,10 +126,10 @@ const Type = union(builtin.TypeId) { | ... | @@ -127,10 +126,10 @@ const Type = union(builtin.TypeId) { |
| 127 | len: usize, | 126 | len: usize, |
| 128 | }; | 127 | }; |
| 129 | 128 | ||
| 130 | fn hash(t: Type) u32 { | 129 | fn hash(t: Type) u64 { |
| 131 | var hasher = std.hash.Wyhash.init(0); | 130 | var hasher = std.hash.Wyhash.init(0); |
| 132 | std.hash.autoHash(&hasher, builtin.TypeId(t)); | 131 | std.hash.autoHash(&hasher, t); |
| 133 | return @truncate(u32, hasher.final()); | 132 | return hasher.final(); |
| 134 | } | 133 | } |
| 135 | 134 | ||
| 136 | fn eql(a: Type, b: Type) bool { | 135 | fn eql(a: Type, b: Type) bool { |
| ... | @@ -144,22 +143,23 @@ const Dump = struct { | ... | @@ -144,22 +143,23 @@ const Dump = struct { |
| 144 | root_name: ?[]const u8 = null, | 143 | root_name: ?[]const u8 = null, |
| 145 | targets: std.ArrayList([]const u8), | 144 | targets: std.ArrayList([]const u8), |
| 146 | 145 | ||
| 147 | const FileMap = std.StringHashMap(usize); | ||
| 148 | file_list: std.ArrayList([]const u8), | 146 | file_list: std.ArrayList([]const u8), |
| 149 | file_map: FileMap, | 147 | file_map: FileMap, |
| 150 | 148 | ||
| 151 | const NodeMap = std.HashMap(Node, usize, Node.hash, Node.eql); | ||
| 152 | node_list: std.ArrayList(Node), | 149 | node_list: std.ArrayList(Node), |
| 153 | node_map: NodeMap, | 150 | node_map: NodeMap, |
| 154 | 151 | ||
| 155 | const ErrorMap = std.HashMap(Error, usize, Error.hash, Error.eql); | ||
| 156 | error_list: std.ArrayList(Error), | 152 | error_list: std.ArrayList(Error), |
| 157 | error_map: ErrorMap, | 153 | error_map: ErrorMap, |
| 158 | 154 | ||
| 159 | const TypeMap = std.HashMap(Type, usize, Type.hash, Type.eql); | ||
| 160 | type_list: std.ArrayList(Type), | 155 | type_list: std.ArrayList(Type), |
| 161 | type_map: TypeMap, | 156 | type_map: TypeMap, |
| 162 | 157 | ||
| 158 | const FileMap = std.StringHashMap(usize); | ||
| 159 | const NodeMap = std.HashMap(Node, usize, Node.hash, Node.eql, 80); | ||
| 160 | const ErrorMap = std.HashMap(Error, usize, Error.hash, Error.eql, 80); | ||
| 161 | const TypeMap = std.HashMap(Type, usize, Type.hash, Type.eql, 80); | ||
| 162 | |||
| 163 | fn init(allocator: *mem.Allocator) Dump { | 163 | fn init(allocator: *mem.Allocator) Dump { |
| 164 | return Dump{ | 164 | return Dump{ |
| 165 | .targets = std.ArrayList([]const u8).init(allocator), | 165 | .targets = std.ArrayList([]const u8).init(allocator), |
| ... | @@ -310,7 +310,7 @@ const Dump = struct { | ... | @@ -310,7 +310,7 @@ const Dump = struct { |
| 310 | try other_types_to_mine.putNoClobber(other_type_index, gop.kv.value); | 310 | try other_types_to_mine.putNoClobber(other_type_index, gop.kv.value); |
| 311 | } | 311 | } |
| 312 | 312 | ||
| 313 | fn render(self: *Dump, stream: var) !void { | 313 | fn render(self: *Dump, stream: anytype) !void { |
| 314 | var jw = json.WriteStream(@TypeOf(stream).Child, 10).init(stream); | 314 | var jw = json.WriteStream(@TypeOf(stream).Child, 10).init(stream); |
| 315 | try jw.beginObject(); | 315 | try jw.beginObject(); |
| 316 | 316 |
tools/update_glibc.zig+6-6| ... | @@ -239,8 +239,8 @@ pub fn main() !void { | ... | @@ -239,8 +239,8 @@ pub fn main() !void { |
| 239 | const vers_txt_path = try fs.path.join(allocator, &[_][]const u8{ glibc_out_dir, "vers.txt" }); | 239 | const vers_txt_path = try fs.path.join(allocator, &[_][]const u8{ glibc_out_dir, "vers.txt" }); |
| 240 | const vers_txt_file = try fs.cwd().createFile(vers_txt_path, .{}); | 240 | const vers_txt_file = try fs.cwd().createFile(vers_txt_path, .{}); |
| 241 | defer vers_txt_file.close(); | 241 | defer vers_txt_file.close(); |
| 242 | var buffered = std.io.bufferedOutStream(vers_txt_file.outStream()); | 242 | var buffered = std.io.bufferedOutStream(vers_txt_file.writer()); |
| 243 | const vers_txt = buffered.outStream(); | 243 | const vers_txt = buffered.writer(); |
| 244 | for (global_ver_list) |name, i| { | 244 | for (global_ver_list) |name, i| { |
| 245 | _ = global_ver_set.put(name, i) catch unreachable; | 245 | _ = global_ver_set.put(name, i) catch unreachable; |
| 246 | try vers_txt.print("{}\n", .{name}); | 246 | try vers_txt.print("{}\n", .{name}); |
| ... | @@ -251,8 +251,8 @@ pub fn main() !void { | ... | @@ -251,8 +251,8 @@ pub fn main() !void { |
| 251 | const fns_txt_path = try fs.path.join(allocator, &[_][]const u8{ glibc_out_dir, "fns.txt" }); | 251 | const fns_txt_path = try fs.path.join(allocator, &[_][]const u8{ glibc_out_dir, "fns.txt" }); |
| 252 | const fns_txt_file = try fs.cwd().createFile(fns_txt_path, .{}); | 252 | const fns_txt_file = try fs.cwd().createFile(fns_txt_path, .{}); |
| 253 | defer fns_txt_file.close(); | 253 | defer fns_txt_file.close(); |
| 254 | var buffered = std.io.bufferedOutStream(fns_txt_file.outStream()); | 254 | var buffered = std.io.bufferedOutStream(fns_txt_file.writer()); |
| 255 | const fns_txt = buffered.outStream(); | 255 | const fns_txt = buffered.writer(); |
| 256 | for (global_fn_list) |name, i| { | 256 | for (global_fn_list) |name, i| { |
| 257 | const entry = global_fn_set.getEntry(name).?; | 257 | const entry = global_fn_set.getEntry(name).?; |
| 258 | entry.value.index = i; | 258 | entry.value.index = i; |
| ... | @@ -282,8 +282,8 @@ pub fn main() !void { | ... | @@ -282,8 +282,8 @@ pub fn main() !void { |
| 282 | const abilist_txt_path = try fs.path.join(allocator, &[_][]const u8{ glibc_out_dir, "abi.txt" }); | 282 | const abilist_txt_path = try fs.path.join(allocator, &[_][]const u8{ glibc_out_dir, "abi.txt" }); |
| 283 | const abilist_txt_file = try fs.cwd().createFile(abilist_txt_path, .{}); | 283 | const abilist_txt_file = try fs.cwd().createFile(abilist_txt_path, .{}); |
| 284 | defer abilist_txt_file.close(); | 284 | defer abilist_txt_file.close(); |
| 285 | var buffered = std.io.bufferedOutStream(abilist_txt_file.outStream()); | 285 | var buffered = std.io.bufferedOutStream(abilist_txt_file.writer()); |
| 286 | const abilist_txt = buffered.outStream(); | 286 | const abilist_txt = buffered.writer(); |
| 287 | 287 | ||
| 288 | // first iterate over the abi lists | 288 | // first iterate over the abi lists |
| 289 | for (abi_lists) |*abi_list, abi_index| { | 289 | for (abi_lists) |*abi_list, abi_index| { |