2abd7c8e216d4c4e1fb0f449f438e164d5e8d89e
[IRC.git] / Robust / src / IR / AssignOperation.java
1 package IR;
2
3 public class AssignOperation {
4     public static final int EQ=1;
5     public static final int MULTEQ=2;
6     public static final int DIVEQ=3;
7     public static final int MODEQ=4;
8     public static final int PLUSEQ=5;
9     public static final int MINUSEQ=6;
10     public static final int LSHIFTEQ=7;
11     public static final int RSHIFTEQ=8;
12     public static final int URSHIFTEQ=9;
13     public static final int ANDEQ=10;
14     public static final int XOREQ=11;
15     public static final int OREQ=12;
16
17     private int operation;
18     public AssignOperation(int op) {
19         this.operation=op;
20     }
21
22     public AssignOperation(String op) {
23         this.operation=parseOp(op);
24     }
25
26     public Operation getBaseOp() {
27         switch(operation) {
28         case EQ:
29             return null;
30         case MULTEQ:
31             return new Operation(Operation.MULT);
32         case DIVEQ:
33             return new Operation(Operation.DIV);
34         case MODEQ:
35             return new Operation(Operation.MOD);
36         case PLUSEQ:
37             return new Operation(Operation.ADD);
38         case MINUSEQ:
39             return new Operation(Operation.SUB);
40         case LSHIFTEQ:
41             return new Operation(Operation.LEFTSHIFT);
42         case RSHIFTEQ:
43             return new Operation(Operation.RIGHTSHIFT);
44         case ANDEQ:
45             return new Operation(Operation.BIT_AND);
46         case XOREQ:
47             return new Operation(Operation.BIT_XOR);
48         case OREQ:
49             return new Operation(Operation.BIT_OR);
50         }
51         throw new Error();
52     }
53
54     public static int parseOp(String st) {
55         if (st.equals("eq"))
56             return EQ;
57         else if (st.equals("multeq"))
58             return MULTEQ;
59         else if (st.equals("diveq"))
60             return DIVEQ;
61         else if (st.equals("modeq"))
62             return MODEQ;
63         else if (st.equals("pluseq"))
64             return PLUSEQ;
65         else if (st.equals("minuseq"))
66             return MINUSEQ;
67         else if (st.equals("lshifteq"))
68             return LSHIFTEQ;
69         else if (st.equals("rshifteq"))
70             return RSHIFTEQ;
71         else if (st.equals("andeq"))
72             return ANDEQ;
73         else if (st.equals("xoreq"))
74             return XOREQ;
75         else if (st.equals("oreq"))
76             return OREQ;
77         else throw new Error();
78     }
79
80     public String toString() {
81         if (operation==EQ)
82             return "=";
83         else if (operation==MULTEQ)
84             return "*=";
85         else if (operation==DIVEQ)
86             return "/=";
87         else if (operation==MODEQ)
88             return "%=";
89         else if (operation==PLUSEQ)
90             return "+=";
91         else if (operation==MINUSEQ)
92             return "-=";
93         else if (operation==LSHIFTEQ)
94             return "<=";
95         else if (operation==RSHIFTEQ)
96             return ">=";
97         else if (operation==ANDEQ)
98             return "&=";
99         else if (operation==XOREQ)
100             return "^=";
101         else if (operation==OREQ)
102             return "|=";
103         else throw new Error();
104     }
105
106
107 }