Skip to content

Commit

Permalink
feat: Implement m_half matcher
Browse files Browse the repository at this point in the history
  • Loading branch information
AmrDeveloper committed Dec 4, 2024
1 parent 9678443 commit d5ada89
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 0 deletions.
1 change: 1 addition & 0 deletions docs/TypeMatcher.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ Types Matchers are functions that build a type matcher to match against LLVM Typ
| m_int64 | () | TypeMatcher | Build Matcher for LLVM Type Int64 |
| m_f32 | () | TypeMatcher | Build Matcher for LLVM Type Float32 |
| m_f64 | () | TypeMatcher | Build Matcher for LLVM Type Float64 |
| m_f64 | () | TypeMatcher | Build Matcher for LLVM Type Half |
| m_void | () | TypeMatcher | Build Matcher for LLVM Type void |
| m_ptr | () | TypeMatcher | Build Matcher for LLVM Type Pointer |
| m_array | (type: TypeMatcher, size: Int?) | TypeMatcher | Build Matcher for LLVM Type Array with optional base and size |
Expand Down
16 changes: 16 additions & 0 deletions src/functions/matchers/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ use crate::ir::values::TypeMatcherValue;
use crate::matchers::types::ArrayTypeMatcher;
use crate::matchers::types::FloatTypeMatcher;
use crate::matchers::types::FloatTypeSize;
use crate::matchers::types::HalfTypeMatcher;
use crate::matchers::types::IntTypeMatcher;
use crate::matchers::types::IntTypeSize;
use crate::matchers::types::PointerTypeMatcher;
Expand All @@ -31,6 +32,9 @@ pub fn register_type_matchers_functions(map: &mut HashMap<&'static str, Function
map.insert("m_f32", match_float32);
map.insert("m_f64", match_float64);

// Matcher fof Half type
map.insert("m_half", match_half);

// Matcher for Void type
map.insert("m_void", match_void);

Expand Down Expand Up @@ -103,6 +107,13 @@ pub fn register_type_matchers_function_signatures(map: &mut HashMap<&'static str
return_type: Box::new(TypeMatcherType),
},
);
map.insert(
"m_half",
Signature {
parameters: vec![],
return_type: Box::new(TypeMatcherType),
},
);
map.insert(
"m_ptr",
Signature {
Expand Down Expand Up @@ -220,6 +231,11 @@ fn match_float64(_values: &[Box<dyn Value>]) -> Box<dyn Value> {
})
}

fn match_half(_values: &[Box<dyn Value>]) -> Box<dyn Value> {
let matcher = Box::new(HalfTypeMatcher);
Box::new(TypeMatcherValue { matcher })
}

fn match_pointer(_values: &[Box<dyn Value>]) -> Box<dyn Value> {
let pointer_matcher = PointerTypeMatcher;
Box::new(TypeMatcherValue {
Expand Down
11 changes: 11 additions & 0 deletions src/matchers/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,17 @@ impl TypeMatcher for FloatTypeMatcher {
}
}

/// Ha;f Type Matcher used to match against LLVM Half Type
#[derive(Clone)]
pub struct HalfTypeMatcher;

impl TypeMatcher for HalfTypeMatcher {
#[allow(clippy::not_unsafe_ptr_arg_deref)]
fn is_match(&self, llvm_type: LLVMTypeRef) -> bool {
unsafe { LLVMGetTypeKind(llvm_type) == LLVMTypeKind::LLVMHalfTypeKind }
}
}

/// Pointer Type Matcher used to match against LLVM Pointer Type
#[derive(Clone)]

Expand Down

0 comments on commit d5ada89

Please sign in to comment.