Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 1 | //===--- CodeGenModule.h - Per-Module 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-translation-unit state used for llvm translation. |
| 11 | // |
| 12 | //===----------------------------------------------------------------------===// |
| 13 | |
| 14 | #ifndef CODEGEN_CODEGENMODULE_H |
| 15 | #define CODEGEN_CODEGENMODULE_H |
| 16 | |
| 17 | #include "CodeGenTypes.h" |
| 18 | #include "llvm/ADT/DenseMap.h" |
Anders Carlsson | c9e2091 | 2007-08-21 00:21:21 +0000 | [diff] [blame] | 19 | #include "llvm/ADT/StringMap.h" |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 20 | |
| 21 | namespace llvm { |
| 22 | class Module; |
| 23 | class Constant; |
| 24 | class Function; |
Devang Patel | 9e32d4b | 2007-10-30 21:27:20 +0000 | [diff] [blame] | 25 | class GlobalVariable; |
Devang Patel | 7a4718e | 2007-10-31 20:01:01 +0000 | [diff] [blame] | 26 | class TargetData; |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 27 | } |
| 28 | |
| 29 | namespace clang { |
| 30 | class ASTContext; |
| 31 | class FunctionDecl; |
| 32 | class Decl; |
Steve Naroff | 8e74c93 | 2007-09-13 21:41:19 +0000 | [diff] [blame] | 33 | class ValueDecl; |
Chris Lattner | 88a69ad | 2007-07-13 05:13:43 +0000 | [diff] [blame] | 34 | class FileVarDecl; |
Chris Lattner | 45e8cbd | 2007-11-28 05:34:05 +0000 | [diff] [blame^] | 35 | struct LangOptions; |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 36 | |
| 37 | namespace CodeGen { |
| 38 | |
| 39 | /// CodeGenModule - This class organizes the cross-module state that is used |
| 40 | /// while generating LLVM code. |
| 41 | class CodeGenModule { |
| 42 | ASTContext &Context; |
Chris Lattner | 45e8cbd | 2007-11-28 05:34:05 +0000 | [diff] [blame^] | 43 | const LangOptions &Features; |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 44 | llvm::Module &TheModule; |
Devang Patel | 7a4718e | 2007-10-31 20:01:01 +0000 | [diff] [blame] | 45 | const llvm::TargetData &TheTargetData; |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 46 | CodeGenTypes Types; |
| 47 | |
| 48 | llvm::Function *MemCpyFn; |
| 49 | llvm::DenseMap<const Decl*, llvm::Constant*> GlobalDeclMap; |
Chris Lattner | 45e8cbd | 2007-11-28 05:34:05 +0000 | [diff] [blame^] | 50 | |
Anders Carlsson | c9e2091 | 2007-08-21 00:21:21 +0000 | [diff] [blame] | 51 | llvm::StringMap<llvm::Constant*> CFConstantStringMap; |
Chris Lattner | 45e8cbd | 2007-11-28 05:34:05 +0000 | [diff] [blame^] | 52 | llvm::StringMap<llvm::Constant*> ConstantStringMap; |
Anders Carlsson | c9e2091 | 2007-08-21 00:21:21 +0000 | [diff] [blame] | 53 | llvm::Constant *CFConstantStringClassRef; |
Chris Lattner | bef20ac | 2007-08-31 04:31:45 +0000 | [diff] [blame] | 54 | |
| 55 | std::vector<llvm::Function *> BuiltinFunctions; |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 56 | public: |
Chris Lattner | 45e8cbd | 2007-11-28 05:34:05 +0000 | [diff] [blame^] | 57 | CodeGenModule(ASTContext &C, const LangOptions &Features, llvm::Module &M, |
| 58 | const llvm::TargetData &TD); |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 59 | |
| 60 | ASTContext &getContext() const { return Context; } |
Chris Lattner | 45e8cbd | 2007-11-28 05:34:05 +0000 | [diff] [blame^] | 61 | const LangOptions &getLangOptions() const { return Features; } |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 62 | llvm::Module &getModule() const { return TheModule; } |
| 63 | CodeGenTypes &getTypes() { return Types; } |
| 64 | |
Steve Naroff | 8e74c93 | 2007-09-13 21:41:19 +0000 | [diff] [blame] | 65 | llvm::Constant *GetAddrOfGlobalDecl(const ValueDecl *D); |
Chris Lattner | bef20ac | 2007-08-31 04:31:45 +0000 | [diff] [blame] | 66 | |
| 67 | /// getBuiltinLibFunction - Given a builtin id for a function like |
| 68 | /// "__builtin_fabsf", return a Function* for "fabsf". |
| 69 | /// |
| 70 | llvm::Function *getBuiltinLibFunction(unsigned BuiltinID); |
Anders Carlsson | c9e2091 | 2007-08-21 00:21:21 +0000 | [diff] [blame] | 71 | llvm::Constant *GetAddrOfConstantCFString(const std::string& str); |
Chris Lattner | 45e8cbd | 2007-11-28 05:34:05 +0000 | [diff] [blame^] | 72 | llvm::Constant *GetAddrOfConstantString(const std::string& str); |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 73 | llvm::Function *getMemCpyFn(); |
| 74 | |
Chris Lattner | bef20ac | 2007-08-31 04:31:45 +0000 | [diff] [blame] | 75 | |
Chris Lattner | 88a69ad | 2007-07-13 05:13:43 +0000 | [diff] [blame] | 76 | void EmitFunction(const FunctionDecl *FD); |
| 77 | void EmitGlobalVar(const FileVarDecl *D); |
Chris Lattner | 32b266c | 2007-07-14 00:16:50 +0000 | [diff] [blame] | 78 | void EmitGlobalVarDeclarator(const FileVarDecl *D); |
Devang Patel | 9e32d4b | 2007-10-30 21:27:20 +0000 | [diff] [blame] | 79 | llvm::Constant *EmitGlobalInit(const FileVarDecl *D, |
| 80 | llvm::GlobalVariable *GV); |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 81 | |
| 82 | void PrintStats() {} |
| 83 | }; |
| 84 | } // end namespace CodeGen |
| 85 | } // end namespace clang |
| 86 | |
| 87 | #endif |