diff options
| author | 2024-02-26 12:24:42 -0400 | |
|---|---|---|
| committer | 2024-02-26 12:24:42 -0400 | |
| commit | 836a4b6e63ac4bd7beb406cb20edf23f0bd342a9 (patch) | |
| tree | 5f806a29594a9cb227aaa4d131209e10ff25aeee /codegen/dwp.zig | |
| parent | Replaced ccc_map with table. 20ms faster (diff) | |
| download | zg-836a4b6e63ac4bd7beb406cb20edf23f0bd342a9.tar.gz zg-836a4b6e63ac4bd7beb406cb20edf23f0bd342a9.tar.xz zg-836a4b6e63ac4bd7beb406cb20edf23f0bd342a9.zip | |
Using separate data struct model.
Diffstat (limited to 'codegen/dwp.zig')
| -rw-r--r-- | codegen/dwp.zig | 23 |
1 files changed, 11 insertions, 12 deletions
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 @@ | |||
| 1 | const std = @import("std"); | 1 | const std = @import("std"); |
| 2 | const builtin = @import("builtin"); | ||
| 2 | 3 | ||
| 3 | const options = @import("options"); | 4 | const options = @import("options"); |
| 4 | 5 | ||
| @@ -229,21 +230,19 @@ pub fn main() !void { | |||
| 229 | _ = args_iter.skip(); | 230 | _ = args_iter.skip(); |
| 230 | const output_path = args_iter.next() orelse @panic("No output file arg!"); | 231 | const output_path = args_iter.next() orelse @panic("No output file arg!"); |
| 231 | 232 | ||
| 233 | const compressor = std.compress.deflate.compressor; | ||
| 232 | var out_file = try std.fs.cwd().createFile(output_path, .{}); | 234 | var out_file = try std.fs.cwd().createFile(output_path, .{}); |
| 233 | defer out_file.close(); | 235 | defer out_file.close(); |
| 234 | var out_buf = std.io.bufferedWriter(out_file.writer()); | 236 | var out_comp = try compressor(allocator, out_file.writer(), .{ .level = .best_compression }); |
| 235 | const writer = out_buf.writer(); | 237 | defer out_comp.deinit(); |
| 238 | const writer = out_comp.writer(); | ||
| 236 | 239 | ||
| 237 | try writer.writeAll("const std = @import(\"std\");\n"); | 240 | const endian = builtin.cpu.arch.endian(); |
| 241 | try writer.writeInt(u16, @intCast(stage1.items.len), endian); | ||
| 242 | for (stage1.items) |i| try writer.writeInt(u16, i, endian); | ||
| 238 | 243 | ||
| 239 | try writer.print("const Stage2Int = std.math.IntFittingRange(0, {});\n", .{stage2.items.len}); | 244 | try writer.writeInt(u16, @intCast(stage2.items.len), endian); |
| 240 | try writer.print("pub const stage_1 = [{}]Stage2Int{{", .{stage1.items.len}); | 245 | for (stage2.items) |i| try writer.writeInt(i8, i, endian); |
| 241 | for (stage1.items) |v| try writer.print("{},", .{v}); | ||
| 242 | try writer.writeAll("};\n"); | ||
| 243 | 246 | ||
| 244 | try writer.print("pub const stage_2 = [{}]i3{{", .{stage2.items.len}); | 247 | try out_comp.flush(); |
| 245 | for (stage2.items) |v| try writer.print("{},", .{v}); | ||
| 246 | try writer.writeAll("};\n"); | ||
| 247 | |||
| 248 | try out_buf.flush(); | ||
| 249 | } | 248 | } |