blob: 4ca4f8c55063e11e8f6b1b056446ec3275e6f68c [file] [log] [blame]
Reid Spencer5f016e22007-07-11 17:01:13 +00001//===--- 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 Carlssonc9e20912007-08-21 00:21:21 +000019#include "llvm/ADT/StringMap.h"
Reid Spencer5f016e22007-07-11 17:01:13 +000020
21namespace llvm {
22 class Module;
23 class Constant;
24 class Function;
Devang Patel9e32d4b2007-10-30 21:27:20 +000025 class GlobalVariable;
Reid Spencer5f016e22007-07-11 17:01:13 +000026}
27
28namespace clang {
29 class ASTContext;
30 class FunctionDecl;
31 class Decl;
Steve Naroff8e74c932007-09-13 21:41:19 +000032 class ValueDecl;
Chris Lattner88a69ad2007-07-13 05:13:43 +000033 class FileVarDecl;
Reid Spencer5f016e22007-07-11 17:01:13 +000034
35namespace CodeGen {
36
37/// CodeGenModule - This class organizes the cross-module state that is used
38/// while generating LLVM code.
39class CodeGenModule {
40 ASTContext &Context;
41 llvm::Module &TheModule;
42 CodeGenTypes Types;
43
44 llvm::Function *MemCpyFn;
45 llvm::DenseMap<const Decl*, llvm::Constant*> GlobalDeclMap;
Anders Carlssonc9e20912007-08-21 00:21:21 +000046
47 llvm::StringMap<llvm::Constant*> CFConstantStringMap;
48 llvm::Constant *CFConstantStringClassRef;
Chris Lattnerbef20ac2007-08-31 04:31:45 +000049
50 std::vector<llvm::Function *> BuiltinFunctions;
Reid Spencer5f016e22007-07-11 17:01:13 +000051public:
Chris Lattnere03cd7b2007-10-31 04:53:03 +000052 CodeGenModule(ASTContext &C, llvm::Module &M);
Reid Spencer5f016e22007-07-11 17:01:13 +000053
54 ASTContext &getContext() const { return Context; }
55 llvm::Module &getModule() const { return TheModule; }
56 CodeGenTypes &getTypes() { return Types; }
57
Steve Naroff8e74c932007-09-13 21:41:19 +000058 llvm::Constant *GetAddrOfGlobalDecl(const ValueDecl *D);
Chris Lattnerbef20ac2007-08-31 04:31:45 +000059
60 /// getBuiltinLibFunction - Given a builtin id for a function like
61 /// "__builtin_fabsf", return a Function* for "fabsf".
62 ///
63 llvm::Function *getBuiltinLibFunction(unsigned BuiltinID);
Anders Carlssonc9e20912007-08-21 00:21:21 +000064 llvm::Constant *GetAddrOfConstantCFString(const std::string& str);
Reid Spencer5f016e22007-07-11 17:01:13 +000065 llvm::Function *getMemCpyFn();
66
Chris Lattnerbef20ac2007-08-31 04:31:45 +000067
Chris Lattner88a69ad2007-07-13 05:13:43 +000068 void EmitFunction(const FunctionDecl *FD);
69 void EmitGlobalVar(const FileVarDecl *D);
Chris Lattner32b266c2007-07-14 00:16:50 +000070 void EmitGlobalVarDeclarator(const FileVarDecl *D);
Devang Patel9e32d4b2007-10-30 21:27:20 +000071 llvm::Constant *EmitGlobalInit(const FileVarDecl *D,
72 llvm::GlobalVariable *GV);
Reid Spencer5f016e22007-07-11 17:01:13 +000073
74 void PrintStats() {}
75};
76} // end namespace CodeGen
77} // end namespace clang
78
79#endif