Mercurial > projects > ldc
annotate gen/elem.c @ 4:e116aa1488e6 trunk
[svn r8] changed backend includes to always use the gen/<foo>.h prefix
fixed passing string literals as array parameters
few other fixes
moved some array routines into gen/arrays
author | lindquist |
---|---|
date | Mon, 03 Sep 2007 17:34:30 +0200 |
parents | c53b6e3fe49a |
children | d3ee9efe20e2 |
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; | |
20 | |
21 vardecl = 0; | |
22 funcdecl = 0; | |
23 } | |
24 | |
25 llvm::Value* elem::getValue() | |
26 { | |
27 assert(val || mem); | |
28 switch(type) | |
29 { | |
30 case NONE: | |
31 assert(0 && "type == NONE"); | |
32 break; | |
33 | |
34 case VAR: | |
35 case REF: { | |
36 if (val) { | |
37 return val; | |
38 } | |
39 else { | |
40 if (!llvm::isa<llvm::PointerType>(mem->getType())) | |
41 { | |
42 Logger::cout() << "unexpected type: " << *mem->getType() << '\n'; | |
43 assert(0); | |
44 } | |
45 const llvm::PointerType* pt = llvm::cast<llvm::PointerType>(mem->getType()); | |
46 if (!pt->getElementType()->isFirstClassType()) { | |
47 return mem; | |
48 } | |
49 else { | |
50 return new llvm::LoadInst(mem, "tmp", gIR->scopebb()); | |
51 } | |
52 } | |
53 } | |
54 | |
55 case VAL: | |
56 case NUL: | |
57 case FUNC: | |
58 case CONST: | |
59 case SLICE: | |
60 return val ? val : mem; | |
61 } | |
62 assert(0 && "type == invalid value"); | |
63 return 0; | |
64 } |