1
|
1 #include <iostream>
|
|
2
|
|
3 #include "llvm/Instructions.h"
|
|
4
|
|
5 #include "elem.h"
|
|
6
|
|
7 #include "irstate.h"
|
|
8 #include "logger.h"
|
|
9
|
|
10 //////////////////////////////////////////////////////////////////////////////////////////
|
|
11
|
|
12 elem::elem()
|
|
13 {
|
|
14 mem = 0;
|
|
15 val = 0;
|
|
16 arg = 0;
|
|
17
|
|
18 type = NONE;
|
|
19 inplace = false;
|
|
20 field = false;
|
|
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 }
|