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 5.47 KB
Newer Older
1
2
3
4
use ast::ptr::P;
use ast::types::*;
use ast::inst::*;

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

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

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

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

qinsoon's avatar
qinsoon committed
33
    // expression
34
35
36
37
    Binary(BinOp),
    Comparison(CmpOp),
    AtomicRMW(AtomicRMWOp),

qinsoon's avatar
qinsoon committed
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
    ExprCall,
    Load,
    Store,
    CmpXchg,
    New,
    AllocA,
    NewHybrid,
    AllocAHybrid,
    NewStack,
    NewThread,
    NewThreadExn,
    NewFrameCursor,
    GetIRef,
    GetFieldIRef,
    GetElementIRef,
    ShiftIRef,
    GetVarPartIRef
}

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

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

qinsoon's avatar
qinsoon committed
115
#[derive(Copy, Clone, Debug, PartialEq, RustcEncodable, RustcDecodable)]
qinsoon's avatar
qinsoon committed
116
117
118
119
120
121
122
123
124
125
126
pub enum BinOp {
    // Int(n) BinOp Int(n) -> Int(n)
    Add,
    Sub,
    Mul,
    Sdiv,
    Srem,
    Udiv,
    And,
    Or,
    Xor,
127

qinsoon's avatar
qinsoon committed
128
129
130
    // Int(n) BinOp Int(m) -> Int(n)
    Shl,
    Lshr,
131
    Ashr,
qinsoon's avatar
qinsoon committed
132
133

    // FP BinOp FP -> FP
134
    FAdd,
qinsoon's avatar
qinsoon committed
135
136
137
138
139
140
    FSub,
    FMul,
    FDiv,
    FRem
}

qinsoon's avatar
qinsoon committed
141
#[derive(Copy, Clone, Debug, PartialEq, RustcEncodable, RustcDecodable)]
qinsoon's avatar
qinsoon committed
142
143
144
145
146
147
148
149
150
151
152
153
pub enum CmpOp {
    // for Int comparison
    EQ,
    NE,
    SGE,
    SGT,
    SLE,
    SLT,
    UGE,
    UGT,
    ULE,
    ULT,
154

qinsoon's avatar
qinsoon committed
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
    // for FP comparison
    FFALSE,
    FTRUE,
    FOEQ,
    FOGT,
    FOGE,
    FOLT,
    FOLE,
    FONE,
    FORD,
    FUEQ,
    FUGT,
    FUGE,
    FULT,
    FULE,
    FUNE,
    FUNO
}

qinsoon's avatar
qinsoon committed
174
#[derive(Copy, Clone, Debug, PartialEq, RustcEncodable, RustcDecodable)]
qinsoon's avatar
qinsoon committed
175
176
177
178
179
180
181
182
183
184
185
186
pub enum AtomicRMWOp {
    XCHG,
    ADD,
    SUB,
    AND,
    NAND,
    OR,
    XOR,
    MAX,
    MIN,
    UMAX,
    UMIN
187
188
}

qinsoon's avatar
qinsoon committed
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
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
    }
}

205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
pub fn pick_op_code_for_inst(inst: &Instruction) -> OpCode {
    match inst.v {
        Instruction_::BinOp(op, _, _) => OpCode::Binary(op),
        Instruction_::CmpOp(op, _, _) => OpCode::Comparison(op),
        Instruction_::AtomicRMW{op, ..} => OpCode::AtomicRMW(op),
        Instruction_::ExprCall{..} => OpCode::ExprCall,
        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_::Watchpoint{..} => OpCode::Watchpoint,
        Instruction_::WPBranch{..} => OpCode::WPBranch,
        Instruction_::Call{..} => OpCode::Call,
        Instruction_::SwapStack{..} => OpCode::SwapStack,
        Instruction_::Switch{..} => OpCode::Switch,
        Instruction_::ExnInstruction{..} => OpCode::ExnInstruction
    }
}