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; |
| 25 | } |
| 26 | |
| 27 | namespace clang { |
| 28 | class ASTContext; |
| 29 | class FunctionDecl; |
| 30 | class Decl; |
Steve Naroff | 8e74c93 | 2007-09-13 21:41:19 +0000 | [diff] [blame^] | 31 | class ValueDecl; |
Chris Lattner | 88a69ad | 2007-07-13 05:13:43 +0000 | [diff] [blame] | 32 | class FileVarDecl; |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 33 | |
| 34 | namespace CodeGen { |
| 35 | |
| 36 | /// CodeGenModule - This class organizes the cross-module state that is used |
| 37 | /// while generating LLVM code. |
| 38 | class CodeGenModule { |
| 39 | ASTContext &Context; |
| 40 | llvm::Module &TheModule; |
| 41 | CodeGenTypes Types; |
| 42 | |
| 43 | llvm::Function *MemCpyFn; |
| 44 | llvm::DenseMap<const Decl*, llvm::Constant*> GlobalDeclMap; |
Anders Carlsson | c9e2091 | 2007-08-21 00:21:21 +0000 | [diff] [blame] | 45 | |
| 46 | llvm::StringMap<llvm::Constant*> CFConstantStringMap; |
| 47 | llvm::Constant *CFConstantStringClassRef; |
Chris Lattner | bef20ac | 2007-08-31 04:31:45 +0000 | [diff] [blame] | 48 | |
| 49 | std::vector<llvm::Function *> BuiltinFunctions; |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 50 | public: |
| 51 | CodeGenModule(ASTContext &C, llvm::Module &M); |
| 52 | |
| 53 | ASTContext &getContext() const { return Context; } |
| 54 | llvm::Module &getModule() const { return TheModule; } |
| 55 | CodeGenTypes &getTypes() { return Types; } |
| 56 | |
Steve Naroff | 8e74c93 | 2007-09-13 21:41:19 +0000 | [diff] [blame^] | 57 | llvm::Constant *GetAddrOfGlobalDecl(const ValueDecl *D); |
Chris Lattner | bef20ac | 2007-08-31 04:31:45 +0000 | [diff] [blame] | 58 | |
| 59 | /// getBuiltinLibFunction - Given a builtin id for a function like |
| 60 | /// "__builtin_fabsf", return a Function* for "fabsf". |
| 61 | /// |
| 62 | llvm::Function *getBuiltinLibFunction(unsigned BuiltinID); |
Anders Carlsson | c9e2091 | 2007-08-21 00:21:21 +0000 | [diff] [blame] | 63 | llvm::Constant *GetAddrOfConstantCFString(const std::string& str); |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 64 | llvm::Function *getMemCpyFn(); |
| 65 | |
Chris Lattner | bef20ac | 2007-08-31 04:31:45 +0000 | [diff] [blame] | 66 | |
Chris Lattner | 88a69ad | 2007-07-13 05:13:43 +0000 | [diff] [blame] | 67 | void EmitFunction(const FunctionDecl *FD); |
| 68 | void EmitGlobalVar(const FileVarDecl *D); |
Chris Lattner | 32b266c | 2007-07-14 00:16:50 +0000 | [diff] [blame] | 69 | void EmitGlobalVarDeclarator(const FileVarDecl *D); |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 70 | |
| 71 | void PrintStats() {} |
| 72 | }; |
| 73 | } // end namespace CodeGen |
| 74 | } // end namespace clang |
| 75 | |
| 76 | #endif |