blob: 97d300015e5fe2246dcc27752a3925c848fcda6f [file] [log] [blame]
Chris Lattnerbed31442007-05-28 01:07:47 +00001//===--- CodeGenFunction.h - Per-Function state for LLVM CodeGen ----------===//
2//
3// The LLVM Compiler Infrastructure
4//
5// This file was developed by Chris Lattner and is distributed under
6// the University of Illinois Open Source License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9//
10// This is the internal per-function state used for llvm translation.
11//
12//===----------------------------------------------------------------------===//
13
14#ifndef CODEGEN_CODEGENFUNCTION_H
15#define CODEGEN_CODEGENFUNCTION_H
16
Chris Lattnerac248202007-05-30 00:13:02 +000017#include "llvm/ADT/DenseMap.h"
Chris Lattner308f4312007-05-29 23:50:05 +000018#include "llvm/Support/LLVMBuilder.h"
19
Chris Lattnerbed31442007-05-28 01:07:47 +000020namespace llvm {
21 class Module;
22namespace clang {
23 class ASTContext;
24 class FunctionDecl;
Chris Lattnerd1af2d22007-05-29 23:17:50 +000025 class QualType;
26 class SourceLocation;
27 class TargetInfo;
Chris Lattner308f4312007-05-29 23:50:05 +000028 class Stmt;
29 class CompoundStmt;
Chris Lattnerac248202007-05-30 00:13:02 +000030 class LabelStmt;
31 class GotoStmt;
Chris Lattnerbed31442007-05-28 01:07:47 +000032
Chris Lattner208ae962007-05-30 17:57:17 +000033 class Expr;
34 class IntegerLiteral;
35
Chris Lattnerbed31442007-05-28 01:07:47 +000036namespace CodeGen {
37 class CodeGenModule;
38
Chris Lattner208ae962007-05-30 17:57:17 +000039struct ExprResult {
40 Value *V;
41 bool isAggregate;
42
43 static ExprResult get(Value *V) {
44 ExprResult ER;
45 ER.V = V;
46 ER.isAggregate = false;
47 return ER;
48 }
49 static ExprResult getAggregate(Value *V) {
50 ExprResult ER;
51 ER.V = V;
52 ER.isAggregate = true;
53 return ER;
54 }
55};
56
Chris Lattnerbed31442007-05-28 01:07:47 +000057/// CodeGenFunction - This class organizes the per-function state that is used
58/// while generating LLVM code.
59class CodeGenFunction {
60 CodeGenModule &CGM; // Per-module state.
Chris Lattnerd1af2d22007-05-29 23:17:50 +000061 TargetInfo &Target;
Chris Lattner308f4312007-05-29 23:50:05 +000062 LLVMBuilder Builder;
Chris Lattnerac248202007-05-30 00:13:02 +000063 llvm::Function *CurFn;
64
65 /// LabelMap - This keeps track of the LLVM basic block for each C label.
66 DenseMap<const LabelStmt*, llvm::BasicBlock*> LabelMap;
Chris Lattnerbed31442007-05-28 01:07:47 +000067public:
Chris Lattnerd1af2d22007-05-29 23:17:50 +000068 CodeGenFunction(CodeGenModule &cgm);
Chris Lattnerbed31442007-05-28 01:07:47 +000069
Chris Lattnerd1af2d22007-05-29 23:17:50 +000070 const llvm::Type *ConvertType(QualType T, SourceLocation Loc);
71
Chris Lattner308f4312007-05-29 23:50:05 +000072 void GenerateCode(const FunctionDecl *FD);
73
Chris Lattnerac248202007-05-30 00:13:02 +000074
75 /// getBasicBlockForLabel - Return the LLVM basicblock that the specified
76 /// label maps to.
77 llvm::BasicBlock *getBasicBlockForLabel(const LabelStmt *S);
78
79
80 void EmitBlock(BasicBlock *BB);
81
Chris Lattner308f4312007-05-29 23:50:05 +000082 //===--------------------------------------------------------------------===//
83 // Statement Emission
84 //===--------------------------------------------------------------------===//
85
86 void EmitStmt(const Stmt *S);
87 void EmitCompoundStmt(const CompoundStmt &S);
Chris Lattnerac248202007-05-30 00:13:02 +000088 void EmitLabelStmt(const LabelStmt &S);
89 void EmitGotoStmt(const GotoStmt &S);
Chris Lattner208ae962007-05-30 17:57:17 +000090
91
92 //===--------------------------------------------------------------------===//
93 // Expression Emission
94 //===--------------------------------------------------------------------===//
95
96 ExprResult EmitExpr(const Expr *E);
97 ExprResult EmitIntegerLiteral(const IntegerLiteral *E);
Chris Lattnerbed31442007-05-28 01:07:47 +000098};
99} // end namespace CodeGen
100} // end namespace clang
101} // end namespace llvm
102
103#endif