1111
1212use serde:: { Deserialize , Serialize } ;
1313use std:: fmt:: { self , Display } ;
14+ use std:: marker:: PhantomData ;
1415
1516pub type CrateHash = u64 ;
1617pub type DefIndex = u32 ;
1718pub type BasicBlockIndex = u32 ;
1819pub type LocalIndex = u32 ;
20+ pub type VariantIndex = u32 ;
21+ pub type PromotedIndex = u32 ;
1922
2023/// A mirror of the compiler's notion of a "definition ID".
2124#[ derive( Serialize , Deserialize , PartialEq , Eq , Debug , Clone ) ]
@@ -93,7 +96,8 @@ impl Display for BasicBlock {
9396pub enum Statement {
9497 Nop ,
9598 Assign ( Place , Rvalue ) ,
96- Unimplemented , // FIXME
99+ SetDiscriminant ( Place , VariantIndex ) ,
100+ Unimplemented ,
97101}
98102
99103impl Display for Statement {
@@ -102,19 +106,112 @@ impl Display for Statement {
102106 }
103107}
104108
109+ /// A place for storing things.
105110#[ derive( Serialize , Deserialize , PartialEq , Eq , Debug , Clone ) ]
106111pub enum Place {
112+ Base ( PlaceBase ) ,
113+ Projection ( PlaceProjection ) ,
114+ }
115+
116+ /// The "base" of a place projection.
117+ #[ derive( Serialize , Deserialize , PartialEq , Eq , Debug , Clone ) ]
118+ pub enum PlaceBase {
107119 Local ( LocalIndex ) ,
108- Unimplemented , // FIXME
120+ Static ( DefId ) ,
121+ Promoted ( PromotedIndex ) ,
109122}
110123
124+ /// A projection (deref, index, field access, ...).
111125#[ derive( Serialize , Deserialize , PartialEq , Eq , Debug , Clone ) ]
112- pub enum Rvalue {
126+ pub struct PlaceProjection {
127+ pub base : Box < Place > ,
128+ pub elem : ProjectionElem < LocalIndex > ,
129+ }
130+
131+ /// Describes a projection operation upon a projection base.
132+ #[ derive( Serialize , Deserialize , PartialEq , Eq , Debug , Clone ) ]
133+ pub enum ProjectionElem < V > {
134+ Unimplemented ( PhantomData < V > ) , // FIXME
135+ }
136+
137+ #[ derive( Serialize , Deserialize , PartialEq , Eq , Debug , Clone ) ]
138+ pub enum Operand {
139+ /// In MIR this is either Move or Copy.
113140 Place ( Place ) ,
114- Phi ( Vec < Place > ) ,
141+ Unimplemented , // FIXME constants
142+ }
143+
144+ /// Borrow descriptions.
145+ #[ derive( Serialize , Deserialize , PartialEq , Eq , Debug , Clone ) ]
146+ pub enum BorrowKind {
147+ Shared ,
148+ Shallow ,
149+ Unique ,
150+ Mut , // FIXME two_phase borrow.
151+ }
152+
153+ /// Things that can appear on the right-hand side of an assignment.
154+ #[ derive( Serialize , Deserialize , PartialEq , Eq , Debug , Clone ) ]
155+ pub enum Rvalue {
156+ Use ( Operand ) ,
157+ Repeat ( Operand , u64 ) ,
158+ Ref ( BorrowKind , Place ) , // We do not store the region.
159+ Len ( Place ) ,
160+ BinaryOp ( BinOp , Operand , Operand ) ,
161+ CheckedBinaryOp ( BinOp , Operand , Operand ) ,
162+ NullaryOp ( NullOp ) ,
163+ UnaryOp ( UnOp , Operand ) ,
164+ Discriminant ( Place ) ,
165+ Aggregate ( AggregateKind , Vec < Operand > ) ,
115166 Unimplemented , // FIXME
116167}
117168
169+ /// Kinds of aggregate types.
170+ #[ derive( Serialize , Deserialize , PartialEq , Eq , Debug , Clone ) ]
171+ pub enum AggregateKind {
172+ Array ,
173+ Tuple ,
174+ Closure ( DefId ) ,
175+ Generator ( DefId ) ,
176+ Unimplemented ,
177+ }
178+
179+ /// Binary operations.
180+ #[ derive( Serialize , Deserialize , PartialEq , Eq , Debug , Clone ) ]
181+ pub enum BinOp {
182+ Add ,
183+ Sub ,
184+ Mul ,
185+ Div ,
186+ Rem ,
187+ BitXor ,
188+ BitAnd ,
189+ BitOr ,
190+ Shl ,
191+ Shr ,
192+ Eq ,
193+ Lt ,
194+ Le ,
195+ Ne ,
196+ Ge ,
197+ Gt ,
198+ Offset ,
199+ }
200+
201+ // Operations with no arguments.
202+ #[ derive( Serialize , Deserialize , PartialEq , Eq , Debug , Clone ) ]
203+ pub enum NullOp {
204+ SizeOf ,
205+ Box ,
206+ }
207+
208+ // Unary operations.
209+ #[ derive( Serialize , Deserialize , PartialEq , Eq , Debug , Clone ) ]
210+ pub enum UnOp {
211+ Not ,
212+ Neg ,
213+ }
214+
118215/// A call target.
119216#[ derive( Serialize , Deserialize , PartialEq , Eq , Debug , Clone ) ]
120217pub enum CallOperand {
0 commit comments