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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
use crate::crate_prelude::*;
use crate::{
mir::{
print::{Context, Print},
rvalue::Rvalue,
visit::{AcceptVisitor, Visitor, WalkVisitor},
},
ty::UnpackedType,
ParamEnv,
};
use std::fmt::Write;
#[moore_derive::visit_without_foreach]
#[derive(Clone, Eq, PartialEq)]
pub struct Lvalue<'a> {
pub id: NodeId,
pub origin: NodeId,
pub env: ParamEnv,
pub span: Span,
pub ty: &'a UnpackedType<'a>,
pub kind: LvalueKind<'a>,
}
impl<'a> Lvalue<'a> {
pub fn is_error(&self) -> bool {
self.ty.is_error() || self.kind.is_error()
}
pub fn get_intf(&self) -> Option<NodeId> {
match self.kind {
mir::LvalueKind::Index { value, .. } => value.get_intf(),
mir::LvalueKind::Intf(intf) => Some(intf),
_ => None,
}
}
}
impl<'a> std::fmt::Debug for Lvalue<'a> {
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
self.print(f)
}
}
impl<'a> Print for Lvalue<'a> {
fn print_context(
&self,
outer: &mut impl Write,
inner: &mut impl Write,
ctx: &mut Context,
) -> std::fmt::Result {
write!(inner, "Lvalue ")?;
match self.kind {
LvalueKind::Transmute(v) => write!(inner, "Transmute({})", ctx.print(outer, v))?,
LvalueKind::DestructArray(ref args) => write!(
inner,
"DestructArray({})",
ctx.print_comma_separated(outer, args),
)?,
LvalueKind::DestructStruct(ref args) => write!(
inner,
"DestructStruct({})",
ctx.print_comma_separated(outer, args),
)?,
LvalueKind::Genvar(arg) => write!(inner, "Genvar({:?})", arg)?,
LvalueKind::Var(arg) => write!(inner, "Var({:?})", arg)?,
LvalueKind::Port(arg) => write!(inner, "Port({:?})", arg)?,
LvalueKind::Intf(arg) => write!(inner, "Intf({:?})", arg)?,
LvalueKind::IntfSignal(arg, sig) => {
write!(inner, "IntfSignal({}, {:?})", ctx.print(outer, arg), sig)?
}
LvalueKind::Index {
value,
base,
length,
} => {
if length == 0 {
write!(
inner,
"{}[{}]",
ctx.print(outer, value),
ctx.print(outer, base),
)?
} else {
write!(
inner,
"{}[{}+:{}]",
ctx.print(outer, value),
ctx.print(outer, base),
length,
)?
}
}
LvalueKind::Member { value, field } => {
write!(inner, "{}.{}", ctx.print(outer, value), field)?
}
LvalueKind::Concat(ref args) => {
write!(inner, "Concat({})", ctx.print_comma_separated(outer, args))?
}
LvalueKind::Repeat(num, arg) => {
write!(inner, "Repeat({} x {})", num, ctx.print(outer, arg))?
}
LvalueKind::Error => write!(inner, "<error>")?,
}
write!(inner, " : {}", self.ty)?;
Ok(())
}
}
#[moore_derive::visit_without_foreach]
#[derive(Debug, Clone, Eq, PartialEq)]
#[allow(missing_docs)]
pub enum LvalueKind<'a> {
Transmute(&'a Lvalue<'a>),
DestructArray(Vec<&'a Lvalue<'a>>),
DestructStruct(Vec<&'a Lvalue<'a>>),
Genvar(NodeId),
Var(NodeId),
Port(NodeId),
Intf(NodeId),
IntfSignal(&'a Lvalue<'a>, NodeId),
Index {
value: &'a Lvalue<'a>,
base: &'a Rvalue<'a>,
length: usize,
},
Member { value: &'a Lvalue<'a>, field: usize },
Concat(Vec<&'a Lvalue<'a>>),
Repeat(usize, &'a Lvalue<'a>),
Error,
}
impl<'a> LvalueKind<'a> {
pub fn is_error(&self) -> bool {
match self {
LvalueKind::Error => true,
_ => false,
}
}
}