lib/choir/src/backends/artifact/model/payload/debug.zig
daab053ee43316e1809a84551d573ddd1e5bf3d2
1 const std = @import("std");
2 const payload = @import("root.zig");
3
4 const Allocator = std.mem.Allocator;
5
6 pub const DebugRecordKind = enum(u8) {
7 line_table = 1,
8 symbol_table = 2,
9 dwarf_section = 3,
10 source_map = 4,
11 note = 5,
12 };
13
14 pub const DebugRecord = struct {
15 name: []const u8,
16 kind: DebugRecordKind,
17 bytes: []const u8,
18
19 pub fn dupe(self: DebugRecord, allocator: Allocator) Allocator.Error!DebugRecord {
20 const name = try payload.slice.dupe(allocator, self.name);
21 errdefer payload.slice.free(allocator, name);
22 return .{
23 .name = name,
24 .kind = self.kind,
25 .bytes = try payload.slice.dupe(allocator, self.bytes),
26 };
27 }
28
29 pub fn deinit(self: DebugRecord, allocator: Allocator) void {
30 payload.slice.free(allocator, self.name);
31 payload.slice.free(allocator, self.bytes);
32 }
33
34 pub fn eql(self: DebugRecord, other: DebugRecord) bool {
35 return self.kind == other.kind and
36 std.mem.eql(u8, self.name, other.name) and
37 std.mem.eql(u8, self.bytes, other.bytes);
38 }
39 };