annotate dmd/XorExp.d @ 67:f708f0452e81

some of the backend/codegen stuff implemented
author korDen
date Mon, 23 Aug 2010 21:21:05 +0400
parents cab4c37afb89
children 2e2a5c3f943a
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1 module dmd.XorExp;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3 import dmd.Expression;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4 import dmd.Identifier;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5 import dmd.InterState;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
6 import dmd.MATCH;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
7 import dmd.Id;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
8 import dmd.Type;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
9 import dmd.OutBuffer;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
10 import dmd.Loc;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
11 import dmd.Scope;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
12 import dmd.IntRange;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
13 import dmd.IRState;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
14 import dmd.ArrayTypes;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
15 import dmd.BinExp;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
16 import dmd.TOK;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
17 import dmd.TY;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
18
67
f708f0452e81 some of the backend/codegen stuff implemented
korDen
parents: 63
diff changeset
19 import dmd.backend.elem;
f708f0452e81 some of the backend/codegen stuff implemented
korDen
parents: 63
diff changeset
20 import dmd.backend.OPER;
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
21 import dmd.expression.Util;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
22 import dmd.expression.Xor;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
23
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
24 class XorExp : BinExp
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
25 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
26 this(Loc loc, Expression e1, Expression e2)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
27 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
28 super(loc, TOK.TOKxor, XorExp.sizeof, e1, e2);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
29 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
30
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
31 Expression semantic(Scope sc)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
32 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
33 Expression e;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
34
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
35 if (!type)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
36 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
37 BinExp.semanticp(sc);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
38 e = op_overload(sc);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
39 if (e)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
40 return e;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
41 if (e1.type.toBasetype().ty == Tbool &&
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
42 e2.type.toBasetype().ty == Tbool)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
43 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
44 type = e1.type;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
45 e = this;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
46 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
47 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
48 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
49 typeCombine(sc);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
50 if (e1.op != TOKslice && e2.op != TOKslice)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
51 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
52 e1.checkIntegral();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
53 e2.checkIntegral();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
54 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
55 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
56 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
57 return this;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
58 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
59
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
60 Expression optimize(int result)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
61 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
62 Expression e;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
63
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
64 e1 = e1.optimize(result);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
65 e2 = e2.optimize(result);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
66 if (e1.isConst() == 1 && e2.isConst() == 1)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
67 e = Xor(type, e1, e2);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
68 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
69 e = this;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
70
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
71 return e;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
72 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
73
63
cab4c37afb89 A bunch of implementations
korDen
parents: 56
diff changeset
74 Expression interpret(InterState istate)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
75 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
76 assert(false);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
77 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
78
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
79 void buildArrayIdent(OutBuffer buf, Expressions arguments)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
80 {
12
832f71e6f96c *Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents: 0
diff changeset
81 Exp_buildArrayIdent(buf, arguments, "Xor");
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
82 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
83
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
84 Expression buildArrayLoop(Arguments fparams)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
85 {
12
832f71e6f96c *Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents: 0
diff changeset
86 /* Evaluate assign expressions left to right
832f71e6f96c *Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents: 0
diff changeset
87 */
832f71e6f96c *Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents: 0
diff changeset
88 Expression ex1 = e1.buildArrayLoop(fparams);
832f71e6f96c *Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents: 0
diff changeset
89 Expression ex2 = e2.buildArrayLoop(fparams);
832f71e6f96c *Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents: 0
diff changeset
90 Expression e = new XorExp(Loc(0), ex1, ex2);
832f71e6f96c *Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents: 0
diff changeset
91 return e;
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
92 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
93
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
94 MATCH implicitConvTo(Type t)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
95 {
56
51605de93870 TupleExp.optimize
korDen
parents: 12
diff changeset
96 MATCH result = Expression.implicitConvTo(t);
51605de93870 TupleExp.optimize
korDen
parents: 12
diff changeset
97
51605de93870 TupleExp.optimize
korDen
parents: 12
diff changeset
98 if (result == MATCHnomatch)
51605de93870 TupleExp.optimize
korDen
parents: 12
diff changeset
99 {
51605de93870 TupleExp.optimize
korDen
parents: 12
diff changeset
100 MATCH m1 = e1.implicitConvTo(t);
51605de93870 TupleExp.optimize
korDen
parents: 12
diff changeset
101 MATCH m2 = e2.implicitConvTo(t);
51605de93870 TupleExp.optimize
korDen
parents: 12
diff changeset
102
51605de93870 TupleExp.optimize
korDen
parents: 12
diff changeset
103 // Pick the worst match
51605de93870 TupleExp.optimize
korDen
parents: 12
diff changeset
104 result = (m1 < m2) ? m1 : m2;
51605de93870 TupleExp.optimize
korDen
parents: 12
diff changeset
105 }
51605de93870 TupleExp.optimize
korDen
parents: 12
diff changeset
106 return result;
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
107 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
108
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
109 IntRange getIntRange()
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
110 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
111 assert(false);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
112 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
113
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
114 bool isCommutative()
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
115 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
116 return true;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
117 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
118
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
119 Identifier opId()
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
120 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
121 return Id.ixor;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
122 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
123
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
124 Identifier opId_r()
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
125 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
126 return Id.ixor_r;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
127 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
128
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
129 elem* toElem(IRState* irs)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
130 {
67
f708f0452e81 some of the backend/codegen stuff implemented
korDen
parents: 63
diff changeset
131 return toElemBin(irs,OPxor);
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
132 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
133 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
134