GitLab will be upgraded on 30 Jan 2023 from 2.00 pm (AEDT) to 3.00 pm (AEDT). During the update, GitLab and Mattermost services will not be available. If you have any concerns with this, please talk to us at N110 (b) CSIT building.

inst.rs 61.2 KB
Newer Older
Isaac Oscar Gariano's avatar
Isaac Oscar Gariano committed
1
// Copyright 2017 The Australian National University
2
//
Isaac Oscar Gariano's avatar
Isaac Oscar Gariano committed
3
4
5
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
6
//
Isaac Oscar Gariano's avatar
Isaac Oscar Gariano committed
7
//     http://www.apache.org/licenses/LICENSE-2.0
8
//
Isaac Oscar Gariano's avatar
Isaac Oscar Gariano committed
9
10
11
12
13
14
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

qinsoon's avatar
qinsoon committed
15
use ir::*;
16
use op::*;
qinsoon's avatar
qinsoon committed
17
18
19
use ptr::*;
use types::*;

20
use utils::vec_utils;
21
22
23

use std::fmt;

24
/// Instruction represents a Mu instruction
25
#[derive(Debug, Clone)] // this implements Display
26
pub struct Instruction {
qinsoon's avatar
qinsoon committed
27
    pub hdr: MuEntityHeader,
28
    /// the values this instruction holds
qinsoon's avatar
qinsoon committed
29
    pub value: Option<Vec<P<Value>>>,
30
31
    /// ops field list all the children nodes,
    /// and in Instruction_, the children nodes are referred by indices
32
33
    /// This design makes it easy for the compiler to iterate through all the
    /// children
qinsoon's avatar
qinsoon committed
34
    pub ops: Vec<P<TreeNode>>,
35
    /// used for pattern matching
36
    pub v: Instruction_
37
38
}

39
// Instruction implements MuEntity
qinsoon's avatar
qinsoon committed
40
41
impl_mu_entity!(Instruction);

42
impl Instruction {
43
44
45
46
47
48
49
    pub fn clone_with_id(&self, new_id: MuID) -> Instruction {
        let mut clone = self.clone();
        clone.hdr = self.hdr.clone_with_id(new_id);

        clone
    }

50
51
    // RTMU add new rt instructions to various spec functions here

qinsoon's avatar
qinsoon committed
52
    /// is this instruction the terminal inst of its block?
53
54
    /// Terminal instructions end Mu blocks, and Mu block ends with a terminal
    /// instruction.
55
56
57
58
    pub fn is_terminal_inst(&self) -> bool {
        use inst::Instruction_::*;

        match self.v {
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
            Return(_)
            | ThreadExit
            | Throw(_)
            | TailCall(_)
            | Branch1(_)
            | Branch2 { .. }
            | Watchpoint { .. }
            | WPBranch { .. }
            | Call { .. }
            | CCall { .. }
            | SwapStackExc { .. }
            | SwapStackKill { .. }
            | Switch { .. }
            | ExnInstruction { .. } => true,
            BinOp(_, _, _)
            | BinOpWithStatus(_, _, _, _)
            | CmpOp(_, _, _)
            | ConvOp { .. }
            | ExprCall { .. }
            | ExprCCall { .. }
            | Load { .. }
            | Store { .. }
            | CmpXchg { .. }
            | AtomicRMW { .. }
            | New(_)
            | AllocA(_)
            | NewHybrid(_, _)
            | AllocAHybrid(_, _)
            | NewStack(_)
            | NewThread { .. }
89
            | NewRTThread { .. }
Javad Ebrahimian Amiri's avatar
Javad Ebrahimian Amiri committed
90
91
            | NewFutex
            | DeleteFutex(_)
92
            | LockFutex(_,_)
Javad Ebrahimian Amiri's avatar
Javad Ebrahimian Amiri committed
93
            | UnlockFutex(_)
94
            | AllocAU(_)
95
            | AllocAUHybrid(_,_)
96
97
98
99
100
101
102
            | NewReg(_)
            | DeleteReg(_)
            | rAlloc(_, _)
            | rAllocHybrid(_, _, _)
            | eAlloc(_)
            | eAllocHybrid(_, _)
            | eDelete(_)
103
            | NotifyThread(_)       // TODO remove - not needed anymore
104
105
106
107
108
            | ThreadSetPriority(_,_)
            | ThreadGetPriority(_)
            | ThreadSetCPU(_,_)
            | ThreadClearCPU(_,_)
            | ThreadIssetCPU(_,_)
109
110
            | GetTime
            | SetTime(_)
Javad Ebrahimian Amiri's avatar
Javad Ebrahimian Amiri committed
111
            | NewTimer
112
            | SetTimer { .. }
Javad Ebrahimian Amiri's avatar
Javad Ebrahimian Amiri committed
113
114
115
            | CancelTimer(_)
            | DeleteTimer(_)
            | Sleep(_)
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
            | NewAttr
            | DeleteAttr(_)
            | ThreadSetAttr(_,_)
            | ThreadGetAttr(_)
            | AttrClearCPU(_,_)
            | AttrIssetCPU(_,_)
            | AttrSetCPU(_,_)
            | AttrZeroCPU(_)
            | AttrSetPriority(_,_)
            | AttrGetPriority(_)
            | eAllocPA(_,_)
            | eAllocHybridPA(_,_,_)
            | BindObject(_)
            | UnbindObject(_)
            | NewRegionPA(_,_)
            | BindRegion(_)
            | UnbindRegion(_)
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
            | NewFrameCursor(_)
            | GetIRef(_)
            | GetFieldIRef { .. }
            | GetElementIRef { .. }
            | ShiftIRef { .. }
            | GetVarPartIRef { .. }
            | Select { .. }
            | Fence(_)
            | CommonInst_GetThreadLocal
            | CommonInst_SetThreadLocal(_)
            | CommonInst_Pin(_)
            | CommonInst_Unpin(_)
            | CommonInst_GetAddr(_)
            | CommonInst_Tr64IsFp(_)
            | CommonInst_Tr64IsInt(_)
            | CommonInst_Tr64IsRef(_)
            | CommonInst_Tr64FromFp(_)
            | CommonInst_Tr64FromInt(_)
            | CommonInst_Tr64FromRef(_, _)
            | CommonInst_Tr64ToFp(_)
            | CommonInst_Tr64ToInt(_)
            | CommonInst_Tr64ToRef(_)
            | CommonInst_Tr64ToTag(_)
            | Move(_)
            | PrintHex(_)
158
            | PrintBool(_)
159
            | PrintTime(_)
160
161
162
163
            | SetRetval(_)
            | GetVMThreadLocal
            | KillStack(_)
            | CurrentStack
164
165
            | RandF(_,_)
            | RandI(_,_)
166
            | SwapStackExpr { .. } => false,
167
168
169
        }
    }

qinsoon's avatar
qinsoon committed
170
    /// is this instruction a non-terminal instruction of its block?
171
172
173
174
    pub fn is_non_terminal_inst(&self) -> bool {
        !self.is_terminal_inst()
    }

qinsoon's avatar
qinsoon committed
175
    /// does this instruction has side effect?
176
177
    /// An instruction has side effect if it affects something other than its
    /// result operands. e.g. affecting memory, stack, thread, etc.
178
179
180
181
182
    // FIXME: need to check correctness
    pub fn has_side_effect(&self) -> bool {
        use inst::Instruction_::*;

        match self.v {
183
184
185
186
187
188
189
190
191
192
            ExprCall { .. }
            | ExprCCall { .. }
            | Load { .. }
            | Store { .. }
            | CmpXchg { .. }
            | AtomicRMW { .. }
            | New(_)
            | AllocA(_)
            | NewHybrid(_, _)
            | AllocAHybrid(_, _)
193
            | AllocAU(_)
194
            | AllocAUHybrid(_,_)
195
196
197
198
199
200
201
            | NewReg(_)
            | DeleteReg(_)
            | rAlloc(_, _)
            | rAllocHybrid(_,_,_)
            | eAlloc(_)
            | eAllocHybrid(_,_)
            | eDelete(_)
202
203
            | NewStack(_)
            | NewThread { .. }
204
            | NewRTThread { .. }
Javad Ebrahimian Amiri's avatar
Javad Ebrahimian Amiri committed
205
206
            | NewFutex
            | DeleteFutex(_)
207
            | LockFutex(_,_)
Javad Ebrahimian Amiri's avatar
Javad Ebrahimian Amiri committed
208
            | UnlockFutex(_)
209
            | NotifyThread(_)
210
211
212
            | ThreadSetPriority(_, _)
            | ThreadClearCPU(_, _)
            | ThreadSetCPU(_, _)
213
214
//            | AffinityZero(_)
            | SetTime(_)
Javad Ebrahimian Amiri's avatar
Javad Ebrahimian Amiri committed
215
            | NewTimer
216
            | SetTimer { .. }
Javad Ebrahimian Amiri's avatar
Javad Ebrahimian Amiri committed
217
218
219
            | CancelTimer(_)
            | DeleteTimer(_)
            | Sleep(_)
220
221
222
223
224
225
226
227
228
229
230
231
232
233
            | NewAttr
            | DeleteAttr(_)
            | ThreadSetAttr(_,_)
            | AttrClearCPU(_,_)
            | AttrSetCPU(_,_)
            | AttrZeroCPU(_)
            | AttrSetPriority(_,_)
            | eAllocPA(_,_)
            | eAllocHybridPA(_,_,_)
            | BindObject(_)
            | UnbindObject(_)
            | NewRegionPA(_,_)
            | BindRegion(_)
            | UnbindRegion(_)
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
            | NewFrameCursor(_)
            | Fence(_)
            | Return(_)
            | ThreadExit
            | Throw(_)
            | TailCall(_)
            | Branch1(_)
            | Branch2 { .. }
            | Watchpoint { .. }
            | WPBranch { .. }
            | Call { .. }
            | CCall { .. }
            | SwapStackExpr { .. }
            | SwapStackExc { .. }
            | SwapStackKill { .. }
            | Switch { .. }
            | ExnInstruction { .. }
            | CommonInst_GetThreadLocal
            | CommonInst_SetThreadLocal(_)
            | CommonInst_Pin(_)
            | CommonInst_Unpin(_)
            | CommonInst_GetAddr(_)
            | PrintHex(_)
257
            | PrintBool(_)
258
            | PrintTime(_)
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
            | SetRetval(_)
            | KillStack(_) => true,
            BinOp(_, _, _)
            | BinOpWithStatus(_, _, _, _)
            | CmpOp(_, _, _)
            | ConvOp { .. }
            | GetIRef(_)
            | GetFieldIRef { .. }
            | GetElementIRef { .. }
            | ShiftIRef { .. }
            | GetVarPartIRef { .. }
            | Select { .. }
            | CommonInst_Tr64IsFp(_)
            | CommonInst_Tr64IsInt(_)
            | CommonInst_Tr64IsRef(_)
            | CommonInst_Tr64FromFp(_)
            | CommonInst_Tr64FromInt(_)
            | CommonInst_Tr64FromRef(_, _)
            | CommonInst_Tr64ToFp(_)
            | CommonInst_Tr64ToInt(_)
            | CommonInst_Tr64ToRef(_)
            | CommonInst_Tr64ToTag(_)
            | Move(_)
            | CurrentStack
283
            | GetVMThreadLocal
284
            | ThreadGetPriority(_)
285
            | GetTime
286
287
288
            | ThreadGetAttr(_)
            | AttrIssetCPU(_,_)
            | AttrGetPriority(_)
289
290
            | RandF(_,_)
            | RandI(_,_)
291
            | ThreadIssetCPU(_, _) => false,
292
//            | AffinityEqual(_, _)
293
294
295
        }
    }

qinsoon's avatar
qinsoon committed
296
297
    /// can this instruction throw exception?
    /// an instruction with an exceptional branch can throw exception
298
299
300
301
    pub fn is_potentially_excepting_instruction(&self) -> bool {
        use inst::Instruction_::*;

        match self.v {
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
            Watchpoint { .. }
            | Call { .. }
            | CCall { .. }
            | SwapStackExc { .. }
            | ExnInstruction { .. } => true,
            BinOp(_, _, _)
            | BinOpWithStatus(_, _, _, _)
            | CmpOp(_, _, _)
            | ConvOp { .. }
            | ExprCall { .. }
            | ExprCCall { .. }
            | Load { .. }
            | Store { .. }
            | CmpXchg { .. }
            | AtomicRMW { .. }
            | New(_)
            | AllocA(_)
            | NewHybrid(_, _)
            | AllocAHybrid(_, _)
            | NewStack(_)
322
            | AllocAU(_)
323
            | AllocAUHybrid(_, _)
324
325
326
            | NewReg(_)
            | DeleteReg(_)
            | rAlloc(_, _)
327
            | rAllocHybrid(_, _, _)
328
            | eAlloc(_)
329
            | eAllocHybrid(_, _)
330
            | eDelete(_)
331
            | NewThread { .. }
332
            | NewRTThread { .. }
Javad Ebrahimian Amiri's avatar
Javad Ebrahimian Amiri committed
333
334
            | NewFutex
            | DeleteFutex(_)
335
            | LockFutex(_, _)
Javad Ebrahimian Amiri's avatar
Javad Ebrahimian Amiri committed
336
            | UnlockFutex(_)
337
            | NotifyThread(_)
338
339
340
341
342
            | ThreadSetPriority(_, _)
            | ThreadGetPriority(_)
            | ThreadClearCPU(_, _)
            | ThreadSetCPU(_, _)
            | ThreadIssetCPU(_, _)
343
344
            | GetTime
            | SetTime(_)
Javad Ebrahimian Amiri's avatar
Javad Ebrahimian Amiri committed
345
            | NewTimer
346
            | SetTimer { .. }
Javad Ebrahimian Amiri's avatar
Javad Ebrahimian Amiri committed
347
348
349
            | CancelTimer(_)
            | DeleteTimer(_)
            | Sleep(_)
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
            | NewAttr
            | DeleteAttr(_)
            | ThreadSetAttr(_, _)
            | ThreadGetAttr(_)
            | AttrClearCPU(_, _)
            | AttrIssetCPU(_, _)
            | AttrSetCPU(_, _)
            | AttrZeroCPU(_)
            | AttrSetPriority(_, _)
            | AttrGetPriority(_)
            | eAllocPA(_, _)
            | eAllocHybridPA(_, _, _)
            | BindObject(_)
            | UnbindObject(_)
            | NewRegionPA(_, _)
            | BindRegion(_)
            | UnbindRegion(_)
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
            | NewFrameCursor(_)
            | GetIRef(_)
            | GetFieldIRef { .. }
            | GetElementIRef { .. }
            | ShiftIRef { .. }
            | GetVarPartIRef { .. }
            | Fence(_)
            | Return(_)
            | ThreadExit
            | Throw(_)
            | TailCall(_)
            | Branch1(_)
            | Branch2 { .. }
            | Select { .. }
            | WPBranch { .. }
            | Switch { .. }
            | CommonInst_GetThreadLocal
            | CommonInst_SetThreadLocal(_)
            | CommonInst_Pin(_)
            | CommonInst_Unpin(_)
            | CommonInst_GetAddr(_)
            | CommonInst_Tr64IsFp(_)
            | CommonInst_Tr64IsInt(_)
            | CommonInst_Tr64IsRef(_)
            | CommonInst_Tr64FromFp(_)
            | CommonInst_Tr64FromInt(_)
            | CommonInst_Tr64FromRef(_, _)
            | CommonInst_Tr64ToFp(_)
            | CommonInst_Tr64ToInt(_)
            | CommonInst_Tr64ToRef(_)
            | CommonInst_Tr64ToTag(_)
            | Move(_)
            | PrintHex(_)
400
            | PrintBool(_)
401
            | PrintTime(_)
402
403
404
405
            | SetRetval(_)
            | GetVMThreadLocal
            | KillStack(_)
            | CurrentStack
406
407
            | RandI(_, _)
            | RandF(_, _)
408
            | SwapStackExpr { .. }
409
            | SwapStackKill { .. } => false
410
411
412
        }
    }

qinsoon's avatar
qinsoon committed
413
    /// does this instruction have an exceptional clause/branch?
414
    pub fn has_exception_clause(&self) -> bool {
415
        self.is_potentially_excepting_instruction()
416
417
    }

qinsoon's avatar
qinsoon committed
418
419
    /// returns exception target(block ID),
    /// returns None if this instruction does not have exceptional branch
420
421
422
    pub fn get_exception_target(&self) -> Option<MuID> {
        use inst::Instruction_::*;
        match self.v {
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
            Watchpoint { ref resume, .. }
            | Call { ref resume, .. }
            | CCall { ref resume, .. }
            | SwapStackExc { ref resume, .. }
            | ExnInstruction { ref resume, .. } => Some(resume.exn_dest.target.id()),
            BinOp(_, _, _)
            | BinOpWithStatus(_, _, _, _)
            | CmpOp(_, _, _)
            | ConvOp { .. }
            | ExprCall { .. }
            | ExprCCall { .. }
            | Load { .. }
            | Store { .. }
            | CmpXchg { .. }
            | AtomicRMW { .. }
            | New(_)
            | AllocA(_)
            | NewHybrid(_, _)
441
            | AllocAU(_)
442
            | AllocAUHybrid(_,_)
443
444
445
446
447
448
449
450
451
452
            | NewReg(_)
            | DeleteReg(_)
            | rAlloc(_, _)
            | rAllocHybrid(_,_,_)
//            | rAllocT(_)
            | eAlloc(_)
            | eAllocHybrid(_,_)
//            | eAllocT(_)
            | eDelete(_)
//            | eDeleteT(_)
453
454
455
            | AllocAHybrid(_, _)
            | NewStack(_)
            | NewThread { .. }
456
            | NewRTThread { .. }
Javad Ebrahimian Amiri's avatar
Javad Ebrahimian Amiri committed
457
458
            | NewFutex
            | DeleteFutex(_)
459
            | LockFutex(_,_)
Javad Ebrahimian Amiri's avatar
Javad Ebrahimian Amiri committed
460
            | UnlockFutex(_)
461
            | NotifyThread(_)
462
463
464
            | ThreadSetPriority(_,_)  // FIXME - Not sure about these
            | ThreadGetPriority(_)
            | ThreadClearCPU(_,_)
465
//            | AffinityEqual(_,_)
466
467
            | ThreadIssetCPU(_,_)
            | ThreadSetCPU(_,_)
468
469
470
//            | AffinityZero(_)
            | SetTime(_)
            | GetTime
Javad Ebrahimian Amiri's avatar
Javad Ebrahimian Amiri committed
471
            | NewTimer
472
            | SetTimer { .. }
Javad Ebrahimian Amiri's avatar
Javad Ebrahimian Amiri committed
473
474
475
            | CancelTimer(_)
            | DeleteTimer(_)
            | Sleep(_)
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
            | NewAttr
            | DeleteAttr(_)
            | ThreadSetAttr(_,_)
            | ThreadGetAttr(_)
            | AttrClearCPU(_,_)
            | AttrIssetCPU(_,_)
            | AttrSetCPU(_,_)
            | AttrZeroCPU(_)
            | AttrSetPriority(_,_)
            | AttrGetPriority(_)
            | eAllocPA(_,_)
            | eAllocHybridPA(_,_,_)
            | BindObject(_)
            | UnbindObject(_)
            | NewRegionPA(_,_)
            | BindRegion(_)
            | UnbindRegion(_)
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
            | NewFrameCursor(_)
            | GetIRef(_)
            | GetFieldIRef { .. }
            | GetElementIRef { .. }
            | ShiftIRef { .. }
            | GetVarPartIRef { .. }
            | Fence(_)
            | Return(_)
            | ThreadExit
            | Throw(_)
            | TailCall(_)
            | Branch1(_)
            | Branch2 { .. }
            | Select { .. }
            | WPBranch { .. }
            | Switch { .. }
            | CommonInst_GetThreadLocal
            | CommonInst_SetThreadLocal(_)
            | CommonInst_Pin(_)
            | CommonInst_Unpin(_)
            | CommonInst_GetAddr(_)
            | CommonInst_Tr64IsFp(_)
            | CommonInst_Tr64IsInt(_)
            | CommonInst_Tr64IsRef(_)
            | CommonInst_Tr64FromFp(_)
            | CommonInst_Tr64FromInt(_)
            | CommonInst_Tr64FromRef(_, _)
            | CommonInst_Tr64ToFp(_)
            | CommonInst_Tr64ToInt(_)
            | CommonInst_Tr64ToRef(_)
            | CommonInst_Tr64ToTag(_)
            | Move(_)
            | PrintHex(_)
526
            | PrintBool(_)
527
            | PrintTime(_)
528
529
530
531
            | SetRetval(_)
            | GetVMThreadLocal
            | KillStack(_)
            | CurrentStack
532
533
            | RandF(_,_)
            | RandI(_,_)
534
535
            | SwapStackExpr { .. }
            | SwapStackKill { .. } => None,
536
537
538
        }
    }

539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
    /// can this instruction throw exception?
    /// (whether or not it containjs a ctach for it)
    pub fn is_potentially_throwing(&self) -> bool {
        use inst::Instruction_::*;

        match self.v {
            // Note: commented out ones are ones where we haven't implemented exceptions yet
            Watchpoint { .. } |
            Call { .. } |
            CCall { .. } |
            SwapStackExc { .. } |
            SwapStackExpr { .. } |
            ExnInstruction { .. } |
            ExprCall { .. } |
            ExprCCall { .. } |
            //Load { .. } |
            //Store { .. } |
            //CmpXchg { .. } |
            //AtomicRMW { .. } |
            //New(_) |
            //NewHybrid(_, _) |
            Throw(_)  => true,

            // BinOp(op, _, _) |
            // BinOpWithStatus(op, _, _, _) if op.may_throw() => true,
            BinOp(_, _, _) |
            BinOpWithStatus(_, _, _, _) |
            CmpOp(_, _, _) |
            ConvOp { .. } |
            AllocA(_) |
            AllocAHybrid(_, _) |
            NewStack(_) |
            NewThread { .. } |
572
            NewRTThread { .. } |
Javad Ebrahimian Amiri's avatar
Javad Ebrahimian Amiri committed
573
574
            NewFutex
            | DeleteFutex(_)
575
            | LockFutex(_,_)
Javad Ebrahimian Amiri's avatar
Javad Ebrahimian Amiri committed
576
577
            | UnlockFutex(_)
            | NotifyThread(_) |
578
            ThreadSetPriority(_,_) |
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
            NewFrameCursor(_) |
            GetIRef(_) |
            GetFieldIRef { .. } |
            GetElementIRef { .. } |
            ShiftIRef { .. } |
            GetVarPartIRef { .. } |
            Fence(_) |
            Return(_) |
            ThreadExit |
            TailCall(_) |
            Branch1(_) |
            Branch2 { .. } |
            Select { .. } |
            WPBranch { .. } |
            Switch { .. } |
            CommonInst_GetThreadLocal |
            CommonInst_SetThreadLocal(_) |
            CommonInst_Pin(_) |
            CommonInst_Unpin(_) |
            CommonInst_GetAddr(_) |
            CommonInst_Tr64IsFp(_) |
            CommonInst_Tr64IsInt(_) |
            CommonInst_Tr64IsRef(_) |
            CommonInst_Tr64FromFp(_) |
            CommonInst_Tr64FromInt(_) |
            CommonInst_Tr64FromRef(_, _) |
            CommonInst_Tr64ToFp(_) |
            CommonInst_Tr64ToInt(_) |
            CommonInst_Tr64ToRef(_) |
            CommonInst_Tr64ToTag(_) |
            Move(_) |
            PrintHex(_) |
611
            PrintBool(_) |
612
            PrintTime(_) |
613
            SetRetval(_) |
qinsoon's avatar
qinsoon committed
614
            GetVMThreadLocal |
615
616
617
618
619
620
621
622
            KillStack(_) |
            CurrentStack |
            SwapStackKill { .. } => false,

            _ => false
        }
    }

623
    fn debug_str(&self, ops: &Vec<P<TreeNode>>) -> String {
Isaac Oscar Gariano's avatar
Isaac Oscar Gariano committed
624
625
626
627
        match &self.v {
            &Instruction_::BinOp(op, op1, op2) => {
                format!("{}<{}> {} {}", op, ops[op1].ty(), ops[op1], ops[op2])
            }
628
629
630
631
632
633
634
635
            &Instruction_::BinOpWithStatus(op, status, op1, op2) => format!(
                "{}{}<{}> {} {}",
                op,
                status,
                ops[op1].ty(),
                ops[op1],
                ops[op2]
            ),
Isaac Oscar Gariano's avatar
Isaac Oscar Gariano committed
636
637
638
639
640
641
642
            &Instruction_::CmpOp(op, op1, op2) => {
                format!("{}<{}> {} {}", op, ops[op1].ty(), ops[op1], ops[op2])
            }
            &Instruction_::ConvOp {
                operation,
                ref from_ty,
                ref to_ty,
643
644
645
646
647
                operand
            } => format!(
                "{} <{} {}> {}",
                operation, from_ty, to_ty, ops[operand]
            ),
Isaac Oscar Gariano's avatar
Isaac Oscar Gariano committed
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
            &Instruction_::ExprCall { ref data, is_abort } => {
                if is_abort {
                    panic!("ABORT is not supported");
                }
                format!("CALL{}", data.debug_str(ops))
            }
            &Instruction_::ExprCCall { ref data, is_abort } => {
                if is_abort {
                    panic!("ABORT is not supported");
                }
                format!("CCALL{}", data.debug_str(ops))
            }
            &Instruction_::Load {
                is_ptr,
                mem_loc,
663
                order
Isaac Oscar Gariano's avatar
Isaac Oscar Gariano committed
664
665
666
667
668
669
670
671
672
673
674
675
676
677
            } => {
                let ptr = select_value!(is_ptr, " PTR", "");
                format!(
                    "LOAD{} {}<{}> {}",
                    ptr,
                    order,
                    ops[mem_loc].ty().get_referent_ty().unwrap(),
                    ops[mem_loc]
                )
            }
            &Instruction_::Store {
                value,
                is_ptr,
                mem_loc,
678
                order
Isaac Oscar Gariano's avatar
Isaac Oscar Gariano committed
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
            } => {
                let ptr = select_value!(is_ptr, " PTR", "");
                format!(
                    "STORE{} {}<{}> {} {}",
                    ptr,
                    order,
                    ops[mem_loc].ty().get_referent_ty().unwrap(),
                    ops[mem_loc],
                    ops[value]
                )
            }
            &Instruction_::CmpXchg {
                is_ptr,
                is_weak,
                success_order,
                fail_order,
                mem_loc,
                expected_value,
697
                desired_value
Isaac Oscar Gariano's avatar
Isaac Oscar Gariano committed
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
            } => {
                let ptr = select_value!(is_ptr, " PTR", "");
                let weak = select_value!(is_weak, " WEAK", "");
                format!(
                    "CMPXCHG{}{} {} {}<{}> {} {} {}",
                    ptr,
                    weak,
                    success_order,
                    fail_order,
                    ops[mem_loc].ty().get_referent_ty().unwrap(),
                    ops[mem_loc],
                    ops[expected_value],
                    ops[desired_value]
                )
            }
            &Instruction_::AtomicRMW {
                is_ptr,
                order,
                op,
                mem_loc,
718
                value
Isaac Oscar Gariano's avatar
Isaac Oscar Gariano committed
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
            } => {
                let ptr = select_value!(is_ptr, " PTR", "");
                format!(
                    "ATOMICRMW{} {} {}<{}> {} {}",
                    ptr,
                    order,
                    op,
                    ops[mem_loc].ty().get_referent_ty().unwrap(),
                    ops[mem_loc],
                    ops[value]
                )
            }
            &Instruction_::New(ref ty) => format!("NEW<{}>", ty),
            &Instruction_::AllocA(ref ty) => format!("ALLOCA<{}>", ty),
            &Instruction_::NewHybrid(ref ty, len) => {
                format!("NEWHYBRID<{} {}> {}", ty, ops[len].ty(), ops[len])
            }
            &Instruction_::AllocAHybrid(ref ty, len) => {
                format!("ALLOCAHYBRID<{} {}> {}", ty, ops[len].ty(), ops[len])
            }
739
740
741
742
743
            &Instruction_::NewStack(func) => format!(
                "COMMINST @uvm.new_stack<[{}]>({})",
                ops[func].ty().get_sig().unwrap(),
                ops[func]
            ),
744
745
746
747
748
749
750
751
752
            &Instruction_::NewReg(size) => {
                format!("COMMINST @uvm.new_region({})", ops[size])
            }
            &Instruction_::DeleteReg(regref) => {
                format!("COMMINST @uvm.delete_region({})", ops[regref])
            }
            &Instruction_::AllocAU(ref ty) => {
                format!("COMMINST @uvm.AllocAU({})", ty.id())
            }
753
754
755
756
757
            &Instruction_::AllocAUHybrid(ref ty, var_len) => format!(
                "COMMINST @uvm.AllocAUHybrid({}, {})",
                ty.id(),
                ops[var_len]
            ),
758
759
760
            &Instruction_::rAlloc(regref, ref ty) => {
                format!("COMMINST @uvm.rAlloc({}, {})", ops[regref], ty.id())
            }
761
762
763
764
765
766
            &Instruction_::rAllocHybrid(regref, ref ty, var_len) => format!(
                "COMMINST @uvm.rAllocHybrid({}, {}, {})",
                ops[regref],
                ty.id(),
                ops[var_len]
            ),
767
768
769
770
771
772
773
            //            &Instruction_::rAllocT(regref, ty) => format!(
            //                "COMMINST @uvm.rAllocT({}, {})",
            //                ops[regref],
            //                ops[ty]
            //            ),
            &Instruction_::eAlloc(ref ty) => {
                format!("COMMINST @uvm.eAlloc({})", ty.id())
774
            }
775
            &Instruction_::eAllocHybrid(ref ty, var_len) => format!(
776
777
778
779
                "COMMINST @uvm.eAllocHybrid({}, {})",
                ty.id(),
                ops[var_len]
            ),
780
781
782
783
784
785
            //            &Instruction_::eAllocT( ty) => format!(
            //                "COMMINST @uvm.eAllocT({})",
            //                ops[ty]
            //            ),
            &Instruction_::eDelete(obj) => {
                format!("COMMINST @uvm.eDelete({})", ops[obj])
786
            }
787
788
789
790
            //            &Instruction_::eDeleteT( obj) => format!(
            //                "COMMINST @uvm.eDeleteT({})",
            //                ops[obj]
            //            ),
Isaac Oscar Gariano's avatar
Isaac Oscar Gariano committed
791
792
793
794
            &Instruction_::NewThread {
                stack,
                thread_local,
                is_exception,
795
                ref args
Isaac Oscar Gariano's avatar
Isaac Oscar Gariano committed
796
            } => {
797
798
                let new_stack_clause =
                    format_new_stack_clause(is_exception, args, ops);
Isaac Oscar Gariano's avatar
Isaac Oscar Gariano committed
799
800
801
802
                let thread_local = thread_local
                    .map(|t| format!(" THREADLOCAL({})", ops[t]))
                    .unwrap_or("".to_string());
                format!(
803
                    "NEWTHREAD {}{} {}",
804
                    ops[stack], thread_local, new_stack_clause,
Isaac Oscar Gariano's avatar
Isaac Oscar Gariano committed
805
                )
806
            }
Javad Ebrahimian Amiri's avatar
Javad Ebrahimian Amiri committed
807
808
809

            &Instruction_::NewFutex => format!("NEWFUTEX"),
            &Instruction_::DeleteFutex(futexref) => {
810
811
812
813
814
                format!("DELETEFUTEX {}", ops[futexref])
            }
            &Instruction_::LockFutex(futexref, timeout) => {
                format!("LockFUTEX ({}, {})", ops[futexref], ops[timeout])
            }
Javad Ebrahimian Amiri's avatar
Javad Ebrahimian Amiri committed
815
            &Instruction_::UnlockFutex(futexref) => {
816
817
                format!("UNLOCKFUTEX {}", ops[futexref])
            }
818
819
820
821
822
823

            &Instruction_::NewRTThread {
                attr,
                stack,
                thread_local,
                is_exception,
824
                ref args
825
            } => {
826
827
                let new_stack_clause =
                    format_new_stack_clause(is_exception, args, ops);
828
829
830
831
832
833
834
                let thread_local = thread_local
                    .map(|t| format!(" THREADLOCAL({})", ops[t]))
                    .unwrap_or("".to_string());
                format!(
                    "NEWRTTHREAD {}, {}, {}, {}",
                    ops[attr], ops[stack], thread_local, new_stack_clause,
                )
835
            }
836

837
838
            &Instruction_::NotifyThread(thread) => {
                format!("COMMINST @uvm.notifythread({})", ops[thread])
839
840
841
            }
            &Instruction_::ThreadSetPriority(thread, priority) => format!(
                "COMMINST @uvm.threadsetpriority({}, {})",
842
843
                ops[thread], ops[priority]
            ),
844
845
            &Instruction_::ThreadGetPriority(thread) => {
                format!("COMMINST @uvm.threadgetpriority({})", ops[thread])
846
            }
847
848
            &Instruction_::ThreadClearCPU(thread, cpu) => format!(
                "COMMINST @uvm.threadclearcpu({}, {})",
849
850
                ops[thread], ops[cpu]
            ),
851
852
            &Instruction_::ThreadSetCPU(thread, cpu) => format!(
                "COMMINST @uvm.threadsetcpu({}, {})",
853
854
                ops[thread], ops[cpu]
            ),
855
856
            &Instruction_::ThreadIssetCPU(thread, cpu) => format!(
                "COMMINST @uvm.threadissetcpu({}, {})",
857
858
                ops[thread], ops[cpu]
            ),
859
860
861
862
863
            &Instruction_::GetTime => format!("COMMINST @uvm.gettime()",),
            &Instruction_::SetTime(time) => {
                format!("COMMINST @uvm.settime({})", ops[time])
            }
            &Instruction_::NewTimer => format!("COMMINST @uvm.newtimer"),
864
865
866
867
868
869
            &Instruction_::SetTimer {
                tmr,
                tm,
                prd,
                ref data
            } => format!(
870
871
                "COMMINST @uvm.settimer({}, {}, {}) ",
                ops[tmr], ops[tm], ops[prd]
872
            ),
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
            &Instruction_::CancelTimer(tmr) => {
                format!("COMMINST @uvm.canceltimer({})", ops[tmr])
            }
            &Instruction_::DeleteTimer(tmr) => {
                format!("COMMINST @uvm.deletetimer({})", ops[tmr])
            }
            &Instruction_::Sleep(dur) => {
                format!("COMMINST @uvm.sleep_ns({})", ops[dur])
            }

            &Instruction_::NewAttr => format!("NEWATTR()"),
            &Instruction_::DeleteAttr(aref) => {
                format!("DELETEATTR({})", ops[aref])
            }
            &Instruction_::ThreadSetAttr(tref, aref) => {
                format!("SETATTR({}, {})", ops[tref], ops[aref])
            }
            &Instruction_::ThreadGetAttr(tref) => {
                format!("GETATTR({})", ops[tref])
            }
            &Instruction_::AttrSetPriority(aref, p) => format!(
                "COMMINST @uvm.attr.setpriority({}, {})",
                ops[aref], ops[p]
896
            ),
897
898
899
900
901
902
903
904
905
            &Instruction_::AttrGetPriority(aref) => {
                format!("COMMINST @uvm.attr.getpriority({})", ops[aref])
            }
            &Instruction_::AttrSetCPU(aref, c) => {
                format!("COMMINST @uvm.attr.setcpu({}, {})", ops[aref], ops[c])
            }
            &Instruction_::AttrClearCPU(aref, c) => format!(
                "COMMINST @uvm.attr.clearcpu({}, {})",
                ops[aref], ops[c]
Javad Ebrahimian Amiri's avatar
Javad Ebrahimian Amiri committed
906
            ),
907
908
909
            &Instruction_::AttrIssetCPU(aref, c) => format!(
                "COMMINST @uvm.attr.issetcpu({}, {})",
                ops[aref], ops[c]
Javad Ebrahimian Amiri's avatar
Javad Ebrahimian Amiri committed
910
            ),
911
912
913
914
915
916
917
            &Instruction_::AttrZeroCPU(aref) => {
                format!("COMMINST @uvm.attr.zerocpu({})", ops[aref])
            }
            &Instruction_::eAllocPA(ref ty, addr) => format!(
                "COMMINST @uvm.emm.eallocpa({}, {})",
                ty.id(),
                ops[addr]
Javad Ebrahimian Amiri's avatar
Javad Ebrahimian Amiri committed
918
            ),
919
920
921
922
923
            &Instruction_::eAllocHybridPA(ref ty, len, addr) => format!(
                "COMMINST @uvm.emm.eallochybridpa({}, {}, {})",
                ty.id(),
                ops[len],
                ops[addr]
Javad Ebrahimian Amiri's avatar
Javad Ebrahimian Amiri committed
924
            ),
925
926
927
928
929
930
931
932
933
            &Instruction_::BindObject(obj) => {
                format!("COMMINST @uvm.emm.bindobject({})", ops[obj])
            }
            &Instruction_::UnbindObject(obj) => {
                format!("COMMINST @uvm.emm.unbindobject({})", ops[obj])
            }
            &Instruction_::NewRegionPA(size, addr) => format!(
                "COMMINST @uvm.regions.newregionpa({}, {})",
                ops[size], ops[addr]
Javad Ebrahimian Amiri's avatar
Javad Ebrahimian Amiri committed
934
            ),
935
936
937
938
939
940
941
            &Instruction_::BindRegion(reg) => {
                format!("COMMINST @uvm.regions.bindregion({})", ops[reg])
            }
            &Instruction_::UnbindRegion(reg) => {
                format!("COMMINST @uvm.regions.unbindregion({})", ops[reg])
            }

Isaac Oscar Gariano's avatar
Isaac Oscar Gariano committed
942
943
944
            &Instruction_::NewFrameCursor(stack) => {
                format!("COMMINST @uvm.meta.new_cursor({})", ops[stack])
            }
945
946
947
948
949
            &Instruction_::GetIRef(reference) => format!(
                "GETIREF<{}> {}",
                ops[reference].ty().get_referent_ty().unwrap(),
                ops[reference]
            ),
Isaac Oscar Gariano's avatar
Isaac Oscar Gariano committed
950
951
952
            &Instruction_::GetFieldIRef {
                is_ptr,
                base,
953
                index
Isaac Oscar Gariano's avatar
Isaac Oscar Gariano committed
954
955
956
957
958
959
960
961
962
963
964
965
966
            } => {
                let ptr = select_value!(is_ptr, " PTR", "");
                format!(
                    "GETFIELDIREF{}<{} {}> {}",
                    ptr,
                    ops[base].ty().get_referent_ty().unwrap(),
                    index,
                    ops[base]
                )
            }
            &Instruction_::GetElementIRef {
                is_ptr,
                base,
967
                index
Isaac Oscar Gariano's avatar
Isaac Oscar Gariano committed
968
969
970
971
972
973
974
975
976
977
978
979
980
981
            } => {
                let ptr = select_value!(is_ptr, " PTR", "");
                format!(
                    "GETELEMIREF{}<{} {}>{} {}",
                    ptr,
                    ops[base].ty().get_referent_ty().unwrap(),
                    ops[index].ty(),
                    ops[base],
                    ops[index]
                )
            }
            &Instruction_::ShiftIRef {
                is_ptr,
                base,
982
                offset
Isaac Oscar Gariano's avatar
Isaac Oscar Gariano committed
983
984
985
            } => {
                let ptr = select_value!(is_ptr, " PTR", "");
                format!(
986
                    "SHIFTIREF{}<{} {}>{} {}",
Isaac Oscar Gariano's avatar
Isaac Oscar Gariano committed
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
                    ptr,
                    ops[base].ty().get_referent_ty().unwrap(),
                    ops[offset].ty(),
                    ops[base],
                    ops[offset]
                )
            }
            &Instruction_::GetVarPartIRef { is_ptr, base } => {
                let ptr = select_value!(is_ptr, " PTR", "");
                format!(
                    "GETVARPARTIREF{}<{}> {}",
                    ptr,
                    ops[base].ty().get_referent_ty().unwrap(),
                    ops[base]
                )
            }

            &Instruction_::Fence(order) => format!("FENCE {}", order),

            &Instruction_::Return(ref vals) => {
                if vals.len() == 0 {
                    format!("RET")
                } else if vals.len() == 1 {
                    format!("RET {}", ops[vals[0]])
                } else {
                    format!("RET ({})", op_vector_str(vals, ops))
                }
            }
1015
1016
1017
1018
1019
1020
1021
1022
1023
            &Instruction_::ThreadExit => {
                "COMMINST @uvm.thread_exit".to_string()
            }
            &Instruction_::CurrentStack => {
                "COMMINST @uvm.current_stack".to_string()
            }
            &Instruction_::KillStack(s) => {
                format!("COMMINST @uvm.kill_stack({})", ops[s])
            }
Isaac Oscar Gariano's avatar
Isaac Oscar Gariano committed
1024
            &Instruction_::Throw(exn_obj) => format!("THROW {}", ops[exn_obj]),
1025
1026
1027
1028
1029
1030
            &Instruction_::TailCall(ref call) => {
                format!("TAILCALL{}", call.debug_str(ops))
            }
            &Instruction_::Branch1(ref dest) => {
                format!("BRANCH {}", dest.debug_str(ops))
            }
Isaac Oscar Gariano's avatar
Isaac Oscar Gariano committed
1031
1032
1033
1034
1035
            &Instruction_::Branch2 {
                cond,
                ref true_dest,
                ref false_dest,
                ..
1036
1037
1038
1039
1040
1041
            } => format!(
                "BRANCH2 {} {} {}",
                ops[cond],
                true_dest.debug_str(ops),
                false_dest.debug_str(ops)
            ),
Isaac Oscar Gariano's avatar
Isaac Oscar Gariano committed
1042
1043
1044
            &Instruction_::Select {
                cond,
                true_val,
1045
                false_val
1046
1047
1048
1049
1050
1051
1052
1053
            } => format!(
                "SELECT<{} {}> {} {} {}",
                ops[cond].ty(),
                ops[true_val].ty(),
                ops[cond],
                ops[true_val],
                ops[false_val]
            ),
Isaac Oscar Gariano's avatar
Isaac Oscar Gariano committed
1054
1055
1056
            &Instruction_::Watchpoint {
                id,
                ref disable_dest,
1057
                ref resume
Isaac Oscar Gariano's avatar
Isaac Oscar Gariano committed
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
            } => {
                match id {
                    Some(id) => {
                        format!(
                            // TODO: WPEXC should be optional
                            "WATCHPOINT {}<{}> {} {} WPEXC({})",
                            id,
                            format_value_types(&self.value),
                            disable_dest.as_ref().unwrap().debug_str(ops),
                            resume.normal_dest.debug_str(ops),
                            resume.exn_dest.debug_str(ops)
                        )
                    }
                    //TRAP < Ts > excClause keepAliveClause
1072
1073
1074
1075
                    None => format!(
                        "TRAP<{}> {}",
                        format_value_types(&self.value),
                        resume.debug_str(ops)
1076
                    )
Isaac Oscar Gariano's avatar
Isaac Oscar Gariano committed
1077
1078
1079
1080
1081
                }
            }
            &Instruction_::WPBranch {
                wp,
                ref disable_dest,
1082
                ref enable_dest
1083
1084
1085
1086
1087
1088
            } => format!(
                "WPBRANCH {} {} {}",
                wp,
                disable_dest.debug_str(ops),
                enable_dest.debug_str(ops)
            ),
Isaac Oscar Gariano's avatar
Isaac Oscar Gariano committed
1089
1090
            &Instruction_::Call {
                ref data,
1091
1092
1093
1094
                ref resume
            } => {
                format!("CALL{} {}", data.debug_str(ops), resume.debug_str(ops))
            }
Isaac Oscar Gariano's avatar
Isaac Oscar Gariano committed
1095
1096
            &Instruction_::CCall {
                ref data,
1097
1098
1099
1100
1101
1102
                ref resume
            } => format!(
                "CCALL{} {}",
                data.debug_str(ops),
                resume.debug_str(ops)
            ),
Isaac Oscar Gariano's avatar
Isaac Oscar Gariano committed
1103
1104
1105
            &Instruction_::SwapStackExpr {
                stack,
                is_exception,
1106
                ref args
1107
1108
1109
1110
1111
1112
            } => format!(
                "SWAPSTACK {} RET_WITH<{}> {}",
                ops[stack],
                format_value_types(&self.value),
                format_new_stack_clause(is_exception, args, ops)
            ),
Isaac Oscar Gariano's avatar
Isaac Oscar Gariano committed
1113
1114
1115
1116
            &Instruction_::SwapStackExc {
                stack,
                is_exception,
                ref args,
1117
                ref resume
1118
1119
1120
1121
1122
1123
1124
            } => format!(
                "SWAPSTACK {} RET_WITH<{}> {} {}",
                ops[stack],
                format_value_types(&self.value),
                format_new_stack_clause(is_exception, args, ops),
                resume.debug_str(ops)
            ),
Isaac Oscar Gariano's avatar
Isaac Oscar Gariano committed
1125
1126
1127
1128

            &Instruction_::SwapStackKill {
                stack,
                is_exception,
1129
                ref args
1130
1131
1132
1133
1134
            } => format!(
                "SWAPSTACK {} KILL_OLD {}",
                ops[stack],
                format_new_stack_clause(is_exception, args, ops)
            ),
Isaac Oscar Gariano's avatar
Isaac Oscar Gariano committed
1135
1136
1137
1138

            &Instruction_::Switch {
                cond,
                ref default,
1139
                ref branches
Isaac Oscar Gariano's avatar
Isaac Oscar Gariano committed
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
            } => {
                //SWITCH < T > opnd default { ( value dest ) rep }
                let mut ret = format!(
                    "SWITCH<{}> {} {} {{",
                    ops[cond].ty(),
                    ops[cond],
                    default.debug_str(ops)
                );
                for i in 0..branches.len() {
                    let (op, ref dest) = branches[i];
1150
1151
1152
                    ret.push_str(
                        format!("{} {}", ops[op], dest.debug_str(ops)).as_str()
                    );
Isaac Oscar Gariano's avatar
Isaac Oscar Gariano committed
1153
1154
1155
1156
                    if i != branches.len() - 1 {
                        ret.push_str(" ");
                    }
                }
Isaac Oscar Gariano's avatar
Isaac Oscar Gariano committed
1157
                ret.push_str("}");
Isaac Oscar Gariano's avatar
Isaac Oscar Gariano committed
1158
1159
1160
1161
1162

                ret
            }
            &Instruction_::ExnInstruction {
                ref inner,
1163
                ref resume
Isaac Oscar Gariano's avatar
Isaac Oscar Gariano committed
1164
1165
1166
            } => format!("{} {}", inner.debug_str(ops), resume.debug_str(ops)),

            // common inst
1167
1168
1169
            &Instruction_::CommonInst_GetThreadLocal => {
                format!("COMMINST @uvm.get_threadlocal")
            }
Isaac Oscar Gariano's avatar
Isaac Oscar Gariano committed
1170
1171
1172
1173
            &Instruction_::CommonInst_SetThreadLocal(op) => {
                format!("COMMINST @uvm.set_threadlocal({})", ops[op])
            }

1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
            &Instruction_::CommonInst_Pin(op) => format!(
                "COMMINST @uvm.native.pin<{}>({})",
                ops[op].ty(),
                ops[op]
            ),
            &Instruction_::CommonInst_Unpin(op) => format!(
                "COMMINST @uvm.native.unpin<{}>({})",
                ops[op].ty(),
                ops[op]
            ),
1184
1185
1186
1187
1188
            &Instruction_::CommonInst_GetAddr(op) => format!(
                "COMMINST @uvm.native.get_addr<{}>({})",
                ops[op].ty(),
                ops[op]
            ),
Isaac Oscar Gariano's avatar
Isaac Oscar Gariano committed
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
            // Tagerf64
            &Instruction_::CommonInst_Tr64IsFp(op) => {
                format!("COMMINST @uvm.tr64.is_fp({})", ops[op])
            }
            &Instruction_::CommonInst_Tr64IsInt(op) => {
                format!("COMMINST @uvm.tr64.is_int({})", ops[op])
            }
            &Instruction_::CommonInst_Tr64IsRef(op) => {
                format!("COMMINST @uvm.tr64.is_ref({})", ops[op])
            }
            &Instruction_::CommonInst_Tr64FromFp(op) => {
                format!("COMMINST @uvm.tr64.from_fp({})", ops[op])
            }
            &Instruction_::CommonInst_Tr64FromInt(op) => {
                format!("COMMINST @uvm.tr64.from_int({})", ops[op])
            }
1205
1206
1207
1208
            &Instruction_::CommonInst_Tr64FromRef(op1, op2) => format!(
                "COMMINST @uvm.tr64.from_ref({} {})",
                ops[op1], ops[op2]
            ),
Isaac Oscar Gariano's avatar
Isaac Oscar Gariano committed
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
            &Instruction_::CommonInst_Tr64ToFp(op) => {
                format!("COMMINST @uvm.tr64.to_fp({})", ops[op])
            }
            &Instruction_::CommonInst_Tr64ToInt(op) => {
                format!("COMMINST @uvm.tr64.to_int({})", ops[op])
            }
            &Instruction_::CommonInst_Tr64ToRef(op) => {
                format!("COMMINST @uvm.tr64.to_ref({})", ops[op])
            }
            &Instruction_::CommonInst_Tr64ToTag(op) => {
                format!("COMMINST @uvm.tr64.to_tag({})", ops[op])
            }

            // move
1223
1224
1225
            &Instruction_::Move(from) => {
                format!("MOVE<{}> {}", ops[from].ty(), ops[from])
            }
Isaac Oscar Gariano's avatar
Isaac Oscar Gariano committed
1226
            // print hex
1227
1228
1229
1230
1231
1232
            &Instruction_::PrintHex(i) => {
                format!("PRINTHEX<{}> {}", ops[i].ty(), ops[i])
            }
            &Instruction_::PrintBool(i) => {
                format!("PRINTBOOL<{}> {}", ops[i].ty(), ops[i])
            }
1233
1234
1235
            &Instruction_::PrintTime(i) => {
                format!("PRINTTIME<{}> {}", ops[i].ty(), ops[i])
            }
Isaac Oscar Gariano's avatar
Isaac Oscar Gariano committed
1236
            // set retval
qinsoon's avatar
qinsoon committed
1237
            &Instruction_::SetRetval(val) => format!("SETRETVAL {}", ops[val]),
1238
1239
1240
1241
1242
1243
            &Instruction_::RandI(min, max) => {
                format!("RandI ({}, {})", ops[min], ops[max])
            }
            &Instruction_::RandF(min, max) => {
                format!("RandF ({}, {})", ops[min], ops[max])
            }
qinsoon's avatar
qinsoon committed
1244
            // get vm thread local
1245
            &Instruction_::GetVMThreadLocal => format!("GETVMTHREADLOCAL")
Isaac Oscar Gariano's avatar
Isaac Oscar Gariano committed
1246
        }
1247
1248
1249
    }
}

1250
1251
const PRINT_INST_NAME: bool = false;

1252
1253
impl fmt::Display for Instruction {
    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
1254
        let ref ops = self.ops;
1255
        let value = match &self.value {
1256
1257
1258
            &Some(ref v) if v.len() == 0 => format!(""),
            &Some(ref v) if v.len() == 1 => format!("{} = ", v[0]),
            &Some(ref v) => format!("({}) = ", vec_utils::as_str_sp(&v)),
1259
            &None => format!("")
1260
1261
1262
        };

        if PRINT_INST_NAME {
Isaac Oscar Gariano's avatar
Isaac Oscar Gariano committed
1263
            write!(f, "{}[{}]{}", value, self.hdr, self.debug_str(ops))
1264
        } else {
Isaac Oscar Gariano's avatar
Isaac Oscar Gariano committed
1265
            write!(f, "{}{}", value, self.debug_str(ops))
1266
1267
1268
1269
        }
    }
}

qinsoon's avatar
qinsoon committed
1270
/// Instruction_ is used for pattern matching for Instruction
qinsoon's avatar
qinsoon committed
1271
#[allow(non_camel_case_types)]
1272
#[derive(Debug, Clone)]
1273
1274
pub enum Instruction_ {
    // non-terminal instruction
qinsoon's avatar
qinsoon committed
1275
    /// binary operations
qinsoon's avatar
qinsoon committed
1276
    BinOp(BinOp, OpIndex, OpIndex),
qinsoon's avatar
qinsoon committed
1277
    /// binary operations with status flag (overflow, sign, etc. )
qinsoon's avatar
qinsoon committed
1278
1279
    BinOpWithStatus(BinOp, BinOpStatus, OpIndex, OpIndex),

qinsoon's avatar
qinsoon committed
1280
    /// comparison operations
1281
    CmpOp(CmpOp, OpIndex, OpIndex),
qinsoon's avatar
qinsoon committed
1282
1283

    /// conversion operations (casting)
qinsoon's avatar
qinsoon committed
1284
    ConvOp {
1285
1286
1287
        operation: ConvOp,
        from_ty: P<MuType>,
        to_ty: P<MuType>,
1288
        operand: OpIndex
1289
    },
qinsoon's avatar
qinsoon committed
1290

1291
1292
1293
    /// a non-terminating Call instruction (the call does not have an
    /// exceptional branch) This instruction is not in the Mu spec, but is
    /// documented in the HOL formal spec
qinsoon's avatar
qinsoon committed
1294
    ExprCall {
1295
        data: CallData,
1296
        is_abort: bool // T to abort, F to rethrow
1297
    },
qinsoon's avatar
qinsoon committed
1298

1299
1300
1301
    /// a non-terminating CCall instruction (the call does not have an
    /// exceptional branch) This instruction is not in the Mu spec, but is
    /// documented in the HOL formal spec
1302
1303
    ExprCCall {
        data: CallData,
1304
        is_abort: bool
1305
    },
qinsoon's avatar
qinsoon committed
1306

qinsoon's avatar
qinsoon committed
1307
    /// load instruction
qinsoon's avatar
qinsoon committed
1308
    Load {
1309
1310
        is_ptr: bool,
        order: MemoryOrder,
1311
        mem_loc: OpIndex
1312
    },
qinsoon's avatar
qinsoon committed
1313

qinsoon's avatar
qinsoon committed
1314
    /// store instruction
qinsoon's avatar
qinsoon committed
1315
    Store {
1316
        is_ptr: bool,
qinsoon's avatar
qinsoon committed
1317
        <