aboutsummaryrefslogtreecommitdiff
path: root/backend/include/rcc/CodeGen/MIRPrinter.h
blob: 4c20bed66ad03c125e3b26fab69304ce38160895 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
// SPDX-License-Identifier: GPL-3.0-or-later

#ifndef RCC_CODEGEN_MIRPRINTER_H
#define RCC_CODEGEN_MIRPRINTER_H

#include "rcc/CodeGen/MIRParser/MIRParser.h"
#include "rcc/Support/Error.h"

#include <string>
#include <vector>

namespace rcc {

class MachineFunction;
class MachineBasicBlock;
class TargetDescription;

namespace mir {

enum class MIPrintMode : unsigned char {
  Complete,
  Readable,
};

struct MIPrinterOptions final {
  MIPrintMode Mode = MIPrintMode::Complete;
};

[[nodiscard]] Expected<void> guessSuccessors(const MachineBasicBlock &Block,
                                             const TargetDescription &Target,
                                             std::vector<MachineBasicBlock *> &Result,
                                             bool &IsFallthrough);

[[nodiscard]] Expected<std::string> printMachineFunctionBody(const MachineFunction &Function,
                                                             const TargetDescription &Target,
                                                             const MIParserContext &Context = {},
                                                             MIPrinterOptions Options = {});

struct MIRDocumentPrinterOptions final {
  MIPrintMode Mode = MIPrintMode::Complete;
  bool EmitEmbeddedIR = true;
  std::string DataLayout;
};

[[nodiscard]] Expected<std::string> printMIRDocument(const MIRDocument &Document,
                                                     const TargetDescription &Target,
                                                     MIRDocumentPrinterOptions Options = {});

} // namespace mir
} // namespace rcc

#endif // RCC_CODEGEN_MIRPRINTER_H