1010//! Types for the Yorick intermediate language.
1111
1212use serde:: { Deserialize , Serialize } ;
13- use std:: fmt:: { self , Display } ;
13+ use std:: {
14+ fmt:: { self , Display } ,
15+ marker:: PhantomData ,
16+ } ;
1417
1518pub type CrateHash = u64 ;
1619pub type DefIndex = u32 ;
1720pub type BasicBlockIndex = u32 ;
1821pub type LocalIndex = u32 ;
22+ pub type VariantIndex = u32 ;
23+ pub type PromotedIndex = u32 ;
1924
2025/// A mirror of the compiler's notion of a "definition ID".
2126#[ derive( Serialize , Deserialize , PartialEq , Eq , Debug , Clone ) ]
@@ -93,7 +98,8 @@ impl Display for BasicBlock {
9398pub enum Statement {
9499 Nop ,
95100 Assign ( Place , Rvalue ) ,
96- Unimplemented , // FIXME
101+ SetDiscriminant ( Place , VariantIndex ) ,
102+ Unimplemented ,
97103}
98104
99105impl Display for Statement {
@@ -102,19 +108,112 @@ impl Display for Statement {
102108 }
103109}
104110
111+ /// A place for storing things.
105112#[ derive( Serialize , Deserialize , PartialEq , Eq , Debug , Clone ) ]
106113pub enum Place {
114+ Base ( PlaceBase ) ,
115+ Projection ( PlaceProjection ) ,
116+ }
117+
118+ /// The "base" of a place projection.
119+ #[ derive( Serialize , Deserialize , PartialEq , Eq , Debug , Clone ) ]
120+ pub enum PlaceBase {
107121 Local ( LocalIndex ) ,
108- Unimplemented , // FIXME
122+ Static ( DefId ) ,
123+ Promoted ( PromotedIndex ) ,
109124}
110125
126+ /// A projection (deref, index, field access, ...).
111127#[ derive( Serialize , Deserialize , PartialEq , Eq , Debug , Clone ) ]
112- pub enum Rvalue {
128+ pub struct PlaceProjection {
129+ pub base : Box < Place > ,
130+ pub elem : ProjectionElem < LocalIndex > ,
131+ }
132+
133+ /// Describes a projection operation upon a projection base.
134+ #[ derive( Serialize , Deserialize , PartialEq , Eq , Debug , Clone ) ]
135+ pub enum ProjectionElem < V > {
136+ Unimplemented ( PhantomData < V > ) , // FIXME
137+ }
138+
139+ #[ derive( Serialize , Deserialize , PartialEq , Eq , Debug , Clone ) ]
140+ pub enum Operand {
141+ /// In MIR this is either Move or Copy.
113142 Place ( Place ) ,
114- Phi ( Vec < Place > ) ,
143+ Unimplemented , // FIXME constants
144+ }
145+
146+ /// Borrow descriptions.
147+ #[ derive( Serialize , Deserialize , PartialEq , Eq , Debug , Clone ) ]
148+ pub enum BorrowKind {
149+ Shared ,
150+ Shallow ,
151+ Unique ,
152+ Mut , // FIXME two_phase borrow.
153+ }
154+
155+ /// Things that can appear on the right-hand side of an assignment.
156+ #[ derive( Serialize , Deserialize , PartialEq , Eq , Debug , Clone ) ]
157+ pub enum Rvalue {
158+ Use ( Operand ) ,
159+ Repeat ( Operand , u64 ) ,
160+ Ref ( BorrowKind , Place ) , // We do not store the region.
161+ Len ( Place ) ,
162+ BinaryOp ( BinOp , Operand , Operand ) ,
163+ CheckedBinaryOp ( BinOp , Operand , Operand ) ,
164+ NullaryOp ( NullOp ) ,
165+ UnaryOp ( UnOp , Operand ) ,
166+ Discriminant ( Place ) ,
167+ Aggregate ( AggregateKind , Vec < Operand > ) ,
115168 Unimplemented , // FIXME
116169}
117170
171+ /// Kinds of aggregate types.
172+ #[ derive( Serialize , Deserialize , PartialEq , Eq , Debug , Clone ) ]
173+ pub enum AggregateKind {
174+ Array ,
175+ Tuple ,
176+ Closure ( DefId ) ,
177+ Generator ( DefId ) ,
178+ Unimplemented ,
179+ }
180+
181+ /// Binary operations.
182+ #[ derive( Serialize , Deserialize , PartialEq , Eq , Debug , Clone ) ]
183+ pub enum BinOp {
184+ Add ,
185+ Sub ,
186+ Mul ,
187+ Div ,
188+ Rem ,
189+ BitXor ,
190+ BitAnd ,
191+ BitOr ,
192+ Shl ,
193+ Shr ,
194+ Eq ,
195+ Lt ,
196+ Le ,
197+ Ne ,
198+ Ge ,
199+ Gt ,
200+ Offset ,
201+ }
202+
203+ // Operations with no arguments.
204+ #[ derive( Serialize , Deserialize , PartialEq , Eq , Debug , Clone ) ]
205+ pub enum NullOp {
206+ SizeOf ,
207+ Box ,
208+ }
209+
210+ // Unary operations.
211+ #[ derive( Serialize , Deserialize , PartialEq , Eq , Debug , Clone ) ]
212+ pub enum UnOp {
213+ Not ,
214+ Neg ,
215+ }
216+
118217/// A call target.
119218#[ derive( Serialize , Deserialize , PartialEq , Eq , Debug , Clone ) ]
120219pub enum CallOperand {
0 commit comments