From cd777dcb52f3cd75ae338d5836ded9da580dc724 Mon Sep 17 00:00:00 2001 From: lyken Date: Sat, 27 Jul 2024 02:12:55 +0800 Subject: [PATCH] core/model: add Pointer::{is_null,is_not_null} --- nac3core/src/codegen/model/pointer.rs | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/nac3core/src/codegen/model/pointer.rs b/nac3core/src/codegen/model/pointer.rs index 22f3c765..bdb29d51 100644 --- a/nac3core/src/codegen/model/pointer.rs +++ b/nac3core/src/codegen/model/pointer.rs @@ -5,7 +5,7 @@ use inkwell::{ AddressSpace, }; -use crate::codegen::CodeGenContext; +use crate::codegen::{model::*, CodeGenContext}; use super::{core::*, OpaqueModel}; @@ -111,4 +111,16 @@ impl<'ctx, E: Model<'ctx>> Pointer<'ctx, E> { .unwrap(); casted_ptr_model.believe_value(casted_ptr) } + + pub fn is_null(&self, ctx: &CodeGenContext<'ctx, '_>, name: &str) -> NInt<'ctx, Bool> { + let model = NIntModel(Bool); + let value = ctx.builder.build_is_null(self.value, name).unwrap(); + model.believe_value(value) + } + + pub fn is_not_null(&self, ctx: &CodeGenContext<'ctx, '_>, name: &str) -> NInt<'ctx, Bool> { + let model = NIntModel(Bool); + let value = ctx.builder.build_is_not_null(self.value, name).unwrap(); + model.believe_value(value) + } }