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
use super::Expression;
use crate::TypeInfo;
use std::hash::{Hash, Hasher};
use sway_types::{ident::Ident, span::Span};
#[derive(Debug, Clone)]
pub struct AsmExpression {
pub(crate) registers: Vec<AsmRegisterDeclaration>,
pub(crate) body: Vec<AsmOp>,
pub(crate) returns: Option<(AsmRegister, Span)>,
pub(crate) return_type: TypeInfo,
pub(crate) whole_block_span: Span,
}
#[derive(Debug, Clone)]
pub struct AsmOp {
pub(crate) op_name: Ident,
pub(crate) op_args: Vec<Ident>,
pub(crate) span: Span,
pub(crate) immediate: Option<Ident>,
}
impl Hash for AsmOp {
fn hash<H: Hasher>(&self, state: &mut H) {
self.op_name.hash(state);
self.op_args.hash(state);
if let Some(immediate) = self.immediate.clone() {
immediate.hash(state);
}
}
}
impl PartialEq for AsmOp {
fn eq(&self, other: &Self) -> bool {
self.op_name == other.op_name
&& self.op_args == other.op_args
&& if let (Some(l), Some(r)) = (self.immediate.clone(), other.immediate.clone()) {
l == r
} else {
true
}
}
}
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub struct AsmRegister {
pub(crate) name: String,
}
impl From<AsmRegister> for String {
fn from(register: AsmRegister) -> String {
register.name
}
}
#[derive(Debug, Clone)]
pub(crate) struct AsmRegisterDeclaration {
pub(crate) name: Ident,
pub(crate) initializer: Option<Expression>,
}