blob: 8cb6d487dc08759dcf1fc94c2ebb0ac4e154b0d7 (
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
|
// SPDX-License-Identifier: GPL-3.0-or-later
#include "rcc/CodeGen/MachineBasicBlockAttributes.h"
#include <cstdint>
#include <string>
#include <string_view>
#include <utility>
namespace rcc {
std::string_view getMachineBasicBlockAttributeName(MachineBasicBlockAttribute Attribute) noexcept {
switch (Attribute) {
case MachineBasicBlockAttribute::MachineBlockAddressTaken:
return "MachineBlockAddressTaken";
case MachineBasicBlockAttribute::IRBlockAddressTaken:
return "IRBlockAddressTaken";
case MachineBasicBlockAttribute::LandingPad:
return "LandingPad";
case MachineBasicBlockAttribute::InlineAsmBrIndirectTarget:
return "InlineAsmBrIndirectTarget";
case MachineBasicBlockAttribute::EHFuncletEntry:
return "EHFuncletEntry";
case MachineBasicBlockAttribute::EHScopeEntry:
return "EHScopeEntry";
case MachineBasicBlockAttribute::Count:
return "Invalid";
}
return "Invalid";
}
Expected<MachineBasicBlockAttributes>
MachineBasicBlockAttributes::fromRawFlags(std::uint8_t RawFlags) {
if ((RawFlags & static_cast<std::uint8_t>(~ValidFlags)) != 0) {
return makeUnexpected(ErrorCode::InvalidArgument,
"machine basic block attributes contain unknown flag bits");
}
MachineBasicBlockAttributes Result;
Result.Flags = RawFlags;
return Result;
}
Expected<void> MachineBasicBlockAttributes::setName(std::string NewName) {
if (NewName.empty()) {
return makeUnexpected(ErrorCode::InvalidArgument, "machine basic block name cannot be empty");
}
Name = std::move(NewName);
return {};
}
Expected<void> MachineBasicBlockAttributes::setIRBlockName(std::string NewName) {
if (NewName.empty()) {
return makeUnexpected(ErrorCode::InvalidArgument,
"machine basic block IR name cannot be empty");
}
IRBlockName = std::move(NewName);
return {};
}
Expected<void> MachineBasicBlockAttributes::verify() const {
if ((Flags & static_cast<std::uint8_t>(~ValidFlags)) != 0) {
return makeUnexpected(ErrorCode::VerificationError,
"machine basic block attributes contain unknown flag bits");
}
if (Name && Name->empty()) {
return makeUnexpected(ErrorCode::VerificationError, "machine basic block name cannot be empty");
}
if (IRBlockName && IRBlockName->empty()) {
return makeUnexpected(ErrorCode::VerificationError,
"machine basic block IR name cannot be empty");
}
if (has(MachineBasicBlockAttribute::IRBlockAddressTaken) && !IRBlockName) {
return makeUnexpected(ErrorCode::VerificationError,
"IR-block-address-taken block requires an IR block reference");
}
if (BlockAlignment.bytes() == 0) {
return makeUnexpected(ErrorCode::VerificationError,
"machine basic block alignment must be nonzero");
}
return {};
}
} // namespace rcc
|