annotate gen/binops.cpp @ 1638:0de4525a9ed6

Apply workaround for #395 by klickverbot.
author Christian Kamm <kamm incasoftware de>
date Mon, 08 Mar 2010 20:06:08 +0100
parents cc5fee7836dc
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
86
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents:
diff changeset
1 #include "gen/llvm.h"
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents:
diff changeset
2
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents:
diff changeset
3 #include "declaration.h"
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents:
diff changeset
4
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents:
diff changeset
5 #include "gen/irstate.h"
104
4d1e9eb001e0 [svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents: 86
diff changeset
6 #include "gen/tollvm.h"
86
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents:
diff changeset
7 #include "gen/dvalue.h"
1503
cc5fee7836dc Made is and !is use the same numeric comparison as == and !=, fixes #328
Christian Kamm <kamm incasoftware de>
parents: 524
diff changeset
8 #include "gen/logger.h"
cc5fee7836dc Made is and !is use the same numeric comparison as == and !=, fixes #328
Christian Kamm <kamm incasoftware de>
parents: 524
diff changeset
9 #include "gen/complex.h"
86
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents:
diff changeset
10
104
4d1e9eb001e0 [svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents: 86
diff changeset
11 //////////////////////////////////////////////////////////////////////////////
4d1e9eb001e0 [svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents: 86
diff changeset
12
86
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents:
diff changeset
13 DValue* DtoBinAdd(DValue* lhs, DValue* rhs)
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents:
diff changeset
14 {
213
7816aafeea3c [svn r229] Updated the object.d implementation to the latest Tango.
lindquist
parents: 104
diff changeset
15 LLValue* v = gIR->ir->CreateAdd(lhs->getRVal(), rhs->getRVal(), "tmp");
86
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents:
diff changeset
16 return new DImValue( lhs->getType(), v );
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents:
diff changeset
17 }
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents:
diff changeset
18
104
4d1e9eb001e0 [svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents: 86
diff changeset
19 //////////////////////////////////////////////////////////////////////////////
4d1e9eb001e0 [svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents: 86
diff changeset
20
86
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents:
diff changeset
21 DValue* DtoBinSub(DValue* lhs, DValue* rhs)
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents:
diff changeset
22 {
213
7816aafeea3c [svn r229] Updated the object.d implementation to the latest Tango.
lindquist
parents: 104
diff changeset
23 LLValue* v = gIR->ir->CreateSub(lhs->getRVal(), rhs->getRVal(), "tmp");
86
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents:
diff changeset
24 return new DImValue( lhs->getType(), v );
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents:
diff changeset
25 }
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents:
diff changeset
26
104
4d1e9eb001e0 [svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents: 86
diff changeset
27 //////////////////////////////////////////////////////////////////////////////
4d1e9eb001e0 [svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents: 86
diff changeset
28
524
ca2dfe98036c Binary ops had the wrong result type for real op imaginary.
Christian Kamm <kamm incasoftware de>
parents: 244
diff changeset
29 DValue* DtoBinMul(Type* targettype, DValue* lhs, DValue* rhs)
86
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents:
diff changeset
30 {
213
7816aafeea3c [svn r229] Updated the object.d implementation to the latest Tango.
lindquist
parents: 104
diff changeset
31 LLValue* v = gIR->ir->CreateMul(lhs->getRVal(), rhs->getRVal(), "tmp");
524
ca2dfe98036c Binary ops had the wrong result type for real op imaginary.
Christian Kamm <kamm incasoftware de>
parents: 244
diff changeset
32 return new DImValue( targettype, v );
86
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents:
diff changeset
33 }
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents:
diff changeset
34
104
4d1e9eb001e0 [svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents: 86
diff changeset
35 //////////////////////////////////////////////////////////////////////////////
4d1e9eb001e0 [svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents: 86
diff changeset
36
524
ca2dfe98036c Binary ops had the wrong result type for real op imaginary.
Christian Kamm <kamm incasoftware de>
parents: 244
diff changeset
37 DValue* DtoBinDiv(Type* targettype, DValue* lhs, DValue* rhs)
86
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents:
diff changeset
38 {
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents:
diff changeset
39 Type* t = lhs->getType();
244
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents: 213
diff changeset
40 LLValue *l, *r;
86
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents:
diff changeset
41 l = lhs->getRVal();
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents:
diff changeset
42 r = rhs->getRVal();
213
7816aafeea3c [svn r229] Updated the object.d implementation to the latest Tango.
lindquist
parents: 104
diff changeset
43 LLValue* res;
86
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents:
diff changeset
44 if (t->isfloating())
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents:
diff changeset
45 res = gIR->ir->CreateFDiv(l, r, "tmp");
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents:
diff changeset
46 else if (!t->isunsigned())
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents:
diff changeset
47 res = gIR->ir->CreateSDiv(l, r, "tmp");
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents:
diff changeset
48 else
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents:
diff changeset
49 res = gIR->ir->CreateUDiv(l, r, "tmp");
524
ca2dfe98036c Binary ops had the wrong result type for real op imaginary.
Christian Kamm <kamm incasoftware de>
parents: 244
diff changeset
50 return new DImValue( targettype, res );
86
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents:
diff changeset
51 }
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents:
diff changeset
52
104
4d1e9eb001e0 [svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents: 86
diff changeset
53 //////////////////////////////////////////////////////////////////////////////
4d1e9eb001e0 [svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents: 86
diff changeset
54
524
ca2dfe98036c Binary ops had the wrong result type for real op imaginary.
Christian Kamm <kamm incasoftware de>
parents: 244
diff changeset
55 DValue* DtoBinRem(Type* targettype, DValue* lhs, DValue* rhs)
86
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents:
diff changeset
56 {
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents:
diff changeset
57 Type* t = lhs->getType();
244
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents: 213
diff changeset
58 LLValue *l, *r;
86
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents:
diff changeset
59 l = lhs->getRVal();
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents:
diff changeset
60 r = rhs->getRVal();
213
7816aafeea3c [svn r229] Updated the object.d implementation to the latest Tango.
lindquist
parents: 104
diff changeset
61 LLValue* res;
86
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents:
diff changeset
62 if (t->isfloating())
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents:
diff changeset
63 res = gIR->ir->CreateFRem(l, r, "tmp");
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents:
diff changeset
64 else if (!t->isunsigned())
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents:
diff changeset
65 res = gIR->ir->CreateSRem(l, r, "tmp");
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents:
diff changeset
66 else
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents:
diff changeset
67 res = gIR->ir->CreateURem(l, r, "tmp");
524
ca2dfe98036c Binary ops had the wrong result type for real op imaginary.
Christian Kamm <kamm incasoftware de>
parents: 244
diff changeset
68 return new DImValue( targettype, res );
86
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents:
diff changeset
69 }
1503
cc5fee7836dc Made is and !is use the same numeric comparison as == and !=, fixes #328
Christian Kamm <kamm incasoftware de>
parents: 524
diff changeset
70
cc5fee7836dc Made is and !is use the same numeric comparison as == and !=, fixes #328
Christian Kamm <kamm incasoftware de>
parents: 524
diff changeset
71 //////////////////////////////////////////////////////////////////////////////
cc5fee7836dc Made is and !is use the same numeric comparison as == and !=, fixes #328
Christian Kamm <kamm incasoftware de>
parents: 524
diff changeset
72
cc5fee7836dc Made is and !is use the same numeric comparison as == and !=, fixes #328
Christian Kamm <kamm incasoftware de>
parents: 524
diff changeset
73 LLValue* DtoBinNumericEquals(Loc loc, DValue* lhs, DValue* rhs, TOK op)
cc5fee7836dc Made is and !is use the same numeric comparison as == and !=, fixes #328
Christian Kamm <kamm incasoftware de>
parents: 524
diff changeset
74 {
cc5fee7836dc Made is and !is use the same numeric comparison as == and !=, fixes #328
Christian Kamm <kamm incasoftware de>
parents: 524
diff changeset
75 assert(op == TOKequal || op == TOKnotequal ||
cc5fee7836dc Made is and !is use the same numeric comparison as == and !=, fixes #328
Christian Kamm <kamm incasoftware de>
parents: 524
diff changeset
76 op == TOKidentity || op == TOKnotidentity);
cc5fee7836dc Made is and !is use the same numeric comparison as == and !=, fixes #328
Christian Kamm <kamm incasoftware de>
parents: 524
diff changeset
77 Type* t = lhs->getType()->toBasetype();
cc5fee7836dc Made is and !is use the same numeric comparison as == and !=, fixes #328
Christian Kamm <kamm incasoftware de>
parents: 524
diff changeset
78 assert(t->isfloating());
cc5fee7836dc Made is and !is use the same numeric comparison as == and !=, fixes #328
Christian Kamm <kamm incasoftware de>
parents: 524
diff changeset
79 Logger::println("numeric equality");
cc5fee7836dc Made is and !is use the same numeric comparison as == and !=, fixes #328
Christian Kamm <kamm incasoftware de>
parents: 524
diff changeset
80
cc5fee7836dc Made is and !is use the same numeric comparison as == and !=, fixes #328
Christian Kamm <kamm incasoftware de>
parents: 524
diff changeset
81 LLValue* lv = lhs->getRVal();
cc5fee7836dc Made is and !is use the same numeric comparison as == and !=, fixes #328
Christian Kamm <kamm incasoftware de>
parents: 524
diff changeset
82 LLValue* rv = rhs->getRVal();
cc5fee7836dc Made is and !is use the same numeric comparison as == and !=, fixes #328
Christian Kamm <kamm incasoftware de>
parents: 524
diff changeset
83 LLValue* res = 0;
cc5fee7836dc Made is and !is use the same numeric comparison as == and !=, fixes #328
Christian Kamm <kamm incasoftware de>
parents: 524
diff changeset
84
cc5fee7836dc Made is and !is use the same numeric comparison as == and !=, fixes #328
Christian Kamm <kamm incasoftware de>
parents: 524
diff changeset
85 if (t->iscomplex())
cc5fee7836dc Made is and !is use the same numeric comparison as == and !=, fixes #328
Christian Kamm <kamm incasoftware de>
parents: 524
diff changeset
86 {
cc5fee7836dc Made is and !is use the same numeric comparison as == and !=, fixes #328
Christian Kamm <kamm incasoftware de>
parents: 524
diff changeset
87 Logger::println("complex");
cc5fee7836dc Made is and !is use the same numeric comparison as == and !=, fixes #328
Christian Kamm <kamm incasoftware de>
parents: 524
diff changeset
88 res = DtoComplexEquals(loc, op, lhs, rhs);
cc5fee7836dc Made is and !is use the same numeric comparison as == and !=, fixes #328
Christian Kamm <kamm incasoftware de>
parents: 524
diff changeset
89 }
cc5fee7836dc Made is and !is use the same numeric comparison as == and !=, fixes #328
Christian Kamm <kamm incasoftware de>
parents: 524
diff changeset
90 else if (t->isfloating())
cc5fee7836dc Made is and !is use the same numeric comparison as == and !=, fixes #328
Christian Kamm <kamm incasoftware de>
parents: 524
diff changeset
91 {
cc5fee7836dc Made is and !is use the same numeric comparison as == and !=, fixes #328
Christian Kamm <kamm incasoftware de>
parents: 524
diff changeset
92 Logger::println("floating");
cc5fee7836dc Made is and !is use the same numeric comparison as == and !=, fixes #328
Christian Kamm <kamm incasoftware de>
parents: 524
diff changeset
93 res = (op == TOKidentity || op == TOKequal)
cc5fee7836dc Made is and !is use the same numeric comparison as == and !=, fixes #328
Christian Kamm <kamm incasoftware de>
parents: 524
diff changeset
94 ? gIR->ir->CreateFCmpOEQ(lv,rv,"tmp")
cc5fee7836dc Made is and !is use the same numeric comparison as == and !=, fixes #328
Christian Kamm <kamm incasoftware de>
parents: 524
diff changeset
95 : gIR->ir->CreateFCmpUNE(lv,rv,"tmp");
cc5fee7836dc Made is and !is use the same numeric comparison as == and !=, fixes #328
Christian Kamm <kamm incasoftware de>
parents: 524
diff changeset
96 }
cc5fee7836dc Made is and !is use the same numeric comparison as == and !=, fixes #328
Christian Kamm <kamm incasoftware de>
parents: 524
diff changeset
97
cc5fee7836dc Made is and !is use the same numeric comparison as == and !=, fixes #328
Christian Kamm <kamm incasoftware de>
parents: 524
diff changeset
98 assert(res);
cc5fee7836dc Made is and !is use the same numeric comparison as == and !=, fixes #328
Christian Kamm <kamm incasoftware de>
parents: 524
diff changeset
99 return res;
cc5fee7836dc Made is and !is use the same numeric comparison as == and !=, fixes #328
Christian Kamm <kamm incasoftware de>
parents: 524
diff changeset
100 }