@@ -12,6 +12,7 @@ enum CastMatcherKind {
1212 FPToUI ,
1313 FPToSI ,
1414 FPTrunc ,
15+ Ext ,
1516 FPExt ,
1617 ZExt ,
1718 SExt ,
@@ -20,19 +21,22 @@ enum CastMatcherKind {
2021}
2122
2223impl CastMatcherKind {
23- pub fn llvm_opcode ( & self ) -> LLVMOpcode {
24- match self {
25- CastMatcherKind :: Trunc => LLVMOpcode :: LLVMTrunc ,
26- CastMatcherKind :: FPToUI => LLVMOpcode :: LLVMFPToUI ,
27- CastMatcherKind :: FPToSI => LLVMOpcode :: LLVMFPToSI ,
28- CastMatcherKind :: FPTrunc => LLVMOpcode :: LLVMFPTrunc ,
29- CastMatcherKind :: FPExt => LLVMOpcode :: LLVMFPExt ,
30- CastMatcherKind :: IntToPtr => LLVMOpcode :: LLVMIntToPtr ,
31- CastMatcherKind :: PtrToInt => LLVMOpcode :: LLVMPtrToInt ,
32- CastMatcherKind :: ZExt => LLVMOpcode :: LLVMZExt ,
33- CastMatcherKind :: SExt => LLVMOpcode :: LLVMSExt ,
34- CastMatcherKind :: BitCast => LLVMOpcode :: LLVMBitCast ,
35- CastMatcherKind :: AddrSpaceCast => LLVMOpcode :: LLVMAddrSpaceCast ,
24+ pub fn match_llvm_opcode ( & self , llvm_op : LLVMOpcode ) -> bool {
25+ match llvm_op {
26+ LLVMOpcode :: LLVMTrunc => matches ! ( self , CastMatcherKind :: Trunc ) ,
27+ LLVMOpcode :: LLVMFPToUI => matches ! ( self , CastMatcherKind :: FPToUI ) ,
28+ LLVMOpcode :: LLVMFPToSI => matches ! ( self , CastMatcherKind :: FPToSI ) ,
29+ LLVMOpcode :: LLVMFPTrunc => matches ! ( self , CastMatcherKind :: FPTrunc ) ,
30+
31+ LLVMOpcode :: LLVMFPExt => matches ! ( self , CastMatcherKind :: Ext | CastMatcherKind :: FPExt ) ,
32+ LLVMOpcode :: LLVMZExt => matches ! ( self , CastMatcherKind :: Ext | CastMatcherKind :: ZExt ) ,
33+ LLVMOpcode :: LLVMSExt => matches ! ( self , CastMatcherKind :: Ext | CastMatcherKind :: SExt ) ,
34+
35+ LLVMOpcode :: LLVMIntToPtr => matches ! ( self , CastMatcherKind :: IntToPtr ) ,
36+ LLVMOpcode :: LLVMPtrToInt => matches ! ( self , CastMatcherKind :: PtrToInt ) ,
37+ LLVMOpcode :: LLVMBitCast => matches ! ( self , CastMatcherKind :: BitCast ) ,
38+ LLVMOpcode :: LLVMAddrSpaceCast => matches ! ( self , CastMatcherKind :: AddrSpaceCast ) ,
39+ _ => false ,
3640 }
3741 }
3842}
@@ -69,6 +73,10 @@ impl CastInstMatcher {
6973 CastInstMatcher :: new ( value_matcher, CastMatcherKind :: FPTrunc )
7074 }
7175
76+ pub fn create_ext ( value_matcher : Box < dyn Matcher < LLVMValueRef > > ) -> CastInstMatcher {
77+ CastInstMatcher :: new ( value_matcher, CastMatcherKind :: Ext )
78+ }
79+
7280 pub fn create_fpext ( value_matcher : Box < dyn Matcher < LLVMValueRef > > ) -> CastInstMatcher {
7381 CastInstMatcher :: new ( value_matcher, CastMatcherKind :: FPExt )
7482 }
@@ -104,7 +112,8 @@ impl Matcher<LLVMValueRef> for CastInstMatcher {
104112 #[ allow( clippy:: not_unsafe_ptr_arg_deref) ]
105113 fn is_match ( & self , instruction : & LLVMValueRef ) -> bool {
106114 unsafe {
107- if self . kind . llvm_opcode ( ) != LLVMGetInstructionOpcode ( * instruction) {
115+ let opcode = LLVMGetInstructionOpcode ( * instruction) ;
116+ if !self . kind . match_llvm_opcode ( opcode) {
108117 return false ;
109118 }
110119
0 commit comments