use crate::{context::Context, irtype::Type, value::Value};
use sway_types::ident::Ident;
#[derive(Clone, Copy, Debug, Eq, PartialEq, Hash)]
pub struct AsmBlock(pub generational_arena::Index);
#[doc(hidden)]
#[derive(Clone, Debug)]
pub struct AsmBlockContent {
pub args_names: Vec<Ident>,
pub body: Vec<AsmInstruction>,
pub return_name: Option<Ident>,
}
#[derive(Clone, Debug)]
pub struct AsmArg {
pub name: Ident,
pub initializer: Option<Value>,
}
#[derive(Clone, Debug)]
pub struct AsmInstruction {
pub name: Ident,
pub args: Vec<Ident>,
pub immediate: Option<Ident>,
}
impl AsmBlock {
pub fn new(
context: &mut Context,
args_names: Vec<Ident>,
body: Vec<AsmInstruction>,
return_name: Option<Ident>,
) -> Self {
let content = AsmBlockContent {
args_names,
body,
return_name,
};
AsmBlock(context.asm_blocks.insert(content))
}
pub fn get_type(&self, context: &Context) -> Option<Type> {
context.asm_blocks[self.0]
.return_name
.as_ref()
.map(|_| Type::Uint(64))
}
}