From 0ea6b1586cdb64bf91d47146135fb7b55c634459 Mon Sep 17 00:00:00 2001 From: Yoshitomo Nakanishi Date: Sun, 24 Nov 2024 18:01:52 +0100 Subject: [PATCH] Add `GetFunctionPtr` instruction --- crates/ir/src/inst/data.rs | 8 +++++++- crates/ir/src/inst/inst_set.rs | 1 + crates/parser/src/inst/data.rs | 1 + 3 files changed, 9 insertions(+), 1 deletion(-) diff --git a/crates/ir/src/inst/data.rs b/crates/ir/src/inst/data.rs index 3b5d874b..42ab1295 100644 --- a/crates/ir/src/inst/data.rs +++ b/crates/ir/src/inst/data.rs @@ -1,7 +1,7 @@ use macros::Inst; use smallvec::SmallVec; -use crate::{inst::impl_inst_write, Type, ValueId}; +use crate::{inst::impl_inst_write, module::FuncRef, Type, ValueId}; #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Inst)] #[inst(side_effect(super::SideEffect::Read))] @@ -30,6 +30,12 @@ pub struct Gep { } impl_inst_write!(Gep); +#[derive(Debug, Clone, PartialEq, Eq, Hash, Inst)] +pub struct GetFunctionPtr { + func: FuncRef, +} +impl_inst_write!(GetFunctionPtr); + #[derive(Debug, Clone, PartialEq, Eq, Hash, Inst)] #[inst(side_effect(super::SideEffect::Write))] pub struct Alloca { diff --git a/crates/ir/src/inst/inst_set.rs b/crates/ir/src/inst/inst_set.rs index 74344acc..dcd4d5b3 100644 --- a/crates/ir/src/inst/inst_set.rs +++ b/crates/ir/src/inst/inst_set.rs @@ -48,6 +48,7 @@ define_inst_set_base! { data::Mload, data::Mstore, data::Gep, + data::GetFunctionPtr, data::Alloca, data::InsertValue, data::ExtractValue, diff --git a/crates/parser/src/inst/data.rs b/crates/parser/src/inst/data.rs index 995855ab..797a5ed5 100644 --- a/crates/parser/src/inst/data.rs +++ b/crates/parser/src/inst/data.rs @@ -6,6 +6,7 @@ use crate::{ast, error::ArityBound, BuildCtx, Error}; super::impl_inst_build! {Mload, (addr: ValueId, ty: Type)} super::impl_inst_build! {Mstore, (addr: ValueId, value: ValueId, ty: Type)} super::impl_inst_build_common! {Gep, ArityBound::AtLeast(2), build_gep} +super::impl_inst_build! {GetFunctionPtr, (func: FuncRef)} super::impl_inst_build! {Alloca, (ty: Type)} super::impl_inst_build! {InsertValue, (dest: ValueId, idx: ValueId, value: ValueId)} super::impl_inst_build! {ExtractValue, (dest: ValueId, idx: ValueId)}