@@ -394,17 +394,34 @@ unsafe impl CoreArrayProviderInner for Array<InstructionTextToken> {
394394pub enum InstructionTextTokenKind {
395395 Text ,
396396 Instruction ,
397+ /// Separator between operands, such as `,` or `+`.
398+ ///
399+ /// This is primarily used to identify the tokens associated with a given operand.
397400 OperandSeparator ,
398401 Register ,
399402 Integer {
400403 value : u64 ,
401404 /// Size of the integer
402405 size : Option < usize > ,
406+ /// The operand this integer is associated with.
407+ ///
408+ /// This is primarily used to change the display type of the integer.
409+ ///
410+ /// NOTE: This will be populated by a post-processing step when rendering, so you can leave this
411+ /// as `None` when emitting in [`Architecture::instruction_text`] and other similar methods.
412+ operand : Option < usize > ,
403413 } ,
404414 PossibleAddress {
405415 value : u64 ,
406416 /// Size of the address
407417 size : Option < usize > ,
418+ /// The operand this integer is associated with.
419+ ///
420+ /// This is primarily used to change the display type of the integer.
421+ ///
422+ /// NOTE: This will be populated by a post-processing step when rendering, so you can leave this
423+ /// as `None` when emitting in [`Architecture::instruction_text`] and other similar methods.
424+ operand : Option < usize > ,
408425 } ,
409426 BeginMemoryOperand ,
410427 EndMemoryOperand ,
@@ -416,7 +433,15 @@ pub enum InstructionTextTokenKind {
416433 Annotation ,
417434 CodeRelativeAddress {
418435 value : u64 ,
436+ /// Size of the address
419437 size : Option < usize > ,
438+ /// The operand this integer is associated with.
439+ ///
440+ /// This is primarily used to change the display type of the integer.
441+ ///
442+ /// NOTE: This will be populated by a post-processing step when rendering, so you can leave this
443+ /// as `None` when emitting in [`Architecture::instruction_text`] and other similar methods.
444+ operand : Option < usize > ,
420445 } ,
421446 ArgumentName {
422447 // TODO: The argument index?
@@ -443,7 +468,15 @@ pub enum InstructionTextTokenKind {
443468 StringContent {
444469 ty : StringType ,
445470 } ,
446- CharacterConstant ,
471+ CharacterConstant {
472+ /// The operand this character is associated with.
473+ ///
474+ /// This is primarily used to change the display type of the character.
475+ ///
476+ /// NOTE: This will be populated by a post-processing step when rendering, so you can leave this
477+ /// as `None` when emitting in [`Architecture::instruction_text`] and other similar methods.
478+ operand : Option < usize > ,
479+ } ,
447480 Keyword {
448481 // Example usage can be found for `BNAnalysisWarningActionType`.
449482 value : u64 ,
@@ -579,13 +612,15 @@ impl InstructionTextTokenKind {
579612 0 => None ,
580613 size => Some ( size) ,
581614 } ,
615+ operand : Some ( value. operand ) ,
582616 } ,
583617 BNInstructionTextTokenType :: PossibleAddressToken => Self :: PossibleAddress {
584618 value : value. value ,
585619 size : match value. size {
586620 0 => None ,
587621 size => Some ( size) ,
588622 } ,
623+ operand : Some ( value. operand ) ,
589624 } ,
590625 BNInstructionTextTokenType :: BeginMemoryOperandToken => Self :: BeginMemoryOperand ,
591626 BNInstructionTextTokenType :: EndMemoryOperandToken => Self :: EndMemoryOperand ,
@@ -603,6 +638,7 @@ impl InstructionTextTokenKind {
603638 0 => None ,
604639 size => Some ( size) ,
605640 } ,
641+ operand : Some ( value. operand ) ,
606642 } ,
607643 BNInstructionTextTokenType :: ArgumentNameToken => {
608644 Self :: ArgumentName { value : value. value }
@@ -640,7 +676,9 @@ impl InstructionTextTokenKind {
640676 }
641677 _ => Self :: String { value : value. value } ,
642678 } ,
643- BNInstructionTextTokenType :: CharacterConstantToken => Self :: CharacterConstant ,
679+ BNInstructionTextTokenType :: CharacterConstantToken => Self :: CharacterConstant {
680+ operand : Some ( value. operand ) ,
681+ } ,
644682 BNInstructionTextTokenType :: KeywordToken => Self :: Keyword { value : value. value } ,
645683 BNInstructionTextTokenType :: TypeNameToken => Self :: TypeName ,
646684 BNInstructionTextTokenType :: FieldNameToken => Self :: FieldName {
@@ -799,6 +837,10 @@ impl InstructionTextTokenKind {
799837 /// Mapping to the [`BNInstructionTextTokenType::operand`] field.
800838 fn try_operand ( & self ) -> Option < usize > {
801839 match self {
840+ InstructionTextTokenKind :: Integer { operand, .. } => * operand,
841+ InstructionTextTokenKind :: PossibleAddress { operand, .. } => * operand,
842+ InstructionTextTokenKind :: CodeRelativeAddress { operand, .. } => * operand,
843+ InstructionTextTokenKind :: CharacterConstant { operand, .. } => * operand,
802844 InstructionTextTokenKind :: LocalVariable { ssa_version, .. } => Some ( * ssa_version) ,
803845 InstructionTextTokenKind :: IndirectImport { source_operand, .. } => {
804846 Some ( * source_operand)
@@ -866,7 +908,7 @@ impl From<InstructionTextTokenKind> for BNInstructionTextTokenType {
866908 InstructionTextTokenKind :: StringContent { .. } => {
867909 BNInstructionTextTokenType :: StringToken
868910 }
869- InstructionTextTokenKind :: CharacterConstant => {
911+ InstructionTextTokenKind :: CharacterConstant { .. } => {
870912 BNInstructionTextTokenType :: CharacterConstantToken
871913 }
872914 InstructionTextTokenKind :: Keyword { .. } => BNInstructionTextTokenType :: KeywordToken ,
0 commit comments