mirror of
https://codeberg.org/ziglang/zig.git
synced 2025-12-08 06:44:27 +00:00
coff: move Symtab and Strtab out of coff.Coff
This should ease interfacing with different std.coff functionalities.
This commit is contained in:
parent
7ef0c9d298
commit
aa5568beb6
1 changed files with 121 additions and 121 deletions
|
|
@ -1100,15 +1100,16 @@ pub const Coff = struct {
|
||||||
mem.copy(u8, out_buff, self.data[sec.pointer_to_raw_data..][0..sec.virtual_size]);
|
mem.copy(u8, out_buff, self.data[sec.pointer_to_raw_data..][0..sec.virtual_size]);
|
||||||
return out_buff;
|
return out_buff;
|
||||||
}
|
}
|
||||||
|
};
|
||||||
|
|
||||||
pub const Symtab = struct {
|
pub const Symtab = struct {
|
||||||
buffer: []const u8,
|
buffer: []const u8,
|
||||||
|
|
||||||
fn len(self: Symtab) usize {
|
pub fn len(self: Symtab) usize {
|
||||||
return @divExact(self.buffer.len, Symbol.sizeOf());
|
return @divExact(self.buffer.len, Symbol.sizeOf());
|
||||||
}
|
}
|
||||||
|
|
||||||
const Tag = enum {
|
pub const Tag = enum {
|
||||||
symbol,
|
symbol,
|
||||||
func_def,
|
func_def,
|
||||||
debug_info,
|
debug_info,
|
||||||
|
|
@ -1117,7 +1118,7 @@ pub const Coff = struct {
|
||||||
sect_def,
|
sect_def,
|
||||||
};
|
};
|
||||||
|
|
||||||
const Record = union(Tag) {
|
pub const Record = union(Tag) {
|
||||||
symbol: Symbol,
|
symbol: Symbol,
|
||||||
debug_info: DebugInfoDefinition,
|
debug_info: DebugInfoDefinition,
|
||||||
func_def: FunctionDefinition,
|
func_def: FunctionDefinition,
|
||||||
|
|
@ -1127,7 +1128,7 @@ pub const Coff = struct {
|
||||||
};
|
};
|
||||||
|
|
||||||
/// Lives as long as Symtab instance.
|
/// Lives as long as Symtab instance.
|
||||||
fn at(self: Symtab, index: usize, tag: Tag) Record {
|
pub fn at(self: Symtab, index: usize, tag: Tag) Record {
|
||||||
const offset = index * Symbol.sizeOf();
|
const offset = index * Symbol.sizeOf();
|
||||||
const raw = self.buffer[offset..][0..Symbol.sizeOf()];
|
const raw = self.buffer[offset..][0..Symbol.sizeOf()];
|
||||||
return switch (tag) {
|
return switch (tag) {
|
||||||
|
|
@ -1197,13 +1198,13 @@ pub const Coff = struct {
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
const Slice = struct {
|
pub const Slice = struct {
|
||||||
buffer: []const u8,
|
buffer: []const u8,
|
||||||
num: usize,
|
num: usize,
|
||||||
count: usize = 0,
|
count: usize = 0,
|
||||||
|
|
||||||
/// Lives as long as Symtab instance.
|
/// Lives as long as Symtab instance.
|
||||||
fn next(self: *Slice) ?Symbol {
|
pub fn next(self: *Slice) ?Symbol {
|
||||||
if (self.count >= self.num) return null;
|
if (self.count >= self.num) return null;
|
||||||
const sym = asSymbol(self.buffer[0..Symbol.sizeOf()]);
|
const sym = asSymbol(self.buffer[0..Symbol.sizeOf()]);
|
||||||
self.count += 1;
|
self.count += 1;
|
||||||
|
|
@ -1212,20 +1213,19 @@ pub const Coff = struct {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
fn slice(self: Symtab, start: usize, end: ?usize) Slice {
|
pub fn slice(self: Symtab, start: usize, end: ?usize) Slice {
|
||||||
const offset = start * Symbol.sizeOf();
|
const offset = start * Symbol.sizeOf();
|
||||||
const llen = if (end) |e| e * Symbol.sizeOf() else self.buffer.len;
|
const llen = if (end) |e| e * Symbol.sizeOf() else self.buffer.len;
|
||||||
const num = @divExact(llen - offset, Symbol.sizeOf());
|
const num = @divExact(llen - offset, Symbol.sizeOf());
|
||||||
return Slice{ .buffer = self.buffer[offset..][0..llen], .num = num };
|
return Slice{ .buffer = self.buffer[offset..][0..llen], .num = num };
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
pub const Strtab = struct {
|
pub const Strtab = struct {
|
||||||
buffer: []const u8,
|
buffer: []const u8,
|
||||||
|
|
||||||
fn get(self: Strtab, off: u32) []const u8 {
|
pub fn get(self: Strtab, off: u32) []const u8 {
|
||||||
assert(off < self.buffer.len);
|
assert(off < self.buffer.len);
|
||||||
return mem.sliceTo(@ptrCast([*:0]const u8, self.buffer.ptr + off), 0);
|
return mem.sliceTo(@ptrCast([*:0]const u8, self.buffer.ptr + off), 0);
|
||||||
}
|
}
|
||||||
};
|
|
||||||
};
|
};
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue