comparison gen/irstate.h @ 40:8b0e809563df trunk

[svn r44] Lots of bug fixes. New array literal support New array ~= operator support (for single element) New with statement support More...
author lindquist
date Fri, 19 Oct 2007 07:43:21 +0200
parents 2841234d2aea
children 28e99b04a132
comparison
equal deleted inserted replaced
39:fd5e8bbfcb25 40:8b0e809563df
2 #define LLVMDC_GEN_IRSTATE_H 2 #define LLVMDC_GEN_IRSTATE_H
3 3
4 #include <stack> 4 #include <stack>
5 #include <vector> 5 #include <vector>
6 #include <deque> 6 #include <deque>
7
8 #include "llvm/DerivedTypes.h"
9 #include "llvm/Module.h"
10 #include "llvm/Function.h"
11 #include "llvm/BasicBlock.h"
12 #include "llvm/Target/TargetData.h"
13 7
14 #include "root.h" 8 #include "root.h"
15 9
16 // global ir state for current module 10 // global ir state for current module
17 struct IRState; 11 struct IRState;
23 struct ClassDeclaration; 17 struct ClassDeclaration;
24 struct FuncDeclaration; 18 struct FuncDeclaration;
25 struct Module; 19 struct Module;
26 struct TypeStruct; 20 struct TypeStruct;
27 21
22 /*
23 struct LLVMValue
24 {
25 std::vector<llvm::Value*> vals;
26 };
27 */
28
28 // represents a scope 29 // represents a scope
29 struct IRScope 30 struct IRScope
30 { 31 {
31 llvm::BasicBlock* begin; 32 llvm::BasicBlock* begin;
32 llvm::BasicBlock* end; 33 llvm::BasicBlock* end;
33 bool returned; 34 LLVMBuilder builder;
34 35
35 IRScope(); 36 IRScope();
36 IRScope(llvm::BasicBlock* b, llvm::BasicBlock* e); 37 IRScope(llvm::BasicBlock* b, llvm::BasicBlock* e);
37 }; 38 };
38 39
39 // represents a struct or class 40 // represents a struct or class
40 struct IRStruct : Object 41 struct IRStruct
41 { 42 {
42 typedef std::vector<const llvm::Type*> TypeVector; 43 typedef std::vector<const llvm::Type*> TypeVector;
43 typedef std::vector<llvm::Constant*> ConstantVector; 44 typedef std::vector<llvm::Constant*> ConstantVector;
44 typedef std::vector<FuncDeclaration*> FuncDeclVec; 45 typedef std::vector<FuncDeclaration*> FuncDeclVec;
45 46
46 public: 47 public:
47 IRStruct(); 48 IRStruct();
48 IRStruct(Type*); 49 IRStruct(Type*);
49 virtual ~IRStruct();
50 50
51 Type* type; 51 Type* type;
52 TypeVector fields; 52 TypeVector fields;
53 ConstantVector inits; 53 ConstantVector inits;
54 llvm::PATypeHolder recty; 54 llvm::PATypeHolder recty;
55 FuncDeclVec funcs; 55 FuncDeclVec funcs;
56 bool queueFuncs; 56 bool queueFuncs;
57 }; 57 };
58 58
59 // represents a finally block
60 struct IRFinally
61 {
62 llvm::BasicBlock* bb;
63 bool ret;
64 llvm::Value* retval;
65
66 IRFinally();
67 IRFinally(llvm::BasicBlock* b);
68 };
69
70 // represents a function
71 struct IRFunction
72 {
73 llvm::Function* func;
74 llvm::Instruction* allocapoint;
75 FuncDeclaration* decl;
76 TypeFunction* type;
77
78 // finally blocks
79 typedef std::vector<IRFinally> FinallyVec;
80 FinallyVec finallys;
81
82 IRFunction(FuncDeclaration*);
83 };
84
85 struct IRBuilderHelper
86 {
87 IRState* state;
88 LLVMBuilder* operator->();
89 };
90
59 // represents the module 91 // represents the module
60 struct IRState : Object 92 struct IRState
61 { 93 {
62 IRState(); 94 IRState();
63 95
64 // module 96 // module
65 Module* dmodule; 97 Module* dmodule;
66 llvm::Module* module; 98 llvm::Module* module;
67 99
68 // functions 100 // functions
69 std::stack<llvm::Function*> funcs; 101 typedef std::vector<IRFunction> FunctionVector;
102 FunctionVector functions;
103 IRFunction& func();
104
70 llvm::Function* topfunc(); 105 llvm::Function* topfunc();
71 std::stack<TypeFunction*> functypes;
72 TypeFunction* topfunctype(); 106 TypeFunction* topfunctype();
73 llvm::Instruction* topallocapoint(); 107 llvm::Instruction* topallocapoint();
74 108
75 // structs 109 // structs
76 typedef std::vector<IRStruct> StructVector; 110 typedef std::vector<IRStruct> StructVector;
107 // might be a better way but it works. problem is I only get a 141 // might be a better way but it works. problem is I only get a
108 // VarDeclaration for __dollar, but I can't see how to get the 142 // VarDeclaration for __dollar, but I can't see how to get the
109 // array pointer from this :( 143 // array pointer from this :(
110 LvalVec arrays; 144 LvalVec arrays;
111 145
112 // keeping track of the declaration for the current function body 146 // builder helper
113 typedef std::vector<FuncDeclaration*> FuncDeclVec; 147 IRBuilderHelper ir;
114 FuncDeclVec funcdecls;
115 }; 148 };
116 149
117 #endif // LLVMDC_GEN_IRSTATE_H 150 #endif // LLVMDC_GEN_IRSTATE_H