;
36#define DEBUG_TYPE "pchcontainer" 42 conststd::string MainFileName;
43 conststd::string OutputFileName;
52std::unique_ptr<llvm::LLVMContext> VMContext;
53std::unique_ptr<llvm::Module> M;
54std::unique_ptr<CodeGen::CodeGenModule> Builder;
55std::unique_ptr<raw_pwrite_stream> OS;
56std::shared_ptr<PCHBuffer> Buffer;
66 static boolCanRepresent(
const Type*Ty) {
80 if(
auto*TD = dyn_cast<TagDecl>(
D))
81 if(!TD->isCompleteDefinition())
94 QualTypeQualTy(
D->getTypeForDecl(), 0);
102 if(isa<CXXDeductionGuideDecl>(
D))
105 if(isa<CXXMethodDecl>(
D))
111 for(
auto*i :
D->parameters())
112ArgTypes.push_back(i->getType());
122 if(!
D->getClassInterface())
125 boolselfIsPseudoStrong, selfIsConsumed;
127ArgTypes.push_back(
D->getSelfType(Ctx,
D->getClassInterface(),
128selfIsPseudoStrong, selfIsConsumed));
130 for(
auto*i :
D->parameters())
131ArgTypes.push_back(i->getType());
142PCHContainerGenerator(
CompilerInstance&CI,
conststd::string &MainFileName,
143 conststd::string &OutputFileName,
144std::unique_ptr<raw_pwrite_stream> OS,
145std::shared_ptr<PCHBuffer> Buffer)
146: CI(CI), Diags(CI.
getDiagnostics()), MainFileName(MainFileName),
147OutputFileName(OutputFileName), Ctx(
nullptr),
153OS(std::move(OS)), Buffer(std::move(Buffer)) {
157LangOpts.setThreadModel(LangOptions::ThreadModelKind::Single);
158CodeGenOpts.DebugTypeExtRefs =
true;
162CodeGenOpts.setDebugInfo(llvm::codegenoptions::FullDebugInfo);
163CodeGenOpts.setDebuggerTuning(CI.
getCodeGenOpts().getDebuggerTuning());
169CodeGenOpts.DebugStrictDwarf = CI.
getCodeGenOpts().DebugStrictDwarf;
172~PCHContainerGenerator()
override=
default;
175assert(!Ctx &&
"initialized multiple times");
178VMContext.reset(
newllvm::LLVMContext());
179M.reset(
newllvm::Module(MainFileName, *VMContext));
182*Ctx, FS, HeaderSearchOpts, PreprocessorOpts, CodeGenOpts, *M, Diags));
185 auto*DI = Builder->getModuleDebugInfo();
186StringRef ModuleName = llvm::sys::path::filename(MainFileName);
187DI->setPCHDescriptor(
189DI->setModuleMap(MMap);
198 if(!I->isFromASTFile()) {
199DebugTypeVisitor DTV(*Builder->getModuleDebugInfo(), *Ctx);
217 if(
D->getName().empty())
223 if(
auto*
D= dyn_cast<TagDecl>(DeclCtx))
224 if(!
D->isCompleteDefinition())
229DebugTypeVisitor DTV(*Builder->getModuleDebugInfo(), *Ctx);
230DTV.TraverseDecl(
D);
231Builder->UpdateCompletedType(
D);
238 if(
const RecordDecl*RD = dyn_cast<RecordDecl>(
D))
239Builder->getModuleDebugInfo()->completeRequiredType(RD);
244Builder->getModuleDebugInfo()->EmitImportDecl(*
D);
249assert(M && VMContext && Builder);
251std::unique_ptr<llvm::LLVMContext> VMContext = std::move(this->VMContext);
252std::unique_ptr<llvm::Module> M = std::move(this->M);
253std::unique_ptr<CodeGen::CodeGenModule> Builder = std::move(this->Builder);
266Buffer->Signature ? Buffer->Signature.truncatedValue() : ~1ULL;
268Builder->getModuleDebugInfo()->setDwoId(Signature);
277 if(!llvm::TargetRegistry::lookupTarget(Triple.getTriple(), Error))
278llvm::report_fatal_error(llvm::Twine(Error));
281assert(Buffer->IsComplete &&
"serialization did not complete");
282 auto&SerializedAST = Buffer->Data;
283 autoSize = SerializedAST.size();
285 if(Triple.isOSBinFormatWasm()) {
291llvm::NamedMDNode *MD =
292M->getOrInsertNamedMetadata(
"wasm.custom_sections");
293llvm::Metadata *Ops[2] = {
294llvm::MDString::get(*VMContext,
"__clangast"),
295llvm::MDString::get(*VMContext,
296StringRef(SerializedAST.data(), Size))};
297 auto*NameAndContent = llvm::MDTuple::get(*VMContext, Ops);
298MD->addOperand(NameAndContent);
300 autoInt8Ty = llvm::Type::getInt8Ty(*VMContext);
301 auto*Ty = llvm::ArrayType::get(Int8Ty, Size);
302 auto*
Data= llvm::ConstantDataArray::getString(
303*VMContext, StringRef(SerializedAST.data(), Size),
305 auto*ASTSym =
newllvm::GlobalVariable(
306*M, Ty,
true, llvm::GlobalVariable::InternalLinkage,
307 Data,
"__clang_ast");
309ASTSym->setAlignment(llvm::Align(8));
312 if(Triple.isOSBinFormatMachO())
313ASTSym->setSection(
"__CLANG,__clangast");
315 else if(Triple.isOSBinFormatCOFF())
316ASTSym->setSection(
"clangast");
318ASTSym->setSection(
"__clangast");
326BackendAction::Backend_EmitLL, FS,
327std::make_unique<llvm::raw_svector_ostream>(Buffer));
328llvm::dbgs() << Buffer;
334BackendAction::Backend_EmitObj, FS, std::move(OS));
338SerializedAST = std::move(
Empty);
344std::unique_ptr<ASTConsumer>
345ObjectFilePCHContainerWriter::CreatePCHContainerGenerator(
347 conststd::string &OutputFileName,
348std::unique_ptr<llvm::raw_pwrite_stream> OS,
349std::shared_ptr<PCHBuffer> Buffer)
const{
350 returnstd::make_unique<PCHContainerGenerator>(
351CI, MainFileName, OutputFileName, std::move(OS), Buffer);
Defines the clang::ASTContext interface.
Defines the Diagnostic-related interfaces.
Defines the clang::Preprocessor interface.
ASTConsumer - This is an abstract interface that should be implemented by clients that read ASTs.
virtual void HandleTagDeclDefinition(TagDecl *D)
HandleTagDeclDefinition - This callback is invoked each time a TagDecl (e.g.
virtual void HandleTranslationUnit(ASTContext &Ctx)
HandleTranslationUnit - This method is called when the ASTs for entire translation unit have been par...
virtual void HandleTagDeclRequiredDefinition(const TagDecl *D)
This callback is invoked the first time each TagDecl is required to be complete.
virtual void HandleTopLevelDeclInObjCContainer(DeclGroupRef D)
Handle the specified top-level declaration that occurred inside and ObjC container.
virtual bool HandleTopLevelDecl(DeclGroupRef D)
HandleTopLevelDecl - Handle the specified top-level declaration.
virtual void Initialize(ASTContext &Context)
Initialize - This is called to initialize the consumer, providing the ASTContext.
virtual void HandleImplicitImportDecl(ImportDecl *D)
Handle an ImportDecl that was implicitly created due to an inclusion directive.
Holds long-lived AST nodes (such as types and decls) that can be referred to throughout the semantic ...
QualType getTypeDeclType(const TypeDecl *Decl, const TypeDecl *PrevDecl=nullptr) const
Return the unique reference to the type for the specified type declaration.
QualType getObjCSelType() const
Retrieve the type that corresponds to the predefined Objective-C 'SEL' type.
QualType getFunctionType(QualType ResultTy, ArrayRef< QualType > Args, const FunctionProtoType::ExtProtoInfo &EPI) const
Return a normal function type with a typed argument list.
const TargetInfo & getTargetInfo() const
CodeGenOptions - Track various options which control how the code is optimized and passed to the back...
llvm::SmallVector< std::pair< std::string, std::string >, 0 > DebugPrefixMap
std::string CodeModel
The code model to use (-mcmodel).
std::string DebugCompilationDir
The string to embed in debug information as the current working directory.
std::string MainFileName
The user provided name for the "main file", if non-empty.
This class gathers all debug information during compilation and is responsible for emitting to llvm g...
llvm::DIType * getOrCreateStandaloneType(QualType Ty, SourceLocation Loc)
Emit standalone debug info for a type.
void EmitFunctionDecl(GlobalDecl GD, SourceLocation Loc, QualType FnType, llvm::Function *Fn=nullptr)
Emit debug info for a function declaration.
void EmitImportDecl(const ImportDecl &ID)
Emit an @import declaration.
This class organizes the cross-function state that is used while generating LLVM code.
CompilerInstance - Helper class for managing a single instance of the Clang compiler.
DiagnosticsEngine & getDiagnostics() const
Get the current diagnostics engine.
Preprocessor & getPreprocessor() const
Return the current preprocessor.
TargetOptions & getTargetOpts()
HeaderSearchOptions & getHeaderSearchOpts()
CompilerInvocation & getInvocation()
PreprocessorOptions & getPreprocessorOpts()
llvm::vfs::FileSystem & getVirtualFileSystem() const
LangOptions & getLangOpts()
CodeGenOptions & getCodeGenOpts()
CodeGenOptions & getCodeGenOpts()
DeclContext * getParent()
getParent - Returns the containing DeclContext.
Module * getImportedOwningModule() const
Get the imported owning module, if this decl is from an imported (non-local) module.
bool isFromASTFile() const
Determine whether this declaration came from an AST file (such as a precompiled header or module) rat...
SourceLocation getLocation() const
DeclContext * getDeclContext()
Concrete class used by the front-end to report problems and issues.
bool hasErrorOccurred() const
Represents a function declaration or definition.
Describes a module import declaration, which makes the contents of the named module visible in the cu...
Keeps track of the various options that can be enabled, which controls the dialect of C or C++ that i...
std::string CurrentModule
The name of the current module, of which the main source file is a part.
Represents an ObjC class declaration.
ObjCMethodDecl - Represents an instance or class method declaration.
PreprocessorOptions - This class is used for passing the various options used in preprocessor initial...
HeaderSearch & getHeaderSearchInfo() const
A (possibly-)qualified type.
bool isNull() const
Return true if this QualType doesn't point to a type yet.
const Type * getTypePtr() const
Retrieves a pointer to the underlying (unqualified) type.
Represents a struct/union/class.
A class that does preorder or postorder depth-first traversal on the entire Clang AST and visits each...
Represents the declaration of a struct/union/class/enum.
const llvm::Triple & getTriple() const
Returns the target triple of the primary target.
const char * getDataLayoutString() const
Options for controlling the target.
Represents a declaration of a type.
The base class of the type hierarchy.
bool isDependentType() const
Whether this type is a dependent type, meaning that its definition somehow depends on a template para...
bool isUndeducedType() const
Determine whether this type is an undeduced type, meaning that it somehow involves a C++11 'auto' typ...
Defines the clang::TargetInfo interface.
The JSON file list parser is used to communicate input to InstallAPI.
void emitBackendOutput(CompilerInstance &CI, CodeGenOptions &CGOpts, StringRef TDesc, llvm::Module *M, BackendAction Action, llvm::IntrusiveRefCntPtr< llvm::vfs::FileSystem > VFS, std::unique_ptr< raw_pwrite_stream > OS, BackendConsumer *BC=nullptr)
static ASTFileSignature createDISentinel()
Extra information about a function prototype.
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4