clang 20.0.0git
CIRGenerator.cpp
Go to the documentation of this file.
1//===--- CIRGenerator.cpp - Emit CIR from ASTs ----------------------------===//
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 builds an AST and converts it to CIR.
10//
11//===----------------------------------------------------------------------===//
12
13#include "CIRGenModule.h"
14
15#include "mlir/IR/MLIRContext.h"
16
17#include "clang/AST/DeclGroup.h"
20
21using namespace cir;
22using namespace clang;
23
24void CIRGenerator::anchor() {}
25
28 const CodeGenOptions &cgo)
29 : diags(diags), fs(std::move(vfs)), codeGenOpts{cgo} {}
31
33 using namespace llvm;
34
35 this->astContext = &astContext;
36
37 mlirContext = std::make_unique<mlir::MLIRContext>();
38 mlirContext->loadDialect<cir::CIRDialect>();
39 cgm = std::make_unique<clang::CIRGen::CIRGenModule>(
40 *mlirContext.get(), astContext, codeGenOpts, diags);
41}
42
43mlir::ModuleOp CIRGenerator::getModule() const { return cgm->getModule(); }
44
46
47 for (Decl *decl : group)
48 cgm->emitTopLevelDecl(decl);
49
50 return true;
51}
CIRGenerator(clang::DiagnosticsEngine &diags, llvm::IntrusiveRefCntPtr< llvm::vfs::FileSystem > fs, const clang::CodeGenOptions &cgo)
mlir::ModuleOp getModule() const
std::unique_ptr< clang::CIRGen::CIRGenModule > cgm
Definition: CIRGenerator.h:48
~CIRGenerator() override
bool HandleTopLevelDecl(clang::DeclGroupRef group) override
HandleTopLevelDecl - Handle the specified top-level declaration.
std::unique_ptr< mlir::MLIRContext > mlirContext
Definition: CIRGenerator.h:47
void Initialize(clang::ASTContext &astContext) override
Initialize - This is called to initialize the consumer, providing the ASTContext.
Holds long-lived AST nodes (such as types and decls) that can be referred to throughout the semantic ...
Definition: ASTContext.h:188
CodeGenOptions - Track various options which control how the code is optimized and passed to the back...
Decl - This represents one declaration (or definition), e.g.
Definition: DeclBase.h:86
Concrete class used by the front-end to report problems and issues.
Definition: Diagnostic.h:231
const internal::VariadicAllOfMatcher< Decl > decl
Matches declarations.
The JSON file list parser is used to communicate input to InstallAPI.
Diagnostic wrappers for TextAPI types for error reporting.
Definition: Dominators.h:30