Mercurial > projects > ldc
annotate gen/elem.c @ 40:8b0e809563df trunk
[svn r44] Lots of bug fixes.
New array literal support
New array ~= operator support (for single element)
New with statement support
More...
author | lindquist |
---|---|
date | Fri, 19 Oct 2007 07:43:21 +0200 |
parents | 4648206ca213 |
children | 0c77619e803b |
rev | line source |
---|---|
1 | 1 #include <iostream> |
2 | |
40 | 3 #include "gen/llvm.h" |
1 | 4 |
4
e116aa1488e6
[svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents:
1
diff
changeset
|
5 #include "gen/elem.h" |
e116aa1488e6
[svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents:
1
diff
changeset
|
6 #include "gen/irstate.h" |
e116aa1488e6
[svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents:
1
diff
changeset
|
7 #include "gen/logger.h" |
1 | 8 |
9 ////////////////////////////////////////////////////////////////////////////////////////// | |
10 | |
11 elem::elem() | |
12 { | |
13 mem = 0; | |
14 val = 0; | |
15 arg = 0; | |
16 | |
17 type = NONE; | |
18 inplace = false; | |
19 field = false; | |
11
d3ee9efe20e2
[svn r15] * Fixed a bunch problems with virtual calls. Seems I did some rather poor testing.
lindquist
parents:
4
diff
changeset
|
20 callconv = (unsigned)-1; |
15
37a4fdab33fc
[svn r19] * Added support for reassigning 'this' inside class constructors.
lindquist
parents:
11
diff
changeset
|
21 isthis = false; |
1 | 22 |
23 vardecl = 0; | |
24 funcdecl = 0; | |
25 } | |
26 | |
27 llvm::Value* elem::getValue() | |
28 { | |
29 assert(val || mem); | |
30 switch(type) | |
31 { | |
32 case NONE: | |
33 assert(0 && "type == NONE"); | |
34 break; | |
35 | |
36 case VAR: | |
34 | 37 case REF: |
38 case ARRAYLEN: | |
1 | 39 if (val) { |
40 return val; | |
41 } | |
42 else { | |
43 if (!llvm::isa<llvm::PointerType>(mem->getType())) | |
44 { | |
45 Logger::cout() << "unexpected type: " << *mem->getType() << '\n'; | |
46 assert(0); | |
47 } | |
48 const llvm::PointerType* pt = llvm::cast<llvm::PointerType>(mem->getType()); | |
49 if (!pt->getElementType()->isFirstClassType()) { | |
50 return mem; | |
51 } | |
52 else { | |
40 | 53 return gIR->ir->CreateLoad(mem, "tmp"); |
1 | 54 } |
55 } | |
56 | |
57 case VAL: | |
58 case NUL: | |
59 case FUNC: | |
60 case CONST: | |
61 case SLICE: | |
62 return val ? val : mem; | |
63 } | |
64 assert(0 && "type == invalid value"); | |
65 return 0; | |
66 } |