clang  10.0.0svn
ModuleBuilder.h
Go to the documentation of this file.
1 //===--- CodeGen/ModuleBuilder.h - Build LLVM from ASTs ---------*- C++ -*-===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 //
9 // This file defines the ModuleBuilder interface.
10 //
11 //===----------------------------------------------------------------------===//
12 
13 #ifndef LLVM_CLANG_CODEGEN_MODULEBUILDER_H
14 #define LLVM_CLANG_CODEGEN_MODULEBUILDER_H
15 
16 #include "clang/AST/ASTConsumer.h"
17 
18 namespace llvm {
19  class Constant;
20  class LLVMContext;
21  class Module;
22  class StringRef;
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  class CGDebugInfo;
38 }
39 
40 /// The primary public interface to the Clang code generator.
41 ///
42 /// This is not really an abstract interface.
43 class CodeGenerator : public ASTConsumer {
44  virtual void anchor();
45 
46 public:
47  /// Return an opaque reference to the CodeGenModule object, which can
48  /// be used in various secondary APIs. It is valid as long as the
49  /// CodeGenerator exists.
51 
52  /// Return the module that this code generator is building into.
53  ///
54  /// This may return null after HandleTranslationUnit is called;
55  /// this signifies that there was an error generating code. A
56  /// diagnostic will have been generated in this case, and the module
57  /// will be deleted.
58  ///
59  /// It will also return null if the module is released.
60  llvm::Module *GetModule();
61 
62  /// Release ownership of the module to the caller.
63  ///
64  /// It is illegal to call methods other than GetModule on the
65  /// CodeGenerator after releasing its module.
66  llvm::Module *ReleaseModule();
67 
68  /// Return debug info code generator.
69  CodeGen::CGDebugInfo *getCGDebugInfo();
70 
71  /// Given a mangled name, return a declaration which mangles that way
72  /// which has been added to this code generator via a Handle method.
73  ///
74  /// This may return null if there was no matching declaration.
75  const Decl *GetDeclForMangledName(llvm::StringRef MangledName);
76 
77  /// Return the LLVM address of the given global entity.
78  ///
79  /// \param isForDefinition If true, the caller intends to define the
80  /// entity; the object returned will be an llvm::GlobalValue of
81  /// some sort. If false, the caller just intends to use the entity;
82  /// the object returned may be any sort of constant value, and the
83  /// code generator will schedule the entity for emission if a
84  /// definition has been registered with this code generator.
85  llvm::Constant *GetAddrOfGlobal(GlobalDecl decl, bool isForDefinition);
86 
87  /// Create a new \c llvm::Module after calling HandleTranslationUnit. This
88  /// enable codegen in interactive processing environments.
89  llvm::Module* StartModule(llvm::StringRef ModuleName, llvm::LLVMContext &C);
90 };
91 
92 /// CreateLLVMCodeGen - Create a CodeGenerator instance.
93 /// It is the responsibility of the caller to call delete on
94 /// the allocated CodeGenerator instance.
96  llvm::StringRef ModuleName,
97  const HeaderSearchOptions &HeaderSearchOpts,
98  const PreprocessorOptions &PreprocessorOpts,
99  const CodeGenOptions &CGO,
100  llvm::LLVMContext& C,
101  CoverageSourceInfo *CoverageInfo = nullptr);
102 
103 } // end namespace clang
104 
105 #endif
ASTConsumer - This is an abstract interface that should be implemented by clients that read ASTs...
Definition: ASTConsumer.h:33
Specialize PointerLikeTypeTraits to allow LazyGenerationalUpdatePtr to be placed into a PointerUnion...
Definition: Dominators.h:30
Decl - This represents one declaration (or definition), e.g.
Definition: DeclBase.h:88
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:54
Concrete class used by the front-end to report problems and issues.
Definition: Diagnostic.h:149
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:43
const internal::VariadicAllOfMatcher< Decl > decl
Matches declarations.
GlobalDecl - represents a global declaration.
Definition: GlobalDecl.h:40
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...