blob: 6e042d986583cb8a1dabd8098cc0f677553604be (
plain)
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
|
//===--- CodeGenFunction.h - Per-Function state for LLVM CodeGen ----------===//
//
// The LLVM Compiler Infrastructure
//
// This file was developed by Chris Lattner and is distributed under
// the University of Illinois Open Source License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
//
// This is the internal per-function state used for llvm translation.
//
//===----------------------------------------------------------------------===//
#ifndef CODEGEN_CODEGENFUNCTION_H
#define CODEGEN_CODEGENFUNCTION_H
#include "llvm/ADT/DenseMap.h"
#include "llvm/Support/LLVMBuilder.h"
namespace llvm {
class Module;
namespace clang {
class ASTContext;
class FunctionDecl;
class QualType;
class SourceLocation;
class TargetInfo;
class Stmt;
class CompoundStmt;
class LabelStmt;
class GotoStmt;
class IfStmt;
class Expr;
class IntegerLiteral;
class BinaryOperator;
namespace CodeGen {
class CodeGenModule;
class ExprResult {
Value *V;
// TODO: Encode this into the low bit of pointer for more efficient
// return-by-value.
bool IsAggregate;
public:
bool isAggregate() const { return IsAggregate; }
bool isScalar() const { return !IsAggregate; }
/// getVal() - Return the Value* of this scalar value.
Value *getVal() const {
assert(!isAggregate() && "Not a scalar!");
return V;
}
/// getAggregateVal() - Return the Value* of the address of the aggregate.
Value *getAggregateVal() const {
assert(isAggregate() && "Not an aggregate!");
return V;
}
static ExprResult get(Value *V) {
ExprResult ER;
ER.V = V;
ER.IsAggregate = false;
return ER;
}
static ExprResult getAggregate(Value *V) {
ExprResult ER;
ER.V = V;
ER.IsAggregate = true;
return ER;
}
};
/// CodeGenFunction - This class organizes the per-function state that is used
/// while generating LLVM code.
class CodeGenFunction {
CodeGenModule &CGM; // Per-module state.
TargetInfo &Target;
LLVMBuilder Builder;
llvm::Function *CurFn;
/// LabelMap - This keeps track of the LLVM basic block for each C label.
DenseMap<const LabelStmt*, llvm::BasicBlock*> LabelMap;
public:
CodeGenFunction(CodeGenModule &cgm);
const llvm::Type *ConvertType(QualType T, SourceLocation Loc);
void GenerateCode(const FunctionDecl *FD);
/// getBasicBlockForLabel - Return the LLVM basicblock that the specified
/// label maps to.
llvm::BasicBlock *getBasicBlockForLabel(const LabelStmt *S);
void EmitBlock(BasicBlock *BB);
//===--------------------------------------------------------------------===//
// Statement Emission
//===--------------------------------------------------------------------===//
void EmitStmt(const Stmt *S);
void EmitCompoundStmt(const CompoundStmt &S);
void EmitLabelStmt(const LabelStmt &S);
void EmitGotoStmt(const GotoStmt &S);
void EmitIfStmt(const IfStmt &S);
//===--------------------------------------------------------------------===//
// Expression Emission
//===--------------------------------------------------------------------===//
ExprResult EmitExpr(const Expr *E);
ExprResult EmitIntegerLiteral(const IntegerLiteral *E);
ExprResult EmitBinaryOperator(const BinaryOperator *E);
void EmitUsualArithmeticConversions(const BinaryOperator *E,
ExprResult &LHS, ExprResult &RHS);
// Binary Operators.
ExprResult EmitBinaryAdd(const BinaryOperator *E);
};
} // end namespace CodeGen
} // end namespace clang
} // end namespace llvm
#endif
|