blob: 798a7471cc8132218bca889d5bc105cfa2771147 (
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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
|
// SPDX-License-Identifier: GPL-3.0-or-later
#ifndef RCC_CODEGEN_MIRPARSER_MIRPARSER_H
#define RCC_CODEGEN_MIRPARSER_MIRPARSER_H
#include "rcc/CodeGen/CompilationUnit.h"
#include "rcc/CodeGen/MIRParser/MIParser.h"
#include "rcc/CodeGen/StableID.h"
#include "rcc/MIR/EmbeddedIR.h"
#include "rcc/Support/TextDiagnostic.h"
#include "rcc/Support/YAML.h"
#include <cstdint>
#include <optional>
#include <span>
#include <string>
#include <utility>
#include <vector>
namespace rcc {
class TargetDescription;
namespace mir {
struct MIRFunctionDocumentInfo final {
MachineFunctionStableID Function;
std::optional<bool> NoPHIs;
std::optional<bool> IsSSA;
std::optional<bool> NoVRegs;
std::optional<bool> HasFakeUses;
friend bool operator==(const MIRFunctionDocumentInfo &Left,
const MIRFunctionDocumentInfo &Right) = default;
};
class MIRDocument final {
public:
MIRDocument();
explicit MIRDocument(CompilationUnit Unit);
MIRDocument(const MIRDocument &) = delete;
MIRDocument &operator=(const MIRDocument &) = delete;
MIRDocument(MIRDocument &&) noexcept;
MIRDocument &operator=(MIRDocument &&) noexcept;
~MIRDocument();
[[nodiscard]] CompilationUnit &unit() noexcept {
return Unit;
}
[[nodiscard]] const CompilationUnit &unit() const noexcept {
return Unit;
}
[[nodiscard]] const EmbeddedIRReferenceIndex *embeddedIR() const noexcept {
return EmbeddedIR ? &*EmbeddedIR : nullptr;
}
[[nodiscard]] std::span<const MIRFunctionDocumentInfo> functionDocumentInfo() const noexcept {
return FunctionInfo;
}
[[nodiscard]] std::span<const MISyncScopeSlot> syncScopes() const noexcept {
return SyncScopes;
}
private:
CompilationUnit Unit;
std::optional<EmbeddedIRReferenceIndex> EmbeddedIR;
std::vector<MIRFunctionDocumentInfo> FunctionInfo;
std::vector<MISyncScopeSlot> SyncScopes;
friend class MIRDocumentParser;
};
struct MIRDocumentParserOptions final {
yaml::ParseOptions YAML;
MIParserOptions MachineInstructions;
std::string DataLayout;
bool VerifyMachineFunctions = true;
};
class MIRDocumentParseResult final {
public:
MIRDocumentParseResult(const MIRDocumentParseResult &) = delete;
MIRDocumentParseResult &operator=(const MIRDocumentParseResult &) = delete;
MIRDocumentParseResult(MIRDocumentParseResult &&) noexcept;
MIRDocumentParseResult &operator=(MIRDocumentParseResult &&) noexcept;
~MIRDocumentParseResult();
[[nodiscard]] bool succeeded() const noexcept {
return Document.has_value() && Diagnostics.empty();
}
[[nodiscard]] MIRDocument *document() noexcept {
return Document ? &*Document : nullptr;
}
[[nodiscard]] const MIRDocument *document() const noexcept {
return Document ? &*Document : nullptr;
}
[[nodiscard]] const TextSource &source() const noexcept {
return Source;
}
[[nodiscard]] std::span<const TextDiagnostic> diagnostics() const noexcept {
return Diagnostics;
}
private:
MIRDocumentParseResult(std::string SourceName, std::string SourceText)
: Source(std::move(SourceName), std::move(SourceText)) {}
TextSource Source;
std::optional<MIRDocument> Document;
std::vector<TextDiagnostic> Diagnostics;
friend class MIRDocumentParser;
};
[[nodiscard]] MIRDocumentParseResult parseMIRDocument(const TargetDescription &Target,
std::string SourceName,
std::string SourceText,
MIRDocumentParserOptions Options = {});
} // namespace mir
} // namespace rcc
#endif // RCC_CODEGEN_MIRPARSER_MIRPARSER_H
|