clang  6.0.0svn
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  class StringRef;
24 }
25 
26 namespace clang {
27  class CodeGenOptions;
28  class CoverageSourceInfo;
29  class Decl;
30  class DiagnosticsEngine;
31  class GlobalDecl;
32  class HeaderSearchOptions;
33  class LangOptions;
34  class PreprocessorOptions;
35 
36 namespace CodeGen {
37  class CodeGenModule;
38  class CGDebugInfo;
39 }
40 
41 /// The primary public interface to the Clang code generator.
42 ///
43 /// This is not really an abstract interface.
44 class CodeGenerator : public ASTConsumer {
45  virtual void anchor();
46 
47 public:
48  /// Return an opaque reference to the CodeGenModule object, which can
49  /// be used in various secondary APIs. It is valid as long as the
50  /// CodeGenerator exists.
52 
53  /// Return the module that this code generator is building into.
54  ///
55  /// This may return null after HandleTranslationUnit is called;
56  /// this signifies that there was an error generating code. A
57  /// diagnostic will have been generated in this case, and the module
58  /// will be deleted.
59  ///
60  /// It will also return null if the module is released.
61  llvm::Module *GetModule();
62 
63  /// Release ownership of the module to the caller.
64  ///
65  /// It is illegal to call methods other than GetModule on the
66  /// CodeGenerator after releasing its module.
67  llvm::Module *ReleaseModule();
68 
69  /// Return debug info code generator.
70  CodeGen::CGDebugInfo *getCGDebugInfo();
71 
72  /// Given a mangled name, return a declaration which mangles that way
73  /// which has been added to this code generator via a Handle method.
74  ///
75  /// This may return null if there was no matching declaration.
76  const Decl *GetDeclForMangledName(llvm::StringRef MangledName);
77 
78  /// Return the LLVM address of the given global entity.
79  ///
80  /// \param isForDefinition If true, the caller intends to define the
81  /// entity; the object returned will be an llvm::GlobalValue of
82  /// some sort. If false, the caller just intends to use the entity;
83  /// the object returned may be any sort of constant value, and the
84  /// code generator will schedule the entity for emission if a
85  /// definition has been registered with this code generator.
86  llvm::Constant *GetAddrOfGlobal(GlobalDecl decl, bool isForDefinition);
87 
88  /// Create a new \c llvm::Module after calling HandleTranslationUnit. This
89  /// enable codegen in interactive processing environments.
90  llvm::Module* StartModule(llvm::StringRef ModuleName, llvm::LLVMContext &C);
91 };
92 
93 /// CreateLLVMCodeGen - Create a CodeGenerator instance.
94 /// It is the responsibility of the caller to call delete on
95 /// the allocated CodeGenerator instance.
97  llvm::StringRef ModuleName,
98  const HeaderSearchOptions &HeaderSearchOpts,
99  const PreprocessorOptions &PreprocessorOpts,
100  const CodeGenOptions &CGO,
101  llvm::LLVMContext& C,
102  CoverageSourceInfo *CoverageInfo = nullptr);
103 
104 } // end namespace clang
105 
106 #endif
ASTConsumer - This is an abstract interface that should be implemented by clients that read ASTs...
Definition: ASTConsumer.h:34
DominatorTree GraphTraits specialization so the DominatorTree can be iterable by generic graph iterat...
Definition: Dominators.h:26
Decl - This represents one declaration (or definition), e.g.
Definition: DeclBase.h:86
Stores additional source code information like skipped ranges which is required by the coverage mappi...
The l-value was an access to a declared entity or something equivalently strong, like the address of ...
PreprocessorOptions - This class is used for passing the various options used in preprocessor initial...
This class gathers all debug information during compilation and is responsible for emitting to llvm g...
Definition: CGDebugInfo.h:53
Concrete class used by the front-end to report problems and issues.
Definition: Diagnostic.h:147
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:44
const internal::VariadicAllOfMatcher< Decl > decl
Matches declarations.
GlobalDecl - represents a global declaration.
Definition: GlobalDecl.h:35
This class organizes the cross-function state that is used while generating LLVM code.
Dataflow Directional Tag Classes.
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...