Skip to content
CodeGenModule.h 3.72 KiB
Newer Older
Chris Lattner's avatar
Chris Lattner committed
//===--- CodeGenModule.h - Per-Module state for LLVM CodeGen --------------===//
//
//                     The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
//
// This is the internal per-translation-unit state used for llvm translation. 
//
//===----------------------------------------------------------------------===//

Chris Lattner's avatar
Chris Lattner committed
#ifndef CODEGEN_CODEGENMODULE_H
#define CODEGEN_CODEGENMODULE_H
#include "llvm/ADT/DenseMap.h"
#include "llvm/ADT/StringMap.h"
  class GlobalVariable;
Devang Patel's avatar
Devang Patel committed
  class TargetData;
namespace clang {
  class ASTContext;
  class FunctionDecl;
Steve Naroff's avatar
 
Steve Naroff committed
  class ValueDecl;
Chris Lattner's avatar
Chris Lattner committed
/// CodeGenModule - This class organizes the cross-module state that is used
/// while generating LLVM code.
class CodeGenModule {
Devang Patel's avatar
Devang Patel committed
  const llvm::TargetData &TheTargetData;
  llvm::DenseMap<const Decl*, llvm::Constant*> GlobalDeclMap;
  llvm::StringMap<llvm::Constant*> CFConstantStringMap;
  llvm::StringMap<llvm::Constant*> ConstantStringMap;
  llvm::Constant *CFConstantStringClassRef;
  
  std::vector<llvm::Function *> BuiltinFunctions;
  CodeGenModule(ASTContext &C, const LangOptions &Features, llvm::Module &M, 
                const llvm::TargetData &TD, Diagnostic &Diags);
  ASTContext &getContext() const { return Context; }
  const LangOptions &getLangOptions() const { return Features; }
  llvm::Module &getModule() const { return TheModule; }
  CodeGenTypes &getTypes() { return Types; }
  Diagnostic &getDiags() const { return Diags; }
  const llvm::TargetData &getTargetData() const { return TheTargetData; }
  llvm::Constant *GetAddrOfFunctionDecl(const FunctionDecl *D,
                                        bool isDefinition);
  llvm::Constant *GetAddrOfGlobalVar(const VarDecl *D, bool isDefinition);
  /// getBuiltinLibFunction - Given a builtin id for a function like
  /// "__builtin_fabsf", return a Function* for "fabsf".
  ///
  llvm::Function *getBuiltinLibFunction(unsigned BuiltinID);
  llvm::Constant *GetAddrOfConstantCFString(const std::string& str);
  llvm::Constant *GetAddrOfConstantString(const std::string& str);
  llvm::Function *getMemCpyFn();
  llvm::Function *getIntrinsic(unsigned IID, const llvm::Type **Tys = 0, 
                               unsigned NumTys = 0);
  void EmitFunction(const FunctionDecl *FD);
  void EmitGlobalVar(const FileVarDecl *D);
  void EmitGlobalVarDeclarator(const FileVarDecl *D);
  void UpdateCompletedType(const TagDecl *D);
  llvm::Constant *EmitGlobalInit(const Expr *E);
  llvm::Constant *EmitConstantExpr(const Expr *E);
    
  /// WarnUnsupported - Print out a warning that codegen doesn't support the
  /// specified stmt yet.
  void WarnUnsupported(const Stmt *S, const char *Type);
  
  /// WarnUnsupported - Print out a warning that codegen doesn't support the
  /// specified decl yet.
  void WarnUnsupported(const Decl *D, const char *Type);
  
private:
  /// ReplaceMapValuesWith - This is a really slow and bad function that
  /// searches for any entries in GlobalDeclMap that point to OldVal, changing
  /// them to point to NewVal.  This is badbadbad, FIXME!
  void ReplaceMapValuesWith(llvm::Constant *OldVal, llvm::Constant *NewVal);
  
};
}  // end namespace CodeGen
}  // end namespace clang

#endif