This update:
[IRC.git] / Robust / src / IR / Operation.java
1 package IR;
2
3 public class Operation {
4     public static final int LOGIC_OR=1;
5     public static final int LOGIC_AND=2;
6     public static final int BIT_OR=3;
7     public static final int BIT_XOR=4;
8     public static final int BIT_AND=5;
9     public static final int EQUAL=6;
10     public static final int NOTEQUAL=7;
11     public static final int LT=8;
12     public static final int GT=9;
13     public static final int LTE=10;
14     public static final int GTE=11;
15     public static final int LEFTSHIFT=12;
16     public static final int RIGHTSHIFT=13;
17     public static final int SUB=14;
18     public static final int ADD=15;
19     public static final int MULT=16;
20     public static final int DIV=17;
21     public static final int MOD=18;
22     public static final int UNARYPLUS=19;
23     public static final int UNARYMINUS=20;
24     public static final int POSTINC=21;
25     public static final int POSTDEC=22;
26     public static final int PREINC=23;
27     public static final int PREDEC=24;
28     public static final int LOGIC_NOT=25;
29     public static final int ISAVAILABLE=26;
30     /* Flat Operations */
31     public static final int ASSIGN=100;
32
33     private int operation;
34     public Operation(int op) {
35         this.operation=op;
36     }
37
38     public Operation(String op) {
39         this.operation=parseOp(op);
40     }
41
42     public int getOp() {
43         return operation;
44     }
45     
46     public static int parseOp(String st) {
47         if (st.equals("logical_or"))
48             return LOGIC_OR;
49         else if (st.equals("logical_and"))
50             return LOGIC_AND;
51         else if (st.equals("bitwise_or"))
52             return BIT_OR;
53         else if (st.equals("bitwise_xor"))
54             return BIT_XOR;
55         else if (st.equals("bitwise_and"))
56             return BIT_AND;
57         else if (st.equals("equal"))
58             return EQUAL;
59         else if (st.equals("not_equal"))
60             return NOTEQUAL;
61         else if (st.equals("comp_lt"))
62             return LT;
63         else if (st.equals("comp_gt"))
64             return GT;
65         else if (st.equals("comp_lte"))
66             return LTE;
67         else if (st.equals("comp_gte"))
68             return GTE;
69         else if (st.equals("leftshift"))
70             return LEFTSHIFT;
71         else if (st.equals("rightshift"))
72             return RIGHTSHIFT;
73         else if (st.equals("sub"))
74             return SUB;
75         else if (st.equals("add"))
76             return ADD;
77         else if (st.equals("mult"))
78             return MULT;
79         else if (st.equals("div"))
80             return DIV;
81         else if (st.equals("mod"))
82             return MOD;
83         else if (st.equals("unaryplus"))
84             return UNARYPLUS;
85         else if (st.equals("unaryminus"))
86             return UNARYMINUS;
87         else if (st.equals("postinc"))
88             return POSTINC;
89         else if (st.equals("postdec"))
90             return POSTDEC;
91         else if (st.equals("preinc"))
92             return PREINC;
93         else if (st.equals("predec"))
94             return PREDEC;
95         else if (st.equals("not"))
96             return LOGIC_NOT;
97         else
98             throw new Error();
99     }
100
101     public String toString() {
102         if (operation==LOGIC_OR)
103             return "||";
104         else if (operation==LOGIC_AND)
105             return "&&";
106         else if (operation==LOGIC_NOT)
107             return "not";
108         else if (operation==BIT_OR)
109             return "|";
110         else if (operation==BIT_XOR)
111             return "^";
112         else if (operation==BIT_AND)
113             return "&";
114         else if (operation==EQUAL)
115             return "==";
116         else if (operation==NOTEQUAL)
117             return "!=";
118         else if (operation==LT)
119             return "<";
120         else if (operation==GT)
121             return ">";
122         else if (operation==LTE)
123             return "<=";
124         else if (operation==GTE)
125             return ">=";
126         else if (operation==LEFTSHIFT)
127             return "<<";
128         else if (operation==RIGHTSHIFT)
129             return ">>";
130         else if (operation==SUB)
131             return "-";
132         else if (operation==ADD)
133             return "+";
134         else if (operation==MULT)
135             return "*";
136         else if (operation==DIV)
137             return "/";
138         else if (operation==MOD)
139             return "%";
140         else if (operation==UNARYPLUS)
141             return "unaryplus";
142         else if (operation==UNARYMINUS)
143             return "unaryminus";
144         else if (operation==POSTINC)
145             return "postinc";
146         else if (operation==POSTDEC)
147             return "postdec";
148         else if (operation==PREINC)
149             return "preinc";
150         else if (operation==PREDEC)
151             return "predec";
152         else if (operation==ASSIGN)
153             return "assign";
154         else throw new Error();
155     }
156
157
158 }