To protect your data, the CISO officer has suggested users to enable GitLab 2FA as soon as possible.

ir.rs 6.66 KB
Newer Older
1
2
3
4
#![allow(dead_code)]
#![allow(unused_variables)]

use ast::ptr::P;
5
6
use ast::types::*;

qinsoon's avatar
qinsoon committed
7
8
9
10
11
pub type WPID  = usize;
pub type MuID  = usize;
pub type MuTag = &'static str;
pub type Address = usize; // TODO: replace this with Address(usize)

12
#[derive(Clone, Debug)]
qinsoon's avatar
qinsoon committed
13
pub struct SSAVar {
14
15
16
17
18
    pub id: MuID,
    pub tag: MuTag,
    pub ty: P<MuType_>
}

19
#[derive(Clone, Debug)]
20
21
22
pub enum Value {
    SSAVar(SSAVar),
    Constant(MuConstant)
qinsoon's avatar
qinsoon committed
23
24
}

25
26
27
28
29
30
31
32
33
34
35
36
#[derive(Debug)]
pub struct TreeNode {
    v: TreeNodeKind,
    children: Vec<P<TreeNode>>,
}

#[derive(Debug)]
pub enum TreeNodeKind {
    Value(Vec<P<Value>>),
    Expression(P<Expression>),
}

37
#[derive(Copy, Clone, Debug)]
38
39
40
41
42
43
44
45
46
47
pub enum MemoryOrder {
    NotAtomic,
    Relaxed,
    Consume,
    Acquire,
    Release,
    AcqRel,
    SeqCst
}

48
#[derive(Copy, Clone, Debug)]
qinsoon's avatar
qinsoon committed
49
50
51
52
53
pub enum CallConvention {
    Mu,
    Foreign(ForeignFFI)
}

54
#[derive(Copy, Clone, Debug)]
qinsoon's avatar
qinsoon committed
55
56
57
58
pub enum ForeignFFI {
    C
}

59
#[derive(Debug)]
qinsoon's avatar
qinsoon committed
60
pub struct CallData {
61
62
63
    pub func: P<SSAVar>,
    pub args: Vec<P<Value>>,
    pub convention: CallConvention
qinsoon's avatar
qinsoon committed
64
65
}

66
#[derive(Debug)]
67
pub struct Block {
68
69
    pub label: MuTag,
    pub content: Option<BlockContent>
qinsoon's avatar
qinsoon committed
70
71
}

72
73
74
75
76
77
impl Block {
    pub fn new(label: MuTag) -> Block {
        Block{label: label, content: None}
    }
}

78
#[derive(Debug)]
79
80
81
82
83
84
pub struct BlockContent {
    pub args: Vec<P<Value>>,
    pub body: Vec<Instruction>,
    pub keepalives: Option<Vec<P<SSAVar>>>    
}

85
#[derive(Debug)]
86
87
88
pub struct ResumptionData {
    pub normal_dest: Destination,
    pub exn_dest: Destination
qinsoon's avatar
qinsoon committed
89
90
}

91
#[derive(Debug)]
qinsoon's avatar
qinsoon committed
92
pub enum DestArg {
93
    Normal(P<Value>),
qinsoon's avatar
qinsoon committed
94
95
96
    Freshbound(usize)
}

97
#[derive(Debug)]
98
99
100
pub struct Destination {
    pub target: MuTag,
    pub args: Vec<DestArg>
qinsoon's avatar
qinsoon committed
101
102
}

103
#[derive(Clone, Debug)]
104
pub enum Constant {
qinsoon's avatar
qinsoon committed
105
    Int(usize, usize),
106
    IRef(P<MuType_>, Address),
qinsoon's avatar
qinsoon committed
107
108
    FloatV(f32),
    DoubleV(f64),
109
    VectorV(Vec<Constant>),
qinsoon's avatar
qinsoon committed
110
111
112
113
    FuncRefV(Address),
    UFuncRefV(Address)
}

114
#[derive(Debug)]
qinsoon's avatar
qinsoon committed
115
pub enum Expression {
116
117
    BinOp(BinOp, P<Value>, P<Value>), 
    CmpOp(CmpOp, P<Value>, P<Value>),
qinsoon's avatar
qinsoon committed
118
119
    
    // yields the constant value
120
    Constant(P<Constant>),
qinsoon's avatar
qinsoon committed
121
    
qinsoon's avatar
qinsoon committed
122
123
124
125
126
127
128
129
130
131
132
133
    // yields a tuple of results from the call
    ExprCall{
        data: CallData,
        is_abort: bool, // T to abort, F to rethrow
    },
    
    // yields the memory value
    Load{
        is_iref: bool,
        mem_loc: P<Value>,
        order: MemoryOrder
    },
qinsoon's avatar
qinsoon committed
134
    
qinsoon's avatar
qinsoon committed
135
136
137
138
139
140
141
142
    // yields nothing
    Store{
        is_iref: bool,
        mem_loc: P<Value>,
        order: MemoryOrder        
    },
    
    // yields pair (oldvalue, boolean (T = success, F = failure))
qinsoon's avatar
qinsoon committed
143
144
145
146
147
    CmpXchg{
        is_iref: bool, // T for iref, F for ptr
        is_strong: bool,
        success_order: MemoryOrder,
        fail_order: MemoryOrder,
148
149
150
        mem_loc: P<SSAVar>,
        expected_value: P<Value>,
        desired_value: P<Value>
qinsoon's avatar
qinsoon committed
151
152
    },
    
qinsoon's avatar
qinsoon committed
153
    // yields old memory value
qinsoon's avatar
qinsoon committed
154
155
156
157
    AtomicRMW{
        is_iref: bool, // T for iref, F for ptr
        order: MemoryOrder,
        op: AtomicRMWOp,
158
159
        mem_loc: P<Value>,
        value: P<Value> // operand for op
qinsoon's avatar
qinsoon committed
160
161
    },
    
qinsoon's avatar
qinsoon committed
162
    // yields a reference of the type
163
    New(P<MuType_>),
qinsoon's avatar
qinsoon committed
164
165
    
    // yields an iref of the type
166
    AllocA(P<MuType_>),
qinsoon's avatar
qinsoon committed
167
168
    
    // yields ref
qinsoon's avatar
qinsoon committed
169
    NewHybrid{    // hybrid type, var part length
170
171
        ty: P<MuType_>, 
        var_len: P<Value>
qinsoon's avatar
qinsoon committed
172
    },  
qinsoon's avatar
qinsoon committed
173
174
    
    // yields iref
qinsoon's avatar
qinsoon committed
175
    AllocAHybrid{
176
177
        ty: P<MuType_>, 
        var_len: P<Value>
qinsoon's avatar
qinsoon committed
178
    },
qinsoon's avatar
qinsoon committed
179
180
    
    // yields stack ref
qinsoon's avatar
qinsoon committed
181
    NewStack{
182
        func: P<Value>
qinsoon's avatar
qinsoon committed
183
    },
qinsoon's avatar
qinsoon committed
184
185
    
    // yields thread reference
qinsoon's avatar
qinsoon committed
186
    NewThread{
187
188
        stack: P<Value>,
        args: Vec<P<Value>>
qinsoon's avatar
qinsoon committed
189
    },
qinsoon's avatar
qinsoon committed
190
191
192
    
    // yields thread reference (thread resumes with exceptional value)
    NewThreadExn{
193
194
        stack: P<Value>,
        exn: P<Value>
qinsoon's avatar
qinsoon committed
195
196
    },
    
qinsoon's avatar
qinsoon committed
197
198
199
200
201
202
203
204
    // yields frame cursor
    NewFrameCursor(P<Value>), // stack
    
    GetIRef(P<Value>),
    
    GetFieldIRef{
        base: P<Value>, // iref or ptr
        index: P<Constant>
qinsoon's avatar
qinsoon committed
205
    },
qinsoon's avatar
qinsoon committed
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
    
    GetElementIRef{
        base: P<Value>,
        index: P<Value>
    },
    
    ShiftIRef{
        base: P<Value>,
        offset: P<Value>
    },
    
    GetVarPartIRef(P<Value>),
    
//    PushFrame{
//        stack: P<Value>,
//        func: P<Value>
//    },
//    PopFrame{
//        stack: P<Value>
//    }
qinsoon's avatar
qinsoon committed
226
227
}

228
#[derive(Debug)]
qinsoon's avatar
qinsoon committed
229
pub enum Instruction {
230
231
232
233
234
235
    NonTerm(NonTermInstruction),
    Term(Terminal)
}

#[derive(Debug)]
pub enum NonTermInstruction {
qinsoon's avatar
qinsoon committed
236
    Assign{
237
        left: Vec<P<Value>>,
qinsoon's avatar
qinsoon committed
238
239
        right: Expression
    },
qinsoon's avatar
qinsoon committed
240
241

    Fence(MemoryOrder),
qinsoon's avatar
qinsoon committed
242
243
}

244
#[derive(Debug)]
245
246
pub enum Terminal {
    Return(Vec<P<Value>>),
qinsoon's avatar
qinsoon committed
247
    ThreadExit,
248
    Throw(Vec<P<Value>>),
qinsoon's avatar
qinsoon committed
249
    TailCall(CallData),
250
    Branch1(Destination),
qinsoon's avatar
qinsoon committed
251
    Branch2{
252
253
254
        cond: P<Value>,
        true_dest: Destination,
        false_dest: Destination
qinsoon's avatar
qinsoon committed
255
    },
256
257
258
259
260
261
262
263
264
    Watchpoint{ // Watchpoint NONE ResumptionData
                //   serves as an unconditional trap. Trap to client, and resume with ResumptionData
                // Watchpoint (WPID dest) ResumptionData
                //   when disabled, jump to dest
                //   when enabled, trap to client and resume
        id: Option<WPID>,
        disable_dest: Option<Destination>,
        resume: ResumptionData
    }, 
qinsoon's avatar
qinsoon committed
265
266
    WPBranch{
        wp: WPID, 
267
268
        disable_dest: Destination,
        enable_dest: Destination
qinsoon's avatar
qinsoon committed
269
270
271
    },
    Call{
        data: CallData,
272
        resume: ResumptionData
qinsoon's avatar
qinsoon committed
273
274
    },
    SwapStack{
275
        stack: P<Value>,
276
        is_exception: bool,
277
        args: Vec<P<Value>>,
278
        resume: ResumptionData
qinsoon's avatar
qinsoon committed
279
280
    },
    Switch{
281
282
283
        cond: P<Value>,
        default: Destination,
        branches: Vec<(P<Constant>, Destination)>
qinsoon's avatar
qinsoon committed
284
285
    },
    ExnInstruction{
286
        inner: NonTermInstruction,
287
        resume: ResumptionData
qinsoon's avatar
qinsoon committed
288
289
290
    }
}

291
#[derive(Clone, Debug)]
292
pub struct MuConstant{
qinsoon's avatar
qinsoon committed
293
294
    pub ty: P<MuType_>, 
    pub val: Constant
295
296
}

297
#[derive(Debug)]
298
299
300
301
302
303
304
pub struct MuFunction {
    pub fn_name: MuTag,
    pub sig: P<MuFuncSig>,
    pub entry: MuTag,
    pub blocks: Vec<(MuTag, Block)>
}

305
#[derive(Copy, Clone, Debug)]
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
pub enum BinOp {
    // Int(n) BinOp Int(n) -> Int(n)
    Add,
    Sub,
    Mul,
    Sdiv,
    Srem,
    Udiv,
    And,
    Or,
    Xor,
        
    // Int(n) BinOp Int(m) -> Int(n)
    Shl,
    Lshr,
    AsHR,

    // FP BinOp FP -> FP
    Fadd,
    FSub,
    FMul,
    FDiv,
    FRem
}

331
#[derive(Copy, Clone, Debug)]
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
pub enum CmpOp {
    // for Int comparison
    EQ,
    NE,
    SGE,
    SGT,
    SLE,
    SLT,
    UGE,
    UGT,
    ULE,
    ULT,
    
    // for FP comparison
    FFALSE,
    FTRUE,
    FOEQ,
    FOGT,
    FOGE,
    FOLT,
    FOLE,
    FONE,
    FORD,
    FUEQ,
    FUGT,
    FUGE,
    FULT,
    FULE,
    FUNE,
    FUNO
}

364
#[derive(Copy, Clone, Debug)]
qinsoon's avatar
qinsoon committed
365
366
367
368
369
370
371
372
373
374
375
376
pub enum AtomicRMWOp {
    XCHG,
    ADD,
    SUB,
    AND,
    NAND,
    OR,
    XOR,
    MAX,
    MIN,
    UMAX,
    UMIN
377
}