xref: /llvm-project/clang/lib/CIR/CodeGen/CIRGenerator.cpp (revision 1bb52e94621d2cba4f34504697cb0ea83805cb98)
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 "clang/AST/DeclGroup.h"
16 #include "clang/CIR/CIRGenerator.h"
17 
18 using namespace cir;
19 using namespace clang;
20 
21 void CIRGenerator::anchor() {}
22 
23 CIRGenerator::CIRGenerator(clang::DiagnosticsEngine &diags,
24                            llvm::IntrusiveRefCntPtr<llvm::vfs::FileSystem> vfs,
25                            const CodeGenOptions &cgo)
26     : diags(diags), fs(std::move(vfs)), codeGenOpts{cgo} {}
27 CIRGenerator::~CIRGenerator() = default;
28 
29 void CIRGenerator::Initialize(ASTContext &astCtx) {
30   using namespace llvm;
31 
32   this->astCtx = &astCtx;
33 
34   cgm = std::make_unique<CIRGenModule>(*mlirCtx, astCtx, codeGenOpts, diags);
35 }
36 
37 bool CIRGenerator::HandleTopLevelDecl(DeclGroupRef group) {
38 
39   for (Decl *decl : group)
40     cgm->buildTopLevelDecl(decl);
41 
42   return true;
43 }
44