clang: lib/CIR/FrontendAction/CIRGenAction.cpp Source File (original) (raw)

1

2

3

4

5

6

7

8

12

13#include "mlir/IR/MLIRContext.h"

14#include "mlir/IR/OwningOpRef.h"

15

16using namespace cir;

17using namespace clang;

18

19namespace cir {

20

22

23 virtual void anchor();

24

26

27 std::unique_ptr<raw_pwrite_stream> OutputStream;

28

31 std::unique_ptr Gen;

32

33public:

42 std::unique_ptr<raw_pwrite_stream> OS)

43 : Action(Action), OutputStream(std::move(OS)), FS(VFS),

46

48 assert(!Context && "initialized multiple times");

49 Context = &Ctx;

50 Gen->Initialize(Ctx);

51 }

52

54 Gen->HandleTopLevelDecl(D);

55 return true;

56 }

57

59 Gen->HandleTranslationUnit(C);

60 mlir::ModuleOp MlirModule = Gen->getModule();

61 switch (Action) {

63 if (OutputStream && MlirModule) {

64 mlir::OpPrintingFlags Flags;

65 Flags.enableDebugInfo(true, false);

66 MlirModule->print(*OutputStream, Flags);

67 }

68 break;

69 }

70 }

71};

72}

73

74void CIRGenConsumer::anchor() {}

75

77 : MLIRCtx(MLIRCtx ? MLIRCtx : new mlir::MLIRContext), Action(Act) {}

78

80

81static std::unique_ptr<raw_pwrite_stream>

84 switch (Action) {

87 }

88 llvm_unreachable("Invalid CIRGenAction::OutputType");

89}

90

91std::unique_ptr

93 std::unique_ptrllvm::raw\_pwrite\_stream Out = CI.takeOutputStream();

94

95 if (!Out)

97

98 auto Result = std::make_uniquecir::CIRGenConsumer(

102

103 return Result;

104}

105

106void EmitCIRAction::anchor() {}

static std::unique_ptr< raw_pwrite_stream > getOutputStream(CompilerInstance &CI, StringRef InFile, CIRGenAction::OutputType Action)

CIRGenAction(OutputType Action, mlir::MLIRContext *MLIRCtx=nullptr)

std::unique_ptr< clang::ASTConsumer > CreateASTConsumer(clang::CompilerInstance &CI, llvm::StringRef InFile) override

CIRGenConsumer(CIRGenAction::OutputType Action, DiagnosticsEngine &DiagnosticsEngine, IntrusiveRefCntPtr< llvm::vfs::FileSystem > VFS, const HeaderSearchOptions &HeaderSearchOptions, const CodeGenOptions &CodeGenOptions, const TargetOptions &TargetOptions, const LangOptions &LangOptions, const FrontendOptions &FEOptions, std::unique_ptr< raw_pwrite_stream > OS)

void Initialize(ASTContext &Ctx) override

Initialize - This is called to initialize the consumer, providing the ASTContext.

bool HandleTopLevelDecl(DeclGroupRef D) override

HandleTopLevelDecl - Handle the specified top-level declaration.

void HandleTranslationUnit(ASTContext &C) override

HandleTranslationUnit - This method is called when the ASTs for entire translation unit have been par...

EmitCIRAction(mlir::MLIRContext *MLIRCtx=nullptr)

ASTConsumer - This is an abstract interface that should be implemented by clients that read ASTs.

Holds long-lived AST nodes (such as types and decls) that can be referred to throughout the semantic ...

CodeGenOptions - Track various options which control how the code is optimized and passed to the back...

CompilerInstance - Helper class for managing a single instance of the Clang compiler.

DiagnosticsEngine & getDiagnostics() const

Get the current diagnostics engine.

std::unique_ptr< raw_pwrite_stream > createDefaultOutputFile(bool Binary=true, StringRef BaseInput="", StringRef Extension="", bool RemoveFileOnSignal=true, bool CreateMissingDirectories=false, bool ForceUseTemporary=false)

Create the default output file (from the invocation's options) and add it to the list of tracked outp...

TargetOptions & getTargetOpts()

std::unique_ptr< llvm::raw_pwrite_stream > takeOutputStream()

FrontendOptions & getFrontendOpts()

HeaderSearchOptions & getHeaderSearchOpts()

llvm::vfs::FileSystem & getVirtualFileSystem() const

LangOptions & getLangOpts()

CodeGenOptions & getCodeGenOpts()

Concrete class used by the front-end to report problems and issues.

FrontendOptions - Options for controlling the behavior of the frontend.

Keeps track of the various options that can be enabled, which controls the dialect of C or C++ that i...

Options for controlling the target.

The JSON file list parser is used to communicate input to InstallAPI.