From 836a4b6e63ac4bd7beb406cb20edf23f0bd342a9 Mon Sep 17 00:00:00 2001 From: Jose Colon Rodriguez Date: Mon, 26 Feb 2024 12:24:42 -0400 Subject: Using separate data struct model. --- codegen/dwp.zig | 23 +++++++++++------------ 1 file changed, 11 insertions(+), 12 deletions(-) (limited to 'codegen/dwp.zig') diff --git a/codegen/dwp.zig b/codegen/dwp.zig index 9e387c6..76a14d3 100644 --- a/codegen/dwp.zig +++ b/codegen/dwp.zig @@ -1,4 +1,5 @@ const std = @import("std"); +const builtin = @import("builtin"); const options = @import("options"); @@ -229,21 +230,19 @@ pub fn main() !void { _ = args_iter.skip(); const output_path = args_iter.next() orelse @panic("No output file arg!"); + const compressor = std.compress.deflate.compressor; var out_file = try std.fs.cwd().createFile(output_path, .{}); defer out_file.close(); - var out_buf = std.io.bufferedWriter(out_file.writer()); - const writer = out_buf.writer(); + var out_comp = try compressor(allocator, out_file.writer(), .{ .level = .best_compression }); + defer out_comp.deinit(); + const writer = out_comp.writer(); - try writer.writeAll("const std = @import(\"std\");\n"); + const endian = builtin.cpu.arch.endian(); + try writer.writeInt(u16, @intCast(stage1.items.len), endian); + for (stage1.items) |i| try writer.writeInt(u16, i, endian); - try writer.print("const Stage2Int = std.math.IntFittingRange(0, {});\n", .{stage2.items.len}); - try writer.print("pub const stage_1 = [{}]Stage2Int{{", .{stage1.items.len}); - for (stage1.items) |v| try writer.print("{},", .{v}); - try writer.writeAll("};\n"); + try writer.writeInt(u16, @intCast(stage2.items.len), endian); + for (stage2.items) |i| try writer.writeInt(i8, i, endian); - try writer.print("pub const stage_2 = [{}]i3{{", .{stage2.items.len}); - for (stage2.items) |v| try writer.print("{},", .{v}); - try writer.writeAll("};\n"); - - try out_buf.flush(); + try out_comp.flush(); } -- cgit v1.2.3