diff options
Diffstat (limited to '')
| -rw-r--r-- | codegen/ccc.zig (renamed from codegen/normp.zig) | 25 |
1 files changed, 11 insertions, 14 deletions
diff --git a/codegen/normp.zig b/codegen/ccc.zig index 25af65c..93da6a0 100644 --- a/codegen/normp.zig +++ b/codegen/ccc.zig | |||
| @@ -1,6 +1,5 @@ | |||
| 1 | const std = @import("std"); | 1 | const std = @import("std"); |
| 2 | 2 | const builtin = @import("builtin"); | |
| 3 | const options = @import("options"); | ||
| 4 | 3 | ||
| 5 | const block_size = 256; | 4 | const block_size = 256; |
| 6 | const Block = [block_size]u8; | 5 | const Block = [block_size]u8; |
| @@ -108,21 +107,19 @@ pub fn main() !void { | |||
| 108 | _ = args_iter.skip(); | 107 | _ = args_iter.skip(); |
| 109 | const output_path = args_iter.next() orelse @panic("No output file arg!"); | 108 | const output_path = args_iter.next() orelse @panic("No output file arg!"); |
| 110 | 109 | ||
| 110 | const compressor = std.compress.deflate.compressor; | ||
| 111 | var out_file = try std.fs.cwd().createFile(output_path, .{}); | 111 | var out_file = try std.fs.cwd().createFile(output_path, .{}); |
| 112 | defer out_file.close(); | 112 | defer out_file.close(); |
| 113 | var out_buf = std.io.bufferedWriter(out_file.writer()); | 113 | var out_comp = try compressor(allocator, out_file.writer(), .{ .level = .best_compression }); |
| 114 | const writer = out_buf.writer(); | 114 | defer out_comp.deinit(); |
| 115 | 115 | const writer = out_comp.writer(); | |
| 116 | try writer.writeAll("const std = @import(\"std\");\n"); | ||
| 117 | 116 | ||
| 118 | try writer.print("const Stage2Int = std.math.IntFittingRange(0, {});\n", .{stage2.items.len}); | 117 | const endian = builtin.cpu.arch.endian(); |
| 119 | try writer.print("pub const stage_1 = [{}]Stage2Int{{", .{stage1.items.len}); | 118 | try writer.writeInt(u16, @intCast(stage1.items.len), endian); |
| 120 | for (stage1.items) |v| try writer.print("{},", .{v}); | 119 | for (stage1.items) |i| try writer.writeInt(u16, i, endian); |
| 121 | try writer.writeAll("};\n"); | ||
| 122 | 120 | ||
| 123 | try writer.print("pub const stage_2 = [{}]u8{{", .{stage2.items.len}); | 121 | try writer.writeInt(u16, @intCast(stage2.items.len), endian); |
| 124 | for (stage2.items) |v| try writer.print("{},", .{v}); | 122 | try writer.writeAll(stage2.items); |
| 125 | try writer.writeAll("};\n"); | ||
| 126 | 123 | ||
| 127 | try out_buf.flush(); | 124 | try out_comp.flush(); |
| 128 | } | 125 | } |