@@ -93,20 +93,26 @@ fn rustc_statement_to_statement(
9393 }
9494}
9595
96- fn rustc_rvalue_to_rvalue ( rvalue : & rustc_middle:: mir:: Rvalue < ' _ > ) -> stable_mir:: mir:: Operand {
96+ fn rustc_rvalue_to_rvalue ( rvalue : & rustc_middle:: mir:: Rvalue < ' _ > ) -> stable_mir:: mir:: Rvalue {
9797 use rustc_middle:: mir:: Rvalue :: * ;
9898 match rvalue {
99- Use ( op) => rustc_op_to_op ( op) ,
99+ Use ( op) => stable_mir :: mir :: Rvalue :: Use ( rustc_op_to_op ( op) ) ,
100100 Repeat ( _, _) => todo ! ( ) ,
101101 Ref ( _, _, _) => todo ! ( ) ,
102102 ThreadLocalRef ( _) => todo ! ( ) ,
103103 AddressOf ( _, _) => todo ! ( ) ,
104104 Len ( _) => todo ! ( ) ,
105105 Cast ( _, _, _) => todo ! ( ) ,
106106 BinaryOp ( _, _) => todo ! ( ) ,
107- CheckedBinaryOp ( _, _) => todo ! ( ) ,
107+ CheckedBinaryOp ( bin_op, ops) => stable_mir:: mir:: Rvalue :: CheckedBinaryOp (
108+ rustc_bin_op_to_bin_op ( bin_op) ,
109+ rustc_op_to_op ( & ops. 0 ) ,
110+ rustc_op_to_op ( & ops. 1 ) ,
111+ ) ,
108112 NullaryOp ( _, _) => todo ! ( ) ,
109- UnaryOp ( _, _) => todo ! ( ) ,
113+ UnaryOp ( un_op, op) => {
114+ stable_mir:: mir:: Rvalue :: UnaryOp ( rustc_un_op_to_un_op ( un_op) , rustc_op_to_op ( op) )
115+ }
110116 Discriminant ( _) => todo ! ( ) ,
111117 Aggregate ( _, _) => todo ! ( ) ,
112118 ShallowInitBox ( _, _) => todo ! ( ) ,
@@ -124,8 +130,10 @@ fn rustc_op_to_op(op: &rustc_middle::mir::Operand<'_>) -> stable_mir::mir::Opera
124130}
125131
126132fn rustc_place_to_place ( place : & rustc_middle:: mir:: Place < ' _ > ) -> stable_mir:: mir:: Place {
127- assert_eq ! ( & place. projection[ ..] , & [ ] ) ;
128- stable_mir:: mir:: Place { local : place. local . as_usize ( ) }
133+ stable_mir:: mir:: Place {
134+ local : place. local . as_usize ( ) ,
135+ projection : format ! ( "{:?}" , place. projection) ,
136+ }
129137}
130138
131139fn rustc_unwind_to_unwind (
@@ -140,6 +148,96 @@ fn rustc_unwind_to_unwind(
140148 }
141149}
142150
151+ fn rustc_assert_msg_to_msg < ' tcx > (
152+ assert_message : & rustc_middle:: mir:: AssertMessage < ' tcx > ,
153+ ) -> stable_mir:: mir:: AssertMessage {
154+ use rustc_middle:: mir:: AssertKind ;
155+ match assert_message {
156+ AssertKind :: BoundsCheck { len, index } => stable_mir:: mir:: AssertMessage :: BoundsCheck {
157+ len : rustc_op_to_op ( len) ,
158+ index : rustc_op_to_op ( index) ,
159+ } ,
160+ AssertKind :: Overflow ( bin_op, op1, op2) => stable_mir:: mir:: AssertMessage :: Overflow (
161+ rustc_bin_op_to_bin_op ( bin_op) ,
162+ rustc_op_to_op ( op1) ,
163+ rustc_op_to_op ( op2) ,
164+ ) ,
165+ AssertKind :: OverflowNeg ( op) => {
166+ stable_mir:: mir:: AssertMessage :: OverflowNeg ( rustc_op_to_op ( op) )
167+ }
168+ AssertKind :: DivisionByZero ( op) => {
169+ stable_mir:: mir:: AssertMessage :: DivisionByZero ( rustc_op_to_op ( op) )
170+ }
171+ AssertKind :: RemainderByZero ( op) => {
172+ stable_mir:: mir:: AssertMessage :: RemainderByZero ( rustc_op_to_op ( op) )
173+ }
174+ AssertKind :: ResumedAfterReturn ( generator) => {
175+ stable_mir:: mir:: AssertMessage :: ResumedAfterReturn ( rustc_generator_to_generator (
176+ generator,
177+ ) )
178+ }
179+ AssertKind :: ResumedAfterPanic ( generator) => {
180+ stable_mir:: mir:: AssertMessage :: ResumedAfterPanic ( rustc_generator_to_generator (
181+ generator,
182+ ) )
183+ }
184+ AssertKind :: MisalignedPointerDereference { required, found } => {
185+ stable_mir:: mir:: AssertMessage :: MisalignedPointerDereference {
186+ required : rustc_op_to_op ( required) ,
187+ found : rustc_op_to_op ( found) ,
188+ }
189+ }
190+ }
191+ }
192+
193+ fn rustc_bin_op_to_bin_op ( bin_op : & rustc_middle:: mir:: BinOp ) -> stable_mir:: mir:: BinOp {
194+ use rustc_middle:: mir:: BinOp ;
195+ match bin_op {
196+ BinOp :: Add => stable_mir:: mir:: BinOp :: Add ,
197+ BinOp :: Sub => stable_mir:: mir:: BinOp :: Sub ,
198+ BinOp :: Mul => stable_mir:: mir:: BinOp :: Mul ,
199+ BinOp :: Div => stable_mir:: mir:: BinOp :: Div ,
200+ BinOp :: Rem => stable_mir:: mir:: BinOp :: Rem ,
201+ BinOp :: BitXor => stable_mir:: mir:: BinOp :: BitXor ,
202+ BinOp :: BitAnd => stable_mir:: mir:: BinOp :: BitAnd ,
203+ BinOp :: BitOr => stable_mir:: mir:: BinOp :: BitOr ,
204+ BinOp :: Shl => stable_mir:: mir:: BinOp :: Shl ,
205+ BinOp :: Shr => stable_mir:: mir:: BinOp :: Shr ,
206+ BinOp :: Eq => stable_mir:: mir:: BinOp :: Eq ,
207+ BinOp :: Lt => stable_mir:: mir:: BinOp :: Lt ,
208+ BinOp :: Le => stable_mir:: mir:: BinOp :: Le ,
209+ BinOp :: Ne => stable_mir:: mir:: BinOp :: Ne ,
210+ BinOp :: Ge => stable_mir:: mir:: BinOp :: Ge ,
211+ BinOp :: Gt => stable_mir:: mir:: BinOp :: Gt ,
212+ BinOp :: Offset => stable_mir:: mir:: BinOp :: Offset ,
213+ }
214+ }
215+
216+ fn rustc_un_op_to_un_op ( unary_op : & rustc_middle:: mir:: UnOp ) -> stable_mir:: mir:: UnOp {
217+ use rustc_middle:: mir:: UnOp ;
218+ match unary_op {
219+ UnOp :: Not => stable_mir:: mir:: UnOp :: Not ,
220+ UnOp :: Neg => stable_mir:: mir:: UnOp :: Neg ,
221+ }
222+ }
223+
224+ fn rustc_generator_to_generator (
225+ generator : & rustc_hir:: GeneratorKind ,
226+ ) -> stable_mir:: mir:: GeneratorKind {
227+ use rustc_hir:: { AsyncGeneratorKind , GeneratorKind } ;
228+ match generator {
229+ GeneratorKind :: Async ( async_gen) => {
230+ let async_gen = match async_gen {
231+ AsyncGeneratorKind :: Block => stable_mir:: mir:: AsyncGeneratorKind :: Block ,
232+ AsyncGeneratorKind :: Closure => stable_mir:: mir:: AsyncGeneratorKind :: Closure ,
233+ AsyncGeneratorKind :: Fn => stable_mir:: mir:: AsyncGeneratorKind :: Fn ,
234+ } ;
235+ stable_mir:: mir:: GeneratorKind :: Async ( async_gen)
236+ }
237+ GeneratorKind :: Gen => stable_mir:: mir:: GeneratorKind :: Gen ,
238+ }
239+ }
240+
143241fn rustc_terminator_to_terminator (
144242 terminator : & rustc_middle:: mir:: Terminator < ' _ > ,
145243) -> stable_mir:: mir:: Terminator {
@@ -162,7 +260,11 @@ fn rustc_terminator_to_terminator(
162260 Terminate => Terminator :: Abort ,
163261 Return => Terminator :: Return ,
164262 Unreachable => Terminator :: Unreachable ,
165- Drop { .. } => todo ! ( ) ,
263+ Drop { place, target, unwind } => Terminator :: Drop {
264+ place : rustc_place_to_place ( place) ,
265+ target : target. as_usize ( ) ,
266+ unwind : rustc_unwind_to_unwind ( unwind) ,
267+ } ,
166268 Call { func, args, destination, target, unwind, from_hir_call : _, fn_span : _ } => {
167269 Terminator :: Call {
168270 func : rustc_op_to_op ( func) ,
@@ -172,9 +274,15 @@ fn rustc_terminator_to_terminator(
172274 unwind : rustc_unwind_to_unwind ( unwind) ,
173275 }
174276 }
175- Assert { .. } => todo ! ( ) ,
277+ Assert { cond, expected, msg, target, unwind } => Terminator :: Assert {
278+ cond : rustc_op_to_op ( cond) ,
279+ expected : * expected,
280+ msg : rustc_assert_msg_to_msg ( msg) ,
281+ target : target. as_usize ( ) ,
282+ unwind : rustc_unwind_to_unwind ( unwind) ,
283+ } ,
176284 Yield { .. } => todo ! ( ) ,
177- GeneratorDrop => todo ! ( ) ,
285+ GeneratorDrop => Terminator :: GeneratorDrop ,
178286 FalseEdge { .. } => todo ! ( ) ,
179287 FalseUnwind { .. } => todo ! ( ) ,
180288 InlineAsm { .. } => todo ! ( ) ,
0 commit comments