2007-05-28 09:07:47 +08:00
|
|
|
//===--- CodeGenFunction.h - Per-Function state for LLVM CodeGen ----------===//
|
2007-05-24 14:29:05 +08:00
|
|
|
//
|
|
|
|
// 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.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
2007-05-28 09:07:47 +08:00
|
|
|
// This is the internal per-function state used for llvm translation.
|
2007-05-24 14:29:05 +08:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2007-05-28 09:07:47 +08:00
|
|
|
#ifndef CODEGEN_CODEGENFUNCTION_H
|
|
|
|
#define CODEGEN_CODEGENFUNCTION_H
|
2007-05-24 14:29:05 +08:00
|
|
|
|
2007-05-30 08:13:02 +08:00
|
|
|
#include "llvm/ADT/DenseMap.h"
|
2007-05-30 07:50:05 +08:00
|
|
|
#include "llvm/Support/LLVMBuilder.h"
|
|
|
|
|
2007-05-24 14:29:05 +08:00
|
|
|
namespace llvm {
|
|
|
|
class Module;
|
|
|
|
namespace clang {
|
|
|
|
class ASTContext;
|
2007-06-02 12:16:21 +08:00
|
|
|
class Decl;
|
2007-05-24 14:29:05 +08:00
|
|
|
class FunctionDecl;
|
2007-05-30 07:17:50 +08:00
|
|
|
class QualType;
|
|
|
|
class SourceLocation;
|
|
|
|
class TargetInfo;
|
2007-06-02 12:16:21 +08:00
|
|
|
|
2007-05-30 07:50:05 +08:00
|
|
|
class Stmt;
|
|
|
|
class CompoundStmt;
|
2007-05-30 08:13:02 +08:00
|
|
|
class LabelStmt;
|
|
|
|
class GotoStmt;
|
2007-05-31 05:03:58 +08:00
|
|
|
class IfStmt;
|
2007-06-02 11:19:07 +08:00
|
|
|
class ReturnStmt;
|
2007-06-02 12:16:21 +08:00
|
|
|
class DeclStmt;
|
2007-05-28 09:07:47 +08:00
|
|
|
|
2007-05-31 01:57:17 +08:00
|
|
|
class Expr;
|
|
|
|
class IntegerLiteral;
|
2007-06-02 08:16:28 +08:00
|
|
|
class BinaryOperator;
|
2007-05-31 01:57:17 +08:00
|
|
|
|
2007-06-02 12:16:21 +08:00
|
|
|
class BlockVarDecl;
|
|
|
|
class EnumConstantDecl;
|
2007-05-24 14:29:05 +08:00
|
|
|
namespace CodeGen {
|
2007-05-28 09:07:47 +08:00
|
|
|
class CodeGenModule;
|
2007-05-24 14:29:05 +08:00
|
|
|
|
2007-05-31 05:03:58 +08:00
|
|
|
class ExprResult {
|
2007-05-31 01:57:17 +08:00
|
|
|
Value *V;
|
2007-06-02 08:16:28 +08:00
|
|
|
// TODO: Encode this into the low bit of pointer for more efficient
|
|
|
|
// return-by-value.
|
2007-05-31 05:03:58 +08:00
|
|
|
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;
|
|
|
|
}
|
2007-05-31 01:57:17 +08:00
|
|
|
|
|
|
|
static ExprResult get(Value *V) {
|
|
|
|
ExprResult ER;
|
|
|
|
ER.V = V;
|
2007-05-31 05:03:58 +08:00
|
|
|
ER.IsAggregate = false;
|
2007-05-31 01:57:17 +08:00
|
|
|
return ER;
|
|
|
|
}
|
|
|
|
static ExprResult getAggregate(Value *V) {
|
|
|
|
ExprResult ER;
|
|
|
|
ER.V = V;
|
2007-05-31 05:03:58 +08:00
|
|
|
ER.IsAggregate = true;
|
2007-05-31 01:57:17 +08:00
|
|
|
return ER;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2007-05-28 09:07:47 +08:00
|
|
|
/// CodeGenFunction - This class organizes the per-function state that is used
|
|
|
|
/// while generating LLVM code.
|
|
|
|
class CodeGenFunction {
|
|
|
|
CodeGenModule &CGM; // Per-module state.
|
2007-05-30 07:17:50 +08:00
|
|
|
TargetInfo &Target;
|
2007-05-30 07:50:05 +08:00
|
|
|
LLVMBuilder Builder;
|
2007-06-02 11:19:07 +08:00
|
|
|
|
|
|
|
const FunctionDecl *CurFuncDecl;
|
2007-05-30 08:13:02 +08:00
|
|
|
llvm::Function *CurFn;
|
|
|
|
|
2007-06-02 12:16:21 +08:00
|
|
|
/// LocalDeclMap - This keeps track of the LLVM allocas or globals for local C
|
|
|
|
/// decls.
|
|
|
|
DenseMap<const Decl*, llvm::Value*> LocalDeclMap;
|
|
|
|
|
2007-05-30 08:13:02 +08:00
|
|
|
/// LabelMap - This keeps track of the LLVM basic block for each C label.
|
|
|
|
DenseMap<const LabelStmt*, llvm::BasicBlock*> LabelMap;
|
2007-05-28 09:07:47 +08:00
|
|
|
public:
|
2007-05-30 07:17:50 +08:00
|
|
|
CodeGenFunction(CodeGenModule &cgm);
|
2007-05-24 14:29:05 +08:00
|
|
|
|
2007-05-30 07:17:50 +08:00
|
|
|
const llvm::Type *ConvertType(QualType T, SourceLocation Loc);
|
|
|
|
|
2007-05-30 07:50:05 +08:00
|
|
|
void GenerateCode(const FunctionDecl *FD);
|
|
|
|
|
2007-05-30 08:13:02 +08:00
|
|
|
|
|
|
|
/// getBasicBlockForLabel - Return the LLVM basicblock that the specified
|
|
|
|
/// label maps to.
|
|
|
|
llvm::BasicBlock *getBasicBlockForLabel(const LabelStmt *S);
|
|
|
|
|
|
|
|
|
|
|
|
void EmitBlock(BasicBlock *BB);
|
2007-06-02 12:16:21 +08:00
|
|
|
|
2007-05-30 08:13:02 +08:00
|
|
|
|
2007-06-02 12:16:21 +08:00
|
|
|
//===--------------------------------------------------------------------===//
|
|
|
|
// Local Declaration Emission
|
|
|
|
//===--------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
void EmitDeclStmt(const DeclStmt &S);
|
|
|
|
void EmitBlockVarDecl(const BlockVarDecl &D);
|
|
|
|
void EmitEnumConstantDecl(const EnumConstantDecl &D);
|
|
|
|
|
2007-05-30 07:50:05 +08:00
|
|
|
//===--------------------------------------------------------------------===//
|
|
|
|
// Statement Emission
|
|
|
|
//===--------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
void EmitStmt(const Stmt *S);
|
|
|
|
void EmitCompoundStmt(const CompoundStmt &S);
|
2007-05-30 08:13:02 +08:00
|
|
|
void EmitLabelStmt(const LabelStmt &S);
|
|
|
|
void EmitGotoStmt(const GotoStmt &S);
|
2007-05-31 05:03:58 +08:00
|
|
|
void EmitIfStmt(const IfStmt &S);
|
2007-06-02 11:19:07 +08:00
|
|
|
void EmitReturnStmt(const ReturnStmt &S);
|
2007-05-31 01:57:17 +08:00
|
|
|
|
|
|
|
//===--------------------------------------------------------------------===//
|
|
|
|
// Expression Emission
|
|
|
|
//===--------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
ExprResult EmitExpr(const Expr *E);
|
|
|
|
ExprResult EmitIntegerLiteral(const IntegerLiteral *E);
|
2007-06-02 08:16:28 +08:00
|
|
|
ExprResult EmitBinaryOperator(const BinaryOperator *E);
|
|
|
|
|
|
|
|
|
|
|
|
void EmitUsualArithmeticConversions(const BinaryOperator *E,
|
|
|
|
ExprResult &LHS, ExprResult &RHS);
|
|
|
|
|
|
|
|
// Binary Operators.
|
|
|
|
ExprResult EmitBinaryAdd(const BinaryOperator *E);
|
2007-05-24 14:29:05 +08:00
|
|
|
};
|
|
|
|
} // end namespace CodeGen
|
|
|
|
} // end namespace clang
|
|
|
|
} // end namespace llvm
|
|
|
|
|
|
|
|
#endif
|