blob: 51bf7be69f54550fca2c97b81b4b7cfda9ce72d8 [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
33namespace CodeGen {
34 class CodeGenModule;
35
36/// CodeGenFunction - This class organizes the per-function state that is used
37/// while generating LLVM code.
38class CodeGenFunction {
39 CodeGenModule &CGM; // Per-module state.
Chris Lattnerd1af2d22007-05-29 23:17:50 +000040 TargetInfo &Target;
Chris Lattner308f4312007-05-29 23:50:05 +000041 LLVMBuilder Builder;
Chris Lattnerac248202007-05-30 00:13:02 +000042 llvm::Function *CurFn;
43
44 /// LabelMap - This keeps track of the LLVM basic block for each C label.
45 DenseMap<const LabelStmt*, llvm::BasicBlock*> LabelMap;
Chris Lattnerbed31442007-05-28 01:07:47 +000046public:
Chris Lattnerd1af2d22007-05-29 23:17:50 +000047 CodeGenFunction(CodeGenModule &cgm);
Chris Lattnerbed31442007-05-28 01:07:47 +000048
Chris Lattnerd1af2d22007-05-29 23:17:50 +000049 const llvm::Type *ConvertType(QualType T, SourceLocation Loc);
50
Chris Lattner308f4312007-05-29 23:50:05 +000051 void GenerateCode(const FunctionDecl *FD);
52
Chris Lattnerac248202007-05-30 00:13:02 +000053
54 /// getBasicBlockForLabel - Return the LLVM basicblock that the specified
55 /// label maps to.
56 llvm::BasicBlock *getBasicBlockForLabel(const LabelStmt *S);
57
58
59 void EmitBlock(BasicBlock *BB);
60
Chris Lattner308f4312007-05-29 23:50:05 +000061 //===--------------------------------------------------------------------===//
62 // Statement Emission
63 //===--------------------------------------------------------------------===//
64
65 void EmitStmt(const Stmt *S);
66 void EmitCompoundStmt(const CompoundStmt &S);
Chris Lattnerac248202007-05-30 00:13:02 +000067 void EmitLabelStmt(const LabelStmt &S);
68 void EmitGotoStmt(const GotoStmt &S);
Chris Lattnerbed31442007-05-28 01:07:47 +000069};
70} // end namespace CodeGen
71} // end namespace clang
72} // end namespace llvm
73
74#endif