Chris Lattner | bed3144 | 2007-05-28 01:07:47 +0000 | [diff] [blame] | 1 | //===--- 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 Lattner | ac24820 | 2007-05-30 00:13:02 +0000 | [diff] [blame] | 17 | #include "llvm/ADT/DenseMap.h" |
Chris Lattner | 308f431 | 2007-05-29 23:50:05 +0000 | [diff] [blame] | 18 | #include "llvm/Support/LLVMBuilder.h" |
| 19 | |
Chris Lattner | bed3144 | 2007-05-28 01:07:47 +0000 | [diff] [blame] | 20 | namespace llvm { |
| 21 | class Module; |
| 22 | namespace clang { |
| 23 | class ASTContext; |
| 24 | class FunctionDecl; |
Chris Lattner | d1af2d2 | 2007-05-29 23:17:50 +0000 | [diff] [blame] | 25 | class QualType; |
| 26 | class SourceLocation; |
| 27 | class TargetInfo; |
Chris Lattner | 308f431 | 2007-05-29 23:50:05 +0000 | [diff] [blame] | 28 | class Stmt; |
| 29 | class CompoundStmt; |
Chris Lattner | ac24820 | 2007-05-30 00:13:02 +0000 | [diff] [blame] | 30 | class LabelStmt; |
| 31 | class GotoStmt; |
Chris Lattner | bed3144 | 2007-05-28 01:07:47 +0000 | [diff] [blame] | 32 | |
Chris Lattner | 208ae96 | 2007-05-30 17:57:17 +0000 | [diff] [blame^] | 33 | class Expr; |
| 34 | class IntegerLiteral; |
| 35 | |
Chris Lattner | bed3144 | 2007-05-28 01:07:47 +0000 | [diff] [blame] | 36 | namespace CodeGen { |
| 37 | class CodeGenModule; |
| 38 | |
Chris Lattner | 208ae96 | 2007-05-30 17:57:17 +0000 | [diff] [blame^] | 39 | struct 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 Lattner | bed3144 | 2007-05-28 01:07:47 +0000 | [diff] [blame] | 57 | /// CodeGenFunction - This class organizes the per-function state that is used |
| 58 | /// while generating LLVM code. |
| 59 | class CodeGenFunction { |
| 60 | CodeGenModule &CGM; // Per-module state. |
Chris Lattner | d1af2d2 | 2007-05-29 23:17:50 +0000 | [diff] [blame] | 61 | TargetInfo &Target; |
Chris Lattner | 308f431 | 2007-05-29 23:50:05 +0000 | [diff] [blame] | 62 | LLVMBuilder Builder; |
Chris Lattner | ac24820 | 2007-05-30 00:13:02 +0000 | [diff] [blame] | 63 | 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 Lattner | bed3144 | 2007-05-28 01:07:47 +0000 | [diff] [blame] | 67 | public: |
Chris Lattner | d1af2d2 | 2007-05-29 23:17:50 +0000 | [diff] [blame] | 68 | CodeGenFunction(CodeGenModule &cgm); |
Chris Lattner | bed3144 | 2007-05-28 01:07:47 +0000 | [diff] [blame] | 69 | |
Chris Lattner | d1af2d2 | 2007-05-29 23:17:50 +0000 | [diff] [blame] | 70 | const llvm::Type *ConvertType(QualType T, SourceLocation Loc); |
| 71 | |
Chris Lattner | 308f431 | 2007-05-29 23:50:05 +0000 | [diff] [blame] | 72 | void GenerateCode(const FunctionDecl *FD); |
| 73 | |
Chris Lattner | ac24820 | 2007-05-30 00:13:02 +0000 | [diff] [blame] | 74 | |
| 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 Lattner | 308f431 | 2007-05-29 23:50:05 +0000 | [diff] [blame] | 82 | //===--------------------------------------------------------------------===// |
| 83 | // Statement Emission |
| 84 | //===--------------------------------------------------------------------===// |
| 85 | |
| 86 | void EmitStmt(const Stmt *S); |
| 87 | void EmitCompoundStmt(const CompoundStmt &S); |
Chris Lattner | ac24820 | 2007-05-30 00:13:02 +0000 | [diff] [blame] | 88 | void EmitLabelStmt(const LabelStmt &S); |
| 89 | void EmitGotoStmt(const GotoStmt &S); |
Chris Lattner | 208ae96 | 2007-05-30 17:57:17 +0000 | [diff] [blame^] | 90 | |
| 91 | |
| 92 | //===--------------------------------------------------------------------===// |
| 93 | // Expression Emission |
| 94 | //===--------------------------------------------------------------------===// |
| 95 | |
| 96 | ExprResult EmitExpr(const Expr *E); |
| 97 | ExprResult EmitIntegerLiteral(const IntegerLiteral *E); |
Chris Lattner | bed3144 | 2007-05-28 01:07:47 +0000 | [diff] [blame] | 98 | }; |
| 99 | } // end namespace CodeGen |
| 100 | } // end namespace clang |
| 101 | } // end namespace llvm |
| 102 | |
| 103 | #endif |