From d5ada891dea3de2cd4aedb0f90df94bef59a1983 Mon Sep 17 00:00:00 2001 From: AmrDeveloper Date: Wed, 4 Dec 2024 19:47:56 +0100 Subject: [PATCH] feat: Implement `m_half` matcher --- docs/TypeMatcher.md | 1 + src/functions/matchers/types.rs | 16 ++++++++++++++++ src/matchers/types.rs | 11 +++++++++++ 3 files changed, 28 insertions(+) diff --git a/docs/TypeMatcher.md b/docs/TypeMatcher.md index 63b1a55..b36d35a 100644 --- a/docs/TypeMatcher.md +++ b/docs/TypeMatcher.md @@ -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 | diff --git a/src/functions/matchers/types.rs b/src/functions/matchers/types.rs index 1d17eec..784f1ff 100644 --- a/src/functions/matchers/types.rs +++ b/src/functions/matchers/types.rs @@ -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; @@ -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); @@ -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 { @@ -220,6 +231,11 @@ fn match_float64(_values: &[Box]) -> Box { }) } +fn match_half(_values: &[Box]) -> Box { + let matcher = Box::new(HalfTypeMatcher); + Box::new(TypeMatcherValue { matcher }) +} + fn match_pointer(_values: &[Box]) -> Box { let pointer_matcher = PointerTypeMatcher; Box::new(TypeMatcherValue { diff --git a/src/matchers/types.rs b/src/matchers/types.rs index 2239614..f3cf7b7 100644 --- a/src/matchers/types.rs +++ b/src/matchers/types.rs @@ -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)]