@@ -42,7 +42,7 @@ pub fn getName(self: Atom, macho_file: *MachO) [:0]const u8 {
4242}
4343
4444pub fn getFile (self : Atom , macho_file : * MachO ) File {
45- return macho_file .getFile (self .file ).? ;
45+ return macho_file .getFile (self .file );
4646}
4747
4848pub fn toRef (self : Atom ) Ref {
@@ -847,7 +847,7 @@ fn format2(
847847 const atom = ctx .atom ;
848848 const macho_file = ctx .macho_file ;
849849 const file = atom .getFile (macho_file );
850- try writer .print ("atom({d }) : {s} : @{x} : sect({d}) : align({x}) : size({x}) : thunk({d})" , .{
850+ try writer .print ("atom({}) : {s} : @{x} : sect({d}) : align({x}) : size({x}) : thunk({d})" , .{
851851 atom .atom_index , atom .getName (macho_file ), atom .getAddress (macho_file ),
852852 atom .out_n_sect , atom .alignment , atom .size ,
853853 atom .getExtra (macho_file ).thunk ,
@@ -876,10 +876,21 @@ pub const Index = enum(u32) {
876876 }
877877
878878 pub fn toRef (index : Index , file : File.Index ) Ref {
879- const result : Ref = @enumFromInt (@intFromEnum (index ) | @as (u64 , @intCast (file )) << 32 );
879+ const result : Ref = @enumFromInt (@intFromEnum (index ) | @as (u64 , @intFromEnum (file )) << 32 );
880880 assert (result != .none );
881881 return result ;
882882 }
883+
884+ pub fn format (
885+ index : Index ,
886+ comptime unused_fmt_string : []const u8 ,
887+ options : std.fmt.FormatOptions ,
888+ writer : anytype ,
889+ ) ! void {
890+ _ = unused_fmt_string ;
891+ _ = options ;
892+ try writer .print ("{d}" , .{@intFromEnum (index )});
893+ }
883894};
884895
885896pub const OptionalIndex = enum (u32 ) {
@@ -890,6 +901,21 @@ pub const OptionalIndex = enum(u32) {
890901 if (opt == .none ) return null ;
891902 return @enumFromInt (@intFromEnum (opt ));
892903 }
904+
905+ pub fn format (
906+ opt : OptionalIndex ,
907+ comptime unused_fmt_string : []const u8 ,
908+ options : std.fmt.FormatOptions ,
909+ writer : anytype ,
910+ ) ! void {
911+ _ = unused_fmt_string ;
912+ _ = options ;
913+ if (opt == .none ) {
914+ try writer .writeAll (".none" );
915+ } else {
916+ try writer .print ("{d}" , .{@intFromEnum (opt )});
917+ }
918+ }
893919};
894920
895921pub const Ref = enum (u64 ) {
@@ -900,7 +926,7 @@ pub const Ref = enum(u64) {
900926 if (ref == .none ) return null ;
901927 const raw = @intFromEnum (ref );
902928 const atom_index : Index = @enumFromInt (@as (u32 , @truncate (raw )));
903- const file_index : File.Index = @truncate (raw >> 32 );
929+ const file_index : File.Index = @enumFromInt ( @as ( u32 , @ truncate (raw >> 32 )) );
904930 return .{ .atom = atom_index , .file = file_index };
905931 }
906932
@@ -918,7 +944,7 @@ pub const UnwrappedRef = struct {
918944 file : File.Index ,
919945
920946 pub fn getAtom (ref : UnwrappedRef , macho_file : * MachO ) * Atom {
921- return macho_file .getFile (ref .file ).? . getAtom (ref .atom );
947+ return macho_file .getFile (ref .file ).getAtom (ref .atom );
922948 }
923949};
924950
0 commit comments