Skip to content

Commit 2ef91ee

Browse files
committed
Implement m_zext and m_sext Matchers
1 parent 1798aa3 commit 2ef91ee

File tree

3 files changed

+34
-0
lines changed

3 files changed

+34
-0
lines changed

docs/matchers/cast.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
| Function | Parameters | Return | Description |
44
| :---------------: | :--------: | :---------: | :--------------------------------------------------------: |
5+
| m_zext | | InstMatcher | Build Inst Matcher that matchers zext instruction |
6+
| m_sext | | InstMatcher | Build Inst Matcher that matchers sext instruction |
57
| m_int_to_ptr | | InstMatcher | Build Inst Matcher that matchers IntToPtr instruction |
68
| m_ptr_to_int | | InstMatcher | Build Inst Matcher that matchers PtrToInt instruction |
79
| m_bit_cast | | InstMatcher | Build Inst Matcher that matchers Bit cast instruction |

src/functions/matchers/cast.rs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ use crate::matchers::cast::CastInstMatcher;
1010

1111
#[inline(always)]
1212
pub fn register_cast_matchers_function(map: &mut HashMap<&'static str, StandardFunction>) {
13+
map.insert("m_zext", match_zext);
14+
map.insert("m_sext", match_sext);
1315
map.insert("m_int_to_ptr", match_int_to_ptr_inst);
1416
map.insert("m_ptr_to_int", match_ptr_to_int_inst);
1517
map.insert("m_bit_cast", match_bit_cast_inst);
@@ -18,6 +20,10 @@ pub fn register_cast_matchers_function(map: &mut HashMap<&'static str, StandardF
1820

1921
#[inline(always)]
2022
pub fn register_cast_matchers_function_signatures(map: &mut HashMap<&'static str, Signature>) {
23+
map.insert("m_zext", Signature::with_return(Box::new(InstMatcherType)));
24+
25+
map.insert("m_sext", Signature::with_return(Box::new(InstMatcherType)));
26+
2127
map.insert(
2228
"m_int_to_ptr",
2329
Signature::with_return(Box::new(InstMatcherType)),
@@ -39,6 +45,16 @@ pub fn register_cast_matchers_function_signatures(map: &mut HashMap<&'static str
3945
);
4046
}
4147

48+
fn match_zext(_values: &[Box<dyn Value>]) -> Box<dyn Value> {
49+
let matcher = Box::new(CastInstMatcher::create_zext());
50+
Box::new(InstMatcherValue { matcher })
51+
}
52+
53+
fn match_sext(_values: &[Box<dyn Value>]) -> Box<dyn Value> {
54+
let matcher = Box::new(CastInstMatcher::create_sext());
55+
Box::new(InstMatcherValue { matcher })
56+
}
57+
4258
fn match_int_to_ptr_inst(_values: &[Box<dyn Value>]) -> Box<dyn Value> {
4359
let matcher = Box::new(CastInstMatcher::create_int_to_ptr());
4460
Box::new(InstMatcherValue { matcher })

src/matchers/cast.rs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,17 @@ use super::InstMatcher;
88
enum CastMatcherKind {
99
IntToPtr,
1010
PtrToInt,
11+
ZExt,
12+
SExt,
1113
BitCast,
1214
AddrSpaceCast,
1315
}
1416

1517
impl CastMatcherKind {
1618
pub fn llvm_opcode(&self) -> LLVMOpcode {
1719
match self {
20+
CastMatcherKind::ZExt => LLVMOpcode::LLVMZExt,
21+
CastMatcherKind::SExt => LLVMOpcode::LLVMSExt,
1822
CastMatcherKind::IntToPtr => LLVMOpcode::LLVMIntToPtr,
1923
CastMatcherKind::PtrToInt => LLVMOpcode::LLVMPtrToInt,
2024
CastMatcherKind::BitCast => LLVMOpcode::LLVMBitCast,
@@ -29,6 +33,18 @@ pub struct CastInstMatcher {
2933
}
3034

3135
impl CastInstMatcher {
36+
pub fn create_zext() -> CastInstMatcher {
37+
CastInstMatcher {
38+
matcher_kind: CastMatcherKind::ZExt,
39+
}
40+
}
41+
42+
pub fn create_sext() -> CastInstMatcher {
43+
CastInstMatcher {
44+
matcher_kind: CastMatcherKind::SExt,
45+
}
46+
}
47+
3248
pub fn create_int_to_ptr() -> CastInstMatcher {
3349
CastInstMatcher {
3450
matcher_kind: CastMatcherKind::IntToPtr,

0 commit comments

Comments
 (0)