@@ -70,9 +70,13 @@ impl FunctionDiff {
70
70
// let (_section, symbol) = object.section_symbol(symbol_ref);
71
71
// Symbol::from(symbol)
72
72
// });
73
- let instructions = symbol_diff. instructions . iter ( ) . map ( InstructionDiff :: from) . collect ( ) ;
73
+ let instructions = symbol_diff
74
+ . instructions
75
+ . iter ( )
76
+ . map ( |ins_diff| InstructionDiff :: new ( object, ins_diff) )
77
+ . collect ( ) ;
74
78
Self {
75
- symbol : Some ( Symbol :: from ( symbol) ) ,
79
+ symbol : Some ( Symbol :: new ( symbol) ) ,
76
80
// diff_symbol,
77
81
instructions,
78
82
match_percent : symbol_diff. match_percent ,
@@ -90,8 +94,8 @@ impl DataDiff {
90
94
}
91
95
}
92
96
93
- impl < ' a > From < & ' a ObjSymbol > for Symbol {
94
- fn from ( value : & ' a ObjSymbol ) -> Self {
97
+ impl Symbol {
98
+ pub fn new ( value : & ObjSymbol ) -> Self {
95
99
Self {
96
100
name : value. name . to_string ( ) ,
97
101
demangled_name : value. demangled_name . clone ( ) ,
@@ -122,38 +126,38 @@ fn symbol_flags(value: ObjSymbolFlagSet) -> u32 {
122
126
flags
123
127
}
124
128
125
- impl < ' a > From < & ' a ObjIns > for Instruction {
126
- fn from ( value : & ' a ObjIns ) -> Self {
129
+ impl Instruction {
130
+ pub fn new ( object : & ObjInfo , instruction : & ObjIns ) -> Self {
127
131
Self {
128
- address : value . address ,
129
- size : value . size as u32 ,
130
- opcode : value . op as u32 ,
131
- mnemonic : value . mnemonic . clone ( ) ,
132
- formatted : value . formatted . clone ( ) ,
133
- arguments : value . args . iter ( ) . map ( Argument :: from ) . collect ( ) ,
134
- relocation : value . reloc . as_ref ( ) . map ( Relocation :: from ) ,
135
- branch_dest : value . branch_dest ,
136
- line_number : value . line ,
137
- original : value . orig . clone ( ) ,
132
+ address : instruction . address ,
133
+ size : instruction . size as u32 ,
134
+ opcode : instruction . op as u32 ,
135
+ mnemonic : instruction . mnemonic . clone ( ) ,
136
+ formatted : instruction . formatted . clone ( ) ,
137
+ arguments : instruction . args . iter ( ) . map ( Argument :: new ) . collect ( ) ,
138
+ relocation : instruction . reloc . as_ref ( ) . map ( |reloc| Relocation :: new ( object , reloc ) ) ,
139
+ branch_dest : instruction . branch_dest ,
140
+ line_number : instruction . line ,
141
+ original : instruction . orig . clone ( ) ,
138
142
}
139
143
}
140
144
}
141
145
142
- impl < ' a > From < & ' a ObjInsArg > for Argument {
143
- fn from ( value : & ' a ObjInsArg ) -> Self {
146
+ impl Argument {
147
+ pub fn new ( value : & ObjInsArg ) -> Self {
144
148
Self {
145
149
value : Some ( match value {
146
150
ObjInsArg :: PlainText ( s) => argument:: Value :: PlainText ( s. to_string ( ) ) ,
147
- ObjInsArg :: Arg ( v) => argument:: Value :: Argument ( ArgumentValue :: from ( v) ) ,
151
+ ObjInsArg :: Arg ( v) => argument:: Value :: Argument ( ArgumentValue :: new ( v) ) ,
148
152
ObjInsArg :: Reloc => argument:: Value :: Relocation ( ArgumentRelocation { } ) ,
149
153
ObjInsArg :: BranchDest ( dest) => argument:: Value :: BranchDest ( * dest) ,
150
154
} ) ,
151
155
}
152
156
}
153
157
}
154
158
155
- impl From < & ObjInsArgValue > for ArgumentValue {
156
- fn from ( value : & ObjInsArgValue ) -> Self {
159
+ impl ArgumentValue {
160
+ pub fn new ( value : & ObjInsArgValue ) -> Self {
157
161
Self {
158
162
value : Some ( match value {
159
163
ObjInsArgValue :: Signed ( v) => argument_value:: Value :: Signed ( * v) ,
@@ -164,42 +168,39 @@ impl From<&ObjInsArgValue> for ArgumentValue {
164
168
}
165
169
}
166
170
167
- impl < ' a > From < & ' a ObjReloc > for Relocation {
168
- fn from ( value : & ObjReloc ) -> Self {
171
+ impl Relocation {
172
+ pub fn new ( object : & ObjInfo , reloc : & ObjReloc ) -> Self {
169
173
Self {
170
- r#type : match value . flags {
174
+ r#type : match reloc . flags {
171
175
object:: RelocationFlags :: Elf { r_type } => r_type,
172
176
object:: RelocationFlags :: MachO { r_type, .. } => r_type as u32 ,
173
177
object:: RelocationFlags :: Coff { typ } => typ as u32 ,
174
178
object:: RelocationFlags :: Xcoff { r_rtype, .. } => r_rtype as u32 ,
175
179
_ => unreachable ! ( ) ,
176
180
} ,
177
- type_name : String :: new ( ) , // TODO
178
- target : Some ( RelocationTarget :: from ( & value. target ) ) ,
181
+ type_name : object. arch . display_reloc ( reloc. flags ) . into_owned ( ) ,
182
+ target : Some ( RelocationTarget {
183
+ symbol : Some ( Symbol :: new ( & reloc. target ) ) ,
184
+ addend : reloc. addend ,
185
+ } ) ,
179
186
}
180
187
}
181
188
}
182
189
183
- impl < ' a > From < & ' a ObjSymbol > for RelocationTarget {
184
- fn from ( value : & ' a ObjSymbol ) -> Self {
185
- Self { symbol : Some ( Symbol :: from ( value) ) , addend : value. addend }
186
- }
187
- }
188
-
189
- impl < ' a > From < & ' a ObjInsDiff > for InstructionDiff {
190
- fn from ( value : & ' a ObjInsDiff ) -> Self {
190
+ impl InstructionDiff {
191
+ pub fn new ( object : & ObjInfo , instruction_diff : & ObjInsDiff ) -> Self {
191
192
Self {
192
- instruction : value . ins . as_ref ( ) . map ( Instruction :: from ) ,
193
- diff_kind : DiffKind :: from ( value . kind ) as i32 ,
194
- branch_from : value . branch_from . as_ref ( ) . map ( InstructionBranchFrom :: from ) ,
195
- branch_to : value . branch_to . as_ref ( ) . map ( InstructionBranchTo :: from ) ,
196
- arg_diff : value . arg_diff . iter ( ) . map ( ArgumentDiff :: from ) . collect ( ) ,
193
+ instruction : instruction_diff . ins . as_ref ( ) . map ( |ins| Instruction :: new ( object , ins ) ) ,
194
+ diff_kind : DiffKind :: from ( instruction_diff . kind ) as i32 ,
195
+ branch_from : instruction_diff . branch_from . as_ref ( ) . map ( InstructionBranchFrom :: new ) ,
196
+ branch_to : instruction_diff . branch_to . as_ref ( ) . map ( InstructionBranchTo :: new ) ,
197
+ arg_diff : instruction_diff . arg_diff . iter ( ) . map ( ArgumentDiff :: new ) . collect ( ) ,
197
198
}
198
199
}
199
200
}
200
201
201
- impl From < & Option < ObjInsArgDiff > > for ArgumentDiff {
202
- fn from ( value : & Option < ObjInsArgDiff > ) -> Self {
202
+ impl ArgumentDiff {
203
+ pub fn new ( value : & Option < ObjInsArgDiff > ) -> Self {
203
204
Self { diff_index : value. as_ref ( ) . map ( |v| v. idx as u32 ) }
204
205
}
205
206
}
@@ -228,17 +229,17 @@ impl From<ObjDataDiffKind> for DiffKind {
228
229
}
229
230
}
230
231
231
- impl < ' a > From < & ' a ObjInsBranchFrom > for InstructionBranchFrom {
232
- fn from ( value : & ' a ObjInsBranchFrom ) -> Self {
232
+ impl InstructionBranchFrom {
233
+ pub fn new ( value : & ObjInsBranchFrom ) -> Self {
233
234
Self {
234
235
instruction_index : value. ins_idx . iter ( ) . map ( |& x| x as u32 ) . collect ( ) ,
235
236
branch_index : value. branch_idx as u32 ,
236
237
}
237
238
}
238
239
}
239
240
240
- impl < ' a > From < & ' a ObjInsBranchTo > for InstructionBranchTo {
241
- fn from ( value : & ' a ObjInsBranchTo ) -> Self {
241
+ impl InstructionBranchTo {
242
+ pub fn new ( value : & ObjInsBranchTo ) -> Self {
242
243
Self { instruction_index : value. ins_idx as u32 , branch_index : value. branch_idx as u32 }
243
244
}
244
245
}
0 commit comments