Mercurial > projects > ldc
annotate gen/elem.c @ 52:0c77619e803b trunk
[svn r56] Initial support for TypeInfo.
Enums not work.
Several other bugfixes.
author | lindquist |
---|---|
date | Tue, 23 Oct 2007 05:55:12 +0200 |
parents | 8b0e809563df |
children | 339422268de1 |
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; |
52 | 22 istypeinfo = false; |
1 | 23 |
24 vardecl = 0; | |
25 funcdecl = 0; | |
26 } | |
27 | |
28 llvm::Value* elem::getValue() | |
29 { | |
30 assert(val || mem); | |
31 switch(type) | |
32 { | |
33 case NONE: | |
34 assert(0 && "type == NONE"); | |
35 break; | |
36 | |
37 case VAR: | |
34 | 38 case REF: |
39 case ARRAYLEN: | |
1 | 40 if (val) { |
41 return val; | |
42 } | |
43 else { | |
44 if (!llvm::isa<llvm::PointerType>(mem->getType())) | |
45 { | |
46 Logger::cout() << "unexpected type: " << *mem->getType() << '\n'; | |
47 assert(0); | |
48 } | |
49 const llvm::PointerType* pt = llvm::cast<llvm::PointerType>(mem->getType()); | |
50 if (!pt->getElementType()->isFirstClassType()) { | |
51 return mem; | |
52 } | |
53 else { | |
40 | 54 return gIR->ir->CreateLoad(mem, "tmp"); |
1 | 55 } |
56 } | |
57 | |
58 case VAL: | |
59 case NUL: | |
60 case FUNC: | |
61 case CONST: | |
62 case SLICE: | |
63 return val ? val : mem; | |
64 } | |
65 assert(0 && "type == invalid value"); | |
66 return 0; | |
67 } |