use sway_types::ident::Ident;
use crate::{
context::Context, irtype::Type, metadata::MetadataIndex, pretty::DebugWithContext, value::Value,
};
#[derive(Clone, Copy, Debug, Eq, PartialEq, Hash, DebugWithContext)]
pub struct AsmBlock(#[in_context(asm_blocks)] pub generational_arena::Index);
#[doc(hidden)]
#[derive(Clone, Debug, DebugWithContext)]
pub struct AsmBlockContent {
pub args_names: Vec<Ident>,
pub body: Vec<AsmInstruction>,
pub return_type: Type,
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>,
pub metadata: Option<MetadataIndex>,
}
impl AsmBlock {
pub fn new(
context: &mut Context,
args_names: Vec<Ident>,
body: Vec<AsmInstruction>,
return_type: Type,
return_name: Option<Ident>,
) -> Self {
let content = AsmBlockContent {
args_names,
body,
return_type,
return_name,
};
AsmBlock(context.asm_blocks.insert(content))
}
pub fn get_type(&self, context: &Context) -> Type {
context.asm_blocks[self.0].return_type
}
pub fn get_content<'a>(&self, context: &'a Context) -> &'a AsmBlockContent {
&context.asm_blocks[self.0]
}
}