Trait iced_x86::FormatterOutput
source · pub trait FormatterOutput {
fn write(&mut self, text: &str, kind: FormatterTextKind);
fn write_prefix(
&mut self,
instruction: &Instruction,
text: &str,
prefix: PrefixKind
) { ... }
fn write_mnemonic(&mut self, instruction: &Instruction, text: &str) { ... }
fn write_number(
&mut self,
instruction: &Instruction,
operand: u32,
instruction_operand: Option<u32>,
text: &str,
value: u64,
number_kind: NumberKind,
kind: FormatterTextKind
) { ... }
fn write_decorator(
&mut self,
instruction: &Instruction,
operand: u32,
instruction_operand: Option<u32>,
text: &str,
decorator: DecoratorKind
) { ... }
fn write_register(
&mut self,
instruction: &Instruction,
operand: u32,
instruction_operand: Option<u32>,
text: &str,
register: Register
) { ... }
fn write_symbol(
&mut self,
instruction: &Instruction,
operand: u32,
instruction_operand: Option<u32>,
address: u64,
symbol: &SymbolResult<'_>
) { ... }
}
Expand description
Required Methods§
sourcefn write(&mut self, text: &str, kind: FormatterTextKind)
fn write(&mut self, text: &str, kind: FormatterTextKind)
Provided Methods§
sourcefn write_prefix(
&mut self,
instruction: &Instruction,
text: &str,
prefix: PrefixKind
)
fn write_prefix(
&mut self,
instruction: &Instruction,
text: &str,
prefix: PrefixKind
)
Examples found in repository?
src/formatter/gas.rs (line 411)
403 404 405 406 407 408 409 410 411 412 413 414
fn format_prefix(
options: &FormatterOptions, output: &mut dyn FormatterOutput, instruction: &Instruction, column: &mut u32, prefix: &FormatterString,
prefix_kind: PrefixKind, need_space: &mut bool,
) {
if *need_space {
*column += 1;
output.write(" ", FormatterTextKind::Text);
}
output.write_prefix(instruction, prefix.get(options.uppercase_prefixes() || options.uppercase_all()), prefix_kind);
*column += prefix.len() as u32;
*need_space = true;
}
More examples
src/formatter/intel.rs (line 376)
368 369 370 371 372 373 374 375 376 377 378 379
fn format_prefix(
options: &FormatterOptions, output: &mut dyn FormatterOutput, instruction: &Instruction, column: &mut u32, prefix: &FormatterString,
prefix_kind: PrefixKind, need_space: &mut bool,
) {
if *need_space {
*column += 1;
output.write(" ", FormatterTextKind::Text);
}
output.write_prefix(instruction, prefix.get(options.uppercase_prefixes() || options.uppercase_all()), prefix_kind);
*column += prefix.len() as u32;
*need_space = true;
}
src/formatter/masm.rs (line 350)
342 343 344 345 346 347 348 349 350 351 352 353
fn format_prefix(
options: &FormatterOptions, output: &mut dyn FormatterOutput, instruction: &Instruction, column: &mut u32, prefix: &FormatterString,
prefix_kind: PrefixKind, need_space: &mut bool,
) {
if *need_space {
*column += 1;
output.write(" ", FormatterTextKind::Text);
}
output.write_prefix(instruction, prefix.get(options.uppercase_prefixes() || options.uppercase_all()), prefix_kind);
*column += prefix.len() as u32;
*need_space = true;
}
src/formatter/nasm.rs (line 374)
366 367 368 369 370 371 372 373 374 375 376 377
fn format_prefix(
options: &FormatterOptions, output: &mut dyn FormatterOutput, instruction: &Instruction, column: &mut u32, prefix: &FormatterString,
prefix_kind: PrefixKind, need_space: &mut bool,
) {
if *need_space {
*column += 1;
output.write(" ", FormatterTextKind::Text);
}
output.write_prefix(instruction, prefix.get(options.uppercase_prefixes() || options.uppercase_all()), prefix_kind);
*column += prefix.len() as u32;
*need_space = true;
}
sourcefn write_mnemonic(&mut self, instruction: &Instruction, text: &str)
fn write_mnemonic(&mut self, instruction: &Instruction, text: &str)
Writes a mnemonic (see Instruction::mnemonic()
)
instruction
: Instructiontext
: Mnemonic text
Examples found in repository?
src/formatter/masm.rs (line 276)
142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280
fn format_mnemonic(
&mut self, instruction: &Instruction, output: &mut dyn FormatterOutput, op_info: &InstrOpInfo<'_>, column: &mut u32, mnemonic_options: u32,
) {
let mut need_space = false;
if (mnemonic_options & FormatMnemonicOptions::NO_PREFIXES) == 0 && (op_info.flags & InstrOpInfoFlags::MNEMONIC_IS_DIRECTIVE as u16) == 0 {
let prefix_seg = instruction.segment_prefix();
if ((prefix_seg as u32)
| instruction_internal::internal_has_any_of_lock_rep_repne_prefix(instruction)
| ((op_info.flags as u32) & (InstrOpInfoFlags::JCC_NOT_TAKEN | InstrOpInfoFlags::JCC_TAKEN | InstrOpInfoFlags::BND_PREFIX)))
!= 0
{
let has_notrack_prefix = prefix_seg == Register::DS && is_notrack_prefix_branch(instruction.code());
if !has_notrack_prefix && prefix_seg != Register::None && self.show_segment_prefix(instruction, op_info) {
MasmFormatter::format_prefix(
&self.d.options,
output,
instruction,
column,
&self.d.all_registers[prefix_seg as usize],
get_segment_register_prefix_kind(prefix_seg),
&mut need_space,
);
}
if instruction.has_xacquire_prefix() {
MasmFormatter::format_prefix(
&self.d.options,
output,
instruction,
column,
&self.d.str_.xacquire,
PrefixKind::Xacquire,
&mut need_space,
);
}
if instruction.has_xrelease_prefix() {
MasmFormatter::format_prefix(
&self.d.options,
output,
instruction,
column,
&self.d.str_.xrelease,
PrefixKind::Xrelease,
&mut need_space,
);
}
if instruction.has_lock_prefix() {
MasmFormatter::format_prefix(&self.d.options, output, instruction, column, &self.d.str_.lock, PrefixKind::Lock, &mut need_space);
}
if (op_info.flags & InstrOpInfoFlags::JCC_NOT_TAKEN as u16) != 0 {
MasmFormatter::format_prefix(
&self.d.options,
output,
instruction,
column,
&self.d.str_.hnt,
PrefixKind::HintNotTaken,
&mut need_space,
);
} else if (op_info.flags & InstrOpInfoFlags::JCC_TAKEN as u16) != 0 {
MasmFormatter::format_prefix(
&self.d.options,
output,
instruction,
column,
&self.d.str_.ht,
PrefixKind::HintTaken,
&mut need_space,
);
}
if has_notrack_prefix {
MasmFormatter::format_prefix(
&self.d.options,
output,
instruction,
column,
&self.d.str_.notrack,
PrefixKind::Notrack,
&mut need_space,
);
}
let has_bnd = (op_info.flags & InstrOpInfoFlags::BND_PREFIX as u16) != 0;
if has_bnd {
MasmFormatter::format_prefix(&self.d.options, output, instruction, column, &self.d.str_.bnd, PrefixKind::Bnd, &mut need_space);
}
if instruction.has_repe_prefix() && show_rep_or_repe_prefix(instruction.code(), &self.d.options) {
if is_repe_or_repne_instruction(instruction.code()) {
MasmFormatter::format_prefix(
&self.d.options,
output,
instruction,
column,
get_mnemonic_cc(&self.d.options, 4, &self.d.str_.repe),
PrefixKind::Repe,
&mut need_space,
);
} else {
MasmFormatter::format_prefix(
&self.d.options,
output,
instruction,
column,
&self.d.str_.rep,
PrefixKind::Rep,
&mut need_space,
);
}
}
if !has_bnd && instruction.has_repne_prefix() && show_repne_prefix(instruction.code(), &self.d.options) {
MasmFormatter::format_prefix(
&self.d.options,
output,
instruction,
column,
get_mnemonic_cc(&self.d.options, 5, &self.d.str_.repne),
PrefixKind::Repne,
&mut need_space,
);
}
}
}
if (mnemonic_options & FormatMnemonicOptions::NO_MNEMONIC) == 0 {
if need_space {
output.write(" ", FormatterTextKind::Text);
*column += 1;
}
let mnemonic = op_info.mnemonic;
if (op_info.flags & InstrOpInfoFlags::MNEMONIC_IS_DIRECTIVE as u16) != 0 {
output.write(mnemonic.get(self.d.options.uppercase_keywords() || self.d.options.uppercase_all()), FormatterTextKind::Directive);
} else {
output.write_mnemonic(instruction, mnemonic.get(self.d.options.uppercase_mnemonics() || self.d.options.uppercase_all()));
}
*column += mnemonic.len() as u32;
}
}
More examples
src/formatter/nasm.rs (line 272)
144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276
fn format_mnemonic(
&mut self, instruction: &Instruction, output: &mut dyn FormatterOutput, op_info: &InstrOpInfo<'_>, column: &mut u32, mnemonic_options: u32,
) {
let mut need_space = false;
if (mnemonic_options & FormatMnemonicOptions::NO_PREFIXES) == 0 && (op_info.flags & InstrOpInfoFlags::MNEMONIC_IS_DIRECTIVE) == 0 {
let prefix_seg = instruction.segment_prefix();
const PREFIX_FLAGS: u32 = (InstrOpInfoFlags::SIZE_OVERRIDE_MASK << InstrOpInfoFlags::OP_SIZE_SHIFT)
| (InstrOpInfoFlags::SIZE_OVERRIDE_MASK << InstrOpInfoFlags::ADDR_SIZE_SHIFT)
| InstrOpInfoFlags::BND_PREFIX;
if ((prefix_seg as u32) | instruction_internal::internal_has_any_of_lock_rep_repne_prefix(instruction) | (op_info.flags & PREFIX_FLAGS))
!= 0
{
let mut prefix;
prefix = &self.d.vec_.nasm_op_size_strings
[((op_info.flags as usize) >> InstrOpInfoFlags::OP_SIZE_SHIFT) & InstrOpInfoFlags::SIZE_OVERRIDE_MASK as usize];
if !prefix.is_default() {
NasmFormatter::format_prefix(&self.d.options, output, instruction, column, prefix, PrefixKind::OperandSize, &mut need_space);
}
prefix = &self.d.vec_.nasm_addr_size_strings
[((op_info.flags as usize) >> InstrOpInfoFlags::ADDR_SIZE_SHIFT) & InstrOpInfoFlags::SIZE_OVERRIDE_MASK as usize];
if !prefix.is_default() {
NasmFormatter::format_prefix(&self.d.options, output, instruction, column, prefix, PrefixKind::AddressSize, &mut need_space);
}
let has_notrack_prefix = prefix_seg == Register::DS && is_notrack_prefix_branch(instruction.code());
if !has_notrack_prefix && prefix_seg != Register::None && self.show_segment_prefix(instruction, op_info) {
NasmFormatter::format_prefix(
&self.d.options,
output,
instruction,
column,
&self.d.all_registers[prefix_seg as usize],
get_segment_register_prefix_kind(prefix_seg),
&mut need_space,
);
}
if instruction.has_xacquire_prefix() {
NasmFormatter::format_prefix(
&self.d.options,
output,
instruction,
column,
&self.d.str_.xacquire,
PrefixKind::Xacquire,
&mut need_space,
);
}
if instruction.has_xrelease_prefix() {
NasmFormatter::format_prefix(
&self.d.options,
output,
instruction,
column,
&self.d.str_.xrelease,
PrefixKind::Xrelease,
&mut need_space,
);
}
if instruction.has_lock_prefix() {
NasmFormatter::format_prefix(&self.d.options, output, instruction, column, &self.d.str_.lock, PrefixKind::Lock, &mut need_space);
}
if has_notrack_prefix {
NasmFormatter::format_prefix(
&self.d.options,
output,
instruction,
column,
&self.d.str_.notrack,
PrefixKind::Notrack,
&mut need_space,
);
}
let has_bnd = (op_info.flags & InstrOpInfoFlags::BND_PREFIX) != 0;
if has_bnd {
NasmFormatter::format_prefix(&self.d.options, output, instruction, column, &self.d.str_.bnd, PrefixKind::Bnd, &mut need_space);
}
if instruction.has_repe_prefix() && show_rep_or_repe_prefix(instruction.code(), &self.d.options) {
if is_repe_or_repne_instruction(instruction.code()) {
NasmFormatter::format_prefix(
&self.d.options,
output,
instruction,
column,
get_mnemonic_cc(&self.d.options, 4, &self.d.str_.repe),
PrefixKind::Repe,
&mut need_space,
);
} else {
NasmFormatter::format_prefix(
&self.d.options,
output,
instruction,
column,
&self.d.str_.rep,
PrefixKind::Rep,
&mut need_space,
);
}
}
if !has_bnd && instruction.has_repne_prefix() && show_repne_prefix(instruction.code(), &self.d.options) {
NasmFormatter::format_prefix(
&self.d.options,
output,
instruction,
column,
get_mnemonic_cc(&self.d.options, 5, &self.d.str_.repne),
PrefixKind::Repne,
&mut need_space,
);
}
}
}
if (mnemonic_options & FormatMnemonicOptions::NO_MNEMONIC) == 0 {
if need_space {
output.write(" ", FormatterTextKind::Text);
*column += 1;
}
let mnemonic = op_info.mnemonic;
if (op_info.flags & InstrOpInfoFlags::MNEMONIC_IS_DIRECTIVE) != 0 {
output.write(mnemonic.get(self.d.options.uppercase_keywords() || self.d.options.uppercase_all()), FormatterTextKind::Directive);
} else {
output.write_mnemonic(instruction, mnemonic.get(self.d.options.uppercase_mnemonics() || self.d.options.uppercase_all()));
}
*column += mnemonic.len() as u32;
}
}
src/formatter/intel.rs (line 296)
142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307
fn format_mnemonic(
&mut self, instruction: &Instruction, output: &mut dyn FormatterOutput, op_info: &InstrOpInfo<'_>, column: &mut u32, mnemonic_options: u32,
) {
let mut need_space = false;
if (mnemonic_options & FormatMnemonicOptions::NO_PREFIXES) == 0 && (op_info.flags & InstrOpInfoFlags::MNEMONIC_IS_DIRECTIVE as u16) == 0 {
let prefix_seg = instruction.segment_prefix();
const PREFIX_FLAGS: u32 = (InstrOpInfoFlags::SIZE_OVERRIDE_MASK << InstrOpInfoFlags::OP_SIZE_SHIFT)
| (InstrOpInfoFlags::SIZE_OVERRIDE_MASK << InstrOpInfoFlags::ADDR_SIZE_SHIFT)
| InstrOpInfoFlags::BND_PREFIX
| InstrOpInfoFlags::JCC_NOT_TAKEN
| InstrOpInfoFlags::JCC_TAKEN;
if ((prefix_seg as u32)
| instruction_internal::internal_has_any_of_lock_rep_repne_prefix(instruction)
| ((op_info.flags as u32) & PREFIX_FLAGS))
!= 0
{
let mut prefix;
prefix = &self.d.vec_.intel_op_size_strings
[((op_info.flags as usize) >> InstrOpInfoFlags::OP_SIZE_SHIFT) & InstrOpInfoFlags::SIZE_OVERRIDE_MASK as usize];
if !prefix.is_default() {
IntelFormatter::format_prefix(&self.d.options, output, instruction, column, prefix, PrefixKind::OperandSize, &mut need_space);
}
prefix = &self.d.vec_.intel_addr_size_strings
[((op_info.flags as usize) >> InstrOpInfoFlags::ADDR_SIZE_SHIFT) & InstrOpInfoFlags::SIZE_OVERRIDE_MASK as usize];
if !prefix.is_default() {
IntelFormatter::format_prefix(&self.d.options, output, instruction, column, prefix, PrefixKind::AddressSize, &mut need_space);
}
let has_notrack_prefix = prefix_seg == Register::DS && is_notrack_prefix_branch(instruction.code());
if !has_notrack_prefix && prefix_seg != Register::None && self.show_segment_prefix(instruction, op_info) {
IntelFormatter::format_prefix(
&self.d.options,
output,
instruction,
column,
&self.d.all_registers[prefix_seg as usize],
get_segment_register_prefix_kind(prefix_seg),
&mut need_space,
);
}
if instruction.has_xacquire_prefix() {
IntelFormatter::format_prefix(
&self.d.options,
output,
instruction,
column,
&self.d.str_.xacquire,
PrefixKind::Xacquire,
&mut need_space,
);
}
if instruction.has_xrelease_prefix() {
IntelFormatter::format_prefix(
&self.d.options,
output,
instruction,
column,
&self.d.str_.xrelease,
PrefixKind::Xrelease,
&mut need_space,
);
}
if instruction.has_lock_prefix() {
IntelFormatter::format_prefix(&self.d.options, output, instruction, column, &self.d.str_.lock, PrefixKind::Lock, &mut need_space);
}
if (op_info.flags & InstrOpInfoFlags::JCC_NOT_TAKEN as u16) != 0 {
IntelFormatter::format_prefix(
&self.d.options,
output,
instruction,
column,
&self.d.str_.hint_not_taken,
PrefixKind::HintNotTaken,
&mut need_space,
);
} else if (op_info.flags & InstrOpInfoFlags::JCC_TAKEN as u16) != 0 {
IntelFormatter::format_prefix(
&self.d.options,
output,
instruction,
column,
&self.d.str_.hint_taken,
PrefixKind::HintTaken,
&mut need_space,
);
}
if has_notrack_prefix {
IntelFormatter::format_prefix(
&self.d.options,
output,
instruction,
column,
&self.d.str_.notrack,
PrefixKind::Notrack,
&mut need_space,
);
}
let has_bnd = (op_info.flags & InstrOpInfoFlags::BND_PREFIX as u16) != 0;
if has_bnd {
IntelFormatter::format_prefix(&self.d.options, output, instruction, column, &self.d.str_.bnd, PrefixKind::Bnd, &mut need_space);
}
if instruction.has_repe_prefix() && show_rep_or_repe_prefix(instruction.code(), &self.d.options) {
if is_repe_or_repne_instruction(instruction.code()) {
IntelFormatter::format_prefix(
&self.d.options,
output,
instruction,
column,
get_mnemonic_cc(&self.d.options, 4, &self.d.str_.repe),
PrefixKind::Repe,
&mut need_space,
);
} else {
IntelFormatter::format_prefix(
&self.d.options,
output,
instruction,
column,
&self.d.str_.rep,
PrefixKind::Rep,
&mut need_space,
);
}
}
if !has_bnd && instruction.has_repne_prefix() && show_repne_prefix(instruction.code(), &self.d.options) {
IntelFormatter::format_prefix(
&self.d.options,
output,
instruction,
column,
get_mnemonic_cc(&self.d.options, 5, &self.d.str_.repne),
PrefixKind::Repne,
&mut need_space,
);
}
}
}
if (mnemonic_options & FormatMnemonicOptions::NO_MNEMONIC) == 0 {
if need_space {
output.write(" ", FormatterTextKind::Text);
*column += 1;
}
let mnemonic = op_info.mnemonic;
if (op_info.flags & InstrOpInfoFlags::MNEMONIC_IS_DIRECTIVE as u16) != 0 {
output.write(mnemonic.get(self.d.options.uppercase_keywords() || self.d.options.uppercase_all()), FormatterTextKind::Directive);
} else {
output.write_mnemonic(instruction, mnemonic.get(self.d.options.uppercase_mnemonics() || self.d.options.uppercase_all()));
}
*column += mnemonic.len() as u32;
if (op_info.flags & InstrOpInfoFlags::FAR_MNEMONIC as u16) != 0 {
output.write(" ", FormatterTextKind::Text);
// This should be treated as part of the mnemonic
output.write_mnemonic(instruction, self.d.str_.far.get(self.d.options.uppercase_mnemonics() || self.d.options.uppercase_all()));
*column += (self.d.str_.far.len() + 1) as u32;
}
}
}
src/formatter/gas.rs (line 312)
156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323
fn format_mnemonic(
&mut self, instruction: &Instruction, output: &mut dyn FormatterOutput, op_info: &InstrOpInfo<'_>, column: &mut u32, mnemonic_options: u32,
) {
let mut need_space = false;
if (mnemonic_options & FormatMnemonicOptions::NO_PREFIXES) == 0 && (op_info.flags & InstrOpInfoFlags::MNEMONIC_IS_DIRECTIVE as u16) == 0 {
let prefix_seg = instruction.segment_prefix();
const PREFIX_FLAGS: u32 = (InstrOpInfoFlags::SIZE_OVERRIDE_MASK << InstrOpInfoFlags::OP_SIZE_SHIFT)
| (InstrOpInfoFlags::SIZE_OVERRIDE_MASK << InstrOpInfoFlags::ADDR_SIZE_SHIFT)
| InstrOpInfoFlags::BND_PREFIX;
if ((prefix_seg as u32)
| instruction_internal::internal_has_any_of_lock_rep_repne_prefix(instruction)
| ((op_info.flags as u32) & PREFIX_FLAGS))
!= 0
{
let mut prefix;
if (op_info.flags & InstrOpInfoFlags::OP_SIZE_IS_BYTE_DIRECTIVE as u16) != 0 {
// SAFETY: generated data is valid
let size_override: SizeOverride = unsafe {
mem::transmute((((op_info.flags as u32) >> InstrOpInfoFlags::OP_SIZE_SHIFT) & InstrOpInfoFlags::SIZE_OVERRIDE_MASK) as u8)
};
match size_override {
SizeOverride::None => {}
SizeOverride::Size16 | SizeOverride::Size32 => {
output.write(
self.d.str_.dot_byte.get(self.d.options.uppercase_keywords() || self.d.options.uppercase_all()),
FormatterTextKind::Directive,
);
output.write(" ", FormatterTextKind::Text);
let number_options = NumberFormattingOptions::with_immediate(&self.d.options);
let s = self.number_formatter.format_u8(&self.d.options, &number_options, 0x66);
output.write(s, FormatterTextKind::Number);
output.write(";", FormatterTextKind::Punctuation);
output.write(" ", FormatterTextKind::Text);
*column += (self.d.str_.dot_byte.len() + 1 + s.len() + 1 + 1) as u32;
}
SizeOverride::Size64 => GasFormatter::format_prefix(
&self.d.options,
output,
instruction,
column,
&self.d.str_.rex_w,
PrefixKind::OperandSize,
&mut need_space,
),
}
} else {
prefix = &self.d.vec_.gas_op_size_strings
[((op_info.flags as usize) >> InstrOpInfoFlags::OP_SIZE_SHIFT) & InstrOpInfoFlags::SIZE_OVERRIDE_MASK as usize];
if !prefix.is_default() {
GasFormatter::format_prefix(&self.d.options, output, instruction, column, prefix, PrefixKind::OperandSize, &mut need_space);
}
}
prefix = &self.d.vec_.gas_addr_size_strings
[((op_info.flags as usize) >> InstrOpInfoFlags::ADDR_SIZE_SHIFT) & InstrOpInfoFlags::SIZE_OVERRIDE_MASK as usize];
if !prefix.is_default() {
GasFormatter::format_prefix(&self.d.options, output, instruction, column, prefix, PrefixKind::AddressSize, &mut need_space);
}
let has_notrack_prefix = prefix_seg == Register::DS && is_notrack_prefix_branch(instruction.code());
if !has_notrack_prefix && prefix_seg != Register::None && self.show_segment_prefix(instruction, op_info) {
GasFormatter::format_prefix(
&self.d.options,
output,
instruction,
column,
&self.d.all_registers_naked[prefix_seg as usize],
get_segment_register_prefix_kind(prefix_seg),
&mut need_space,
);
}
if instruction.has_xacquire_prefix() {
GasFormatter::format_prefix(
&self.d.options,
output,
instruction,
column,
&self.d.str_.xacquire,
PrefixKind::Xacquire,
&mut need_space,
);
}
if instruction.has_xrelease_prefix() {
GasFormatter::format_prefix(
&self.d.options,
output,
instruction,
column,
&self.d.str_.xrelease,
PrefixKind::Xrelease,
&mut need_space,
);
}
if instruction.has_lock_prefix() {
GasFormatter::format_prefix(&self.d.options, output, instruction, column, &self.d.str_.lock, PrefixKind::Lock, &mut need_space);
}
if has_notrack_prefix {
GasFormatter::format_prefix(
&self.d.options,
output,
instruction,
column,
&self.d.str_.notrack,
PrefixKind::Notrack,
&mut need_space,
);
}
let has_bnd = (op_info.flags & InstrOpInfoFlags::BND_PREFIX as u16) != 0;
if has_bnd {
GasFormatter::format_prefix(&self.d.options, output, instruction, column, &self.d.str_.bnd, PrefixKind::Bnd, &mut need_space);
}
if instruction.has_repe_prefix() && show_rep_or_repe_prefix(instruction.code(), &self.d.options) {
if is_repe_or_repne_instruction(instruction.code()) {
GasFormatter::format_prefix(
&self.d.options,
output,
instruction,
column,
get_mnemonic_cc(&self.d.options, 4, &self.d.str_.repe),
PrefixKind::Repe,
&mut need_space,
);
} else {
GasFormatter::format_prefix(&self.d.options, output, instruction, column, &self.d.str_.rep, PrefixKind::Rep, &mut need_space);
}
}
if !has_bnd && instruction.has_repne_prefix() && show_repne_prefix(instruction.code(), &self.d.options) {
GasFormatter::format_prefix(
&self.d.options,
output,
instruction,
column,
get_mnemonic_cc(&self.d.options, 5, &self.d.str_.repne),
PrefixKind::Repne,
&mut need_space,
);
}
}
}
if (mnemonic_options & FormatMnemonicOptions::NO_MNEMONIC) == 0 {
if need_space {
output.write(" ", FormatterTextKind::Text);
*column += 1;
}
let mnemonic = op_info.mnemonic;
if (op_info.flags & InstrOpInfoFlags::MNEMONIC_IS_DIRECTIVE as u16) != 0 {
output.write(mnemonic.get(self.d.options.uppercase_keywords() || self.d.options.uppercase_all()), FormatterTextKind::Directive);
} else {
output.write_mnemonic(instruction, mnemonic.get(self.d.options.uppercase_mnemonics() || self.d.options.uppercase_all()));
}
*column += mnemonic.len() as u32;
}
if (mnemonic_options & FormatMnemonicOptions::NO_PREFIXES) == 0 {
if (op_info.flags & InstrOpInfoFlags::JCC_NOT_TAKEN as u16) != 0 {
GasFormatter::format_branch_hint(&self.d.options, output, column, &self.d.str_.pn);
} else if (op_info.flags & InstrOpInfoFlags::JCC_TAKEN as u16) != 0 {
GasFormatter::format_branch_hint(&self.d.options, output, column, &self.d.str_.pt);
}
}
}
sourcefn write_number(
&mut self,
instruction: &Instruction,
operand: u32,
instruction_operand: Option<u32>,
text: &str,
value: u64,
number_kind: NumberKind,
kind: FormatterTextKind
)
fn write_number(
&mut self,
instruction: &Instruction,
operand: u32,
instruction_operand: Option<u32>,
text: &str,
value: u64,
number_kind: NumberKind,
kind: FormatterTextKind
)
Writes a number
Arguments
instruction
: Instructionoperand
: Operand number, 0-based. This is a formatter operand and isn’t necessarily the same as an instruction operand.instruction_operand
: Instruction operand number, 0-based, orNone
if it’s an operand created by the formatter.text
: Number textvalue
: Valuenumber_kind
: Number kindkind
: Text kind
Examples found in repository?
src/formatter/mod.rs (line 345)
298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363
fn write2(
output: &mut dyn FormatterOutput, instruction: &Instruction, operand: u32, instruction_operand: Option<u32>, options: &FormatterOptions,
number_formatter: &mut NumberFormatter, number_options: &NumberFormattingOptions<'_>, address: u64, symbol: &SymbolResult<'_>,
show_symbol_address: bool, write_minus_if_signed: bool, spaces_between_op: bool,
) {
let mut displ = address.wrapping_sub(symbol.address) as i64;
if (symbol.flags & SymbolFlags::SIGNED) != 0 {
if write_minus_if_signed {
output.write("-", FormatterTextKind::Operator);
}
displ = displ.wrapping_neg();
}
output.write_symbol(instruction, operand, instruction_operand, address, symbol);
let mut number_kind: NumberKind;
if displ != 0 {
if spaces_between_op {
output.write(" ", FormatterTextKind::Text);
}
let orig_displ = displ as u64;
if displ < 0 {
output.write("-", FormatterTextKind::Operator);
displ = displ.wrapping_neg();
if displ <= i8::MAX as i64 + 1 {
number_kind = NumberKind::Int8;
} else if displ <= i16::MAX as i64 + 1 {
number_kind = NumberKind::Int16;
} else if displ <= i32::MAX as i64 + 1 {
number_kind = NumberKind::Int32;
} else {
number_kind = NumberKind::Int64;
}
} else {
output.write("+", FormatterTextKind::Operator);
if displ <= i8::MAX as i64 {
number_kind = NumberKind::Int8;
} else if displ <= i16::MAX as i64 {
number_kind = NumberKind::Int16;
} else if displ <= i32::MAX as i64 {
number_kind = NumberKind::Int32;
} else {
number_kind = NumberKind::Int64;
}
}
if spaces_between_op {
output.write(" ", FormatterTextKind::Text);
}
let s = number_formatter.format_u64_zeros(options, number_options, displ as u64, false);
output.write_number(instruction, operand, instruction_operand, s, orig_displ, number_kind, FormatterTextKind::Number);
}
if show_symbol_address {
output.write(" ", FormatterTextKind::Text);
output.write("(", FormatterTextKind::Punctuation);
let s = if address <= u16::MAX as u64 {
number_kind = NumberKind::UInt16;
number_formatter.format_u16_zeros(options, number_options, address as u16, true)
} else if address <= u32::MAX as u64 {
number_kind = NumberKind::UInt32;
number_formatter.format_u32_zeros(options, number_options, address as u32, true)
} else {
number_kind = NumberKind::UInt64;
number_formatter.format_u64_zeros(options, number_options, address, true)
};
output.write_number(instruction, operand, instruction_operand, s, address, number_kind, FormatterTextKind::Number);
output.write(")", FormatterTextKind::Punctuation);
}
}
More examples
src/formatter/gas.rs (lines 523-531)
428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321
fn format_operand(&mut self, instruction: &Instruction, output: &mut dyn FormatterOutput, op_info: &InstrOpInfo<'_>, operand: u32) {
debug_assert!(operand < op_info.op_count as u32);
#[cfg(feature = "mvex")]
let mvex_rm_operand = {
if IcedConstants::is_mvex(instruction.code()) {
let op_count = instruction.op_count();
debug_assert_ne!(op_count, 0);
(instruction.op_kind(op_count.wrapping_sub(1)) == OpKind::Immediate8 && op_info.op_count as u32 == op_count) as u32
} else {
u32::MAX
}
};
let instruction_operand = op_info.instruction_index(operand);
if (op_info.flags & InstrOpInfoFlags::INDIRECT_OPERAND as u16) != 0 {
output.write("*", FormatterTextKind::Operator);
}
let flow_control;
let mut imm8;
let mut imm16;
let mut imm32;
let mut imm64;
let value64;
let imm_size;
let mut operand_options;
let number_kind;
let op_kind = op_info.op_kind(operand);
match op_kind {
InstrOpKind::Register => {
GasFormatter::format_register_internal(&self.d, output, instruction, operand, instruction_operand, op_info.op_register(operand))
}
InstrOpKind::NearBranch16 | InstrOpKind::NearBranch32 | InstrOpKind::NearBranch64 => {
if op_kind == InstrOpKind::NearBranch64 {
imm_size = 8;
imm64 = instruction.near_branch64();
number_kind = NumberKind::UInt64;
} else if op_kind == InstrOpKind::NearBranch32 {
imm_size = 4;
imm64 = instruction.near_branch32() as u64;
number_kind = NumberKind::UInt32;
} else {
imm_size = 2;
imm64 = instruction.near_branch16() as u64;
number_kind = NumberKind::UInt16;
}
let mut number_options = NumberFormattingOptions::with_branch(&self.d.options);
operand_options = FormatterOperandOptions::default();
if let Some(ref mut options_provider) = self.options_provider {
options_provider.operand_options(instruction, operand, instruction_operand, &mut operand_options, &mut number_options);
}
if let Some(ref symbol) = if let Some(ref mut symbol_resolver) = self.symbol_resolver {
symbol_resolver.symbol(instruction, operand, instruction_operand, imm64, imm_size)
} else {
None
} {
FormatterOutputMethods::write1(
output,
instruction,
operand,
instruction_operand,
&self.d.options,
&mut self.number_formatter,
&number_options,
imm64,
symbol,
self.d.options.show_symbol_address(),
);
} else {
flow_control = get_flow_control(instruction);
let s = if op_kind == InstrOpKind::NearBranch32 {
self.number_formatter.format_u32_zeros(
&self.d.options,
&number_options,
instruction.near_branch32(),
number_options.leading_zeros,
)
} else if op_kind == InstrOpKind::NearBranch64 {
self.number_formatter.format_u64_zeros(
&self.d.options,
&number_options,
instruction.near_branch64(),
number_options.leading_zeros,
)
} else {
self.number_formatter.format_u16_zeros(
&self.d.options,
&number_options,
instruction.near_branch16(),
number_options.leading_zeros,
)
};
output.write_number(
instruction,
operand,
instruction_operand,
s,
imm64,
number_kind,
if is_call(flow_control) { FormatterTextKind::FunctionAddress } else { FormatterTextKind::LabelAddress },
);
}
}
InstrOpKind::FarBranch16 | InstrOpKind::FarBranch32 => {
if op_kind == InstrOpKind::FarBranch32 {
imm_size = 4;
imm64 = instruction.far_branch32() as u64;
number_kind = NumberKind::UInt32;
} else {
imm_size = 2;
imm64 = instruction.far_branch16() as u64;
number_kind = NumberKind::UInt16;
}
let mut number_options = NumberFormattingOptions::with_branch(&self.d.options);
operand_options = FormatterOperandOptions::default();
if let Some(ref mut options_provider) = self.options_provider {
options_provider.operand_options(instruction, operand, instruction_operand, &mut operand_options, &mut number_options);
}
let mut vec: Vec<SymResTextPart<'_>> = Vec::new();
if let Some(ref symbol) = if let Some(ref mut symbol_resolver) = self.symbol_resolver {
to_owned(symbol_resolver.symbol(instruction, operand, instruction_operand, imm64 as u32 as u64, imm_size), &mut vec)
} else {
None
} {
output.write(GasFormatter::IMMEDIATE_VALUE_PREFIX, FormatterTextKind::Operator);
debug_assert!(operand + 1 == 1);
let selector_symbol = if let Some(ref mut symbol_resolver) = self.symbol_resolver {
symbol_resolver.symbol(instruction, operand + 1, instruction_operand, instruction.far_branch_selector() as u64, 2)
} else {
None
};
if let Some(ref selector_symbol) = selector_symbol {
FormatterOutputMethods::write1(
output,
instruction,
operand,
instruction_operand,
&self.d.options,
&mut self.number_formatter,
&number_options,
instruction.far_branch_selector() as u64,
selector_symbol,
self.d.options.show_symbol_address(),
);
} else {
let s = self.number_formatter.format_u16_zeros(
&self.d.options,
&number_options,
instruction.far_branch_selector(),
number_options.leading_zeros,
);
output.write_number(
instruction,
operand,
instruction_operand,
s,
instruction.far_branch_selector() as u64,
NumberKind::UInt16,
FormatterTextKind::SelectorValue,
);
}
output.write(",", FormatterTextKind::Punctuation);
if self.d.options.space_after_operand_separator() {
output.write(" ", FormatterTextKind::Text);
}
output.write(GasFormatter::IMMEDIATE_VALUE_PREFIX, FormatterTextKind::Operator);
FormatterOutputMethods::write1(
output,
instruction,
operand,
instruction_operand,
&self.d.options,
&mut self.number_formatter,
&number_options,
imm64,
symbol,
self.d.options.show_symbol_address(),
);
} else {
flow_control = get_flow_control(instruction);
let s = self.number_formatter.format_u16_zeros(
&self.d.options,
&number_options,
instruction.far_branch_selector(),
number_options.leading_zeros,
);
output.write(GasFormatter::IMMEDIATE_VALUE_PREFIX, FormatterTextKind::Operator);
output.write_number(
instruction,
operand,
instruction_operand,
s,
instruction.far_branch_selector() as u64,
NumberKind::UInt16,
FormatterTextKind::SelectorValue,
);
output.write(",", FormatterTextKind::Punctuation);
if self.d.options.space_after_operand_separator() {
output.write(" ", FormatterTextKind::Text);
}
let s = if op_kind == InstrOpKind::FarBranch32 {
self.number_formatter.format_u32_zeros(
&self.d.options,
&number_options,
instruction.far_branch32(),
number_options.leading_zeros,
)
} else {
self.number_formatter.format_u16_zeros(
&self.d.options,
&number_options,
instruction.far_branch16(),
number_options.leading_zeros,
)
};
output.write(GasFormatter::IMMEDIATE_VALUE_PREFIX, FormatterTextKind::Operator);
output.write_number(
instruction,
operand,
instruction_operand,
s,
imm64,
number_kind,
if is_call(flow_control) { FormatterTextKind::FunctionAddress } else { FormatterTextKind::LabelAddress },
);
}
}
InstrOpKind::Immediate8 | InstrOpKind::Immediate8_2nd | InstrOpKind::DeclareByte => {
if op_kind != InstrOpKind::DeclareByte {
output.write(GasFormatter::IMMEDIATE_VALUE_PREFIX, FormatterTextKind::Operator);
}
if op_kind == InstrOpKind::Immediate8 {
imm8 = instruction.immediate8();
} else if op_kind == InstrOpKind::Immediate8_2nd {
imm8 = instruction.immediate8_2nd();
} else {
imm8 = instruction.get_declare_byte_value(operand as usize);
}
let mut number_options = NumberFormattingOptions::with_immediate(&self.d.options);
operand_options = FormatterOperandOptions::default();
if let Some(ref mut options_provider) = self.options_provider {
options_provider.operand_options(instruction, operand, instruction_operand, &mut operand_options, &mut number_options);
}
if let Some(ref symbol) = if let Some(ref mut symbol_resolver) = self.symbol_resolver {
symbol_resolver.symbol(instruction, operand, instruction_operand, imm8 as u64, 1)
} else {
None
} {
FormatterOutputMethods::write1(
output,
instruction,
operand,
instruction_operand,
&self.d.options,
&mut self.number_formatter,
&number_options,
imm8 as u64,
symbol,
self.d.options.show_symbol_address(),
);
} else {
if number_options.signed_number {
imm64 = imm8 as i8 as u64;
number_kind = NumberKind::Int8;
if (imm8 as i8) < 0 {
output.write("-", FormatterTextKind::Operator);
imm8 = (imm8 as i8).wrapping_neg() as u8;
}
} else {
imm64 = imm8 as u64;
number_kind = NumberKind::UInt8;
}
let s = self.number_formatter.format_u8(&self.d.options, &number_options, imm8);
output.write_number(instruction, operand, instruction_operand, s, imm64, number_kind, FormatterTextKind::Number);
}
}
InstrOpKind::Immediate16 | InstrOpKind::Immediate8to16 | InstrOpKind::DeclareWord => {
if op_kind != InstrOpKind::DeclareWord {
output.write(GasFormatter::IMMEDIATE_VALUE_PREFIX, FormatterTextKind::Operator);
}
if op_kind == InstrOpKind::Immediate16 {
imm16 = instruction.immediate16();
} else if op_kind == InstrOpKind::Immediate8to16 {
imm16 = instruction.immediate8to16() as u16;
} else {
imm16 = instruction.get_declare_word_value(operand as usize);
}
let mut number_options = NumberFormattingOptions::with_immediate(&self.d.options);
operand_options = FormatterOperandOptions::default();
if let Some(ref mut options_provider) = self.options_provider {
options_provider.operand_options(instruction, operand, instruction_operand, &mut operand_options, &mut number_options);
}
if let Some(ref symbol) = if let Some(ref mut symbol_resolver) = self.symbol_resolver {
symbol_resolver.symbol(instruction, operand, instruction_operand, imm16 as u64, 2)
} else {
None
} {
FormatterOutputMethods::write1(
output,
instruction,
operand,
instruction_operand,
&self.d.options,
&mut self.number_formatter,
&number_options,
imm16 as u64,
symbol,
self.d.options.show_symbol_address(),
);
} else {
if number_options.signed_number {
imm64 = imm16 as i16 as u64;
number_kind = NumberKind::Int16;
if (imm16 as i16) < 0 {
output.write("-", FormatterTextKind::Operator);
imm16 = (imm16 as i16).wrapping_neg() as u16;
}
} else {
imm64 = imm16 as u64;
number_kind = NumberKind::UInt16;
}
let s = self.number_formatter.format_u16(&self.d.options, &number_options, imm16);
output.write_number(instruction, operand, instruction_operand, s, imm64, number_kind, FormatterTextKind::Number);
}
}
InstrOpKind::Immediate32 | InstrOpKind::Immediate8to32 | InstrOpKind::DeclareDword => {
if op_kind != InstrOpKind::DeclareDword {
output.write(GasFormatter::IMMEDIATE_VALUE_PREFIX, FormatterTextKind::Operator);
}
if op_kind == InstrOpKind::Immediate32 {
imm32 = instruction.immediate32();
} else if op_kind == InstrOpKind::Immediate8to32 {
imm32 = instruction.immediate8to32() as u32;
} else {
imm32 = instruction.get_declare_dword_value(operand as usize);
}
let mut number_options = NumberFormattingOptions::with_immediate(&self.d.options);
operand_options = FormatterOperandOptions::default();
if let Some(ref mut options_provider) = self.options_provider {
options_provider.operand_options(instruction, operand, instruction_operand, &mut operand_options, &mut number_options);
}
if let Some(ref symbol) = if let Some(ref mut symbol_resolver) = self.symbol_resolver {
symbol_resolver.symbol(instruction, operand, instruction_operand, imm32 as u64, 4)
} else {
None
} {
FormatterOutputMethods::write1(
output,
instruction,
operand,
instruction_operand,
&self.d.options,
&mut self.number_formatter,
&number_options,
imm32 as u64,
symbol,
self.d.options.show_symbol_address(),
);
} else {
if number_options.signed_number {
imm64 = imm32 as i32 as u64;
number_kind = NumberKind::Int32;
if (imm32 as i32) < 0 {
output.write("-", FormatterTextKind::Operator);
imm32 = (imm32 as i32).wrapping_neg() as u32;
}
} else {
imm64 = imm32 as u64;
number_kind = NumberKind::UInt32;
}
let s = self.number_formatter.format_u32(&self.d.options, &number_options, imm32);
output.write_number(instruction, operand, instruction_operand, s, imm64, number_kind, FormatterTextKind::Number);
}
}
InstrOpKind::Immediate64 | InstrOpKind::Immediate8to64 | InstrOpKind::Immediate32to64 | InstrOpKind::DeclareQword => {
if op_kind != InstrOpKind::DeclareQword {
output.write(GasFormatter::IMMEDIATE_VALUE_PREFIX, FormatterTextKind::Operator);
}
if op_kind == InstrOpKind::Immediate32to64 {
imm64 = instruction.immediate32to64() as u64;
} else if op_kind == InstrOpKind::Immediate8to64 {
imm64 = instruction.immediate8to64() as u64;
} else if op_kind == InstrOpKind::Immediate64 {
imm64 = instruction.immediate64();
} else {
imm64 = instruction.get_declare_qword_value(operand as usize);
}
let mut number_options = NumberFormattingOptions::with_immediate(&self.d.options);
operand_options = FormatterOperandOptions::default();
if let Some(ref mut options_provider) = self.options_provider {
options_provider.operand_options(instruction, operand, instruction_operand, &mut operand_options, &mut number_options);
}
if let Some(ref symbol) = if let Some(ref mut symbol_resolver) = self.symbol_resolver {
symbol_resolver.symbol(instruction, operand, instruction_operand, imm64, 8)
} else {
None
} {
FormatterOutputMethods::write1(
output,
instruction,
operand,
instruction_operand,
&self.d.options,
&mut self.number_formatter,
&number_options,
imm64,
symbol,
self.d.options.show_symbol_address(),
);
} else {
value64 = imm64;
if number_options.signed_number {
number_kind = NumberKind::Int64;
if (imm64 as i64) < 0 {
output.write("-", FormatterTextKind::Operator);
imm64 = (imm64 as i64).wrapping_neg() as u64;
}
} else {
number_kind = NumberKind::UInt64;
}
let s = self.number_formatter.format_u64(&self.d.options, &number_options, imm64);
output.write_number(instruction, operand, instruction_operand, s, value64, number_kind, FormatterTextKind::Number);
}
}
InstrOpKind::MemorySegSI => self.format_memory(
output,
instruction,
operand,
instruction_operand,
instruction.memory_segment(),
Register::SI,
Register::None,
0,
0,
0,
2,
),
InstrOpKind::MemorySegESI => self.format_memory(
output,
instruction,
operand,
instruction_operand,
instruction.memory_segment(),
Register::ESI,
Register::None,
0,
0,
0,
4,
),
InstrOpKind::MemorySegRSI => self.format_memory(
output,
instruction,
operand,
instruction_operand,
instruction.memory_segment(),
Register::RSI,
Register::None,
0,
0,
0,
8,
),
InstrOpKind::MemorySegDI => self.format_memory(
output,
instruction,
operand,
instruction_operand,
instruction.memory_segment(),
Register::DI,
Register::None,
0,
0,
0,
2,
),
InstrOpKind::MemorySegEDI => self.format_memory(
output,
instruction,
operand,
instruction_operand,
instruction.memory_segment(),
Register::EDI,
Register::None,
0,
0,
0,
4,
),
InstrOpKind::MemorySegRDI => self.format_memory(
output,
instruction,
operand,
instruction_operand,
instruction.memory_segment(),
Register::RDI,
Register::None,
0,
0,
0,
8,
),
InstrOpKind::MemoryESDI => {
self.format_memory(output, instruction, operand, instruction_operand, Register::ES, Register::DI, Register::None, 0, 0, 0, 2)
}
InstrOpKind::MemoryESEDI => {
self.format_memory(output, instruction, operand, instruction_operand, Register::ES, Register::EDI, Register::None, 0, 0, 0, 4)
}
InstrOpKind::MemoryESRDI => {
self.format_memory(output, instruction, operand, instruction_operand, Register::ES, Register::RDI, Register::None, 0, 0, 0, 8)
}
InstrOpKind::Memory => {
let displ_size = instruction.memory_displ_size();
let base_reg = instruction.memory_base();
let mut index_reg = instruction.memory_index();
let addr_size = get_address_size_in_bytes(base_reg, index_reg, displ_size, instruction.code_size());
let displ = if addr_size == 8 { instruction.memory_displacement64() as i64 } else { instruction.memory_displacement32() as i64 };
if (op_info.flags & InstrOpInfoFlags::IGNORE_INDEX_REG as u16) != 0 {
index_reg = Register::None;
}
self.format_memory(
output,
instruction,
operand,
instruction_operand,
instruction.memory_segment(),
base_reg,
index_reg,
instruction_internal::internal_get_memory_index_scale(instruction),
displ_size,
displ,
addr_size,
);
}
InstrOpKind::Sae => GasFormatter::format_decorator(
&self.d.options,
output,
instruction,
operand,
instruction_operand,
&self.d.str_.sae,
DecoratorKind::SuppressAllExceptions,
),
InstrOpKind::RnSae => GasFormatter::format_decorator(
&self.d.options,
output,
instruction,
operand,
instruction_operand,
&self.d.str_.rn_sae,
DecoratorKind::RoundingControl,
),
InstrOpKind::RdSae => GasFormatter::format_decorator(
&self.d.options,
output,
instruction,
operand,
instruction_operand,
&self.d.str_.rd_sae,
DecoratorKind::RoundingControl,
),
InstrOpKind::RuSae => GasFormatter::format_decorator(
&self.d.options,
output,
instruction,
operand,
instruction_operand,
&self.d.str_.ru_sae,
DecoratorKind::RoundingControl,
),
InstrOpKind::RzSae => GasFormatter::format_decorator(
&self.d.options,
output,
instruction,
operand,
instruction_operand,
&self.d.str_.rz_sae,
DecoratorKind::RoundingControl,
),
InstrOpKind::Rn => GasFormatter::format_decorator(
&self.d.options,
output,
instruction,
operand,
instruction_operand,
&self.d.str_.rn,
DecoratorKind::RoundingControl,
),
InstrOpKind::Rd => GasFormatter::format_decorator(
&self.d.options,
output,
instruction,
operand,
instruction_operand,
&self.d.str_.rd,
DecoratorKind::RoundingControl,
),
InstrOpKind::Ru => GasFormatter::format_decorator(
&self.d.options,
output,
instruction,
operand,
instruction_operand,
&self.d.str_.ru,
DecoratorKind::RoundingControl,
),
InstrOpKind::Rz => GasFormatter::format_decorator(
&self.d.options,
output,
instruction,
operand,
instruction_operand,
&self.d.str_.rz,
DecoratorKind::RoundingControl,
),
}
if operand + 1 == op_info.op_count as u32 && instruction_internal::internal_has_op_mask_or_zeroing_masking(instruction) {
if instruction.has_op_mask() {
output.write("{", FormatterTextKind::Punctuation);
GasFormatter::format_register_internal(&self.d, output, instruction, operand, instruction_operand, instruction.op_mask());
output.write("}", FormatterTextKind::Punctuation);
}
if instruction.zeroing_masking() {
GasFormatter::format_decorator(
&self.d.options,
output,
instruction,
operand,
instruction_operand,
&self.d.str_.z,
DecoratorKind::ZeroingMasking,
);
}
}
#[cfg(feature = "mvex")]
if mvex_rm_operand == operand {
let conv = instruction.mvex_reg_mem_conv();
if conv != MvexRegMemConv::None {
let mvex = crate::mvex::get_mvex_info(instruction.code());
if mvex.conv_fn != MvexConvFn::None {
let tbl = if mvex.is_conv_fn_32() { &self.d.vec_.mvex_reg_mem_consts_32 } else { &self.d.vec_.mvex_reg_mem_consts_64 };
let s = tbl[conv as usize];
if s.len() != 0 {
Self::format_decorator(&self.d.options, output, instruction, operand, instruction_operand, s, DecoratorKind::SwizzleMemConv);
}
}
}
}
}
fn format_decorator(
options: &FormatterOptions, output: &mut dyn FormatterOutput, instruction: &Instruction, operand: u32, instruction_operand: Option<u32>,
text: &FormatterString, decorator: DecoratorKind,
) {
output.write("{", FormatterTextKind::Punctuation);
output.write_decorator(
instruction,
operand,
instruction_operand,
text.get(options.uppercase_decorators() || options.uppercase_all()),
decorator,
);
output.write("}", FormatterTextKind::Punctuation);
}
#[inline]
fn get_reg_str(d: &SelfData, mut reg: Register) -> &'static str {
if d.options.prefer_st0() && reg == REGISTER_ST {
reg = Register::ST0;
}
let reg_str = &GasFormatter::all_registers(d)[reg as usize];
reg_str.get(d.options.uppercase_registers() || d.options.uppercase_all())
}
#[inline]
fn format_register_internal(
d: &SelfData, output: &mut dyn FormatterOutput, instruction: &Instruction, operand: u32, instruction_operand: Option<u32>, reg: Register,
) {
output.write_register(instruction, operand, instruction_operand, GasFormatter::get_reg_str(d, reg), reg);
}
#[allow(clippy::too_many_arguments)]
fn format_memory(
&mut self, output: &mut dyn FormatterOutput, instruction: &Instruction, operand: u32, instruction_operand: Option<u32>, seg_reg: Register,
mut base_reg: Register, index_reg: Register, scale: u32, mut displ_size: u32, mut displ: i64, addr_size: u32,
) {
debug_assert!((scale as usize) < SCALE_NUMBERS.len());
debug_assert!(get_address_size_in_bytes(base_reg, index_reg, displ_size, instruction.code_size()) == addr_size);
let mut operand_options = FormatterOperandOptions::with_memory_size_options(self.d.options.memory_size_options());
operand_options.set_rip_relative_addresses(self.d.options.rip_relative_addresses());
let mut number_options = NumberFormattingOptions::with_displacement(&self.d.options);
if let Some(ref mut options_provider) = self.options_provider {
options_provider.operand_options(instruction, operand, instruction_operand, &mut operand_options, &mut number_options);
}
let abs_addr;
if base_reg == Register::RIP {
abs_addr = displ as u64;
if self.d.options.rip_relative_addresses() {
displ = displ.wrapping_sub(instruction.next_ip() as i64);
} else {
debug_assert_eq!(index_reg, Register::None);
base_reg = Register::None;
}
displ_size = 8;
} else if base_reg == Register::EIP {
abs_addr = displ as u32 as u64;
if self.d.options.rip_relative_addresses() {
displ = (displ as u32).wrapping_sub(instruction.next_ip32()) as i32 as i64;
} else {
debug_assert_eq!(index_reg, Register::None);
base_reg = Register::None;
}
displ_size = 4;
} else {
abs_addr = displ as u64;
}
let symbol = if let Some(ref mut symbol_resolver) = self.symbol_resolver {
symbol_resolver.symbol(instruction, operand, instruction_operand, abs_addr, addr_size)
} else {
None
};
let use_scale =
if addr_size == 2 || !show_index_scale(instruction, &self.d.options) { false } else { scale != 0 || self.d.options.always_show_scale() };
let has_base_or_index_reg = base_reg != Register::None || index_reg != Register::None;
let code_size = instruction.code_size();
let seg_override = instruction.segment_prefix();
let notrack_prefix = seg_override == Register::DS
&& is_notrack_prefix_branch(instruction.code())
&& !((code_size == CodeSize::Code16 || code_size == CodeSize::Code32)
&& (base_reg == Register::BP || base_reg == Register::EBP || base_reg == Register::ESP));
if self.d.options.always_show_segment_register()
|| (seg_override != Register::None && !notrack_prefix && show_segment_prefix(Register::None, instruction, &self.d.options))
{
GasFormatter::format_register_internal(&self.d, output, instruction, operand, instruction_operand, seg_reg);
output.write(":", FormatterTextKind::Punctuation);
}
if let Some(ref symbol) = symbol {
FormatterOutputMethods::write1(
output,
instruction,
operand,
instruction_operand,
&self.d.options,
&mut self.number_formatter,
&number_options,
abs_addr,
symbol,
self.d.options.show_symbol_address(),
);
} else if !has_base_or_index_reg || (displ_size != 0 && (self.d.options.show_zero_displacements() || displ != 0)) {
let orig_displ = displ as u64;
let is_signed;
if has_base_or_index_reg {
is_signed = number_options.signed_number;
if addr_size == 8 {
if number_options.signed_number && displ < 0 {
output.write("-", FormatterTextKind::Operator);
displ = displ.wrapping_neg();
}
if number_options.displacement_leading_zeros {
displ_size = 4;
}
} else if addr_size == 4 {
if number_options.signed_number && (displ as i32) < 0 {
output.write("-", FormatterTextKind::Operator);
displ = (displ as i32).wrapping_neg() as u32 as i64;
}
if number_options.displacement_leading_zeros {
displ_size = 4;
}
} else {
debug_assert_eq!(addr_size, 2);
if number_options.signed_number && (displ as i16) < 0 {
output.write("-", FormatterTextKind::Operator);
displ = (displ as i16).wrapping_neg() as u16 as i64;
}
if number_options.displacement_leading_zeros {
displ_size = 2;
}
}
} else {
is_signed = false;
}
let (s, displ_kind) = if displ_size <= 1 && displ as u64 <= u8::MAX as u64 {
(
self.number_formatter.format_displ_u8(&self.d.options, &number_options, displ as u8),
if is_signed { NumberKind::Int8 } else { NumberKind::UInt8 },
)
} else if displ_size <= 2 && displ as u64 <= u16::MAX as u64 {
(
self.number_formatter.format_displ_u16(&self.d.options, &number_options, displ as u16),
if is_signed { NumberKind::Int16 } else { NumberKind::UInt16 },
)
} else if displ_size <= 4 && displ as u64 <= u32::MAX as u64 {
(
self.number_formatter.format_displ_u32(&self.d.options, &number_options, displ as u32),
if is_signed { NumberKind::Int32 } else { NumberKind::UInt32 },
)
} else if displ_size <= 8 {
(
self.number_formatter.format_displ_u64(&self.d.options, &number_options, displ as u64),
if is_signed { NumberKind::Int64 } else { NumberKind::UInt64 },
)
} else {
unreachable!();
};
output.write_number(instruction, operand, instruction_operand, s, orig_displ, displ_kind, FormatterTextKind::Number);
}
if has_base_or_index_reg {
output.write("(", FormatterTextKind::Punctuation);
if self.d.options.space_after_memory_bracket() {
output.write(" ", FormatterTextKind::Text);
}
if base_reg != Register::None && index_reg == Register::None && !use_scale {
GasFormatter::format_register_internal(&self.d, output, instruction, operand, instruction_operand, base_reg);
} else {
if base_reg != Register::None {
GasFormatter::format_register_internal(&self.d, output, instruction, operand, instruction_operand, base_reg);
}
output.write(",", FormatterTextKind::Punctuation);
if self.d.options.gas_space_after_memory_operand_comma() {
output.write(" ", FormatterTextKind::Text);
}
if index_reg != Register::None {
GasFormatter::format_register_internal(&self.d, output, instruction, operand, instruction_operand, index_reg);
if use_scale {
output.write(",", FormatterTextKind::Punctuation);
if self.d.options.gas_space_after_memory_operand_comma() {
output.write(" ", FormatterTextKind::Text);
}
output.write_number(
instruction,
operand,
instruction_operand,
SCALE_NUMBERS[scale as usize],
1u64 << scale,
NumberKind::Int32,
FormatterTextKind::Number,
);
}
}
}
if self.d.options.space_after_memory_bracket() {
output.write(" ", FormatterTextKind::Text);
}
output.write(")", FormatterTextKind::Punctuation);
}
let mem_size = instruction.memory_size();
debug_assert!((mem_size as usize) < self.d.all_memory_sizes.len());
let bcst_to = self.d.all_memory_sizes[mem_size as usize];
if !bcst_to.is_default() {
GasFormatter::format_decorator(&self.d.options, output, instruction, operand, instruction_operand, bcst_to, DecoratorKind::Broadcast);
}
#[cfg(feature = "mvex")]
if instruction.is_mvex_eviction_hint() {
Self::format_decorator(
&self.d.options,
output,
instruction,
operand,
instruction_operand,
&self.d.str_.mvex.eh,
DecoratorKind::EvictionHint,
);
}
}
src/formatter/nasm.rs (lines 505-513)
391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457
fn format_operand(&mut self, instruction: &Instruction, output: &mut dyn FormatterOutput, op_info: &InstrOpInfo<'_>, operand: u32) {
debug_assert!(operand < op_info.op_count as u32);
#[cfg(feature = "mvex")]
let mvex_rm_operand = {
if IcedConstants::is_mvex(instruction.code()) {
let op_count = instruction.op_count();
debug_assert_ne!(op_count, 0);
if instruction.op_kind(op_count.wrapping_sub(1)) == OpKind::Immediate8 {
op_count.wrapping_sub(2)
} else {
op_count.wrapping_sub(1)
}
} else {
u32::MAX
}
};
let instruction_operand = op_info.instruction_index(operand);
let flow_control;
let mut imm8;
let mut imm16;
let mut imm32;
let mut imm64;
let value64;
let imm_size;
let mut operand_options;
let number_kind;
let op_kind = op_info.op_kind(operand);
match op_kind {
InstrOpKind::Register => {
if (op_info.flags & InstrOpInfoFlags::REGISTER_TO) != 0 {
NasmFormatter::format_keyword(&self.d.options, output, &self.d.str_.to);
output.write(" ", FormatterTextKind::Text);
}
NasmFormatter::format_register_internal(&self.d, output, instruction, operand, instruction_operand, op_info.op_register(operand));
}
InstrOpKind::NearBranch16 | InstrOpKind::NearBranch32 | InstrOpKind::NearBranch64 => {
if op_kind == InstrOpKind::NearBranch64 {
imm_size = 8;
imm64 = instruction.near_branch64();
number_kind = NumberKind::UInt64;
} else if op_kind == InstrOpKind::NearBranch32 {
imm_size = 4;
imm64 = instruction.near_branch32() as u64;
number_kind = NumberKind::UInt32;
} else {
imm_size = 2;
imm64 = instruction.near_branch16() as u64;
number_kind = NumberKind::UInt16;
}
operand_options = FormatterOperandOptions::new(if self.d.options.show_branch_size() {
FormatterOperandOptionsFlags::NONE
} else {
FormatterOperandOptionsFlags::NO_BRANCH_SIZE
});
if let Some(ref symbol) = if let Some(ref mut symbol_resolver) = self.symbol_resolver {
symbol_resolver.symbol(instruction, operand, instruction_operand, imm64, imm_size)
} else {
None
} {
NasmFormatter::format_flow_control(&self.d, output, op_info.flags, operand_options);
let mut number_options = NumberFormattingOptions::with_branch(&self.d.options);
if let Some(ref mut options_provider) = self.options_provider {
options_provider.operand_options(instruction, operand, instruction_operand, &mut operand_options, &mut number_options);
}
FormatterOutputMethods::write1(
output,
instruction,
operand,
instruction_operand,
&self.d.options,
&mut self.number_formatter,
&number_options,
imm64,
symbol,
self.d.options.show_symbol_address(),
);
} else {
operand_options = FormatterOperandOptions::new(if self.d.options.show_branch_size() {
FormatterOperandOptionsFlags::NONE
} else {
FormatterOperandOptionsFlags::NO_BRANCH_SIZE
});
flow_control = get_flow_control(instruction);
NasmFormatter::format_flow_control(&self.d, output, op_info.flags, operand_options);
let mut number_options = NumberFormattingOptions::with_branch(&self.d.options);
if let Some(ref mut options_provider) = self.options_provider {
options_provider.operand_options(instruction, operand, instruction_operand, &mut operand_options, &mut number_options);
}
let s = if op_kind == InstrOpKind::NearBranch32 {
self.number_formatter.format_u32_zeros(
&self.d.options,
&number_options,
instruction.near_branch32(),
number_options.leading_zeros,
)
} else if op_kind == InstrOpKind::NearBranch64 {
self.number_formatter.format_u64_zeros(
&self.d.options,
&number_options,
instruction.near_branch64(),
number_options.leading_zeros,
)
} else {
self.number_formatter.format_u16_zeros(
&self.d.options,
&number_options,
instruction.near_branch16(),
number_options.leading_zeros,
)
};
output.write_number(
instruction,
operand,
instruction_operand,
s,
imm64,
number_kind,
if is_call(flow_control) { FormatterTextKind::FunctionAddress } else { FormatterTextKind::LabelAddress },
);
}
}
InstrOpKind::FarBranch16 | InstrOpKind::FarBranch32 => {
if op_kind == InstrOpKind::FarBranch32 {
imm_size = 4;
imm64 = instruction.far_branch32() as u64;
number_kind = NumberKind::UInt32;
} else {
imm_size = 2;
imm64 = instruction.far_branch16() as u64;
number_kind = NumberKind::UInt16;
}
operand_options = FormatterOperandOptions::new(if self.d.options.show_branch_size() {
FormatterOperandOptionsFlags::NONE
} else {
FormatterOperandOptionsFlags::NO_BRANCH_SIZE
});
let mut vec: Vec<SymResTextPart<'_>> = Vec::new();
if let Some(ref symbol) = if let Some(ref mut symbol_resolver) = self.symbol_resolver {
to_owned(symbol_resolver.symbol(instruction, operand, instruction_operand, imm64 as u32 as u64, imm_size), &mut vec)
} else {
None
} {
NasmFormatter::format_flow_control(&self.d, output, op_info.flags, operand_options);
debug_assert!(operand + 1 == 1);
let mut number_options = NumberFormattingOptions::with_branch(&self.d.options);
if let Some(ref mut options_provider) = self.options_provider {
options_provider.operand_options(instruction, operand, instruction_operand, &mut operand_options, &mut number_options);
}
let selector_symbol = if let Some(ref mut symbol_resolver) = self.symbol_resolver {
symbol_resolver.symbol(instruction, operand + 1, instruction_operand, instruction.far_branch_selector() as u64, 2)
} else {
None
};
if let Some(ref selector_symbol) = selector_symbol {
FormatterOutputMethods::write1(
output,
instruction,
operand,
instruction_operand,
&self.d.options,
&mut self.number_formatter,
&number_options,
instruction.far_branch_selector() as u64,
selector_symbol,
self.d.options.show_symbol_address(),
);
} else {
let s = self.number_formatter.format_u16_zeros(
&self.d.options,
&number_options,
instruction.far_branch_selector(),
number_options.leading_zeros,
);
output.write_number(
instruction,
operand,
instruction_operand,
s,
instruction.far_branch_selector() as u64,
NumberKind::UInt16,
FormatterTextKind::SelectorValue,
);
}
output.write(":", FormatterTextKind::Punctuation);
FormatterOutputMethods::write1(
output,
instruction,
operand,
instruction_operand,
&self.d.options,
&mut self.number_formatter,
&number_options,
imm64,
symbol,
self.d.options.show_symbol_address(),
);
} else {
flow_control = get_flow_control(instruction);
NasmFormatter::format_flow_control(&self.d, output, op_info.flags, operand_options);
let mut number_options = NumberFormattingOptions::with_branch(&self.d.options);
if let Some(ref mut options_provider) = self.options_provider {
options_provider.operand_options(instruction, operand, instruction_operand, &mut operand_options, &mut number_options);
}
let s = self.number_formatter.format_u16_zeros(
&self.d.options,
&number_options,
instruction.far_branch_selector(),
number_options.leading_zeros,
);
output.write_number(
instruction,
operand,
instruction_operand,
s,
instruction.far_branch_selector() as u64,
NumberKind::UInt16,
FormatterTextKind::SelectorValue,
);
output.write(":", FormatterTextKind::Punctuation);
let s = if op_kind == InstrOpKind::FarBranch32 {
self.number_formatter.format_u32_zeros(
&self.d.options,
&number_options,
instruction.far_branch32(),
number_options.leading_zeros,
)
} else {
self.number_formatter.format_u16_zeros(
&self.d.options,
&number_options,
instruction.far_branch16(),
number_options.leading_zeros,
)
};
output.write_number(
instruction,
operand,
instruction_operand,
s,
imm64,
number_kind,
if is_call(flow_control) { FormatterTextKind::FunctionAddress } else { FormatterTextKind::LabelAddress },
);
}
}
InstrOpKind::Immediate8 | InstrOpKind::Immediate8_2nd | InstrOpKind::DeclareByte => {
if op_kind == InstrOpKind::Immediate8 {
imm8 = instruction.immediate8();
} else if op_kind == InstrOpKind::Immediate8_2nd {
imm8 = instruction.immediate8_2nd();
} else {
imm8 = instruction.get_declare_byte_value(operand as usize);
}
operand_options = FormatterOperandOptions::default();
let mut number_options = NumberFormattingOptions::with_immediate(&self.d.options);
if let Some(ref mut options_provider) = self.options_provider {
options_provider.operand_options(instruction, operand, instruction_operand, &mut operand_options, &mut number_options);
}
if let Some(ref symbol) = if let Some(ref mut symbol_resolver) = self.symbol_resolver {
symbol_resolver.symbol(instruction, operand, instruction_operand, imm8 as u64, 1)
} else {
None
} {
FormatterOutputMethods::write1(
output,
instruction,
operand,
instruction_operand,
&self.d.options,
&mut self.number_formatter,
&number_options,
imm8 as u64,
symbol,
self.d.options.show_symbol_address(),
);
} else {
if number_options.signed_number {
imm64 = imm8 as i8 as u64;
number_kind = NumberKind::Int8;
if (imm8 as i8) < 0 {
output.write("-", FormatterTextKind::Operator);
imm8 = (imm8 as i8).wrapping_neg() as u8;
}
} else {
imm64 = imm8 as u64;
number_kind = NumberKind::UInt8;
}
let s = self.number_formatter.format_u8(&self.d.options, &number_options, imm8);
output.write_number(instruction, operand, instruction_operand, s, imm64, number_kind, FormatterTextKind::Number);
}
}
InstrOpKind::Immediate16 | InstrOpKind::Immediate8to16 | InstrOpKind::DeclareWord => {
NasmFormatter::show_sign_extend_info(&self.d, output, op_info.flags);
if op_kind == InstrOpKind::Immediate16 {
imm16 = instruction.immediate16();
} else if op_kind == InstrOpKind::Immediate8to16 {
imm16 = instruction.immediate8to16() as u16;
} else {
imm16 = instruction.get_declare_word_value(operand as usize);
}
operand_options = FormatterOperandOptions::default();
let mut number_options = NumberFormattingOptions::with_immediate(&self.d.options);
if let Some(ref mut options_provider) = self.options_provider {
options_provider.operand_options(instruction, operand, instruction_operand, &mut operand_options, &mut number_options);
}
if let Some(ref symbol) = if let Some(ref mut symbol_resolver) = self.symbol_resolver {
symbol_resolver.symbol(instruction, operand, instruction_operand, imm16 as u64, 2)
} else {
None
} {
FormatterOutputMethods::write1(
output,
instruction,
operand,
instruction_operand,
&self.d.options,
&mut self.number_formatter,
&number_options,
imm16 as u64,
symbol,
self.d.options.show_symbol_address(),
);
} else {
if number_options.signed_number {
imm64 = imm16 as i16 as u64;
number_kind = NumberKind::Int16;
if (imm16 as i16) < 0 {
output.write("-", FormatterTextKind::Operator);
imm16 = (imm16 as i16).wrapping_neg() as u16;
}
} else {
imm64 = imm16 as u64;
number_kind = NumberKind::UInt16;
}
let s = self.number_formatter.format_u16(&self.d.options, &number_options, imm16);
output.write_number(instruction, operand, instruction_operand, s, imm64, number_kind, FormatterTextKind::Number);
}
}
InstrOpKind::Immediate32 | InstrOpKind::Immediate8to32 | InstrOpKind::DeclareDword => {
NasmFormatter::show_sign_extend_info(&self.d, output, op_info.flags);
if op_kind == InstrOpKind::Immediate32 {
imm32 = instruction.immediate32();
} else if op_kind == InstrOpKind::Immediate8to32 {
imm32 = instruction.immediate8to32() as u32;
} else {
imm32 = instruction.get_declare_dword_value(operand as usize);
}
operand_options = FormatterOperandOptions::default();
let mut number_options = NumberFormattingOptions::with_immediate(&self.d.options);
if let Some(ref mut options_provider) = self.options_provider {
options_provider.operand_options(instruction, operand, instruction_operand, &mut operand_options, &mut number_options);
}
if let Some(ref symbol) = if let Some(ref mut symbol_resolver) = self.symbol_resolver {
symbol_resolver.symbol(instruction, operand, instruction_operand, imm32 as u64, 4)
} else {
None
} {
FormatterOutputMethods::write1(
output,
instruction,
operand,
instruction_operand,
&self.d.options,
&mut self.number_formatter,
&number_options,
imm32 as u64,
symbol,
self.d.options.show_symbol_address(),
);
} else {
if number_options.signed_number {
imm64 = imm32 as i32 as u64;
number_kind = NumberKind::Int32;
if (imm32 as i32) < 0 {
output.write("-", FormatterTextKind::Operator);
imm32 = (imm32 as i32).wrapping_neg() as u32;
}
} else {
imm64 = imm32 as u64;
number_kind = NumberKind::UInt32;
}
let s = self.number_formatter.format_u32(&self.d.options, &number_options, imm32);
output.write_number(instruction, operand, instruction_operand, s, imm64, number_kind, FormatterTextKind::Number);
}
}
InstrOpKind::Immediate64 | InstrOpKind::Immediate8to64 | InstrOpKind::Immediate32to64 | InstrOpKind::DeclareQword => {
NasmFormatter::show_sign_extend_info(&self.d, output, op_info.flags);
if op_kind == InstrOpKind::Immediate32to64 {
imm64 = instruction.immediate32to64() as u64;
} else if op_kind == InstrOpKind::Immediate8to64 {
imm64 = instruction.immediate8to64() as u64;
} else if op_kind == InstrOpKind::Immediate64 {
imm64 = instruction.immediate64();
} else {
imm64 = instruction.get_declare_qword_value(operand as usize);
}
operand_options = FormatterOperandOptions::default();
let mut number_options = NumberFormattingOptions::with_immediate(&self.d.options);
if let Some(ref mut options_provider) = self.options_provider {
options_provider.operand_options(instruction, operand, instruction_operand, &mut operand_options, &mut number_options);
}
if let Some(ref symbol) = if let Some(ref mut symbol_resolver) = self.symbol_resolver {
symbol_resolver.symbol(instruction, operand, instruction_operand, imm64, 8)
} else {
None
} {
FormatterOutputMethods::write1(
output,
instruction,
operand,
instruction_operand,
&self.d.options,
&mut self.number_formatter,
&number_options,
imm64,
symbol,
self.d.options.show_symbol_address(),
);
} else {
value64 = imm64;
if number_options.signed_number {
number_kind = NumberKind::Int64;
if (imm64 as i64) < 0 {
output.write("-", FormatterTextKind::Operator);
imm64 = (imm64 as i64).wrapping_neg() as u64;
}
} else {
number_kind = NumberKind::UInt64;
}
let s = self.number_formatter.format_u64(&self.d.options, &number_options, imm64);
output.write_number(instruction, operand, instruction_operand, s, value64, number_kind, FormatterTextKind::Number);
}
}
InstrOpKind::MemorySegSI => self.format_memory(
output,
instruction,
operand,
instruction_operand,
op_info.memory_size(),
instruction.memory_segment(),
Register::SI,
Register::None,
0,
0,
0,
2,
op_info.flags,
),
InstrOpKind::MemorySegESI => self.format_memory(
output,
instruction,
operand,
instruction_operand,
op_info.memory_size(),
instruction.memory_segment(),
Register::ESI,
Register::None,
0,
0,
0,
4,
op_info.flags,
),
InstrOpKind::MemorySegRSI => self.format_memory(
output,
instruction,
operand,
instruction_operand,
op_info.memory_size(),
instruction.memory_segment(),
Register::RSI,
Register::None,
0,
0,
0,
8,
op_info.flags,
),
InstrOpKind::MemorySegDI => self.format_memory(
output,
instruction,
operand,
instruction_operand,
op_info.memory_size(),
instruction.memory_segment(),
Register::DI,
Register::None,
0,
0,
0,
2,
op_info.flags,
),
InstrOpKind::MemorySegEDI => self.format_memory(
output,
instruction,
operand,
instruction_operand,
op_info.memory_size(),
instruction.memory_segment(),
Register::EDI,
Register::None,
0,
0,
0,
4,
op_info.flags,
),
InstrOpKind::MemorySegRDI => self.format_memory(
output,
instruction,
operand,
instruction_operand,
op_info.memory_size(),
instruction.memory_segment(),
Register::RDI,
Register::None,
0,
0,
0,
8,
op_info.flags,
),
InstrOpKind::MemoryESDI => self.format_memory(
output,
instruction,
operand,
instruction_operand,
op_info.memory_size(),
Register::ES,
Register::DI,
Register::None,
0,
0,
0,
2,
op_info.flags,
),
InstrOpKind::MemoryESEDI => self.format_memory(
output,
instruction,
operand,
instruction_operand,
op_info.memory_size(),
Register::ES,
Register::EDI,
Register::None,
0,
0,
0,
4,
op_info.flags,
),
InstrOpKind::MemoryESRDI => self.format_memory(
output,
instruction,
operand,
instruction_operand,
op_info.memory_size(),
Register::ES,
Register::RDI,
Register::None,
0,
0,
0,
8,
op_info.flags,
),
InstrOpKind::Memory => {
let displ_size = instruction.memory_displ_size();
let base_reg = instruction.memory_base();
let index_reg = instruction.memory_index();
let addr_size = get_address_size_in_bytes(base_reg, index_reg, displ_size, instruction.code_size());
let displ = if addr_size == 8 { instruction.memory_displacement64() as i64 } else { instruction.memory_displacement32() as i64 };
self.format_memory(
output,
instruction,
operand,
instruction_operand,
op_info.memory_size(),
instruction.memory_segment(),
base_reg,
index_reg,
instruction_internal::internal_get_memory_index_scale(instruction),
displ_size,
displ,
addr_size,
op_info.flags,
);
}
InstrOpKind::Sae => NasmFormatter::format_decorator(
&self.d.options,
output,
instruction,
operand,
instruction_operand,
&self.d.str_.sae,
DecoratorKind::SuppressAllExceptions,
),
InstrOpKind::RnSae => NasmFormatter::format_decorator(
&self.d.options,
output,
instruction,
operand,
instruction_operand,
&self.d.str_.rn_sae,
DecoratorKind::RoundingControl,
),
InstrOpKind::RdSae => NasmFormatter::format_decorator(
&self.d.options,
output,
instruction,
operand,
instruction_operand,
&self.d.str_.rd_sae,
DecoratorKind::RoundingControl,
),
InstrOpKind::RuSae => NasmFormatter::format_decorator(
&self.d.options,
output,
instruction,
operand,
instruction_operand,
&self.d.str_.ru_sae,
DecoratorKind::RoundingControl,
),
InstrOpKind::RzSae => NasmFormatter::format_decorator(
&self.d.options,
output,
instruction,
operand,
instruction_operand,
&self.d.str_.rz_sae,
DecoratorKind::RoundingControl,
),
InstrOpKind::Rn => NasmFormatter::format_decorator(
&self.d.options,
output,
instruction,
operand,
instruction_operand,
&self.d.str_.rn,
DecoratorKind::RoundingControl,
),
InstrOpKind::Rd => NasmFormatter::format_decorator(
&self.d.options,
output,
instruction,
operand,
instruction_operand,
&self.d.str_.rd,
DecoratorKind::RoundingControl,
),
InstrOpKind::Ru => NasmFormatter::format_decorator(
&self.d.options,
output,
instruction,
operand,
instruction_operand,
&self.d.str_.ru,
DecoratorKind::RoundingControl,
),
InstrOpKind::Rz => NasmFormatter::format_decorator(
&self.d.options,
output,
instruction,
operand,
instruction_operand,
&self.d.str_.rz,
DecoratorKind::RoundingControl,
),
}
if operand == 0 && instruction_internal::internal_has_op_mask_or_zeroing_masking(instruction) {
if instruction.has_op_mask() {
output.write("{", FormatterTextKind::Punctuation);
NasmFormatter::format_register_internal(&self.d, output, instruction, operand, instruction_operand, instruction.op_mask());
output.write("}", FormatterTextKind::Punctuation);
}
if instruction.zeroing_masking() {
NasmFormatter::format_decorator(
&self.d.options,
output,
instruction,
operand,
instruction_operand,
&self.d.str_.z,
DecoratorKind::ZeroingMasking,
);
}
}
#[cfg(feature = "mvex")]
if mvex_rm_operand == operand {
let conv = instruction.mvex_reg_mem_conv();
if conv != MvexRegMemConv::None {
let mvex = crate::mvex::get_mvex_info(instruction.code());
if mvex.conv_fn != MvexConvFn::None {
let tbl = if mvex.is_conv_fn_32() { &self.d.vec_.mvex_reg_mem_consts_32 } else { &self.d.vec_.mvex_reg_mem_consts_64 };
let s = tbl[conv as usize];
if s.len() != 0 {
Self::format_decorator(&self.d.options, output, instruction, operand, instruction_operand, s, DecoratorKind::SwizzleMemConv);
}
}
}
}
}
fn show_sign_extend_info(d: &SelfData, output: &mut dyn FormatterOutput, flags: u32) {
if !d.options.nasm_show_sign_extended_immediate_size() {
return;
}
// SAFETY: generated data is valid
let sex_info: SignExtendInfo =
unsafe { mem::transmute(((flags >> InstrOpInfoFlags::SIGN_EXTEND_INFO_SHIFT) & InstrOpInfoFlags::SIGN_EXTEND_INFO_MASK) as u8) };
let keyword = match sex_info {
SignExtendInfo::None => return,
SignExtendInfo::Sex1to2 | SignExtendInfo::Sex1to4 | SignExtendInfo::Sex1to8 => &d.str_.byte,
SignExtendInfo::Sex2 => &d.str_.word,
SignExtendInfo::Sex4 => &d.str_.dword,
SignExtendInfo::Sex4to8 => &d.str_.qword,
};
NasmFormatter::format_keyword(&d.options, output, keyword);
output.write(" ", FormatterTextKind::Text);
}
fn format_flow_control(d: &SelfData, output: &mut dyn FormatterOutput, flags: u32, operand_options: FormatterOperandOptions) {
if !operand_options.branch_size() {
return;
}
let keywords = &d.vec_.nasm_branch_infos
[((flags as usize) >> InstrOpInfoFlags::BRANCH_SIZE_INFO_SHIFT) & InstrOpInfoFlags::BRANCH_SIZE_INFO_MASK as usize];
for &keyword in keywords {
NasmFormatter::format_keyword(&d.options, output, keyword);
output.write(" ", FormatterTextKind::Text);
}
}
fn format_decorator(
options: &FormatterOptions, output: &mut dyn FormatterOutput, instruction: &Instruction, operand: u32, instruction_operand: Option<u32>,
text: &FormatterString, decorator: DecoratorKind,
) {
output.write("{", FormatterTextKind::Punctuation);
output.write_decorator(
instruction,
operand,
instruction_operand,
text.get(options.uppercase_decorators() || options.uppercase_all()),
decorator,
);
output.write("}", FormatterTextKind::Punctuation);
}
#[inline]
fn get_reg_str(d: &SelfData, reg: Register) -> &'static str {
let reg_str = &d.all_registers[reg as usize];
reg_str.get(d.options.uppercase_registers() || d.options.uppercase_all())
}
#[inline]
fn format_register_internal(
d: &SelfData, output: &mut dyn FormatterOutput, instruction: &Instruction, operand: u32, instruction_operand: Option<u32>, reg: Register,
) {
output.write_register(instruction, operand, instruction_operand, NasmFormatter::get_reg_str(d, reg), reg);
}
#[allow(clippy::too_many_arguments)]
fn format_memory(
&mut self, output: &mut dyn FormatterOutput, instruction: &Instruction, operand: u32, instruction_operand: Option<u32>, mem_size: MemorySize,
seg_reg: Register, mut base_reg: Register, index_reg: Register, scale: u32, mut displ_size: u32, mut displ: i64, addr_size: u32,
mut flags: u32,
) {
debug_assert!((scale as usize) < SCALE_NUMBERS.len());
debug_assert!(get_address_size_in_bytes(base_reg, index_reg, displ_size, instruction.code_size()) == addr_size);
let mut operand_options = FormatterOperandOptions::with_memory_size_options(self.d.options.memory_size_options());
operand_options.set_rip_relative_addresses(self.d.options.rip_relative_addresses());
let mut number_options = NumberFormattingOptions::with_displacement(&self.d.options);
if let Some(ref mut options_provider) = self.options_provider {
options_provider.operand_options(instruction, operand, instruction_operand, &mut operand_options, &mut number_options);
}
let abs_addr;
let mut add_rel_keyword = false;
if base_reg == Register::RIP {
abs_addr = displ as u64;
if self.d.options.rip_relative_addresses() {
displ = displ.wrapping_sub(instruction.next_ip() as i64);
} else {
debug_assert_eq!(index_reg, Register::None);
base_reg = Register::None;
flags &= !(InstrOpInfoFlags::MEMORY_SIZE_INFO_MASK << InstrOpInfoFlags::MEMORY_SIZE_INFO_SHIFT);
add_rel_keyword = true;
}
displ_size = 8;
} else if base_reg == Register::EIP {
abs_addr = displ as u32 as u64;
if self.d.options.rip_relative_addresses() {
displ = (displ as u32).wrapping_sub(instruction.next_ip32()) as i32 as i64;
} else {
debug_assert_eq!(index_reg, Register::None);
base_reg = Register::None;
flags = (flags & !(InstrOpInfoFlags::MEMORY_SIZE_INFO_MASK << InstrOpInfoFlags::MEMORY_SIZE_INFO_SHIFT))
| ((self::enums::MemorySizeInfo::Dword as u32) << InstrOpInfoFlags::MEMORY_SIZE_INFO_SHIFT);
add_rel_keyword = true;
}
displ_size = 4;
} else {
abs_addr = displ as u64;
}
let symbol = if let Some(ref mut symbol_resolver) = self.symbol_resolver {
symbol_resolver.symbol(instruction, operand, instruction_operand, abs_addr, addr_size)
} else {
None
};
let mut use_scale = scale != 0 || self.d.options.always_show_scale();
if !use_scale {
// [rsi] = base reg, [rsi*1] = index reg
if base_reg == Register::None {
use_scale = true;
}
}
if addr_size == 2 || !show_index_scale(instruction, &self.d.options) {
use_scale = false;
}
NasmFormatter::format_memory_size(&self.d, output, mem_size, flags, operand_options);
output.write("[", FormatterTextKind::Punctuation);
if self.d.options.space_after_memory_bracket() {
output.write(" ", FormatterTextKind::Text);
}
let mem_size_name = &self.d.vec_.nasm_mem_size_infos
[((flags >> InstrOpInfoFlags::MEMORY_SIZE_INFO_SHIFT) & InstrOpInfoFlags::MEMORY_SIZE_INFO_MASK) as usize];
if !mem_size_name.is_default() {
NasmFormatter::format_keyword(&self.d.options, output, mem_size_name);
output.write(" ", FormatterTextKind::Text);
}
if add_rel_keyword {
NasmFormatter::format_keyword(&self.d.options, output, &self.d.str_.rel);
output.write(" ", FormatterTextKind::Text);
}
let code_size = instruction.code_size();
let seg_override = instruction.segment_prefix();
let notrack_prefix = seg_override == Register::DS
&& is_notrack_prefix_branch(instruction.code())
&& !((code_size == CodeSize::Code16 || code_size == CodeSize::Code32)
&& (base_reg == Register::BP || base_reg == Register::EBP || base_reg == Register::ESP));
if self.d.options.always_show_segment_register()
|| (seg_override != Register::None && !notrack_prefix && show_segment_prefix(Register::None, instruction, &self.d.options))
{
NasmFormatter::format_register_internal(&self.d, output, instruction, operand, instruction_operand, seg_reg);
output.write(":", FormatterTextKind::Punctuation);
}
let mut need_plus = if base_reg != Register::None {
NasmFormatter::format_register_internal(&self.d, output, instruction, operand, instruction_operand, base_reg);
true
} else {
false
};
if index_reg != Register::None {
if need_plus {
if self.d.options.space_between_memory_add_operators() {
output.write(" ", FormatterTextKind::Text);
}
output.write("+", FormatterTextKind::Operator);
if self.d.options.space_between_memory_add_operators() {
output.write(" ", FormatterTextKind::Text);
}
}
need_plus = true;
if !use_scale {
NasmFormatter::format_register_internal(&self.d, output, instruction, operand, instruction_operand, index_reg);
} else if self.d.options.scale_before_index() {
output.write_number(
instruction,
operand,
instruction_operand,
SCALE_NUMBERS[scale as usize],
1u64 << scale,
NumberKind::Int32,
FormatterTextKind::Number,
);
if self.d.options.space_between_memory_mul_operators() {
output.write(" ", FormatterTextKind::Text);
}
output.write("*", FormatterTextKind::Operator);
if self.d.options.space_between_memory_mul_operators() {
output.write(" ", FormatterTextKind::Text);
}
NasmFormatter::format_register_internal(&self.d, output, instruction, operand, instruction_operand, index_reg);
} else {
NasmFormatter::format_register_internal(&self.d, output, instruction, operand, instruction_operand, index_reg);
if self.d.options.space_between_memory_mul_operators() {
output.write(" ", FormatterTextKind::Text);
}
output.write("*", FormatterTextKind::Operator);
if self.d.options.space_between_memory_mul_operators() {
output.write(" ", FormatterTextKind::Text);
}
output.write_number(
instruction,
operand,
instruction_operand,
SCALE_NUMBERS[scale as usize],
1u64 << scale,
NumberKind::Int32,
FormatterTextKind::Number,
);
}
}
if let Some(ref symbol) = symbol {
if need_plus {
if self.d.options.space_between_memory_add_operators() {
output.write(" ", FormatterTextKind::Text);
}
if (symbol.flags & SymbolFlags::SIGNED) != 0 {
output.write("-", FormatterTextKind::Operator);
} else {
output.write("+", FormatterTextKind::Operator);
}
if self.d.options.space_between_memory_add_operators() {
output.write(" ", FormatterTextKind::Text);
}
} else if (symbol.flags & SymbolFlags::SIGNED) != 0 {
output.write("-", FormatterTextKind::Operator);
}
FormatterOutputMethods::write2(
output,
instruction,
operand,
instruction_operand,
&self.d.options,
&mut self.number_formatter,
&number_options,
abs_addr,
symbol,
self.d.options.show_symbol_address(),
false,
self.d.options.space_between_memory_add_operators(),
);
} else if !need_plus || (displ_size != 0 && (self.d.options.show_zero_displacements() || displ != 0)) {
let orig_displ = displ as u64;
let is_signed;
if need_plus {
is_signed = number_options.signed_number;
if self.d.options.space_between_memory_add_operators() {
output.write(" ", FormatterTextKind::Text);
}
if addr_size == 8 {
if !number_options.signed_number {
output.write("+", FormatterTextKind::Operator);
} else if displ < 0 {
displ = displ.wrapping_neg();
output.write("-", FormatterTextKind::Operator);
} else {
output.write("+", FormatterTextKind::Operator);
}
if number_options.displacement_leading_zeros {
displ_size = 4;
}
} else if addr_size == 4 {
if !number_options.signed_number {
output.write("+", FormatterTextKind::Operator);
} else if (displ as i32) < 0 {
displ = (displ as i32).wrapping_neg() as u32 as i64;
output.write("-", FormatterTextKind::Operator);
} else {
output.write("+", FormatterTextKind::Operator);
}
if number_options.displacement_leading_zeros {
displ_size = 4;
}
} else {
debug_assert_eq!(addr_size, 2);
if !number_options.signed_number {
output.write("+", FormatterTextKind::Operator);
} else if (displ as i16) < 0 {
displ = (displ as i16).wrapping_neg() as u16 as i64;
output.write("-", FormatterTextKind::Operator);
} else {
output.write("+", FormatterTextKind::Operator);
}
if number_options.displacement_leading_zeros {
displ_size = 2;
}
}
if self.d.options.space_between_memory_add_operators() {
output.write(" ", FormatterTextKind::Text);
}
} else {
is_signed = false;
}
let (s, displ_kind) = if displ_size <= 1 && displ as u64 <= u8::MAX as u64 {
(
self.number_formatter.format_displ_u8(&self.d.options, &number_options, displ as u8),
if is_signed { NumberKind::Int8 } else { NumberKind::UInt8 },
)
} else if displ_size <= 2 && displ as u64 <= u16::MAX as u64 {
(
self.number_formatter.format_displ_u16(&self.d.options, &number_options, displ as u16),
if is_signed { NumberKind::Int16 } else { NumberKind::UInt16 },
)
} else if displ_size <= 4 && displ as u64 <= u32::MAX as u64 {
(
self.number_formatter.format_displ_u32(&self.d.options, &number_options, displ as u32),
if is_signed { NumberKind::Int32 } else { NumberKind::UInt32 },
)
} else if displ_size <= 8 {
(
self.number_formatter.format_displ_u64(&self.d.options, &number_options, displ as u64),
if is_signed { NumberKind::Int64 } else { NumberKind::UInt64 },
)
} else {
unreachable!();
};
output.write_number(instruction, operand, instruction_operand, s, orig_displ, displ_kind, FormatterTextKind::Number);
}
if self.d.options.space_after_memory_bracket() {
output.write(" ", FormatterTextKind::Text);
}
output.write("]", FormatterTextKind::Punctuation);
debug_assert!((mem_size as usize) < self.d.all_memory_sizes.len());
let bcst_to = &self.d.all_memory_sizes[mem_size as usize].bcst_to;
if !bcst_to.is_default() {
NasmFormatter::format_decorator(&self.d.options, output, instruction, operand, instruction_operand, bcst_to, DecoratorKind::Broadcast);
}
#[cfg(feature = "mvex")]
if instruction.is_mvex_eviction_hint() {
Self::format_decorator(
&self.d.options,
output,
instruction,
operand,
instruction_operand,
&self.d.str_.mvex.eh,
DecoratorKind::EvictionHint,
);
}
}
src/formatter/masm.rs (lines 472-480)
367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408
fn format_operand(&mut self, instruction: &Instruction, output: &mut dyn FormatterOutput, op_info: &InstrOpInfo<'_>, operand: u32) {
debug_assert!(operand < op_info.op_count as u32);
#[cfg(feature = "mvex")]
let mvex_rm_operand = {
if IcedConstants::is_mvex(instruction.code()) {
let op_count = instruction.op_count();
debug_assert_ne!(op_count, 0);
if instruction.op_kind(op_count.wrapping_sub(1)) == OpKind::Immediate8 {
op_count.wrapping_sub(2)
} else {
op_count.wrapping_sub(1)
}
} else {
u32::MAX
}
};
let instruction_operand = op_info.instruction_index(operand);
let flow_control;
let mut imm8;
let mut imm16;
let mut imm32;
let mut imm64;
let value64;
let imm_size;
let mut operand_options;
let number_kind;
let op_kind = op_info.op_kind(operand);
match op_kind {
InstrOpKind::Register => {
MasmFormatter::format_register_internal(&self.d, output, instruction, operand, instruction_operand, op_info.op_register(operand))
}
InstrOpKind::NearBranch16 | InstrOpKind::NearBranch32 | InstrOpKind::NearBranch64 => {
if op_kind == InstrOpKind::NearBranch64 {
imm_size = 8;
imm64 = instruction.near_branch64();
number_kind = NumberKind::UInt64;
} else if op_kind == InstrOpKind::NearBranch32 {
imm_size = 4;
imm64 = instruction.near_branch32() as u64;
number_kind = NumberKind::UInt32;
} else {
imm_size = 2;
imm64 = instruction.near_branch16() as u64;
number_kind = NumberKind::UInt16;
}
operand_options = FormatterOperandOptions::new(if self.d.options.show_branch_size() {
FormatterOperandOptionsFlags::NONE
} else {
FormatterOperandOptionsFlags::NO_BRANCH_SIZE
});
if let Some(ref symbol) = if let Some(ref mut symbol_resolver) = self.symbol_resolver {
symbol_resolver.symbol(instruction, operand, instruction_operand, imm64, imm_size)
} else {
None
} {
MasmFormatter::format_flow_control(&self.d, output, get_flow_control(instruction), operand_options);
let mut number_options = NumberFormattingOptions::with_branch(&self.d.options);
if let Some(ref mut options_provider) = self.options_provider {
options_provider.operand_options(instruction, operand, instruction_operand, &mut operand_options, &mut number_options);
}
FormatterOutputMethods::write1(
output,
instruction,
operand,
instruction_operand,
&self.d.options,
&mut self.number_formatter,
&number_options,
imm64,
symbol,
self.d.options.show_symbol_address(),
);
} else {
flow_control = get_flow_control(instruction);
MasmFormatter::format_flow_control(&self.d, output, flow_control, operand_options);
let mut number_options = NumberFormattingOptions::with_branch(&self.d.options);
if let Some(ref mut options_provider) = self.options_provider {
options_provider.operand_options(instruction, operand, instruction_operand, &mut operand_options, &mut number_options);
}
let s = if op_kind == InstrOpKind::NearBranch32 {
self.number_formatter.format_u32_zeros(
&self.d.options,
&number_options,
instruction.near_branch32(),
number_options.leading_zeros,
)
} else if op_kind == InstrOpKind::NearBranch64 {
self.number_formatter.format_u64_zeros(
&self.d.options,
&number_options,
instruction.near_branch64(),
number_options.leading_zeros,
)
} else {
self.number_formatter.format_u16_zeros(
&self.d.options,
&number_options,
instruction.near_branch16(),
number_options.leading_zeros,
)
};
output.write_number(
instruction,
operand,
instruction_operand,
s,
imm64,
number_kind,
if is_call(flow_control) { FormatterTextKind::FunctionAddress } else { FormatterTextKind::LabelAddress },
);
}
}
InstrOpKind::FarBranch16 | InstrOpKind::FarBranch32 => {
if op_kind == InstrOpKind::FarBranch32 {
imm_size = 4;
imm64 = instruction.far_branch32() as u64;
number_kind = NumberKind::UInt32;
} else {
imm_size = 2;
imm64 = instruction.far_branch16() as u64;
number_kind = NumberKind::UInt16;
}
operand_options = FormatterOperandOptions::new(if self.d.options.show_branch_size() {
FormatterOperandOptionsFlags::NONE
} else {
FormatterOperandOptionsFlags::NO_BRANCH_SIZE
});
let mut vec: Vec<SymResTextPart<'_>> = Vec::new();
if let Some(ref symbol) = if let Some(ref mut symbol_resolver) = self.symbol_resolver {
to_owned(symbol_resolver.symbol(instruction, operand, instruction_operand, imm64 as u32 as u64, imm_size), &mut vec)
} else {
None
} {
MasmFormatter::format_flow_control(&self.d, output, get_flow_control(instruction), operand_options);
debug_assert!(operand + 1 == 1);
let mut number_options = NumberFormattingOptions::with_branch(&self.d.options);
if let Some(ref mut options_provider) = self.options_provider {
options_provider.operand_options(instruction, operand, instruction_operand, &mut operand_options, &mut number_options);
}
let selector_symbol = if let Some(ref mut symbol_resolver) = self.symbol_resolver {
symbol_resolver.symbol(instruction, operand + 1, instruction_operand, instruction.far_branch_selector() as u64, 2)
} else {
None
};
if let Some(ref selector_symbol) = selector_symbol {
FormatterOutputMethods::write1(
output,
instruction,
operand,
instruction_operand,
&self.d.options,
&mut self.number_formatter,
&number_options,
instruction.far_branch_selector() as u64,
selector_symbol,
self.d.options.show_symbol_address(),
);
} else {
let s = self.number_formatter.format_u16_zeros(
&self.d.options,
&number_options,
instruction.far_branch_selector(),
number_options.leading_zeros,
);
output.write_number(
instruction,
operand,
instruction_operand,
s,
instruction.far_branch_selector() as u64,
NumberKind::UInt16,
FormatterTextKind::SelectorValue,
);
}
output.write(":", FormatterTextKind::Punctuation);
FormatterOutputMethods::write1(
output,
instruction,
operand,
instruction_operand,
&self.d.options,
&mut self.number_formatter,
&number_options,
imm64,
symbol,
self.d.options.show_symbol_address(),
);
} else {
flow_control = get_flow_control(instruction);
MasmFormatter::format_flow_control(&self.d, output, flow_control, operand_options);
let mut number_options = NumberFormattingOptions::with_branch(&self.d.options);
if let Some(ref mut options_provider) = self.options_provider {
options_provider.operand_options(instruction, operand, instruction_operand, &mut operand_options, &mut number_options);
}
let s = self.number_formatter.format_u16_zeros(
&self.d.options,
&number_options,
instruction.far_branch_selector(),
number_options.leading_zeros,
);
output.write_number(
instruction,
operand,
instruction_operand,
s,
instruction.far_branch_selector() as u64,
NumberKind::UInt16,
FormatterTextKind::SelectorValue,
);
output.write(":", FormatterTextKind::Punctuation);
let s = if op_kind == InstrOpKind::FarBranch32 {
self.number_formatter.format_u32_zeros(
&self.d.options,
&number_options,
instruction.far_branch32(),
number_options.leading_zeros,
)
} else {
self.number_formatter.format_u16_zeros(
&self.d.options,
&number_options,
instruction.far_branch16(),
number_options.leading_zeros,
)
};
output.write_number(
instruction,
operand,
instruction_operand,
s,
imm64,
number_kind,
if is_call(flow_control) { FormatterTextKind::FunctionAddress } else { FormatterTextKind::LabelAddress },
);
}
}
InstrOpKind::Immediate8 | InstrOpKind::Immediate8_2nd | InstrOpKind::ExtraImmediate8_Value3 | InstrOpKind::DeclareByte => {
if op_kind == InstrOpKind::Immediate8 {
imm8 = instruction.immediate8();
} else if op_kind == InstrOpKind::ExtraImmediate8_Value3 {
imm8 = 3;
} else if op_kind == InstrOpKind::Immediate8_2nd {
imm8 = instruction.immediate8_2nd();
} else {
imm8 = instruction.get_declare_byte_value(operand as usize);
}
operand_options = FormatterOperandOptions::default();
if let Some(ref symbol) = if let Some(ref mut symbol_resolver) = self.symbol_resolver {
symbol_resolver.symbol(instruction, operand, instruction_operand, imm8 as u64, 1)
} else {
None
} {
if (symbol.flags & SymbolFlags::RELATIVE) == 0 {
MasmFormatter::format_keyword(&self.d.options, output, &self.d.str_.offset);
output.write(" ", FormatterTextKind::Text);
}
let mut number_options = NumberFormattingOptions::with_immediate(&self.d.options);
if let Some(ref mut options_provider) = self.options_provider {
options_provider.operand_options(instruction, operand, instruction_operand, &mut operand_options, &mut number_options);
}
FormatterOutputMethods::write1(
output,
instruction,
operand,
instruction_operand,
&self.d.options,
&mut self.number_formatter,
&number_options,
imm8 as u64,
symbol,
self.d.options.show_symbol_address(),
);
} else {
let mut number_options = NumberFormattingOptions::with_immediate(&self.d.options);
if let Some(ref mut options_provider) = self.options_provider {
options_provider.operand_options(instruction, operand, instruction_operand, &mut operand_options, &mut number_options);
}
if number_options.signed_number {
imm64 = imm8 as i8 as u64;
number_kind = NumberKind::Int8;
if (imm8 as i8) < 0 {
output.write("-", FormatterTextKind::Operator);
imm8 = (imm8 as i8).wrapping_neg() as u8;
}
} else {
imm64 = imm8 as u64;
number_kind = NumberKind::UInt8;
}
let s = self.number_formatter.format_u8(&self.d.options, &number_options, imm8);
output.write_number(instruction, operand, instruction_operand, s, imm64, number_kind, FormatterTextKind::Number);
}
}
InstrOpKind::Immediate16 | InstrOpKind::Immediate8to16 | InstrOpKind::DeclareWord => {
if op_kind == InstrOpKind::Immediate16 {
imm16 = instruction.immediate16();
} else if op_kind == InstrOpKind::Immediate8to16 {
imm16 = instruction.immediate8to16() as u16;
} else {
imm16 = instruction.get_declare_word_value(operand as usize);
}
operand_options = FormatterOperandOptions::default();
if let Some(ref symbol) = if let Some(ref mut symbol_resolver) = self.symbol_resolver {
symbol_resolver.symbol(instruction, operand, instruction_operand, imm16 as u64, 2)
} else {
None
} {
if (symbol.flags & SymbolFlags::RELATIVE) == 0 {
MasmFormatter::format_keyword(&self.d.options, output, &self.d.str_.offset);
output.write(" ", FormatterTextKind::Text);
}
let mut number_options = NumberFormattingOptions::with_immediate(&self.d.options);
if let Some(ref mut options_provider) = self.options_provider {
options_provider.operand_options(instruction, operand, instruction_operand, &mut operand_options, &mut number_options);
}
FormatterOutputMethods::write1(
output,
instruction,
operand,
instruction_operand,
&self.d.options,
&mut self.number_formatter,
&number_options,
imm16 as u64,
symbol,
self.d.options.show_symbol_address(),
);
} else {
let mut number_options = NumberFormattingOptions::with_immediate(&self.d.options);
if let Some(ref mut options_provider) = self.options_provider {
options_provider.operand_options(instruction, operand, instruction_operand, &mut operand_options, &mut number_options);
}
if number_options.signed_number {
imm64 = imm16 as i16 as u64;
number_kind = NumberKind::Int16;
if (imm16 as i16) < 0 {
output.write("-", FormatterTextKind::Operator);
imm16 = (imm16 as i16).wrapping_neg() as u16;
}
} else {
imm64 = imm16 as u64;
number_kind = NumberKind::UInt16;
}
let s = self.number_formatter.format_u16(&self.d.options, &number_options, imm16);
output.write_number(instruction, operand, instruction_operand, s, imm64, number_kind, FormatterTextKind::Number);
}
}
InstrOpKind::Immediate32 | InstrOpKind::Immediate8to32 | InstrOpKind::DeclareDword => {
if op_kind == InstrOpKind::Immediate32 {
imm32 = instruction.immediate32();
} else if op_kind == InstrOpKind::Immediate8to32 {
imm32 = instruction.immediate8to32() as u32;
} else {
imm32 = instruction.get_declare_dword_value(operand as usize);
}
operand_options = FormatterOperandOptions::default();
if let Some(ref symbol) = if let Some(ref mut symbol_resolver) = self.symbol_resolver {
symbol_resolver.symbol(instruction, operand, instruction_operand, imm32 as u64, 4)
} else {
None
} {
if (symbol.flags & SymbolFlags::RELATIVE) == 0 {
MasmFormatter::format_keyword(&self.d.options, output, &self.d.str_.offset);
output.write(" ", FormatterTextKind::Text);
}
let mut number_options = NumberFormattingOptions::with_immediate(&self.d.options);
if let Some(ref mut options_provider) = self.options_provider {
options_provider.operand_options(instruction, operand, instruction_operand, &mut operand_options, &mut number_options);
}
FormatterOutputMethods::write1(
output,
instruction,
operand,
instruction_operand,
&self.d.options,
&mut self.number_formatter,
&number_options,
imm32 as u64,
symbol,
self.d.options.show_symbol_address(),
);
} else {
let mut number_options = NumberFormattingOptions::with_immediate(&self.d.options);
if let Some(ref mut options_provider) = self.options_provider {
options_provider.operand_options(instruction, operand, instruction_operand, &mut operand_options, &mut number_options);
}
if number_options.signed_number {
imm64 = imm32 as i32 as u64;
number_kind = NumberKind::Int32;
if (imm32 as i32) < 0 {
output.write("-", FormatterTextKind::Operator);
imm32 = (imm32 as i32).wrapping_neg() as u32;
}
} else {
imm64 = imm32 as u64;
number_kind = NumberKind::UInt32;
}
let s = self.number_formatter.format_u32(&self.d.options, &number_options, imm32);
output.write_number(instruction, operand, instruction_operand, s, imm64, number_kind, FormatterTextKind::Number);
}
}
InstrOpKind::Immediate64 | InstrOpKind::Immediate8to64 | InstrOpKind::Immediate32to64 | InstrOpKind::DeclareQword => {
if op_kind == InstrOpKind::Immediate32to64 {
imm64 = instruction.immediate32to64() as u64;
} else if op_kind == InstrOpKind::Immediate8to64 {
imm64 = instruction.immediate8to64() as u64;
} else if op_kind == InstrOpKind::Immediate64 {
imm64 = instruction.immediate64();
} else {
imm64 = instruction.get_declare_qword_value(operand as usize);
}
operand_options = FormatterOperandOptions::default();
if let Some(ref symbol) = if let Some(ref mut symbol_resolver) = self.symbol_resolver {
symbol_resolver.symbol(instruction, operand, instruction_operand, imm64, 8)
} else {
None
} {
if (symbol.flags & SymbolFlags::RELATIVE) == 0 {
MasmFormatter::format_keyword(&self.d.options, output, &self.d.str_.offset);
output.write(" ", FormatterTextKind::Text);
}
let mut number_options = NumberFormattingOptions::with_immediate(&self.d.options);
if let Some(ref mut options_provider) = self.options_provider {
options_provider.operand_options(instruction, operand, instruction_operand, &mut operand_options, &mut number_options);
}
FormatterOutputMethods::write1(
output,
instruction,
operand,
instruction_operand,
&self.d.options,
&mut self.number_formatter,
&number_options,
imm64,
symbol,
self.d.options.show_symbol_address(),
);
} else {
value64 = imm64;
let mut number_options = NumberFormattingOptions::with_immediate(&self.d.options);
if let Some(ref mut options_provider) = self.options_provider {
options_provider.operand_options(instruction, operand, instruction_operand, &mut operand_options, &mut number_options);
}
if number_options.signed_number {
number_kind = NumberKind::Int64;
if (imm64 as i64) < 0 {
output.write("-", FormatterTextKind::Operator);
imm64 = (imm64 as i64).wrapping_neg() as u64;
}
} else {
number_kind = NumberKind::UInt64;
}
let s = self.number_formatter.format_u64(&self.d.options, &number_options, imm64);
output.write_number(instruction, operand, instruction_operand, s, value64, number_kind, FormatterTextKind::Number);
}
}
InstrOpKind::MemorySegSI => self.format_memory(
output,
instruction,
operand,
instruction_operand,
instruction.memory_segment(),
Register::SI,
Register::None,
0,
0,
0,
2,
op_info.flags as u32,
),
InstrOpKind::MemorySegESI => self.format_memory(
output,
instruction,
operand,
instruction_operand,
instruction.memory_segment(),
Register::ESI,
Register::None,
0,
0,
0,
4,
op_info.flags as u32,
),
InstrOpKind::MemorySegRSI => self.format_memory(
output,
instruction,
operand,
instruction_operand,
instruction.memory_segment(),
Register::RSI,
Register::None,
0,
0,
0,
8,
op_info.flags as u32,
),
InstrOpKind::MemorySegDI => self.format_memory(
output,
instruction,
operand,
instruction_operand,
instruction.memory_segment(),
Register::DI,
Register::None,
0,
0,
0,
2,
op_info.flags as u32,
),
InstrOpKind::MemorySegEDI => self.format_memory(
output,
instruction,
operand,
instruction_operand,
instruction.memory_segment(),
Register::EDI,
Register::None,
0,
0,
0,
4,
op_info.flags as u32,
),
InstrOpKind::MemorySegRDI => self.format_memory(
output,
instruction,
operand,
instruction_operand,
instruction.memory_segment(),
Register::RDI,
Register::None,
0,
0,
0,
8,
op_info.flags as u32,
),
InstrOpKind::MemoryESDI => self.format_memory(
output,
instruction,
operand,
instruction_operand,
Register::ES,
Register::DI,
Register::None,
0,
0,
0,
2,
op_info.flags as u32,
),
InstrOpKind::MemoryESEDI => self.format_memory(
output,
instruction,
operand,
instruction_operand,
Register::ES,
Register::EDI,
Register::None,
0,
0,
0,
4,
op_info.flags as u32,
),
InstrOpKind::MemoryESRDI => self.format_memory(
output,
instruction,
operand,
instruction_operand,
Register::ES,
Register::RDI,
Register::None,
0,
0,
0,
8,
op_info.flags as u32,
),
InstrOpKind::Memory => {
let displ_size = instruction.memory_displ_size();
let base_reg = instruction.memory_base();
let mut index_reg = instruction.memory_index();
let addr_size = get_address_size_in_bytes(base_reg, index_reg, displ_size, instruction.code_size());
let displ = if addr_size == 8 { instruction.memory_displacement64() as i64 } else { instruction.memory_displacement32() as i64 };
if (op_info.flags & InstrOpInfoFlags::IGNORE_INDEX_REG as u16) != 0 {
index_reg = Register::None;
}
self.format_memory(
output,
instruction,
operand,
instruction_operand,
instruction.memory_segment(),
base_reg,
index_reg,
instruction_internal::internal_get_memory_index_scale(instruction),
displ_size,
displ,
addr_size,
op_info.flags as u32,
);
}
}
if operand == 0 && instruction_internal::internal_has_op_mask_or_zeroing_masking(instruction) {
if instruction.has_op_mask() {
output.write("{", FormatterTextKind::Punctuation);
MasmFormatter::format_register_internal(&self.d, output, instruction, operand, instruction_operand, instruction.op_mask());
output.write("}", FormatterTextKind::Punctuation);
}
if instruction.zeroing_masking() {
MasmFormatter::format_decorator(
&self.d.options,
output,
instruction,
operand,
instruction_operand,
&self.d.str_.z,
DecoratorKind::ZeroingMasking,
);
}
}
if operand + 1 == op_info.op_count as u32 && instruction_internal::internal_has_rounding_control_or_sae(instruction) {
let rc = instruction.rounding_control();
if rc != RoundingControl::None && can_show_rounding_control(instruction, &self.d.options) {
let dec_str = if IcedConstants::is_mvex(instruction.code()) {
if instruction.suppress_all_exceptions() {
self.d.vec_.masm_rc_sae_strings[rc as usize]
} else {
self.d.vec_.masm_rc_strings[rc as usize]
}
} else {
self.d.vec_.masm_rc_sae_strings[rc as usize]
};
MasmFormatter::format_decorator(
&self.d.options,
output,
instruction,
operand,
instruction_operand,
dec_str,
DecoratorKind::RoundingControl,
);
} else if instruction.suppress_all_exceptions() {
MasmFormatter::format_decorator(
&self.d.options,
output,
instruction,
operand,
instruction_operand,
&self.d.str_.sae,
DecoratorKind::SuppressAllExceptions,
);
}
}
#[cfg(feature = "mvex")]
if mvex_rm_operand == operand {
let conv = instruction.mvex_reg_mem_conv();
if conv != MvexRegMemConv::None {
let mvex = crate::mvex::get_mvex_info(instruction.code());
if mvex.conv_fn != MvexConvFn::None {
let tbl = if mvex.is_conv_fn_32() { &self.d.vec_.mvex_reg_mem_consts_32 } else { &self.d.vec_.mvex_reg_mem_consts_64 };
let s = tbl[conv as usize];
if s.len() != 0 {
Self::format_decorator(&self.d.options, output, instruction, operand, instruction_operand, s, DecoratorKind::SwizzleMemConv);
}
}
}
}
}
fn format_decorator(
options: &FormatterOptions, output: &mut dyn FormatterOutput, instruction: &Instruction, operand: u32, instruction_operand: Option<u32>,
text: &FormatterString, decorator: DecoratorKind,
) {
output.write("{", FormatterTextKind::Punctuation);
output.write_decorator(
instruction,
operand,
instruction_operand,
text.get(options.uppercase_decorators() || options.uppercase_all()),
decorator,
);
output.write("}", FormatterTextKind::Punctuation);
}
#[inline]
fn get_reg_str(d: &SelfData, mut reg: Register) -> &'static str {
if d.options.prefer_st0() && reg == REGISTER_ST {
reg = Register::ST0;
}
let reg_str = &d.all_registers[reg as usize];
reg_str.get(d.options.uppercase_registers() || d.options.uppercase_all())
}
#[inline]
fn format_register_internal(
d: &SelfData, output: &mut dyn FormatterOutput, instruction: &Instruction, operand: u32, instruction_operand: Option<u32>, reg: Register,
) {
output.write_register(instruction, operand, instruction_operand, MasmFormatter::get_reg_str(d, reg), reg);
}
#[allow(clippy::too_many_arguments)]
fn format_memory(
&mut self, output: &mut dyn FormatterOutput, instruction: &Instruction, operand: u32, instruction_operand: Option<u32>, seg_reg: Register,
mut base_reg: Register, index_reg: Register, scale: u32, mut displ_size: u32, mut displ: i64, addr_size: u32, flags: u32,
) {
debug_assert!((scale as usize) < SCALE_NUMBERS.len());
debug_assert!(get_address_size_in_bytes(base_reg, index_reg, displ_size, instruction.code_size()) == addr_size);
let mut operand_options = FormatterOperandOptions::with_memory_size_options(self.d.options.memory_size_options());
operand_options.set_rip_relative_addresses(self.d.options.rip_relative_addresses());
let mut number_options = NumberFormattingOptions::with_displacement(&self.d.options);
if let Some(ref mut options_provider) = self.options_provider {
options_provider.operand_options(instruction, operand, instruction_operand, &mut operand_options, &mut number_options);
}
let abs_addr;
if base_reg == Register::RIP {
abs_addr = displ as u64;
if self.d.options.rip_relative_addresses() {
displ = displ.wrapping_sub(instruction.next_ip() as i64);
} else {
debug_assert_eq!(index_reg, Register::None);
base_reg = Register::None;
}
displ_size = 8;
} else if base_reg == Register::EIP {
abs_addr = displ as u32 as u64;
if self.d.options.rip_relative_addresses() {
displ = (displ as u32).wrapping_sub(instruction.next_ip32()) as i32 as i64;
} else {
debug_assert_eq!(index_reg, Register::None);
base_reg = Register::None;
}
displ_size = 4;
} else {
abs_addr = displ as u64;
}
let symbol = if let Some(ref mut symbol_resolver) = self.symbol_resolver {
symbol_resolver.symbol(instruction, operand, instruction_operand, abs_addr, addr_size)
} else {
None
};
let mut use_scale = scale != 0 || self.d.options.always_show_scale();
if !use_scale {
// [rsi] = base reg, [rsi*1] = index reg
if base_reg == Register::None {
use_scale = true;
}
}
if addr_size == 2 || !show_index_scale(instruction, &self.d.options) {
use_scale = false;
}
let code_size = instruction.code_size();
let is1632 = code_size == CodeSize::Code16 || code_size == CodeSize::Code32;
let has_mem_reg = base_reg != Register::None || index_reg != Register::None;
let seg_override = instruction.segment_prefix();
let displ_in_brackets = if (!is1632 && !has_mem_reg && symbol.is_none())
|| (is1632 && !has_mem_reg && symbol.is_none() && !self.d.options.masm_add_ds_prefix32() && seg_override == Register::None)
{
true
} else {
if symbol.is_some() {
self.d.options.masm_symbol_displ_in_brackets()
} else {
self.d.options.masm_displ_in_brackets()
}
};
let need_brackets = has_mem_reg || displ_in_brackets;
MasmFormatter::format_memory_size(&self.d, output, instruction, &symbol, instruction.memory_size(), flags, operand_options);
let notrack_prefix = seg_override == Register::DS
&& is_notrack_prefix_branch(instruction.code())
&& !((code_size == CodeSize::Code16 || code_size == CodeSize::Code32)
&& (base_reg == Register::BP || base_reg == Register::EBP || base_reg == Register::ESP));
if self.d.options.always_show_segment_register()
|| (seg_override != Register::None && !notrack_prefix && show_segment_prefix(Register::None, instruction, &self.d.options))
|| (is1632 && !has_mem_reg && symbol.is_none() && self.d.options.masm_add_ds_prefix32())
{
MasmFormatter::format_register_internal(&self.d, output, instruction, operand, instruction_operand, seg_reg);
output.write(":", FormatterTextKind::Punctuation);
}
if !displ_in_brackets {
MasmFormatter::format_memory_displ(
&self.d,
&mut self.number_formatter,
&mut number_options,
output,
instruction,
operand,
instruction_operand,
&symbol,
abs_addr,
displ,
displ_size,
addr_size,
false,
!has_mem_reg,
);
}
if need_brackets {
output.write("[", FormatterTextKind::Punctuation);
if self.d.options.space_after_memory_bracket() {
output.write(" ", FormatterTextKind::Text);
}
}
let mut need_plus = if base_reg != Register::None {
MasmFormatter::format_register_internal(&self.d, output, instruction, operand, instruction_operand, base_reg);
true
} else {
false
};
if index_reg != Register::None {
if need_plus {
if self.d.options.space_between_memory_add_operators() {
output.write(" ", FormatterTextKind::Text);
}
output.write("+", FormatterTextKind::Operator);
if self.d.options.space_between_memory_add_operators() {
output.write(" ", FormatterTextKind::Text);
}
}
need_plus = true;
if !use_scale {
MasmFormatter::format_register_internal(&self.d, output, instruction, operand, instruction_operand, index_reg);
} else if self.d.options.scale_before_index() {
output.write_number(
instruction,
operand,
instruction_operand,
SCALE_NUMBERS[scale as usize],
1u64 << scale,
NumberKind::Int32,
FormatterTextKind::Number,
);
if self.d.options.space_between_memory_mul_operators() {
output.write(" ", FormatterTextKind::Text);
}
output.write("*", FormatterTextKind::Operator);
if self.d.options.space_between_memory_mul_operators() {
output.write(" ", FormatterTextKind::Text);
}
MasmFormatter::format_register_internal(&self.d, output, instruction, operand, instruction_operand, index_reg);
} else {
MasmFormatter::format_register_internal(&self.d, output, instruction, operand, instruction_operand, index_reg);
if self.d.options.space_between_memory_mul_operators() {
output.write(" ", FormatterTextKind::Text);
}
output.write("*", FormatterTextKind::Operator);
if self.d.options.space_between_memory_mul_operators() {
output.write(" ", FormatterTextKind::Text);
}
output.write_number(
instruction,
operand,
instruction_operand,
SCALE_NUMBERS[scale as usize],
1u64 << scale,
NumberKind::Int32,
FormatterTextKind::Number,
);
}
}
if displ_in_brackets {
MasmFormatter::format_memory_displ(
&self.d,
&mut self.number_formatter,
&mut number_options,
output,
instruction,
operand,
instruction_operand,
&symbol,
abs_addr,
displ,
displ_size,
addr_size,
need_plus,
!need_plus,
);
}
if need_brackets {
if self.d.options.space_after_memory_bracket() {
output.write(" ", FormatterTextKind::Text);
}
output.write("]", FormatterTextKind::Punctuation);
}
#[cfg(feature = "mvex")]
if instruction.is_mvex_eviction_hint() {
Self::format_decorator(
&self.d.options,
output,
instruction,
operand,
instruction_operand,
&self.d.str_.mvex.eh,
DecoratorKind::EvictionHint,
);
}
}
#[allow(clippy::too_many_arguments)]
fn format_memory_displ(
d: &SelfData, number_formatter: &mut NumberFormatter, number_options: &mut NumberFormattingOptions<'_>, output: &mut dyn FormatterOutput,
instruction: &Instruction, operand: u32, instruction_operand: Option<u32>, symbol: &Option<SymbolResult<'_>>, abs_addr: u64, mut displ: i64,
mut displ_size: u32, addr_size: u32, need_plus: bool, force_displ: bool,
) {
if let &Some(ref symbol) = symbol {
if need_plus {
if d.options.space_between_memory_add_operators() {
output.write(" ", FormatterTextKind::Text);
}
if (symbol.flags & SymbolFlags::SIGNED) != 0 {
output.write("-", FormatterTextKind::Operator);
} else {
output.write("+", FormatterTextKind::Operator);
}
if d.options.space_between_memory_add_operators() {
output.write(" ", FormatterTextKind::Text);
}
} else if (symbol.flags & SymbolFlags::SIGNED) != 0 {
output.write("-", FormatterTextKind::Operator);
}
FormatterOutputMethods::write2(
output,
instruction,
operand,
instruction_operand,
&d.options,
number_formatter,
number_options,
abs_addr,
symbol,
d.options.show_symbol_address(),
false,
d.options.space_between_memory_add_operators(),
);
} else if force_displ || (displ_size != 0 && (d.options.show_zero_displacements() || displ != 0)) {
let orig_displ = displ as u64;
let is_signed;
if need_plus {
is_signed = number_options.signed_number;
if d.options.space_between_memory_add_operators() {
output.write(" ", FormatterTextKind::Text);
}
if addr_size == 8 {
if !number_options.signed_number {
output.write("+", FormatterTextKind::Operator);
} else if displ < 0 {
displ = displ.wrapping_neg();
output.write("-", FormatterTextKind::Operator);
} else {
output.write("+", FormatterTextKind::Operator);
}
if number_options.displacement_leading_zeros {
displ_size = 4;
}
} else if addr_size == 4 {
if !number_options.signed_number {
output.write("+", FormatterTextKind::Operator);
} else if (displ as i32) < 0 {
displ = (displ as i32).wrapping_neg() as u32 as i64;
output.write("-", FormatterTextKind::Operator);
} else {
output.write("+", FormatterTextKind::Operator);
}
if number_options.displacement_leading_zeros {
displ_size = 4;
}
} else {
debug_assert_eq!(addr_size, 2);
if !number_options.signed_number {
output.write("+", FormatterTextKind::Operator);
} else if (displ as i16) < 0 {
displ = (displ as i16).wrapping_neg() as u16 as i64;
output.write("-", FormatterTextKind::Operator);
} else {
output.write("+", FormatterTextKind::Operator);
}
if number_options.displacement_leading_zeros {
displ_size = 2;
}
}
if d.options.space_between_memory_add_operators() {
output.write(" ", FormatterTextKind::Text);
}
} else {
is_signed = false;
}
let (s, displ_kind) = if displ_size <= 1 && displ as u64 <= u8::MAX as u64 {
(
number_formatter.format_displ_u8(&d.options, number_options, displ as u8),
if is_signed { NumberKind::Int8 } else { NumberKind::UInt8 },
)
} else if displ_size <= 2 && displ as u64 <= u16::MAX as u64 {
(
number_formatter.format_displ_u16(&d.options, number_options, displ as u16),
if is_signed { NumberKind::Int16 } else { NumberKind::UInt16 },
)
} else if displ_size <= 4 && displ as u64 <= u32::MAX as u64 {
(
number_formatter.format_displ_u32(&d.options, number_options, displ as u32),
if is_signed { NumberKind::Int32 } else { NumberKind::UInt32 },
)
} else if displ_size <= 8 {
(
number_formatter.format_displ_u64(&d.options, number_options, displ as u64),
if is_signed { NumberKind::Int64 } else { NumberKind::UInt64 },
)
} else {
unreachable!();
};
output.write_number(instruction, operand, instruction_operand, s, orig_displ, displ_kind, FormatterTextKind::Number);
}
}
src/formatter/intel.rs (lines 498-506)
393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393
fn format_operand(&mut self, instruction: &Instruction, output: &mut dyn FormatterOutput, op_info: &InstrOpInfo<'_>, operand: u32) {
debug_assert!(operand < op_info.op_count as u32);
#[cfg(feature = "mvex")]
let mvex_rm_operand = {
if IcedConstants::is_mvex(instruction.code()) {
let op_count = instruction.op_count();
debug_assert_ne!(op_count, 0);
if instruction.op_kind(op_count.wrapping_sub(1)) == OpKind::Immediate8 {
op_count.wrapping_sub(2)
} else {
op_count.wrapping_sub(1)
}
} else {
u32::MAX
}
};
let instruction_operand = op_info.instruction_index(operand);
let flow_control;
let mut imm8;
let mut imm16;
let mut imm32;
let mut imm64;
let value64;
let imm_size;
let mut operand_options;
let number_kind;
let op_kind = op_info.op_kind(operand);
match op_kind {
InstrOpKind::Register => {
IntelFormatter::format_register_internal(&self.d, output, instruction, operand, instruction_operand, op_info.op_register(operand))
}
InstrOpKind::NearBranch16 | InstrOpKind::NearBranch32 | InstrOpKind::NearBranch64 => {
if op_kind == InstrOpKind::NearBranch64 {
imm_size = 8;
imm64 = instruction.near_branch64();
number_kind = NumberKind::UInt64;
} else if op_kind == InstrOpKind::NearBranch32 {
imm_size = 4;
imm64 = instruction.near_branch32() as u64;
number_kind = NumberKind::UInt32;
} else {
imm_size = 2;
imm64 = instruction.near_branch16() as u64;
number_kind = NumberKind::UInt16;
}
operand_options = FormatterOperandOptions::new(if self.d.options.show_branch_size() {
FormatterOperandOptionsFlags::NONE
} else {
FormatterOperandOptionsFlags::NO_BRANCH_SIZE
});
if let Some(ref symbol) = if let Some(ref mut symbol_resolver) = self.symbol_resolver {
symbol_resolver.symbol(instruction, operand, instruction_operand, imm64, imm_size)
} else {
None
} {
IntelFormatter::format_flow_control(&self.d, output, op_info.flags as u32, operand_options);
let mut number_options = NumberFormattingOptions::with_branch(&self.d.options);
if let Some(ref mut options_provider) = self.options_provider {
options_provider.operand_options(instruction, operand, instruction_operand, &mut operand_options, &mut number_options);
}
FormatterOutputMethods::write1(
output,
instruction,
operand,
instruction_operand,
&self.d.options,
&mut self.number_formatter,
&number_options,
imm64,
symbol,
self.d.options.show_symbol_address(),
);
} else {
flow_control = get_flow_control(instruction);
IntelFormatter::format_flow_control(&self.d, output, op_info.flags as u32, operand_options);
let mut number_options = NumberFormattingOptions::with_branch(&self.d.options);
if let Some(ref mut options_provider) = self.options_provider {
options_provider.operand_options(instruction, operand, instruction_operand, &mut operand_options, &mut number_options);
}
let s = if op_kind == InstrOpKind::NearBranch32 {
self.number_formatter.format_u32_zeros(
&self.d.options,
&number_options,
instruction.near_branch32(),
number_options.leading_zeros,
)
} else if op_kind == InstrOpKind::NearBranch64 {
self.number_formatter.format_u64_zeros(
&self.d.options,
&number_options,
instruction.near_branch64(),
number_options.leading_zeros,
)
} else {
self.number_formatter.format_u16_zeros(
&self.d.options,
&number_options,
instruction.near_branch16(),
number_options.leading_zeros,
)
};
output.write_number(
instruction,
operand,
instruction_operand,
s,
imm64,
number_kind,
if is_call(flow_control) { FormatterTextKind::FunctionAddress } else { FormatterTextKind::LabelAddress },
);
}
}
InstrOpKind::FarBranch16 | InstrOpKind::FarBranch32 => {
if op_kind == InstrOpKind::FarBranch32 {
imm_size = 4;
imm64 = instruction.far_branch32() as u64;
number_kind = NumberKind::UInt32;
} else {
imm_size = 2;
imm64 = instruction.far_branch16() as u64;
number_kind = NumberKind::UInt16;
}
operand_options = FormatterOperandOptions::new(if self.d.options.show_branch_size() {
FormatterOperandOptionsFlags::NONE
} else {
FormatterOperandOptionsFlags::NO_BRANCH_SIZE
});
let mut vec: Vec<SymResTextPart<'_>> = Vec::new();
if let Some(ref symbol) = if let Some(ref mut symbol_resolver) = self.symbol_resolver {
to_owned(symbol_resolver.symbol(instruction, operand, instruction_operand, imm64 as u32 as u64, imm_size), &mut vec)
} else {
None
} {
IntelFormatter::format_flow_control(&self.d, output, op_info.flags as u32, operand_options);
let mut number_options = NumberFormattingOptions::with_branch(&self.d.options);
if let Some(ref mut options_provider) = self.options_provider {
options_provider.operand_options(instruction, operand, instruction_operand, &mut operand_options, &mut number_options);
}
FormatterOutputMethods::write1(
output,
instruction,
operand,
instruction_operand,
&self.d.options,
&mut self.number_formatter,
&number_options,
imm64,
symbol,
self.d.options.show_symbol_address(),
);
output.write(",", FormatterTextKind::Punctuation);
if self.d.options.space_after_operand_separator() {
output.write(" ", FormatterTextKind::Text);
}
debug_assert!(operand + 1 == 1);
let selector_symbol = if let Some(ref mut symbol_resolver) = self.symbol_resolver {
symbol_resolver.symbol(instruction, operand + 1, instruction_operand, instruction.far_branch_selector() as u64, 2)
} else {
None
};
if let Some(ref selector_symbol) = selector_symbol {
let mut number_options = NumberFormattingOptions::with_branch(&self.d.options);
if let Some(ref mut options_provider) = self.options_provider {
options_provider.operand_options(instruction, operand, instruction_operand, &mut operand_options, &mut number_options);
}
FormatterOutputMethods::write1(
output,
instruction,
operand,
instruction_operand,
&self.d.options,
&mut self.number_formatter,
&number_options,
instruction.far_branch_selector() as u64,
selector_symbol,
self.d.options.show_symbol_address(),
);
} else {
let mut number_options = NumberFormattingOptions::with_branch(&self.d.options);
if let Some(ref mut options_provider) = self.options_provider {
options_provider.operand_options(instruction, operand, instruction_operand, &mut operand_options, &mut number_options);
}
let s = self.number_formatter.format_u16_zeros(
&self.d.options,
&number_options,
instruction.far_branch_selector(),
number_options.leading_zeros,
);
output.write_number(
instruction,
operand,
instruction_operand,
s,
instruction.far_branch_selector() as u64,
NumberKind::UInt16,
FormatterTextKind::SelectorValue,
);
}
} else {
flow_control = get_flow_control(instruction);
IntelFormatter::format_flow_control(&self.d, output, op_info.flags as u32, operand_options);
let s = if op_kind == InstrOpKind::FarBranch32 {
let mut number_options = NumberFormattingOptions::with_branch(&self.d.options);
if let Some(ref mut options_provider) = self.options_provider {
options_provider.operand_options(instruction, operand, instruction_operand, &mut operand_options, &mut number_options);
}
self.number_formatter.format_u32_zeros(
&self.d.options,
&number_options,
instruction.far_branch32(),
number_options.leading_zeros,
)
} else {
let mut number_options = NumberFormattingOptions::with_branch(&self.d.options);
if let Some(ref mut options_provider) = self.options_provider {
options_provider.operand_options(instruction, operand, instruction_operand, &mut operand_options, &mut number_options);
}
self.number_formatter.format_u16_zeros(
&self.d.options,
&number_options,
instruction.far_branch16(),
number_options.leading_zeros,
)
};
output.write_number(
instruction,
operand,
instruction_operand,
s,
imm64,
number_kind,
if is_call(flow_control) { FormatterTextKind::FunctionAddress } else { FormatterTextKind::LabelAddress },
);
output.write(",", FormatterTextKind::Punctuation);
if self.d.options.space_after_operand_separator() {
output.write(" ", FormatterTextKind::Text);
}
let mut number_options = NumberFormattingOptions::with_branch(&self.d.options);
if let Some(ref mut options_provider) = self.options_provider {
options_provider.operand_options(instruction, operand, instruction_operand, &mut operand_options, &mut number_options);
}
let s = self.number_formatter.format_u16_zeros(
&self.d.options,
&number_options,
instruction.far_branch_selector(),
number_options.leading_zeros,
);
output.write_number(
instruction,
operand,
instruction_operand,
s,
instruction.far_branch_selector() as u64,
NumberKind::UInt16,
FormatterTextKind::SelectorValue,
);
}
}
InstrOpKind::Immediate8 | InstrOpKind::Immediate8_2nd | InstrOpKind::DeclareByte => {
if op_kind == InstrOpKind::Immediate8 {
imm8 = instruction.immediate8();
} else if op_kind == InstrOpKind::Immediate8_2nd {
imm8 = instruction.immediate8_2nd();
} else {
imm8 = instruction.get_declare_byte_value(operand as usize);
}
operand_options = FormatterOperandOptions::default();
if let Some(ref symbol) = if let Some(ref mut symbol_resolver) = self.symbol_resolver {
symbol_resolver.symbol(instruction, operand, instruction_operand, imm8 as u64, 1)
} else {
None
} {
let mut number_options = NumberFormattingOptions::with_immediate(&self.d.options);
if let Some(ref mut options_provider) = self.options_provider {
options_provider.operand_options(instruction, operand, instruction_operand, &mut operand_options, &mut number_options);
}
FormatterOutputMethods::write1(
output,
instruction,
operand,
instruction_operand,
&self.d.options,
&mut self.number_formatter,
&number_options,
imm8 as u64,
symbol,
self.d.options.show_symbol_address(),
);
} else {
let mut number_options = NumberFormattingOptions::with_immediate(&self.d.options);
if let Some(ref mut options_provider) = self.options_provider {
options_provider.operand_options(instruction, operand, instruction_operand, &mut operand_options, &mut number_options);
}
if number_options.signed_number {
imm64 = imm8 as i8 as u64;
number_kind = NumberKind::Int8;
if (imm8 as i8) < 0 {
output.write("-", FormatterTextKind::Operator);
imm8 = (imm8 as i8).wrapping_neg() as u8;
}
} else {
imm64 = imm8 as u64;
number_kind = NumberKind::UInt8;
}
let s = self.number_formatter.format_u8(&self.d.options, &number_options, imm8);
output.write_number(instruction, operand, instruction_operand, s, imm64, number_kind, FormatterTextKind::Number);
}
}
InstrOpKind::Immediate16 | InstrOpKind::Immediate8to16 | InstrOpKind::DeclareWord => {
if op_kind == InstrOpKind::Immediate16 {
imm16 = instruction.immediate16();
} else if op_kind == InstrOpKind::Immediate8to16 {
imm16 = instruction.immediate8to16() as u16;
} else {
imm16 = instruction.get_declare_word_value(operand as usize);
}
operand_options = FormatterOperandOptions::default();
if let Some(ref symbol) = if let Some(ref mut symbol_resolver) = self.symbol_resolver {
symbol_resolver.symbol(instruction, operand, instruction_operand, imm16 as u64, 2)
} else {
None
} {
let mut number_options = NumberFormattingOptions::with_immediate(&self.d.options);
if let Some(ref mut options_provider) = self.options_provider {
options_provider.operand_options(instruction, operand, instruction_operand, &mut operand_options, &mut number_options);
}
FormatterOutputMethods::write1(
output,
instruction,
operand,
instruction_operand,
&self.d.options,
&mut self.number_formatter,
&number_options,
imm16 as u64,
symbol,
self.d.options.show_symbol_address(),
);
} else {
let mut number_options = NumberFormattingOptions::with_immediate(&self.d.options);
if let Some(ref mut options_provider) = self.options_provider {
options_provider.operand_options(instruction, operand, instruction_operand, &mut operand_options, &mut number_options);
}
if number_options.signed_number {
imm64 = imm16 as i16 as u64;
number_kind = NumberKind::Int16;
if (imm16 as i16) < 0 {
output.write("-", FormatterTextKind::Operator);
imm16 = (imm16 as i16).wrapping_neg() as u16;
}
} else {
imm64 = imm16 as u64;
number_kind = NumberKind::UInt16;
}
let s = self.number_formatter.format_u16(&self.d.options, &number_options, imm16);
output.write_number(instruction, operand, instruction_operand, s, imm64, number_kind, FormatterTextKind::Number);
}
}
InstrOpKind::Immediate32 | InstrOpKind::Immediate8to32 | InstrOpKind::DeclareDword => {
if op_kind == InstrOpKind::Immediate32 {
imm32 = instruction.immediate32();
} else if op_kind == InstrOpKind::Immediate8to32 {
imm32 = instruction.immediate8to32() as u32;
} else {
imm32 = instruction.get_declare_dword_value(operand as usize);
}
operand_options = FormatterOperandOptions::default();
if let Some(ref symbol) = if let Some(ref mut symbol_resolver) = self.symbol_resolver {
symbol_resolver.symbol(instruction, operand, instruction_operand, imm32 as u64, 4)
} else {
None
} {
let mut number_options = NumberFormattingOptions::with_immediate(&self.d.options);
if let Some(ref mut options_provider) = self.options_provider {
options_provider.operand_options(instruction, operand, instruction_operand, &mut operand_options, &mut number_options);
}
FormatterOutputMethods::write1(
output,
instruction,
operand,
instruction_operand,
&self.d.options,
&mut self.number_formatter,
&number_options,
imm32 as u64,
symbol,
self.d.options.show_symbol_address(),
);
} else {
let mut number_options = NumberFormattingOptions::with_immediate(&self.d.options);
if let Some(ref mut options_provider) = self.options_provider {
options_provider.operand_options(instruction, operand, instruction_operand, &mut operand_options, &mut number_options);
}
if number_options.signed_number {
imm64 = imm32 as i32 as u64;
number_kind = NumberKind::Int32;
if (imm32 as i32) < 0 {
output.write("-", FormatterTextKind::Operator);
imm32 = (imm32 as i32).wrapping_neg() as u32;
}
} else {
imm64 = imm32 as u64;
number_kind = NumberKind::UInt32;
}
let s = self.number_formatter.format_u32(&self.d.options, &number_options, imm32);
output.write_number(instruction, operand, instruction_operand, s, imm64, number_kind, FormatterTextKind::Number);
}
}
InstrOpKind::Immediate64 | InstrOpKind::Immediate8to64 | InstrOpKind::Immediate32to64 | InstrOpKind::DeclareQword => {
if op_kind == InstrOpKind::Immediate32to64 {
imm64 = instruction.immediate32to64() as u64;
} else if op_kind == InstrOpKind::Immediate8to64 {
imm64 = instruction.immediate8to64() as u64;
} else if op_kind == InstrOpKind::Immediate64 {
imm64 = instruction.immediate64();
} else {
imm64 = instruction.get_declare_qword_value(operand as usize);
}
operand_options = FormatterOperandOptions::default();
if let Some(ref symbol) = if let Some(ref mut symbol_resolver) = self.symbol_resolver {
symbol_resolver.symbol(instruction, operand, instruction_operand, imm64, 8)
} else {
None
} {
let mut number_options = NumberFormattingOptions::with_immediate(&self.d.options);
if let Some(ref mut options_provider) = self.options_provider {
options_provider.operand_options(instruction, operand, instruction_operand, &mut operand_options, &mut number_options);
}
FormatterOutputMethods::write1(
output,
instruction,
operand,
instruction_operand,
&self.d.options,
&mut self.number_formatter,
&number_options,
imm64,
symbol,
self.d.options.show_symbol_address(),
);
} else {
value64 = imm64;
let mut number_options = NumberFormattingOptions::with_immediate(&self.d.options);
if let Some(ref mut options_provider) = self.options_provider {
options_provider.operand_options(instruction, operand, instruction_operand, &mut operand_options, &mut number_options);
}
if number_options.signed_number {
number_kind = NumberKind::Int64;
if (imm64 as i64) < 0 {
output.write("-", FormatterTextKind::Operator);
imm64 = (imm64 as i64).wrapping_neg() as u64;
}
} else {
number_kind = NumberKind::UInt64;
}
let s = self.number_formatter.format_u64(&self.d.options, &number_options, imm64);
output.write_number(instruction, operand, instruction_operand, s, value64, number_kind, FormatterTextKind::Number);
}
}
InstrOpKind::MemorySegSI => self.format_memory(
output,
instruction,
operand,
instruction_operand,
instruction.memory_segment(),
Register::SI,
Register::None,
0,
0,
0,
2,
op_info.flags as u32,
),
InstrOpKind::MemorySegESI => self.format_memory(
output,
instruction,
operand,
instruction_operand,
instruction.memory_segment(),
Register::ESI,
Register::None,
0,
0,
0,
4,
op_info.flags as u32,
),
InstrOpKind::MemorySegRSI => self.format_memory(
output,
instruction,
operand,
instruction_operand,
instruction.memory_segment(),
Register::RSI,
Register::None,
0,
0,
0,
8,
op_info.flags as u32,
),
InstrOpKind::MemorySegDI => self.format_memory(
output,
instruction,
operand,
instruction_operand,
instruction.memory_segment(),
Register::DI,
Register::None,
0,
0,
0,
2,
op_info.flags as u32,
),
InstrOpKind::MemorySegEDI => self.format_memory(
output,
instruction,
operand,
instruction_operand,
instruction.memory_segment(),
Register::EDI,
Register::None,
0,
0,
0,
4,
op_info.flags as u32,
),
InstrOpKind::MemorySegRDI => self.format_memory(
output,
instruction,
operand,
instruction_operand,
instruction.memory_segment(),
Register::RDI,
Register::None,
0,
0,
0,
8,
op_info.flags as u32,
),
InstrOpKind::MemoryESDI => self.format_memory(
output,
instruction,
operand,
instruction_operand,
Register::ES,
Register::DI,
Register::None,
0,
0,
0,
2,
op_info.flags as u32,
),
InstrOpKind::MemoryESEDI => self.format_memory(
output,
instruction,
operand,
instruction_operand,
Register::ES,
Register::EDI,
Register::None,
0,
0,
0,
4,
op_info.flags as u32,
),
InstrOpKind::MemoryESRDI => self.format_memory(
output,
instruction,
operand,
instruction_operand,
Register::ES,
Register::RDI,
Register::None,
0,
0,
0,
8,
op_info.flags as u32,
),
InstrOpKind::Memory => {
let displ_size = instruction.memory_displ_size();
let base_reg = instruction.memory_base();
let mut index_reg = instruction.memory_index();
let addr_size = get_address_size_in_bytes(base_reg, index_reg, displ_size, instruction.code_size());
let displ = if addr_size == 8 { instruction.memory_displacement64() as i64 } else { instruction.memory_displacement32() as i64 };
if (op_info.flags & InstrOpInfoFlags::IGNORE_INDEX_REG as u16) != 0 {
index_reg = Register::None;
}
self.format_memory(
output,
instruction,
operand,
instruction_operand,
instruction.memory_segment(),
base_reg,
index_reg,
instruction_internal::internal_get_memory_index_scale(instruction),
displ_size,
displ,
addr_size,
op_info.flags as u32,
);
}
}
if operand == 0 && instruction_internal::internal_has_op_mask_or_zeroing_masking(instruction) {
if instruction.has_op_mask() && (op_info.flags & InstrOpInfoFlags::IGNORE_OP_MASK as u16) == 0 {
output.write("{", FormatterTextKind::Punctuation);
IntelFormatter::format_register_internal(&self.d, output, instruction, operand, instruction_operand, instruction.op_mask());
output.write("}", FormatterTextKind::Punctuation);
}
if instruction.zeroing_masking() {
IntelFormatter::format_decorator(
&self.d.options,
output,
instruction,
operand,
instruction_operand,
&self.d.str_.z,
DecoratorKind::ZeroingMasking,
);
}
}
if operand == 0 && instruction_internal::internal_has_rounding_control_or_sae(instruction) {
let rc = instruction.rounding_control();
if rc != RoundingControl::None && can_show_rounding_control(instruction, &self.d.options) {
let dec_str = if IcedConstants::is_mvex(instruction.code()) {
if instruction.suppress_all_exceptions() {
self.d.vec_.intel_rc_sae_strings[rc as usize]
} else {
self.d.vec_.intel_rc_strings[rc as usize]
}
} else {
self.d.vec_.intel_rc_sae_strings[rc as usize]
};
IntelFormatter::format_decorator(
&self.d.options,
output,
instruction,
operand,
instruction_operand,
dec_str,
DecoratorKind::RoundingControl,
);
} else if instruction.suppress_all_exceptions() {
IntelFormatter::format_decorator(
&self.d.options,
output,
instruction,
operand,
instruction_operand,
&self.d.str_.sae,
DecoratorKind::SuppressAllExceptions,
);
}
}
#[cfg(feature = "mvex")]
if mvex_rm_operand == operand {
let conv = instruction.mvex_reg_mem_conv();
if conv != MvexRegMemConv::None {
let mvex = crate::mvex::get_mvex_info(instruction.code());
if mvex.conv_fn != MvexConvFn::None {
let tbl = if mvex.is_conv_fn_32() { &self.d.vec_.mvex_reg_mem_consts_32 } else { &self.d.vec_.mvex_reg_mem_consts_64 };
let s = tbl[conv as usize];
if s.len() != 0 {
Self::format_decorator(&self.d.options, output, instruction, operand, instruction_operand, s, DecoratorKind::SwizzleMemConv);
}
}
}
}
}
fn format_flow_control(d: &SelfData, output: &mut dyn FormatterOutput, flags: u32, operand_options: FormatterOperandOptions) {
if !operand_options.branch_size() {
return;
}
let keywords = &d.vec_.intel_branch_infos
[((flags as usize) >> InstrOpInfoFlags::BRANCH_SIZE_INFO_SHIFT) & InstrOpInfoFlags::BRANCH_SIZE_INFO_MASK as usize];
for &keyword in keywords {
IntelFormatter::format_keyword(&d.options, output, keyword);
output.write(" ", FormatterTextKind::Text);
}
}
fn format_decorator(
options: &FormatterOptions, output: &mut dyn FormatterOutput, instruction: &Instruction, operand: u32, instruction_operand: Option<u32>,
text: &FormatterString, decorator: DecoratorKind,
) {
output.write("{", FormatterTextKind::Punctuation);
output.write_decorator(
instruction,
operand,
instruction_operand,
text.get(options.uppercase_decorators() || options.uppercase_all()),
decorator,
);
output.write("}", FormatterTextKind::Punctuation);
}
#[inline]
fn get_reg_str(d: &SelfData, mut reg: Register) -> &'static str {
if d.options.prefer_st0() && reg == REGISTER_ST {
reg = Register::ST0;
}
let reg_str = &d.all_registers[reg as usize];
reg_str.get(d.options.uppercase_registers() || d.options.uppercase_all())
}
#[inline]
fn format_register_internal(
d: &SelfData, output: &mut dyn FormatterOutput, instruction: &Instruction, operand: u32, instruction_operand: Option<u32>, reg: Register,
) {
output.write_register(instruction, operand, instruction_operand, IntelFormatter::get_reg_str(d, reg), reg);
}
#[allow(clippy::too_many_arguments)]
fn format_memory(
&mut self, output: &mut dyn FormatterOutput, instruction: &Instruction, operand: u32, instruction_operand: Option<u32>, seg_reg: Register,
mut base_reg: Register, index_reg: Register, scale: u32, mut displ_size: u32, mut displ: i64, addr_size: u32, flags: u32,
) {
debug_assert!((scale as usize) < SCALE_NUMBERS.len());
debug_assert!(get_address_size_in_bytes(base_reg, index_reg, displ_size, instruction.code_size()) == addr_size);
let mut operand_options = FormatterOperandOptions::with_memory_size_options(self.d.options.memory_size_options());
operand_options.set_rip_relative_addresses(self.d.options.rip_relative_addresses());
let mut number_options = NumberFormattingOptions::with_displacement(&self.d.options);
if let Some(ref mut options_provider) = self.options_provider {
options_provider.operand_options(instruction, operand, instruction_operand, &mut operand_options, &mut number_options);
}
let abs_addr;
if base_reg == Register::RIP {
abs_addr = displ as u64;
if self.d.options.rip_relative_addresses() {
displ = displ.wrapping_sub(instruction.next_ip() as i64);
} else {
debug_assert_eq!(index_reg, Register::None);
base_reg = Register::None;
}
displ_size = 8;
} else if base_reg == Register::EIP {
abs_addr = displ as u32 as u64;
if self.d.options.rip_relative_addresses() {
displ = (displ as u32).wrapping_sub(instruction.next_ip32()) as i32 as i64;
} else {
debug_assert_eq!(index_reg, Register::None);
base_reg = Register::None;
}
displ_size = 4;
} else {
abs_addr = displ as u64;
}
let symbol = if let Some(ref mut symbol_resolver) = self.symbol_resolver {
symbol_resolver.symbol(instruction, operand, instruction_operand, abs_addr, addr_size)
} else {
None
};
let mut use_scale = scale != 0 || self.d.options.always_show_scale();
if !use_scale {
// [rsi] = base reg, [rsi*1] = index reg
if base_reg == Register::None {
use_scale = true;
}
}
if addr_size == 2 || !show_index_scale(instruction, &self.d.options) {
use_scale = false;
}
IntelFormatter::format_memory_size(&self.d, output, &symbol, instruction.memory_size(), flags, operand_options);
let code_size = instruction.code_size();
let seg_override = instruction.segment_prefix();
let notrack_prefix = seg_override == Register::DS
&& is_notrack_prefix_branch(instruction.code())
&& !((code_size == CodeSize::Code16 || code_size == CodeSize::Code32)
&& (base_reg == Register::BP || base_reg == Register::EBP || base_reg == Register::ESP));
if self.d.options.always_show_segment_register()
|| (seg_override != Register::None && !notrack_prefix && show_segment_prefix(Register::None, instruction, &self.d.options))
{
IntelFormatter::format_register_internal(&self.d, output, instruction, operand, instruction_operand, seg_reg);
output.write(":", FormatterTextKind::Punctuation);
}
output.write("[", FormatterTextKind::Punctuation);
if self.d.options.space_after_memory_bracket() {
output.write(" ", FormatterTextKind::Text);
}
let mut need_plus = if base_reg != Register::None {
IntelFormatter::format_register_internal(&self.d, output, instruction, operand, instruction_operand, base_reg);
true
} else {
false
};
if index_reg != Register::None {
if need_plus {
if self.d.options.space_between_memory_add_operators() {
output.write(" ", FormatterTextKind::Text);
}
output.write("+", FormatterTextKind::Operator);
if self.d.options.space_between_memory_add_operators() {
output.write(" ", FormatterTextKind::Text);
}
}
need_plus = true;
if !use_scale {
IntelFormatter::format_register_internal(&self.d, output, instruction, operand, instruction_operand, index_reg);
} else if self.d.options.scale_before_index() {
output.write_number(
instruction,
operand,
instruction_operand,
SCALE_NUMBERS[scale as usize],
1u64 << scale,
NumberKind::Int32,
FormatterTextKind::Number,
);
if self.d.options.space_between_memory_mul_operators() {
output.write(" ", FormatterTextKind::Text);
}
output.write("*", FormatterTextKind::Operator);
if self.d.options.space_between_memory_mul_operators() {
output.write(" ", FormatterTextKind::Text);
}
IntelFormatter::format_register_internal(&self.d, output, instruction, operand, instruction_operand, index_reg);
} else {
IntelFormatter::format_register_internal(&self.d, output, instruction, operand, instruction_operand, index_reg);
if self.d.options.space_between_memory_mul_operators() {
output.write(" ", FormatterTextKind::Text);
}
output.write("*", FormatterTextKind::Operator);
if self.d.options.space_between_memory_mul_operators() {
output.write(" ", FormatterTextKind::Text);
}
output.write_number(
instruction,
operand,
instruction_operand,
SCALE_NUMBERS[scale as usize],
1u64 << scale,
NumberKind::Int32,
FormatterTextKind::Number,
);
}
}
if let Some(ref symbol) = symbol {
if need_plus {
if self.d.options.space_between_memory_add_operators() {
output.write(" ", FormatterTextKind::Text);
}
if (symbol.flags & SymbolFlags::SIGNED) != 0 {
output.write("-", FormatterTextKind::Operator);
} else {
output.write("+", FormatterTextKind::Operator);
}
if self.d.options.space_between_memory_add_operators() {
output.write(" ", FormatterTextKind::Text);
}
} else if (symbol.flags & SymbolFlags::SIGNED) != 0 {
output.write("-", FormatterTextKind::Operator);
}
FormatterOutputMethods::write2(
output,
instruction,
operand,
instruction_operand,
&self.d.options,
&mut self.number_formatter,
&number_options,
abs_addr,
symbol,
self.d.options.show_symbol_address(),
false,
self.d.options.space_between_memory_add_operators(),
);
} else if !need_plus || (displ_size != 0 && (self.d.options.show_zero_displacements() || displ != 0)) {
let orig_displ = displ as u64;
let is_signed;
if need_plus {
is_signed = number_options.signed_number;
if self.d.options.space_between_memory_add_operators() {
output.write(" ", FormatterTextKind::Text);
}
if addr_size == 8 {
if !number_options.signed_number {
output.write("+", FormatterTextKind::Operator);
} else if displ < 0 {
displ = displ.wrapping_neg();
output.write("-", FormatterTextKind::Operator);
} else {
output.write("+", FormatterTextKind::Operator);
}
if number_options.displacement_leading_zeros {
displ_size = 4;
}
} else if addr_size == 4 {
if !number_options.signed_number {
output.write("+", FormatterTextKind::Operator);
} else if (displ as i32) < 0 {
displ = (displ as i32).wrapping_neg() as u32 as i64;
output.write("-", FormatterTextKind::Operator);
} else {
output.write("+", FormatterTextKind::Operator);
}
if number_options.displacement_leading_zeros {
displ_size = 4;
}
} else {
debug_assert_eq!(addr_size, 2);
if !number_options.signed_number {
output.write("+", FormatterTextKind::Operator);
} else if (displ as i16) < 0 {
displ = (displ as i16).wrapping_neg() as u16 as i64;
output.write("-", FormatterTextKind::Operator);
} else {
output.write("+", FormatterTextKind::Operator);
}
if number_options.displacement_leading_zeros {
displ_size = 2;
}
}
if self.d.options.space_between_memory_add_operators() {
output.write(" ", FormatterTextKind::Text);
}
} else {
is_signed = false;
}
let (s, displ_kind) = if displ_size <= 1 && displ as u64 <= u8::MAX as u64 {
(
self.number_formatter.format_displ_u8(&self.d.options, &number_options, displ as u8),
if is_signed { NumberKind::Int8 } else { NumberKind::UInt8 },
)
} else if displ_size <= 2 && displ as u64 <= u16::MAX as u64 {
(
self.number_formatter.format_displ_u16(&self.d.options, &number_options, displ as u16),
if is_signed { NumberKind::Int16 } else { NumberKind::UInt16 },
)
} else if displ_size <= 4 && displ as u64 <= u32::MAX as u64 {
(
self.number_formatter.format_displ_u32(&self.d.options, &number_options, displ as u32),
if is_signed { NumberKind::Int32 } else { NumberKind::UInt32 },
)
} else if displ_size <= 8 {
(
self.number_formatter.format_displ_u64(&self.d.options, &number_options, displ as u64),
if is_signed { NumberKind::Int64 } else { NumberKind::UInt64 },
)
} else {
unreachable!();
};
output.write_number(instruction, operand, instruction_operand, s, orig_displ, displ_kind, FormatterTextKind::Number);
}
if self.d.options.space_after_memory_bracket() {
output.write(" ", FormatterTextKind::Text);
}
output.write("]", FormatterTextKind::Punctuation);
let mem_size = instruction.memory_size();
debug_assert!((mem_size as usize) < self.d.all_memory_sizes.len());
let bcst_to = &self.d.all_memory_sizes[mem_size as usize].bcst_to;
if !bcst_to.is_default() {
IntelFormatter::format_decorator(&self.d.options, output, instruction, operand, instruction_operand, bcst_to, DecoratorKind::Broadcast);
}
#[cfg(feature = "mvex")]
if instruction.is_mvex_eviction_hint() {
Self::format_decorator(
&self.d.options,
output,
instruction,
operand,
instruction_operand,
&self.d.str_.mvex.eh,
DecoratorKind::EvictionHint,
);
}
}
sourcefn write_decorator(
&mut self,
instruction: &Instruction,
operand: u32,
instruction_operand: Option<u32>,
text: &str,
decorator: DecoratorKind
)
fn write_decorator(
&mut self,
instruction: &Instruction,
operand: u32,
instruction_operand: Option<u32>,
text: &str,
decorator: DecoratorKind
)
Writes a decorator
Arguments
instruction
: Instructionoperand
: Operand number, 0-based. This is a formatter operand and isn’t necessarily the same as an instruction operand.instruction_operand
: Instruction operand number, 0-based, orNone
if it’s an operand created by the formatter.text
: Decorator textdecorator
: Decorator
Examples found in repository?
src/formatter/gas.rs (lines 1095-1101)
1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103
fn format_decorator(
options: &FormatterOptions, output: &mut dyn FormatterOutput, instruction: &Instruction, operand: u32, instruction_operand: Option<u32>,
text: &FormatterString, decorator: DecoratorKind,
) {
output.write("{", FormatterTextKind::Punctuation);
output.write_decorator(
instruction,
operand,
instruction_operand,
text.get(options.uppercase_decorators() || options.uppercase_all()),
decorator,
);
output.write("}", FormatterTextKind::Punctuation);
}
More examples
src/formatter/intel.rs (lines 1099-1105)
1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107
fn format_decorator(
options: &FormatterOptions, output: &mut dyn FormatterOutput, instruction: &Instruction, operand: u32, instruction_operand: Option<u32>,
text: &FormatterString, decorator: DecoratorKind,
) {
output.write("{", FormatterTextKind::Punctuation);
output.write_decorator(
instruction,
operand,
instruction_operand,
text.get(options.uppercase_decorators() || options.uppercase_all()),
decorator,
);
output.write("}", FormatterTextKind::Punctuation);
}
src/formatter/masm.rs (lines 1057-1063)
1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065
fn format_decorator(
options: &FormatterOptions, output: &mut dyn FormatterOutput, instruction: &Instruction, operand: u32, instruction_operand: Option<u32>,
text: &FormatterString, decorator: DecoratorKind,
) {
output.write("{", FormatterTextKind::Punctuation);
output.write_decorator(
instruction,
operand,
instruction_operand,
text.get(options.uppercase_decorators() || options.uppercase_all()),
decorator,
);
output.write("}", FormatterTextKind::Punctuation);
}
src/formatter/nasm.rs (lines 1147-1153)
1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155
fn format_decorator(
options: &FormatterOptions, output: &mut dyn FormatterOutput, instruction: &Instruction, operand: u32, instruction_operand: Option<u32>,
text: &FormatterString, decorator: DecoratorKind,
) {
output.write("{", FormatterTextKind::Punctuation);
output.write_decorator(
instruction,
operand,
instruction_operand,
text.get(options.uppercase_decorators() || options.uppercase_all()),
decorator,
);
output.write("}", FormatterTextKind::Punctuation);
}
sourcefn write_register(
&mut self,
instruction: &Instruction,
operand: u32,
instruction_operand: Option<u32>,
text: &str,
register: Register
)
fn write_register(
&mut self,
instruction: &Instruction,
operand: u32,
instruction_operand: Option<u32>,
text: &str,
register: Register
)
Writes a register
Arguments
instruction
: Instructionoperand
: Operand number, 0-based. This is a formatter operand and isn’t necessarily the same as an instruction operand.instruction_operand
: Instruction operand number, 0-based, orNone
if it’s an operand created by the formatter.text
: Register textregister
: Register
Examples found in repository?
More examples
sourcefn write_symbol(
&mut self,
instruction: &Instruction,
operand: u32,
instruction_operand: Option<u32>,
address: u64,
symbol: &SymbolResult<'_>
)
fn write_symbol(
&mut self,
instruction: &Instruction,
operand: u32,
instruction_operand: Option<u32>,
address: u64,
symbol: &SymbolResult<'_>
)
Writes a symbol
Arguments
instruction
: Instructionoperand
: Operand number, 0-based. This is a formatter operand and isn’t necessarily the same as an instruction operand.instruction_operand
: Instruction operand number, 0-based, orNone
if it’s an operand created by the formatter.address
: Addresssymbol
: Symbol
Examples found in repository?
src/formatter/mod.rs (line 310)
298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363
fn write2(
output: &mut dyn FormatterOutput, instruction: &Instruction, operand: u32, instruction_operand: Option<u32>, options: &FormatterOptions,
number_formatter: &mut NumberFormatter, number_options: &NumberFormattingOptions<'_>, address: u64, symbol: &SymbolResult<'_>,
show_symbol_address: bool, write_minus_if_signed: bool, spaces_between_op: bool,
) {
let mut displ = address.wrapping_sub(symbol.address) as i64;
if (symbol.flags & SymbolFlags::SIGNED) != 0 {
if write_minus_if_signed {
output.write("-", FormatterTextKind::Operator);
}
displ = displ.wrapping_neg();
}
output.write_symbol(instruction, operand, instruction_operand, address, symbol);
let mut number_kind: NumberKind;
if displ != 0 {
if spaces_between_op {
output.write(" ", FormatterTextKind::Text);
}
let orig_displ = displ as u64;
if displ < 0 {
output.write("-", FormatterTextKind::Operator);
displ = displ.wrapping_neg();
if displ <= i8::MAX as i64 + 1 {
number_kind = NumberKind::Int8;
} else if displ <= i16::MAX as i64 + 1 {
number_kind = NumberKind::Int16;
} else if displ <= i32::MAX as i64 + 1 {
number_kind = NumberKind::Int32;
} else {
number_kind = NumberKind::Int64;
}
} else {
output.write("+", FormatterTextKind::Operator);
if displ <= i8::MAX as i64 {
number_kind = NumberKind::Int8;
} else if displ <= i16::MAX as i64 {
number_kind = NumberKind::Int16;
} else if displ <= i32::MAX as i64 {
number_kind = NumberKind::Int32;
} else {
number_kind = NumberKind::Int64;
}
}
if spaces_between_op {
output.write(" ", FormatterTextKind::Text);
}
let s = number_formatter.format_u64_zeros(options, number_options, displ as u64, false);
output.write_number(instruction, operand, instruction_operand, s, orig_displ, number_kind, FormatterTextKind::Number);
}
if show_symbol_address {
output.write(" ", FormatterTextKind::Text);
output.write("(", FormatterTextKind::Punctuation);
let s = if address <= u16::MAX as u64 {
number_kind = NumberKind::UInt16;
number_formatter.format_u16_zeros(options, number_options, address as u16, true)
} else if address <= u32::MAX as u64 {
number_kind = NumberKind::UInt32;
number_formatter.format_u32_zeros(options, number_options, address as u32, true)
} else {
number_kind = NumberKind::UInt64;
number_formatter.format_u64_zeros(options, number_options, address, true)
};
output.write_number(instruction, operand, instruction_operand, s, address, number_kind, FormatterTextKind::Number);
output.write(")", FormatterTextKind::Punctuation);
}
}