Skip to content

Commit 55726cb

Browse files
committed
Implement m_const_expr matcher function
1 parent e7efaed commit 55726cb

File tree

3 files changed

+21
-0
lines changed

3 files changed

+21
-0
lines changed

docs/matchers/constants.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
| Function | Parameters | Return | Description |
44
| :------------: | :---------------------: | :---------: | :--------------------------------------------------------------: |
5+
| m_const_expr | | InstMatcher | Build Inst Matcher that match constants expr |
56
| m_const_num | | InstMatcher | Build Inst Matcher that match constants number value |
67
| m_const_int | | InstMatcher | Build Inst Matcher that match constants int value |
78
| m_zero | | InstMatcher | Build Inst Matcher that match constants int with value 0 |

src/functions/matchers/constants.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,16 @@ use gitql_core::values::Value;
88
use crate::functions::matcher_signature_without_parameters;
99
use crate::ir::types::InstMatcherType;
1010
use crate::ir::values::InstMatcherValue;
11+
use crate::matchers::constants::ConstExprMatcher;
1112
use crate::matchers::constants::ConstFloatMatcher;
1213
use crate::matchers::constants::ConstIntMatcher;
1314
use crate::matchers::constants::ConstNumberMatcher;
1415
use crate::matchers::constants::ConstPointerNullMatcher;
1516

1617
#[inline(always)]
1718
pub fn register_constants_matchers_functions(map: &mut HashMap<&'static str, StandardFunction>) {
19+
map.insert("m_const_expr", match_const_expr_inst);
20+
1821
map.insert("m_const_num", match_const_num_inst);
1922
map.insert("m_const_int", match_const_int_inst);
2023
map.insert("m_zero", match_const_zero_inst);
@@ -29,6 +32,7 @@ pub fn register_constants_matchers_functions(map: &mut HashMap<&'static str, Sta
2932

3033
#[inline(always)]
3134
pub fn register_constants_matchers_function_signatures(map: &mut HashMap<&'static str, Signature>) {
35+
map.insert("m_const_expr", matcher_signature_without_parameters());
3236
map.insert("m_const_num", matcher_signature_without_parameters());
3337
map.insert("m_const_int", matcher_signature_without_parameters());
3438
map.insert("m_zero", matcher_signature_without_parameters());
@@ -54,6 +58,11 @@ pub fn register_constants_matchers_function_signatures(map: &mut HashMap<&'stati
5458
map.insert("m_const_null", matcher_signature_without_parameters());
5559
}
5660

61+
fn match_const_expr_inst(_values: &[Box<dyn Value>]) -> Box<dyn Value> {
62+
let matcher = Box::new(ConstExprMatcher);
63+
Box::new(InstMatcherValue { matcher })
64+
}
65+
5766
fn match_const_num_inst(_values: &[Box<dyn Value>]) -> Box<dyn Value> {
5867
let matcher = Box::new(ConstNumberMatcher);
5968
Box::new(InstMatcherValue { matcher })

src/matchers/constants.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,23 @@
11
use inkwell::llvm_sys::core::LLVMConstIntGetSExtValue;
22
use inkwell::llvm_sys::core::LLVMGetValueKind;
3+
use inkwell::llvm_sys::core::LLVMIsAConstantExpr;
34
use inkwell::llvm_sys::core::LLVMIsAConstantFP;
45
use inkwell::llvm_sys::core::LLVMIsAConstantInt;
56
use inkwell::llvm_sys::prelude::LLVMValueRef;
67
use inkwell::llvm_sys::LLVMValueKind;
78

89
use super::Matcher;
910

11+
/// Return instruction matcher to check if current value is a constants expr
12+
#[derive(Clone)]
13+
pub struct ConstExprMatcher;
14+
15+
impl Matcher<LLVMValueRef> for ConstExprMatcher {
16+
fn is_match(&self, instruction: &LLVMValueRef) -> bool {
17+
unsafe { !LLVMIsAConstantExpr(*instruction).is_null() }
18+
}
19+
}
20+
1021
#[derive(Clone)]
1122
enum ConstIntMatcherCondition {
1223
Specific(i64),

0 commit comments

Comments
 (0)