Skip to content

Commit a883a40

Browse files
committed
Change the Matcher interface to be generic interface for any kind of matchers
1 parent c776ed7 commit a883a40

16 files changed

Lines changed: 547 additions & 538 deletions

File tree

src/functions/matchers/combine.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,15 @@ use gitql_ast::types::varargs::VarargsType;
44
use gitql_core::signature::Signature;
55
use gitql_core::signature::StandardFunction;
66
use gitql_core::values::base::Value;
7+
use inkwell::llvm_sys::prelude::LLVMValueRef;
78

89
use crate::functions::binary_matchers_sides;
910
use crate::ir::types::InstMatcherType;
1011
use crate::ir::values::InstMatcherValue;
1112
use crate::matchers::combine::CombineBinaryInstMatcher;
1213
use crate::matchers::combine::CombineInstMatcher;
1314
use crate::matchers::combine::CombineUnaryInstMatcher;
14-
use crate::matchers::InstMatcher;
15+
use crate::matchers::Matcher;
1516

1617
#[inline(always)]
1718
pub fn register_combine_matchers_function(map: &mut HashMap<&'static str, StandardFunction>) {
@@ -101,7 +102,7 @@ pub fn register_combine_matchers_function_signatures(map: &mut HashMap<&'static
101102
}
102103

103104
fn match_oneof_combine_inst(values: &[Box<dyn Value>]) -> Box<dyn Value> {
104-
let mut matchers: Vec<Box<dyn InstMatcher>> = vec![];
105+
let mut matchers: Vec<Box<dyn Matcher<LLVMValueRef>>> = vec![];
105106
for value in values.iter() {
106107
if let Some(inst_matcher) = value.as_any().downcast_ref::<InstMatcherValue>() {
107108
matchers.push(inst_matcher.matcher.to_owned());
@@ -112,7 +113,7 @@ fn match_oneof_combine_inst(values: &[Box<dyn Value>]) -> Box<dyn Value> {
112113
}
113114

114115
fn match_allof_combine_inst(values: &[Box<dyn Value>]) -> Box<dyn Value> {
115-
let mut matchers: Vec<Box<dyn InstMatcher>> = vec![];
116+
let mut matchers: Vec<Box<dyn Matcher<LLVMValueRef>>> = vec![];
116117
for value in values.iter() {
117118
if let Some(inst_matcher) = value.as_any().downcast_ref::<InstMatcherValue>() {
118119
matchers.push(inst_matcher.matcher.to_owned());
@@ -123,7 +124,7 @@ fn match_allof_combine_inst(values: &[Box<dyn Value>]) -> Box<dyn Value> {
123124
}
124125

125126
fn match_noneof_combine_inst(values: &[Box<dyn Value>]) -> Box<dyn Value> {
126-
let mut matchers: Vec<Box<dyn InstMatcher>> = vec![];
127+
let mut matchers: Vec<Box<dyn Matcher<LLVMValueRef>>> = vec![];
127128
for value in values.iter() {
128129
if let Some(inst_matcher) = value.as_any().downcast_ref::<InstMatcherValue>() {
129130
matchers.push(inst_matcher.matcher.to_owned());

src/functions/matchers/other.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ use crate::ir::types::TypeMatcherType;
1717
use crate::ir::values::InstMatcherValue;
1818
use crate::ir::values::LLVMInstValue;
1919
use crate::ir::values::TypeMatcherValue;
20+
use crate::matchers::other::AnyInstMatcher;
2021
use crate::matchers::other::ArgumentMatcher;
2122
use crate::matchers::other::ExtractValueInstMatcher;
2223
use crate::matchers::other::InstTypeMatcher;
@@ -25,7 +26,6 @@ use crate::matchers::other::OperandCountMatcher;
2526
use crate::matchers::other::PoisonValueMatcher;
2627
use crate::matchers::other::ReturnInstMatcher;
2728
use crate::matchers::other::UnreachableInstMatcher;
28-
use crate::matchers::AnyInstMatcher;
2929

3030
#[inline(always)]
3131
pub fn register_other_inst_matchers_functions(map: &mut HashMap<&'static str, StandardFunction>) {
@@ -136,7 +136,7 @@ fn match_inst(values: &[Box<dyn Value>]) -> Box<dyn Value> {
136136
.downcast_ref::<InstMatcherValue>()
137137
.unwrap();
138138

139-
let is_match = matcher.matcher.is_match(inst.llvm_value);
139+
let is_match = matcher.matcher.is_match(&inst.llvm_value);
140140
Box::new(BoolValue { value: is_match })
141141
}
142142

src/functions/mod.rs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ use gitql_core::values::base::Value;
88

99
use gitql_std::standard::standard_function_signatures;
1010
use gitql_std::standard::standard_functions;
11+
use inkwell::llvm_sys::prelude::LLVMValueRef;
1112
use matchers::arithmetic::register_arithmetic_matchers_function_signatures;
1213
use matchers::arithmetic::register_arithmetic_matchers_functions;
1314
use matchers::binary::register_binary_inst_matchers_function_signatures;
@@ -37,8 +38,8 @@ use matchers::usage::register_usage_matchers_functions;
3738

3839
use crate::ir::types::InstMatcherType;
3940
use crate::ir::values::InstMatcherValue;
40-
use crate::matchers::AnyInstMatcher;
41-
use crate::matchers::InstMatcher;
41+
use crate::matchers::other::AnyInstMatcher;
42+
use crate::matchers::Matcher;
4243

4344
pub(crate) mod matchers;
4445

@@ -102,7 +103,10 @@ pub fn matcher_signature_without_parameters() -> Signature {
102103
#[inline]
103104
pub fn binary_matchers_sides(
104105
values: &[Box<dyn Value>],
105-
) -> (Box<dyn InstMatcher>, Box<dyn InstMatcher>) {
106+
) -> (
107+
Box<dyn Matcher<LLVMValueRef>>,
108+
Box<dyn Matcher<LLVMValueRef>>,
109+
) {
106110
let args_len = values.len();
107111

108112
let lhs_matcher = if args_len > 0 {

src/ir/values.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,7 @@ use llvm_sys::prelude::LLVMValueRef;
1111

1212
use crate::matchers::combine::CombineBinaryInstMatcher;
1313
use crate::matchers::combine::CombineUnaryInstMatcher;
14-
use crate::matchers::InstMatcher;
15-
use crate::matchers::TypeMatcher;
14+
use crate::matchers::Matcher;
1615

1716
use super::types::InstMatcherType;
1817
use super::types::LLVMDataType;
@@ -102,7 +101,7 @@ impl Value for LLVMTypeValue {
102101

103102
#[derive(Clone)]
104103
pub struct InstMatcherValue {
105-
pub matcher: Box<dyn InstMatcher>,
104+
pub matcher: Box<dyn Matcher<LLVMValueRef>>,
106105
}
107106

108107
impl Value for InstMatcherValue {
@@ -170,7 +169,7 @@ impl Value for InstMatcherValue {
170169

171170
#[derive(Clone)]
172171
pub struct TypeMatcherValue {
173-
pub matcher: Box<dyn TypeMatcher>,
172+
pub matcher: Box<dyn Matcher<LLVMTypeRef>>,
174173
}
175174

176175
impl Value for TypeMatcherValue {

0 commit comments

Comments
 (0)