comparison ir/irstruct.h @ 797:340acf1535d0

Removed KDevelop3 project files, CMake can generate them just fine! Fixed function literals in static initializers. Changed alignment of delegates from 2*PTRSIZE to just PTRSIZE. Changed errors to go to stderr instead of stdout. Fairly major rewriting of struct/union/class handling, STILL A BIT BUGGY !!!
author Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
date Sat, 29 Nov 2008 21:25:43 +0100
parents 041c1596d217
children 28ce72c60a21
comparison
equal deleted inserted replaced
796:6e7a4c3b64d2 797:340acf1535d0
4 #include "ir/ir.h" 4 #include "ir/ir.h"
5 5
6 #include <vector> 6 #include <vector>
7 #include <map> 7 #include <map>
8 8
9 struct IrInterface : IrBase 9 struct IrInterface;
10
11 //////////////////////////////////////////////////////////////////////////////
12 //////////////////////////////////////////////////////////////////////////////
13 //////////////////////////////////////////////////////////////////////////////
14
15 // represents a struct or class
16 // it is used during codegen to hold all the vital info we need
17 struct IrStruct : IrBase
10 { 18 {
11 BaseClass* base; 19 /////////////////////////////////////////////////////////////////////
12 ClassDeclaration* decl; 20 /////////////////////////////////////////////////////////////////////
13 21
14 llvm::PATypeHolder* vtblTy; 22 typedef std::vector<VarDeclaration*> VarDeclVector;
15 LLConstant* vtblInit; 23
24 typedef std::map<ClassDeclaration*, IrInterface*> InterfaceMap;
25 typedef InterfaceMap::iterator InterfaceMapIter;
26
27 typedef std::vector<IrInterface*> InterfaceVector;
28 typedef InterfaceVector::iterator InterfaceVectorIter;
29
30 // vector of LLVM types
31 typedef std::vector<const llvm::Type*> TypeVector;
32
33 /////////////////////////////////////////////////////////////////////
34 /////////////////////////////////////////////////////////////////////
35
36 // Anon represents an anonymous struct union block inside an aggregate
37 // during LLVM type construction.
38 struct Anon
39 {
40 bool isunion;
41 Anon* parent;
42
43 TypeVector types;
44
45 Anon(bool IsUnion, Anon* par) : isunion(IsUnion), parent(par) {}
46 };
47
48 /////////////////////////////////////////////////////////////////////
49 /////////////////////////////////////////////////////////////////////
50
51 /// ctor
52 IrStruct(AggregateDeclaration* agg);
53
54 /// dtor
55 virtual ~IrStruct();
56
57 /////////////////////////////////////////////////////////////////////
58 /////////////////////////////////////////////////////////////////////
59
60 /// push an anonymous struct/union
61 void pushAnon(bool isunion);
62
63 /// pops an anonymous struct/union
64 void popAnon();
65
66 /// adds field
67 void addVar(VarDeclaration* var);
68
69 /////////////////////////////////////////////////////////////////////
70 /////////////////////////////////////////////////////////////////////
71
72 /// build the aggr type
73 const LLType* build();
74
75 /// put the aggr initializers in a vector
76 void buildDefaultConstInit(std::vector<llvm::Constant*>& inits);
77
78 /// ditto - but also builds the constant struct, for convenience
79 LLConstant* buildDefaultConstInit();
80
81 /////////////////////////////////////////////////////////////////////
82 /////////////////////////////////////////////////////////////////////
83
84 // the D aggregate
85 AggregateDeclaration* aggrdecl;
86
87 // vector of VarDeclarations in this aggregate
88 VarDeclVector varDecls;
89
90 // vector of VarDeclarations that contribute to the default initializer
91 VarDeclVector defVars;
92
93 // true if the default initializer has been built
94 bool defaultFound;
95
96 // top element
97 Anon* anon;
98
99 // toplevel types in this aggr
100 TypeVector types;
101
102 // current index
103 // always the same as types.size()
104 size_t index;
105
106 // aggregate D type
107 Type* type;
108
109 // class vtable type
110 llvm::PATypeHolder vtblTy;
111 llvm::PATypeHolder vtblInitTy;
112
113 // initializer type opaque (type of global matches initializer, not formal type)
114 llvm::PATypeHolder initOpaque;
115 llvm::PATypeHolder classInfoOpaque;
116
117 // map/vector of interfaces implemented
118 InterfaceMap interfaceMap;
119 InterfaceVector interfaceVec;
120
121 // interface info array global
122 LLGlobalVariable* interfaceInfos;
123
124 // ...
125 bool defined;
126 bool constinited;
127
128 // vtbl global and initializer
16 LLGlobalVariable* vtbl; 129 LLGlobalVariable* vtbl;
130 LLConstant* constVtbl;
17 131
18 const LLStructType* infoTy; 132 // static initializers global and constant
19 LLConstantStruct* infoInit; 133 LLGlobalVariable* init;
20 LLConstant* info; 134 LLConstant* constInit;
21 135
22 int index; 136 // classinfo global and initializer constant
137 LLGlobalVariable* classInfo;
138 LLConstant* constClassInfo;
139 bool classInfoDeclared;
140 bool classInfoDefined;
23 141
24 IrInterface(BaseClass* b); 142 // align(1) struct S { ... }
25 ~IrInterface(); 143 bool packed;
144
145 // dwarf composite global
146 LLGlobalVariable* dwarfComposite;
26 }; 147 };
27 148
28 ////////////////////////////////////////////////////////////////////////////// 149 //////////////////////////////////////////////////////////////////////////////
29 ////////////////////////////////////////////////////////////////////////////// 150 //////////////////////////////////////////////////////////////////////////////
30 ////////////////////////////////////////////////////////////////////////////// 151 //////////////////////////////////////////////////////////////////////////////
31 152
32 // represents a struct or class 153 // represents interface implemented by a class
33 struct IrStruct : IrBase 154 struct IrInterface : IrBase
34 { 155 {
35 struct Offset 156 BaseClass* base;
36 { 157 ClassDeclaration* decl;
37 VarDeclaration* var;
38 const LLType* type;
39 LLConstant* init;
40 158
41 Offset(VarDeclaration* v, const LLType* ty) 159 llvm::PATypeHolder vtblInitTy;
42 : var(v), type(ty), init(NULL) {}
43 };
44 160
45 typedef std::multimap<unsigned, Offset> OffsetMap; 161 LLConstant* vtblInit;
46 typedef std::vector<VarDeclaration*> VarDeclVector; 162 LLGlobalVariable* vtbl;
47 typedef std::map<ClassDeclaration*, IrInterface*> InterfaceMap;
48 typedef InterfaceMap::iterator InterfaceMapIter;
49 typedef std::vector<IrInterface*> InterfaceVector;
50 typedef InterfaceVector::iterator InterfaceVectorIter;
51 163
52 public: 164 const LLStructType* infoTy;
53 IrStruct(Type*); 165 LLConstant* infoInit;
54 virtual ~IrStruct(); 166 LLConstant* info;
55 167
56 void addField(VarDeclaration* v); 168 size_t index;
57 169
58 Type* type; 170 IrInterface(BaseClass* b);
59 llvm::PATypeHolder recty;
60 OffsetMap offsets;
61 VarDeclVector defaultFields;
62
63 InterfaceMap interfaceMap;
64 InterfaceVector interfaceVec;
65 const llvm::ArrayType* interfaceInfosTy;
66 LLGlobalVariable* interfaceInfos;
67
68 bool defined;
69 bool constinited;
70
71 LLGlobalVariable* vtbl;
72 #if OPAQUE_VTBLS
73 LLConstant* constVtbl;
74 #else
75 LLConstantStruct* constVtbl;
76 #endif
77 LLGlobalVariable* init;
78 LLConstant* constInit;
79 LLGlobalVariable* classInfo;
80 LLConstant* constClassInfo;
81 bool hasUnions;
82 DUnion* dunion;
83 bool classDeclared;
84 bool classDefined;
85
86 bool packed; // true for: align(1) struct S { ... }
87
88 LLGlobalVariable* dwarfComposite;
89 }; 171 };
90 172
91 #endif 173 #endif