Mercurial > projects > ldc
annotate gen/elem.c @ 11:d3ee9efe20e2 trunk
[svn r15] * Fixed a bunch problems with virtual calls. Seems I did some rather poor testing.
* Now 50/51 tests compile.
* Added a simple runalltests.d scripts that should be run with 'gdmd -run runalltests.d' - LLVMDC will not compile it yet.
author | lindquist |
---|---|
date | Tue, 02 Oct 2007 05:10:18 +0200 |
parents | e116aa1488e6 |
children | 37a4fdab33fc |
rev | line source |
---|---|
1 | 1 #include <iostream> |
2 | |
3 #include "llvm/Instructions.h" | |
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; |
1 | 21 |
22 vardecl = 0; | |
23 funcdecl = 0; | |
24 } | |
25 | |
26 llvm::Value* elem::getValue() | |
27 { | |
28 assert(val || mem); | |
29 switch(type) | |
30 { | |
31 case NONE: | |
32 assert(0 && "type == NONE"); | |
33 break; | |
34 | |
35 case VAR: | |
36 case REF: { | |
37 if (val) { | |
38 return val; | |
39 } | |
40 else { | |
41 if (!llvm::isa<llvm::PointerType>(mem->getType())) | |
42 { | |
43 Logger::cout() << "unexpected type: " << *mem->getType() << '\n'; | |
44 assert(0); | |
45 } | |
46 const llvm::PointerType* pt = llvm::cast<llvm::PointerType>(mem->getType()); | |
47 if (!pt->getElementType()->isFirstClassType()) { | |
48 return mem; | |
49 } | |
50 else { | |
51 return new llvm::LoadInst(mem, "tmp", gIR->scopebb()); | |
52 } | |
53 } | |
54 } | |
55 | |
56 case VAL: | |
57 case NUL: | |
58 case FUNC: | |
59 case CONST: | |
60 case SLICE: | |
61 return val ? val : mem; | |
62 } | |
63 assert(0 && "type == invalid value"); | |
64 return 0; | |
65 } |