clang  3.9.0
ModuleBuilder.h
Go to the documentation of this file.
1 //===--- CodeGen/ModuleBuilder.h - Build LLVM from ASTs ---------*- C++ -*-===//
2 //
3 // The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 //
10 // This file defines the ModuleBuilder interface.
11 //
12 //===----------------------------------------------------------------------===//
13 
14 #ifndef LLVM_CLANG_CODEGEN_MODULEBUILDER_H
15 #define LLVM_CLANG_CODEGEN_MODULEBUILDER_H
16 
17 #include "clang/AST/ASTConsumer.h"
18 
19 namespace llvm {
20  class Constant;
21  class LLVMContext;
22  class Module;
23 }
24 
25 namespace clang {
26  class CodeGenOptions;
27  class CoverageSourceInfo;
28  class Decl;
29  class DiagnosticsEngine;
30  class GlobalDecl;
31  class HeaderSearchOptions;
32  class LangOptions;
33  class PreprocessorOptions;
34 
35 namespace CodeGen {
36  class CodeGenModule;
37 }
38 
39 /// The primary public interface to the Clang code generator.
40 ///
41 /// This is not really an abstract interface.
42 class CodeGenerator : public ASTConsumer {
43  virtual void anchor();
44 
45 public:
46  /// Return an opaque reference to the CodeGenModule object, which can
47  /// be used in various secondary APIs. It is valid as long as the
48  /// CodeGenerator exists.
50 
51  /// Return the module that this code generator is building into.
52  ///
53  /// This may return null after HandleTranslationUnit is called;
54  /// this signifies that there was an error generating code. A
55  /// diagnostic will have been generated in this case, and the module
56  /// will be deleted.
57  ///
58  /// It will also return null if the module is released.
59  llvm::Module *GetModule();
60 
61  /// Release ownership of the module to the caller.
62  ///
63  /// It is illegal to call methods other than GetModule on the
64  /// CodeGenerator after releasing its module.
65  llvm::Module *ReleaseModule();
66 
67  /// Given a mangled name, return a declaration which mangles that way
68  /// which has been added to this code generator via a Handle method.
69  ///
70  /// This may return null if there was no matching declaration.
71  const Decl *GetDeclForMangledName(llvm::StringRef MangledName);
72 
73  /// Return the LLVM address of the given global entity.
74  ///
75  /// \param isForDefinition If true, the caller intends to define the
76  /// entity; the object returned will be an llvm::GlobalValue of
77  /// some sort. If false, the caller just intends to use the entity;
78  /// the object returned may be any sort of constant value, and the
79  /// code generator will schedule the entity for emission if a
80  /// definition has been registered with this code generator.
81  llvm::Constant *GetAddrOfGlobal(GlobalDecl decl, bool isForDefinition);
82 };
83 
84 /// CreateLLVMCodeGen - Create a CodeGenerator instance.
85 /// It is the responsibility of the caller to call delete on
86 /// the allocated CodeGenerator instance.
88  llvm::StringRef ModuleName,
89  const HeaderSearchOptions &HeaderSearchOpts,
90  const PreprocessorOptions &PreprocessorOpts,
91  const CodeGenOptions &CGO,
92  llvm::LLVMContext& C,
93  CoverageSourceInfo *CoverageInfo = nullptr);
94 
95 } // end namespace clang
96 
97 #endif
llvm::Constant * GetAddrOfGlobal(GlobalDecl decl, bool isForDefinition)
Return the LLVM address of the given global entity.
ASTConsumer - This is an abstract interface that should be implemented by clients that read ASTs...
Definition: ASTConsumer.h:36
Stores additional source code information like skipped ranges which is required by the coverage mappi...
PreprocessorOptions - This class is used for passing the various options used in preprocessor initial...
llvm::Module * ReleaseModule()
Release ownership of the module to the caller.
const internal::VariadicAllOfMatcher< Decl > decl
Matches declarations.
Definition: ASTMatchers.h:283
Concrete class used by the front-end to report problems and issues.
Definition: Diagnostic.h:135
CodeGenerator * CreateLLVMCodeGen(DiagnosticsEngine &Diags, llvm::StringRef ModuleName, const HeaderSearchOptions &HeaderSearchOpts, const PreprocessorOptions &PreprocessorOpts, const CodeGenOptions &CGO, llvm::LLVMContext &C, CoverageSourceInfo *CoverageInfo=nullptr)
CreateLLVMCodeGen - Create a CodeGenerator instance.
The primary public interface to the Clang code generator.
Definition: ModuleBuilder.h:42
llvm::Module * GetModule()
Return the module that this code generator is building into.
GlobalDecl - represents a global declaration.
Definition: GlobalDecl.h:29
CodeGen::CodeGenModule & CGM()
Return an opaque reference to the CodeGenModule object, which can be used in various secondary APIs...
const Decl * GetDeclForMangledName(llvm::StringRef MangledName)
Given a mangled name, return a declaration which mangles that way which has been added to this code g...
This class organizes the cross-function state that is used while generating LLVM code.
CodeGenOptions - Track various options which control how the code is optimized and passed to the back...
HeaderSearchOptions - Helper class for storing options related to the initialization of the HeaderSea...