-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add
function_
module temporarily for the inst transition
- Loading branch information
Showing
3 changed files
with
101 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
use super::{dfg_::DataFlowGraph, module::FuncRef, value_::ValueId, Layout, Type}; | ||
use crate::{module::ModuleCtx, Linkage}; | ||
use rustc_hash::FxHashMap; | ||
use smallvec::SmallVec; | ||
|
||
pub struct Function { | ||
/// Signature of the function. | ||
pub sig: Signature, | ||
pub arg_values: smallvec::SmallVec<[ValueId; 8]>, | ||
pub dfg: DataFlowGraph, | ||
pub layout: Layout, | ||
|
||
/// Stores signatures of all functions that are called by the function. | ||
pub callees: FxHashMap<FuncRef, Signature>, | ||
} | ||
|
||
impl Function { | ||
pub fn new(ctx: &ModuleCtx, sig: Signature) -> Self { | ||
let mut dfg = DataFlowGraph::new(ctx.clone()); | ||
let arg_values = sig | ||
.args() | ||
.iter() | ||
.enumerate() | ||
.map(|(idx, arg_ty)| { | ||
let value = dfg.make_arg_value(*arg_ty, idx); | ||
dfg.make_value(value) | ||
}) | ||
.collect(); | ||
|
||
Self { | ||
sig, | ||
arg_values, | ||
dfg, | ||
layout: Layout::default(), | ||
callees: FxHashMap::default(), | ||
} | ||
} | ||
} | ||
|
||
#[derive(Debug, Clone, PartialEq, Eq, Default)] | ||
pub struct Signature { | ||
/// Name of the function. | ||
name: String, | ||
|
||
/// Linkage of the function. | ||
linkage: Linkage, | ||
|
||
args: SmallVec<[Type; 8]>, | ||
ret_ty: Type, | ||
} | ||
|
||
impl Signature { | ||
pub fn new(name: &str, linkage: Linkage, args: &[Type], ret_ty: Type) -> Self { | ||
Self { | ||
name: name.to_string(), | ||
linkage, | ||
args: args.into(), | ||
ret_ty, | ||
} | ||
} | ||
pub fn name(&self) -> &str { | ||
&self.name | ||
} | ||
|
||
pub fn linkage(&self) -> Linkage { | ||
self.linkage | ||
} | ||
|
||
pub fn args(&self) -> &[Type] { | ||
&self.args | ||
} | ||
|
||
pub fn ret_ty(&self) -> Type { | ||
self.ret_ty | ||
} | ||
|
||
#[doc(hidden)] | ||
pub fn set_ret_ty(&mut self, ty: Type) { | ||
self.ret_ty = ty; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters