Mercurial > projects > ldc
comparison gen/irstate.h @ 1:c53b6e3fe49a trunk
[svn r5] Initial commit. Most things are very rough.
author | lindquist |
---|---|
date | Sat, 01 Sep 2007 21:43:27 +0200 |
parents | |
children | 35d93ce68cf4 |
comparison
equal
deleted
inserted
replaced
0:a9e71648e74d | 1:c53b6e3fe49a |
---|---|
1 #ifndef LLVMDC_GEN_IRSTATE_H | |
2 #define LLVMDC_GEN_IRSTATE_H | |
3 | |
4 #include <stack> | |
5 #include <vector> | |
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 | |
14 #include "root.h" | |
15 | |
16 // global ir state for current module | |
17 struct IRState; | |
18 extern IRState* gIR; | |
19 extern llvm::TargetData* gTargetData; | |
20 | |
21 struct TypeFunction; | |
22 struct TypeStruct; | |
23 struct ClassDeclaration; | |
24 struct FuncDeclaration; | |
25 struct Module; | |
26 struct TypeStruct; | |
27 | |
28 // represents a scope | |
29 struct IRScope | |
30 { | |
31 llvm::BasicBlock* begin; | |
32 llvm::BasicBlock* end; | |
33 bool returned; | |
34 | |
35 IRScope(); | |
36 IRScope(llvm::BasicBlock* b, llvm::BasicBlock* e); | |
37 }; | |
38 | |
39 // represents a struct | |
40 struct IRStruct : Object | |
41 { | |
42 typedef std::vector<const llvm::Type*> TypeVector; | |
43 typedef std::vector<llvm::Constant*> ConstantVector; | |
44 typedef std::vector<llvm::PATypeHolder> PATypeHolderVector; | |
45 | |
46 public: | |
47 IRStruct(); | |
48 IRStruct(TypeStruct*); | |
49 virtual ~IRStruct(); | |
50 | |
51 TypeStruct* type; | |
52 TypeVector fields; | |
53 ConstantVector inits; | |
54 llvm::PATypeHolder recty; | |
55 }; | |
56 | |
57 // represents a clas | |
58 struct IRClass : Object | |
59 { | |
60 // TODO | |
61 }; | |
62 | |
63 // represents the module | |
64 struct IRState : Object | |
65 { | |
66 IRState(); | |
67 | |
68 // module | |
69 Module* dmodule; | |
70 llvm::Module* module; | |
71 | |
72 // functions | |
73 std::stack<llvm::Function*> funcs; | |
74 llvm::Function* topfunc(); | |
75 std::stack<TypeFunction*> functypes; | |
76 TypeFunction* topfunctype(); | |
77 llvm::Instruction* topallocapoint(); | |
78 | |
79 // structs | |
80 typedef std::vector<IRStruct> StructVector; | |
81 StructVector structs; | |
82 IRStruct& topstruct(); | |
83 | |
84 // classes TODO move into IRClass | |
85 typedef std::vector<ClassDeclaration*> ClassDeclVec; | |
86 ClassDeclVec classes; | |
87 typedef std::vector<FuncDeclaration*> FuncDeclVec; | |
88 typedef std::vector<FuncDeclVec> ClassMethodVec; | |
89 ClassMethodVec classmethods; | |
90 typedef std::vector<bool> BoolVec; | |
91 BoolVec queueClassMethods; | |
92 | |
93 // D main function | |
94 bool emitMain; | |
95 llvm::Function* mainFunc; | |
96 | |
97 // L-values | |
98 bool inLvalue; | |
99 typedef std::vector<llvm::Value*> LvalVec; | |
100 LvalVec lvals; | |
101 llvm::Value* toplval(); | |
102 | |
103 // basic block scopes | |
104 std::vector<IRScope> scopes; | |
105 IRScope& scope(); | |
106 llvm::BasicBlock* scopebegin(); | |
107 llvm::BasicBlock* scopeend(); | |
108 llvm::BasicBlock* scopebb(); | |
109 bool scopereturned(); | |
110 | |
111 // loop blocks | |
112 typedef std::vector<IRScope> BBVec; | |
113 BBVec loopbbs; | |
114 | |
115 // this holds the array being indexed or sliced so $ will work | |
116 // might be a better way but it works. problem is I only get a | |
117 // VarDeclaration for __dollar, but I can't see how to get the | |
118 // array pointer from this :( | |
119 LvalVec arrays; | |
120 }; | |
121 | |
122 #endif // LLVMDC_GEN_IRSTATE_H |