WARNING! Access to this system is limited to authorised users only.
Unauthorised users may be subject to prosecution.
Unauthorised access to this system is a criminal offence under Australian law (Federal Crimes Act 1914 Part VIA)
It is a criminal offence to:
(1) Obtain access to data without authority. -Penalty 2 years imprisonment.
(2) Damage, delete, alter or insert data without authority. -Penalty 10 years imprisonment.
User activity is monitored and recorded. Anyone using this system expressly consents to such monitoring and recording.

To protect your data, the CISO officer has suggested users to enable 2FA as soon as possible.
Currently 2.7% of users enabled 2FA.

op.rs 7.23 KB
Newer Older
qinsoon's avatar
qinsoon committed
1
2
3
4
use ptr::P;
use types::*;
use inst::*;
use types::MuType_::*;
5

qinsoon's avatar
qinsoon committed
6
#[derive(Copy, Clone, Debug, PartialEq, RustcEncodable, RustcDecodable)]
qinsoon's avatar
qinsoon committed
7
8
9
10
pub enum OpCode {
    // SSA
    RegI64,
    RegFP,
11

qinsoon's avatar
qinsoon committed
12
13
14
    // Constant
    IntImmI64,
    FPImm,
15

qinsoon's avatar
qinsoon committed
16
17
18
    // non-terminal
    Assign,
    Fence,
19

qinsoon's avatar
qinsoon committed
20
21
22
23
24
25
26
    //terminal
    Return,
    ThreadExit,
    Throw,
    TailCall,
    Branch1,
    Branch2,
qinsoon's avatar
qinsoon committed
27
    Select,
qinsoon's avatar
qinsoon committed
28
29
30
    Watchpoint,
    WPBranch,
    Call,
qinsoon's avatar
qinsoon committed
31
    CCall,
qinsoon's avatar
qinsoon committed
32
33
34
    SwapStack,
    Switch,
    ExnInstruction,
35

qinsoon's avatar
qinsoon committed
36
    // expression
37
38
    Binary(BinOp),
    Comparison(CmpOp),
39
    Conversion(ConvOp),
40
41
    AtomicRMW(AtomicRMWOp),

qinsoon's avatar
qinsoon committed
42
    ExprCall,
qinsoon's avatar
qinsoon committed
43
    ExprCCall,
qinsoon's avatar
qinsoon committed
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
    Load,
    Store,
    CmpXchg,
    New,
    AllocA,
    NewHybrid,
    AllocAHybrid,
    NewStack,
    NewThread,
    NewThreadExn,
    NewFrameCursor,
    GetIRef,
    GetFieldIRef,
    GetElementIRef,
    ShiftIRef,
59
60
61
    GetVarPartIRef,

    CommonInst_GetThreadLocal,
62
63
64
    CommonInst_SetThreadLocal,

    Move
qinsoon's avatar
qinsoon committed
65
66
}

67
pub fn pick_op_code_for_ssa(ty: &P<MuType>) -> OpCode {
qinsoon's avatar
qinsoon committed
68
69
    let a : &MuType = ty;
    match a.v {
70
        // currently use i64 for all ints
qinsoon's avatar
qinsoon committed
71
        Int(_) => OpCode::RegI64,
72
        // currently do not differentiate float and double
qinsoon's avatar
qinsoon committed
73
74
        Float
        | Double => OpCode::RegFP,
75
        // ref and pointer types use RegI64
qinsoon's avatar
qinsoon committed
76
77
78
79
80
81
82
83
84
        Ref(_)
        | IRef(_)
        | WeakRef(_)
        | UPtr(_)
        | ThreadRef
        | StackRef
        | Tagref64
        | FuncRef(_)
        | UFuncPtr(_) => OpCode::RegI64,
85
        // we are not supposed to have these as SSA
qinsoon's avatar
qinsoon committed
86
87
        Struct(_)
        | Array(_, _)
88
        | Hybrid(_)
qinsoon's avatar
qinsoon committed
89
        | Void => panic!("Not expecting {} as SSA", ty),
90
        // unimplemented
qinsoon's avatar
qinsoon committed
91
        Vector(_, _) => unimplemented!()
92
93
94
    }
}

qinsoon's avatar
qinsoon committed
95
pub fn pick_op_code_for_value(ty: &P<MuType>) -> OpCode {
qinsoon's avatar
qinsoon committed
96
97
    let a : &MuType = ty;
    match a.v {
98
        // currently use i64 for all ints
qinsoon's avatar
qinsoon committed
99
        Int(_) => OpCode::IntImmI64,
100
        // currently do not differentiate float and double
qinsoon's avatar
qinsoon committed
101
102
        Float
        | Double => OpCode::FPImm,
103
        // ref and pointer types use RegI64
qinsoon's avatar
qinsoon committed
104
105
106
107
108
109
110
111
112
        Ref(_)
        | IRef(_)
        | WeakRef(_)
        | UPtr(_)
        | ThreadRef
        | StackRef
        | Tagref64
        | FuncRef(_)
        | UFuncPtr(_) => OpCode::IntImmI64,
113
        // we are not supposed to have these as SSA
qinsoon's avatar
qinsoon committed
114
115
        Struct(_)
        | Array(_, _)
116
        | Hybrid(_)
qinsoon's avatar
qinsoon committed
117
        | Void => unimplemented!(),
118
        // unimplemented
qinsoon's avatar
qinsoon committed
119
        Vector(_, _) => unimplemented!()
120
121
122
    }
}

qinsoon's avatar
qinsoon committed
123
#[derive(Copy, Clone, Debug, PartialEq, RustcEncodable, RustcDecodable)]
qinsoon's avatar
qinsoon committed
124
125
126
127
128
129
130
131
pub enum BinOp {
    // Int(n) BinOp Int(n) -> Int(n)
    Add,
    Sub,
    Mul,
    Sdiv,
    Srem,
    Udiv,
132
    Urem,
qinsoon's avatar
qinsoon committed
133
134
135
    And,
    Or,
    Xor,
136

qinsoon's avatar
qinsoon committed
137
138
139
    // Int(n) BinOp Int(m) -> Int(n)
    Shl,
    Lshr,
140
    Ashr,
qinsoon's avatar
qinsoon committed
141
142

    // FP BinOp FP -> FP
143
    FAdd,
qinsoon's avatar
qinsoon committed
144
145
146
147
148
149
    FSub,
    FMul,
    FDiv,
    FRem
}

qinsoon's avatar
qinsoon committed
150
#[derive(Copy, Clone, Debug, PartialEq, RustcEncodable, RustcDecodable)]
qinsoon's avatar
qinsoon committed
151
152
153
154
155
156
157
158
159
160
161
162
pub enum CmpOp {
    // for Int comparison
    EQ,
    NE,
    SGE,
    SGT,
    SLE,
    SLT,
    UGE,
    UGT,
    ULE,
    ULT,
163

qinsoon's avatar
qinsoon committed
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
    // for FP comparison
    FFALSE,
    FTRUE,
    FOEQ,
    FOGT,
    FOGE,
    FOLT,
    FOLE,
    FONE,
    FORD,
    FUEQ,
    FUGT,
    FUGE,
    FULT,
    FULE,
    FUNE,
    FUNO
}

183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
impl CmpOp {
    pub fn swap_operands(self) -> CmpOp {
        use op::CmpOp::*;
        match self {
            EQ => EQ,
            NE => NE,
            SGE => SLT,
            SGT => SLE,
            SLE => SGT,
            SLT => SGE,
            UGE => ULT,
            UGT => ULE,
            ULE => UGT,
            ULT => UGE,

            _ => unimplemented!()
        }
    }
}

203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
#[derive(Copy, Clone, Debug, PartialEq, RustcEncodable, RustcDecodable)]
pub enum ConvOp {
    TRUNC,
    ZEXT,
    SEXT,
    FPTRUNC,
    FPEXT,
    FPTOUI,
    FPTOSI,
    UITOFP,
    SITOFP,
    BITCAST,
    REFCAST,
    PTRCAST
}

qinsoon's avatar
qinsoon committed
219
#[derive(Copy, Clone, Debug, PartialEq, RustcEncodable, RustcDecodable)]
qinsoon's avatar
qinsoon committed
220
221
222
223
224
225
226
227
228
229
230
231
pub enum AtomicRMWOp {
    XCHG,
    ADD,
    SUB,
    AND,
    NAND,
    OR,
    XOR,
    MAX,
    MIN,
    UMAX,
    UMIN
232
233
}

qinsoon's avatar
qinsoon committed
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
pub fn is_int_cmp(op: CmpOp) -> bool {
    match op {
        CmpOp::EQ
        | CmpOp::NE
        | CmpOp::SGE
        | CmpOp::SGT
        | CmpOp::SLE
        | CmpOp::SLT
        | CmpOp::UGE
        | CmpOp::UGT
        | CmpOp::ULE
        | CmpOp::ULT => true,
        _ => false
    }
}

250
251
pub fn pick_op_code_for_inst(inst: &Instruction) -> OpCode {
    match inst.v {
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
        Instruction_::BinOp(op, _, _)               => OpCode::Binary(op),
        Instruction_::CmpOp(op, _, _)               => OpCode::Comparison(op),
        Instruction_::ConvOp{operation, ..}         => OpCode::Conversion(operation),
        Instruction_::AtomicRMW{op, ..}             => OpCode::AtomicRMW(op),
        Instruction_::ExprCall{..}                  => OpCode::ExprCall,
        Instruction_::ExprCCall{..}                 => OpCode::ExprCCall,
        Instruction_::Load{..}                      => OpCode::Load,
        Instruction_::Store{..}                     => OpCode::Store,
        Instruction_::CmpXchg{..}                   => OpCode::CmpXchg,
        Instruction_::New(_)                        => OpCode::New,
        Instruction_::AllocA(_)                     => OpCode::AllocA,
        Instruction_::NewHybrid(_, _)               => OpCode::NewHybrid,
        Instruction_::AllocAHybrid(_, _)            => OpCode::AllocAHybrid,
        Instruction_::NewStack(_)                   => OpCode::NewStack,
        Instruction_::NewThread(_, _)               => OpCode::NewThread,
        Instruction_::NewThreadExn(_, _)            => OpCode::NewThreadExn,
        Instruction_::NewFrameCursor(_)             => OpCode::NewFrameCursor,
        Instruction_::GetIRef(_)                    => OpCode::GetIRef,
        Instruction_::GetFieldIRef{..}              => OpCode::GetFieldIRef,
        Instruction_::GetElementIRef{..}            => OpCode::GetElementIRef,
        Instruction_::ShiftIRef{..}                 => OpCode::ShiftIRef,
        Instruction_::GetVarPartIRef{..}            => OpCode::GetVarPartIRef,
        Instruction_::Fence(_)                      => OpCode::Fence,
        Instruction_::Return(_)                     => OpCode::Return,
        Instruction_::ThreadExit                    => OpCode::ThreadExit,
        Instruction_::Throw(_)                      => OpCode::Throw,
        Instruction_::TailCall(_)                   => OpCode::TailCall,
        Instruction_::Branch1(_)                    => OpCode::Branch1,
        Instruction_::Branch2{..}                   => OpCode::Branch2,
        Instruction_::Select{..}                    => OpCode::Select,
        Instruction_::Watchpoint{..}                => OpCode::Watchpoint,
        Instruction_::WPBranch{..}                  => OpCode::WPBranch,
        Instruction_::Call{..}                      => OpCode::Call,
        Instruction_::CCall{..}                     => OpCode::CCall,
        Instruction_::SwapStack{..}                 => OpCode::SwapStack,
        Instruction_::Switch{..}                    => OpCode::Switch,
        Instruction_::ExnInstruction{..}            => OpCode::ExnInstruction,
        Instruction_::CommonInst_GetThreadLocal     => OpCode::CommonInst_GetThreadLocal,
290
291
        Instruction_::CommonInst_SetThreadLocal(_)  => OpCode::CommonInst_SetThreadLocal,
        Instruction_::Move(_)                    => OpCode::Move,
292
293
    }
}