Skip to content

Commit

Permalink
svm: conform to style guide
Browse files Browse the repository at this point in the history
  • Loading branch information
Rexicon226 committed Jan 14, 2025
1 parent f1219fd commit 23a0932
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 8 deletions.
18 changes: 14 additions & 4 deletions src/svm/Elf.zig
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,8 @@ pub const Elf = struct {
const headers = Headers.parse(bytes);
const data = try Data.parse(headers);

const text_section = data.getShdrByName(headers, ".text") orelse return error.NoTextSection;
const text_section = data.getShdrByName(headers, ".text") orelse
return error.NoTextSection;
const offset = headers.header.e_entry -| text_section.sh_addr;
const entry_pc = try std.math.divExact(u64, offset, 8);

Expand Down Expand Up @@ -344,9 +345,13 @@ pub const Elf = struct {
if (std.mem.startsWith(u8, name, ".bss")) {
return error.WritableSectionsNotSupported;
}
if (std.mem.startsWith(u8, name, ".data") and !std.mem.startsWith(u8, name, ".data.rel")) {
if (std.mem.startsWith(u8, name, ".data") and
!std.mem.startsWith(u8, name, ".data.rel"))
{
// TODO: use a packed struct here, this is ugly
if (shdr.sh_flags & (elf.SHF_ALLOC | elf.SHF_WRITE) == elf.SHF_ALLOC | elf.SHF_WRITE) {
if (shdr.sh_flags & (elf.SHF_ALLOC | elf.SHF_WRITE) ==
elf.SHF_ALLOC | elf.SHF_WRITE)
{
return error.WritableSectionsNotSupported;
}
}
Expand Down Expand Up @@ -482,7 +487,12 @@ pub const Elf = struct {
.little,
);
const ref_addr = memory.PROGRAM_START +| address;
std.mem.writeInt(u64, self.bytes[r_offset..][0..8], ref_addr, .little);
std.mem.writeInt(
u64,
self.bytes[r_offset..][0..8],
ref_addr,
.little,
);
},
else => @panic("TODO"),
}
Expand Down
9 changes: 6 additions & 3 deletions src/svm/Vm.zig
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,10 @@ pub const Vm = struct {
.rsh32_imm,
=> {
const lhs_large = registers.get(inst.dst);
const rhs_large = if (opcode.isReg()) registers.get(inst.src) else extend(inst.imm);
const rhs_large = if (opcode.isReg())
registers.get(inst.src)
else
extend(inst.imm);
const lhs = if (opcode.is64()) lhs_large else @as(u32, @truncate(lhs_large));
const rhs = if (opcode.is64()) rhs_large else @as(u32, @truncate(rhs_large));

Expand Down Expand Up @@ -222,8 +225,8 @@ pub const Vm = struct {
};

const access = code.accessType();
const address = if (access == .constant) inst.src else inst.dst;
const vaddr: u64 = @bitCast(@as(i64, @bitCast(registers.get(address))) +% inst.off);
const address: i64 = @bitCast(if (access == .constant) inst.src else inst.dst);
const vaddr: u64 = @bitCast(address +% inst.off);

switch (access) {
.constant => registers.set(inst.dst, try self.load(T, vaddr)),
Expand Down
1 change: 0 additions & 1 deletion src/svm/syscalls.zig
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ const std = @import("std");
const sig = @import("../sig.zig");
const builtin = @import("builtin");
const Vm = @import("vm.zig").Vm;
const Executable = @import("executable.zig").Executable;

const Pubkey = sig.core.Pubkey;

Expand Down

0 comments on commit 23a0932

Please sign in to comment.