Skip to content

Commit cc95766

Browse files
committed
feat: Implement first version of m_invoke matcher
1 parent 9c24e8a commit cc95766

File tree

3 files changed

+28
-3
lines changed

3 files changed

+28
-3
lines changed

docs/InstructionMatcher.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,4 +131,5 @@ Instructions Matchers are functions that build a instruction matcher to match ag
131131

132132
| Function | Parameters | Return | Description |
133133
| :----------: | :--------: | :---------: | :--------------------------------------------------: |
134+
| m_invoke | () | InstMatcher | Build Inst Matcher that match invoke Instruction |
134135
| m_landingpad | () | InstMatcher | Build Inst Matcher that match landingpad Instruction |

src/functions/matchers/exception.rs

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ use std::collections::HashMap;
22

33
use crate::ir::types::InstMatcherType;
44
use crate::ir::values::InstMatcherValue;
5+
use crate::matchers::exception::InvokeInstMatcher;
56
use crate::matchers::exception::LandingPadInstMatcher;
67

78
use gitql_core::signature::Function;
@@ -10,13 +11,22 @@ use gitql_core::values::base::Value;
1011

1112
#[inline(always)]
1213
pub fn register_exception_inst_matchers_functions(map: &mut HashMap<&'static str, Function>) {
14+
map.insert("m_invoke", match_invoke_inst);
1315
map.insert("m_landingpad", match_landingpad_inst);
1416
}
1517

1618
#[inline(always)]
1719
pub fn register_exception_inst_matchers_function_signatures(
1820
map: &mut HashMap<&'static str, Signature>,
1921
) {
22+
map.insert(
23+
"m_invoke",
24+
Signature {
25+
parameters: vec![],
26+
return_type: Box::new(InstMatcherType),
27+
},
28+
);
29+
2030
map.insert(
2131
"m_landingpad",
2232
Signature {
@@ -26,8 +36,12 @@ pub fn register_exception_inst_matchers_function_signatures(
2636
);
2737
}
2838

39+
fn match_invoke_inst(_values: &[Box<dyn Value>]) -> Box<dyn Value> {
40+
let matcher = Box::new(InvokeInstMatcher);
41+
Box::new(InstMatcherValue { matcher })
42+
}
43+
2944
fn match_landingpad_inst(_values: &[Box<dyn Value>]) -> Box<dyn Value> {
30-
Box::new(InstMatcherValue {
31-
matcher: Box::new(LandingPadInstMatcher),
32-
})
45+
let matcher = Box::new(LandingPadInstMatcher);
46+
Box::new(InstMatcherValue { matcher })
3347
}

src/matchers/exception.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,13 @@ impl InstMatcher for LandingPadInstMatcher {
1313
unsafe { LLVMOpcode::LLVMLandingPad == LLVMGetInstructionOpcode(instruction) }
1414
}
1515
}
16+
17+
#[derive(Clone)]
18+
pub struct InvokeInstMatcher;
19+
20+
impl InstMatcher for InvokeInstMatcher {
21+
#[allow(clippy::not_unsafe_ptr_arg_deref)]
22+
fn is_match(&self, instruction: LLVMValueRef) -> bool {
23+
unsafe { LLVMOpcode::LLVMInvoke == LLVMGetInstructionOpcode(instruction) }
24+
}
25+
}

0 commit comments

Comments
 (0)