diff options
Diffstat (limited to 'codegen')
| -rw-r--r-- | codegen/ccc.zig (renamed from codegen/normp.zig) | 25 | ||||
| -rw-r--r-- | codegen/dwp.zig | 23 | ||||
| -rw-r--r-- | codegen/gbp.zig | 68 |
3 files changed, 40 insertions, 76 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 | } |
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 | } |
diff --git a/codegen/gbp.zig b/codegen/gbp.zig index 3bd9a4d..39e0da3 100644 --- a/codegen/gbp.zig +++ b/codegen/gbp.zig | |||
| @@ -1,4 +1,5 @@ | |||
| 1 | const std = @import("std"); | 1 | const std = @import("std"); |
| 2 | const builtin = @import("builtin"); | ||
| 2 | 3 | ||
| 3 | const Indic = enum { | 4 | const Indic = enum { |
| 4 | none, | 5 | none, |
| @@ -226,56 +227,23 @@ pub fn main() !void { | |||
| 226 | _ = args_iter.skip(); | 227 | _ = args_iter.skip(); |
| 227 | const output_path = args_iter.next() orelse @panic("No output file arg!"); | 228 | const output_path = args_iter.next() orelse @panic("No output file arg!"); |
| 228 | 229 | ||
| 230 | const compressor = std.compress.deflate.compressor; | ||
| 229 | var out_file = try std.fs.cwd().createFile(output_path, .{}); | 231 | var out_file = try std.fs.cwd().createFile(output_path, .{}); |
| 230 | defer out_file.close(); | 232 | defer out_file.close(); |
| 231 | var out_buf = std.io.bufferedWriter(out_file.writer()); | 233 | var out_comp = try compressor(allocator, out_file.writer(), .{ .level = .best_compression }); |
| 232 | const writer = out_buf.writer(); | 234 | defer out_comp.deinit(); |
| 233 | 235 | const writer = out_comp.writer(); | |
| 234 | const prop_code = | 236 | |
| 235 | \\const std = @import("std"); | 237 | const endian = builtin.cpu.arch.endian(); |
| 236 | \\ | 238 | try writer.writeInt(u16, @intCast(stage1.items.len), endian); |
| 237 | \\pub const Indic = enum { | 239 | for (stage1.items) |i| try writer.writeInt(u16, i, endian); |
| 238 | \\ none, | 240 | |
| 239 | \\ | 241 | try writer.writeInt(u16, @intCast(stage2.items.len), endian); |
| 240 | \\ Consonant, | 242 | for (stage2.items) |i| try writer.writeInt(u16, i, endian); |
| 241 | \\ Extend, | 243 | |
| 242 | \\ Linker, | 244 | const props_bytes = stage3.keys(); |
| 243 | \\}; | 245 | try writer.writeInt(u16, @intCast(props_bytes.len), endian); |
| 244 | \\ | 246 | try writer.writeAll(props_bytes); |
| 245 | \\pub const Gbp = enum { | 247 | |
| 246 | \\ none, | 248 | try out_comp.flush(); |
| 247 | \\ Control, | ||
| 248 | \\ CR, | ||
| 249 | \\ Extend, | ||
| 250 | \\ L, | ||
| 251 | \\ LF, | ||
| 252 | \\ LV, | ||
| 253 | \\ LVT, | ||
| 254 | \\ Prepend, | ||
| 255 | \\ Regional_Indicator, | ||
| 256 | \\ SpacingMark, | ||
| 257 | \\ T, | ||
| 258 | \\ V, | ||
| 259 | \\ ZWJ, | ||
| 260 | \\}; | ||
| 261 | \\ | ||
| 262 | ; | ||
| 263 | |||
| 264 | try writer.writeAll(prop_code); | ||
| 265 | |||
| 266 | try writer.print("const Stage2Int = std.math.IntFittingRange(0, {});\n", .{stage2.items.len}); | ||
| 267 | try writer.print("pub const stage_1 = [{}]Stage2Int{{", .{stage1.items.len}); | ||
| 268 | for (stage1.items) |v| try writer.print("{},", .{v}); | ||
| 269 | try writer.writeAll("};\n"); | ||
| 270 | |||
| 271 | try writer.print("const Stage3Int = std.math.IntFittingRange(0, {});\n", .{stage3_len}); | ||
| 272 | try writer.print("pub const stage_2 = [{}]Stage3Int{{", .{stage2.items.len}); | ||
| 273 | for (stage2.items) |v| try writer.print("{},", .{v}); | ||
| 274 | try writer.writeAll("};\n"); | ||
| 275 | |||
| 276 | try writer.print("pub const stage_3 = [{}]u8{{", .{stage3_len}); | ||
| 277 | for (stage3.keys()) |v| try writer.print("{},", .{v}); | ||
| 278 | try writer.writeAll("};\n"); | ||
| 279 | |||
| 280 | try out_buf.flush(); | ||
| 281 | } | 249 | } |