1
|
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
|
6
|
39 // represents a struct or class
|
1
|
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();
|
6
|
48 IRStruct(Type*);
|
1
|
49 virtual ~IRStruct();
|
|
50
|
6
|
51 Type* type;
|
1
|
52 TypeVector fields;
|
|
53 ConstantVector inits;
|
|
54 llvm::PATypeHolder recty;
|
|
55 };
|
|
56
|
|
57 // represents the module
|
|
58 struct IRState : Object
|
|
59 {
|
|
60 IRState();
|
|
61
|
|
62 // module
|
|
63 Module* dmodule;
|
|
64 llvm::Module* module;
|
|
65
|
|
66 // functions
|
|
67 std::stack<llvm::Function*> funcs;
|
|
68 llvm::Function* topfunc();
|
|
69 std::stack<TypeFunction*> functypes;
|
|
70 TypeFunction* topfunctype();
|
|
71 llvm::Instruction* topallocapoint();
|
|
72
|
|
73 // structs
|
|
74 typedef std::vector<IRStruct> StructVector;
|
|
75 StructVector structs;
|
|
76 IRStruct& topstruct();
|
|
77
|
|
78 // classes TODO move into IRClass
|
|
79 typedef std::vector<ClassDeclaration*> ClassDeclVec;
|
|
80 ClassDeclVec classes;
|
|
81 typedef std::vector<FuncDeclaration*> FuncDeclVec;
|
|
82 typedef std::vector<FuncDeclVec> ClassMethodVec;
|
|
83 ClassMethodVec classmethods;
|
|
84 typedef std::vector<bool> BoolVec;
|
|
85 BoolVec queueClassMethods;
|
|
86
|
|
87 // D main function
|
|
88 bool emitMain;
|
|
89 llvm::Function* mainFunc;
|
|
90
|
|
91 // L-values
|
|
92 bool inLvalue;
|
|
93 typedef std::vector<llvm::Value*> LvalVec;
|
|
94 LvalVec lvals;
|
|
95 llvm::Value* toplval();
|
|
96
|
|
97 // basic block scopes
|
|
98 std::vector<IRScope> scopes;
|
|
99 IRScope& scope();
|
|
100 llvm::BasicBlock* scopebegin();
|
|
101 llvm::BasicBlock* scopeend();
|
|
102 llvm::BasicBlock* scopebb();
|
|
103 bool scopereturned();
|
|
104
|
|
105 // loop blocks
|
|
106 typedef std::vector<IRScope> BBVec;
|
|
107 BBVec loopbbs;
|
|
108
|
|
109 // this holds the array being indexed or sliced so $ will work
|
|
110 // might be a better way but it works. problem is I only get a
|
|
111 // VarDeclaration for __dollar, but I can't see how to get the
|
|
112 // array pointer from this :(
|
|
113 LvalVec arrays;
|
|
114 };
|
|
115
|
|
116 #endif // LLVMDC_GEN_IRSTATE_H
|