Skip to content

Commit 102321c

Browse files
committed
Implement m_begin_catch and m_end_catch matchers
1 parent ee9b378 commit 102321c

File tree

3 files changed

+51
-0
lines changed

3 files changed

+51
-0
lines changed

docs/matchers/exceptions.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,6 @@
1010
| m_eh_typeid | | InstMatcher | Build Inst Matcher that match call to `llvm.eh.typeid.for` |
1111
| m_alloca_exception | | InstMatcher | Build Inst Matcher that match call to `__cxa_allocate_exception` |
1212
| m_free_exception | | InstMatcher | Build Inst Matcher that match call to `__cxa_free_exception` |
13+
| m_begin_catch | | InstMatcher | Build Inst Matcher that match call to `__cxa_begin_catch` |
14+
| m_end_catch | | InstMatcher | Build Inst Matcher that match call to `__cxa_end_catch` |
15+

src/functions/matchers/exception.rs

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ use std::collections::HashMap;
33
use crate::ir::types::InstMatcherType;
44
use crate::ir::values::InstMatcherValue;
55
use crate::matchers::exception::AllocaExceptionInstMatcher;
6+
use crate::matchers::exception::CatchBeginInstMatcher;
7+
use crate::matchers::exception::CatchEndInstMatcher;
68
use crate::matchers::exception::EHTypeIdInstMatcher;
79
use crate::matchers::exception::FreeExceptionInstMatcher;
810
use crate::matchers::exception::InvokeInstMatcher;
@@ -27,6 +29,8 @@ pub fn register_exception_inst_matchers_functions(
2729
map.insert("m_eh_typeid", match_eh_typeid_inst);
2830
map.insert("m_alloca_exception", match_alloca_exception_inst);
2931
map.insert("m_free_exception", match_free_exception_inst);
32+
map.insert("m_begin_catch", match_begin_catch_inst);
33+
map.insert("m_end_catch", match_end_catch_inst);
3034
}
3135

3236
#[inline(always)]
@@ -96,6 +100,22 @@ pub fn register_exception_inst_matchers_function_signatures(
96100
return_type: Box::new(InstMatcherType),
97101
},
98102
);
103+
104+
map.insert(
105+
"m_begin_catch",
106+
Signature {
107+
parameters: vec![],
108+
return_type: Box::new(InstMatcherType),
109+
},
110+
);
111+
112+
map.insert(
113+
"m_end_catch",
114+
Signature {
115+
parameters: vec![],
116+
return_type: Box::new(InstMatcherType),
117+
},
118+
);
99119
}
100120

101121
fn match_invoke_inst(_values: &[Box<dyn Value>]) -> Box<dyn Value> {
@@ -137,3 +157,13 @@ fn match_free_exception_inst(_values: &[Box<dyn Value>]) -> Box<dyn Value> {
137157
let matcher = Box::new(FreeExceptionInstMatcher);
138158
Box::new(InstMatcherValue { matcher })
139159
}
160+
161+
fn match_begin_catch_inst(_values: &[Box<dyn Value>]) -> Box<dyn Value> {
162+
let matcher = Box::new(CatchBeginInstMatcher);
163+
Box::new(InstMatcherValue { matcher })
164+
}
165+
166+
fn match_end_catch_inst(_values: &[Box<dyn Value>]) -> Box<dyn Value> {
167+
let matcher = Box::new(CatchEndInstMatcher);
168+
Box::new(InstMatcherValue { matcher })
169+
}

src/matchers/exception.rs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,3 +81,21 @@ impl Matcher<LLVMValueRef> for FreeExceptionInstMatcher {
8181
is_call_base_inst_with_specific_name(instruction, "__cxa_free_exception")
8282
}
8383
}
84+
85+
#[derive(Clone)]
86+
pub struct CatchBeginInstMatcher;
87+
88+
impl Matcher<LLVMValueRef> for CatchBeginInstMatcher {
89+
fn is_match(&self, instruction: &LLVMValueRef) -> bool {
90+
is_call_base_inst_with_specific_name(instruction, "__cxa_begin_catch")
91+
}
92+
}
93+
94+
#[derive(Clone)]
95+
pub struct CatchEndInstMatcher;
96+
97+
impl Matcher<LLVMValueRef> for CatchEndInstMatcher {
98+
fn is_match(&self, instruction: &LLVMValueRef) -> bool {
99+
is_call_base_inst_with_specific_name(instruction, "__cxa_end_catch")
100+
}
101+
}

0 commit comments

Comments
 (0)