1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
use sway_types::ident::Ident;
use crate::{context::Context, irtype::Type, metadata::MetadataIndex, value::Value};
#[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_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) -> Option<Type> {
Some(context.asm_blocks[self.0].return_type)
}
}