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
127
128
129
130
131
132
133
134
135
136
|
//===--- CodeGenModule.h - Per-Module state for LLVM CodeGen --------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
//
// This is the internal per-translation-unit state used for llvm translation.
//
//===----------------------------------------------------------------------===//
#ifndef CLANG_CODEGEN_CODEGENMODULE_H
#define CLANG_CODEGEN_CODEGENMODULE_H
#include "CodeGenTypes.h"
#include "CGObjCRuntime.h"
#include "llvm/ADT/DenseMap.h"
#include "llvm/ADT/StringMap.h"
namespace llvm {
class Module;
class Constant;
class Function;
class GlobalValue;
class TargetData;
}
namespace clang {
class ASTContext;
class FunctionDecl;
class ObjCMethodDecl;
class Decl;
class Expr;
class Stmt;
class ValueDecl;
class VarDecl;
class TypeDecl;
struct LangOptions;
class Diagnostic;
class AnnotateAttr;
namespace CodeGen {
class CodeGenFunction;
/// CodeGenModule - This class organizes the cross-module state that is used
/// while generating LLVM code.
class CodeGenModule {
ASTContext &Context;
const LangOptions &Features;
llvm::Module &TheModule;
const llvm::TargetData &TheTargetData;
Diagnostic &Diags;
CodeGenTypes Types;
CGObjCRuntime *Runtime;
llvm::Function *MemCpyFn;
llvm::Function *MemSetFn;
llvm::DenseMap<const Decl*, llvm::Constant*> GlobalDeclMap;
std::vector<llvm::Constant*> GlobalCtors;
std::vector<llvm::Constant*> Annotations;
llvm::StringMap<llvm::Constant*> CFConstantStringMap;
llvm::StringMap<llvm::Constant*> ConstantStringMap;
llvm::Constant *CFConstantStringClassRef;
std::vector<llvm::Function *> BuiltinFunctions;
public:
CodeGenModule(ASTContext &C, const LangOptions &Features, llvm::Module &M,
const llvm::TargetData &TD, Diagnostic &Diags);
~CodeGenModule();
CGObjCRuntime *getObjCRuntime() { return Runtime; }
ASTContext &getContext() const { return Context; }
const LangOptions &getLangOptions() const { return Features; }
llvm::Module &getModule() const { return TheModule; }
CodeGenTypes &getTypes() { return Types; }
Diagnostic &getDiags() const { return Diags; }
const llvm::TargetData &getTargetData() const { return TheTargetData; }
llvm::Constant *GetAddrOfFunctionDecl(const FunctionDecl *D,
bool isDefinition);
llvm::Constant *GetAddrOfGlobalVar(const VarDecl *D, bool isDefinition);
/// getBuiltinLibFunction - Given a builtin id for a function like
/// "__builtin_fabsf", return a Function* for "fabsf".
///
llvm::Function *getBuiltinLibFunction(unsigned BuiltinID);
llvm::Constant *GetAddrOfConstantCFString(const std::string& str);
/// GetAddrOfConstantString -- returns a pointer to the character
/// array containing the literal. The result is pointer to array type.
llvm::Constant *GetAddrOfConstantString(const std::string& str);
llvm::Function *getMemCpyFn();
llvm::Function *getMemSetFn();
llvm::Function *getIntrinsic(unsigned IID, const llvm::Type **Tys = 0,
unsigned NumTys = 0);
void AddGlobalCtor(llvm::Function * Ctor);
void EmitGlobalCtors(void);
void AddAnnotation(llvm::Constant *C) { Annotations.push_back(C); }
void EmitAnnotations(void);
void EmitObjCMethod(const ObjCMethodDecl *OMD);
void EmitFunction(const FunctionDecl *FD);
void EmitGlobalVar(const VarDecl *D);
void EmitGlobalVarDeclarator(const VarDecl *D);
void UpdateCompletedType(const TagDecl *D);
llvm::Constant *EmitGlobalInit(const Expr *E);
llvm::Constant *EmitConstantExpr(const Expr *E, CodeGenFunction *CGF = 0);
llvm::Constant *EmitAnnotateAttr(llvm::GlobalValue *GV,
const AnnotateAttr *AA, unsigned LineNo);
/// WarnUnsupported - Print out a warning that codegen doesn't support the
/// specified stmt yet.
void WarnUnsupported(const Stmt *S, const char *Type);
/// WarnUnsupported - Print out a warning that codegen doesn't support the
/// specified decl yet.
void WarnUnsupported(const Decl *D, const char *Type);
private:
/// ReplaceMapValuesWith - This is a really slow and bad function that
/// searches for any entries in GlobalDeclMap that point to OldVal, changing
/// them to point to NewVal. This is badbadbad, FIXME!
void ReplaceMapValuesWith(llvm::Constant *OldVal, llvm::Constant *NewVal);
};
} // end namespace CodeGen
} // end namespace clang
#endif
|