diff gen/irstate.h @ 100:5071469303d4 trunk

[svn r104] TONS OF FIXES. Split up declaration, constant initializer gen and definition for globals, structs, classes and functions. Improved ClassInfo support (not complete), not in vtable yet. Fixed a bunch of forward reference problems. Much more. Major commit! :)
author lindquist
date Fri, 16 Nov 2007 08:21:47 +0100
parents 6789050b5ad1
children 027b8d8b71ec
line wrap: on
line diff
--- a/gen/irstate.h	Thu Nov 15 00:24:44 2007 +0100
+++ b/gen/irstate.h	Fri Nov 16 08:21:47 2007 +0100
@@ -39,19 +39,20 @@
 };
 
 // represents a struct or class
-struct IRStruct
+struct IRStruct : Object
 {
     struct Offset
     {
         VarDeclaration* var;
+        const llvm::Type* type;
         llvm::Constant* init;
 
-        Offset(VarDeclaration* v, llvm::Constant* i)
-        : var(v), init(i) {}
+        Offset(VarDeclaration* v, const llvm::Type* ty)
+        : var(v), type(ty), init(NULL) {}
     };
 
-    typedef std::vector<FuncDeclaration*> FuncDeclVector;
     typedef std::multimap<unsigned, Offset> OffsetMap;
+    typedef std::vector<VarDeclaration*> VarDeclVector;
 
 public:
     IRStruct();
@@ -59,10 +60,11 @@
 
     Type* type;
     llvm::PATypeHolder recty;
-    FuncDeclVector funcs;
-    bool queueFuncs;
+    OffsetMap offsets;
+    VarDeclVector defaultFields;
 
-    OffsetMap offsets;
+    bool defined;
+    bool constinited;
 };
 
 // represents a finally block
@@ -76,7 +78,7 @@
 };
 
 // represents a function
-struct IRFunction
+struct IRFunction : Object
 {
     llvm::Function* func;
     llvm::Instruction* allocapoint;
@@ -88,6 +90,8 @@
     FinallyVec finallys;
     llvm::Value* finallyretval;
 
+    bool defined;
+
     IRFunction(FuncDeclaration*);
 };
 
@@ -106,6 +110,15 @@
     IRExp(Expression* l, Expression* r, DValue* val);
 };
 
+// represents a global variable
+struct IRGlobal : Object
+{
+    VarDeclaration* var;
+    llvm::PATypeHolder type;
+
+    IRGlobal(VarDeclaration* v);
+};
+
 // represents the module
 struct IRState
 {
@@ -116,18 +129,18 @@
     llvm::Module* module;
 
     // functions
-    typedef std::vector<IRFunction> FunctionVector;
+    typedef std::vector<IRFunction*> FunctionVector;
     FunctionVector functions;
-    IRFunction& func();
+    IRFunction* func();
 
     llvm::Function* topfunc();
     TypeFunction* topfunctype();
     llvm::Instruction* topallocapoint();
 
     // structs
-    typedef std::vector<IRStruct> StructVector;
+    typedef std::vector<IRStruct*> StructVector;
     StructVector structs;
-    IRStruct& topstruct();
+    IRStruct* topstruct();
 
     // classes TODO move into IRClass
     typedef std::vector<ClassDeclaration*> ClassDeclVec;
@@ -163,9 +176,11 @@
     // builder helper
     IRBuilderHelper ir;
 
-    // functions queued for lazy definition
-    typedef std::vector<FuncDeclaration*> FuncDeclVector;
-    FuncDeclVector funcQueue;
+    typedef std::vector<Dsymbol*> DsymbolVector;
+    // dsymbols that need constant initializers constructed
+    DsymbolVector constInitQueue;
+    // dsymbols that need definitions (symbols in current module)
+    DsymbolVector defineQueue;
 };
 
 #endif // LLVMDC_GEN_IRSTATE_H