/
irvar.h
126 lines (102 loc) · 3.42 KB
/
irvar.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
//===-- ir/irdsymbol.h - Codegen state for D vars/fields/params -*- C++ -*-===//
//
// LDC – the LLVM D compiler
//
// This file is distributed under the BSD-style LDC license. See the LICENSE
// file for details.
//
//===----------------------------------------------------------------------===//
//
// Classes for representing the status of D variables on their way though the
// codegen process.
//
//===----------------------------------------------------------------------===//
#ifndef LDC_IR_IRVAR_H
#define LDC_IR_IRVAR_H
#if LDC_LLVM_VER >= 303
#include "llvm/IR/Type.h"
#else
#include "llvm/Type.h"
#endif
#if LDC_LLVM_VER >= 305
#include "llvm/IR/DebugInfo.h"
#elif LDC_LLVM_VER >= 302
#include "llvm/DebugInfo.h"
#else
#include "llvm/Analysis/DebugInfo.h"
#endif
struct IrFuncTyArg;
class VarDeclaration;
struct IrVar
{
IrVar(VarDeclaration* var)
: V(var), value(0) { }
IrVar(VarDeclaration* var, llvm::Value* value)
: V(var), value(value) { }
VarDeclaration* V;
llvm::Value* value;
// debug description
llvm::DIVariable debugVariable;
llvm::DISubprogram debugFunc;
};
// represents a global variable
struct IrGlobal : IrVar
{
IrGlobal(VarDeclaration* v)
: IrVar(v), type(0), constInit(0), nakedUse(false) { }
IrGlobal(VarDeclaration* v, llvm::Type *type, llvm::Constant* constInit = 0)
: IrVar(v), type(type), constInit(constInit), nakedUse(false) { }
llvm::Type *type;
llvm::Constant* constInit;
// This var is used by a naked function.
bool nakedUse;
};
// represents a local variable variable
struct IrLocal : IrVar
{
IrLocal(VarDeclaration* v)
: IrVar(v), nestedDepth(0), nestedIndex(-1) { }
IrLocal(VarDeclaration* v, llvm::Value* value)
: IrVar(v, value), nestedDepth(0), nestedIndex(-1) { }
IrLocal(VarDeclaration* v, int nestedDepth, int nestedIndex)
: IrVar(v), nestedDepth(nestedDepth), nestedIndex(nestedIndex) { }
// Used for hybrid nested context creation.
int nestedDepth;
int nestedIndex;
};
// represents a function parameter
struct IrParameter : IrLocal
{
IrParameter(VarDeclaration* v)
: IrLocal(v), arg(0), isVthis(false) { }
IrParameter(VarDeclaration* v, llvm::Value* value)
: IrLocal(v, value), arg(0), isVthis(false) { }
IrParameter(VarDeclaration* v, llvm::Value* value, IrFuncTyArg *arg, bool isVthis = false)
: IrLocal(v, value), arg(arg), isVthis(isVthis) { }
IrFuncTyArg *arg;
bool isVthis; // true, if it is the 'this' parameter
};
// represents an aggregate field variable
struct IrField : IrVar
{
IrField(VarDeclaration* v);
void setAggrIndex(unsigned aggrIndex);
unsigned index;
unsigned unionOffset;
llvm::Constant* getDefaultInit();
protected:
/// FIXME: only used for StructLiteralsExps
llvm::Constant* constInit;
};
IrVar *getIrVar(VarDeclaration *decl);
llvm::Value *getIrValue(VarDeclaration *decl);
bool isIrVarCreated(VarDeclaration *decl);
IrGlobal *getIrGlobal(VarDeclaration *decl, bool create = false);
bool isIrGlobalCreated(VarDeclaration *decl);
IrLocal *getIrLocal(VarDeclaration *decl, bool create = false);
bool isIrLocalCreated(VarDeclaration *decl);
IrParameter *getIrParameter(VarDeclaration *decl, bool create = false);
bool isIrParameterCreated(VarDeclaration *decl);
IrField *getIrField(VarDeclaration *decl, bool create = false);
bool isIrFieldCreated(VarDeclaration *decl);
#endif