22#define DEBUG_TYPE "cg-data"
25using namespace cgdata;
28 const std::string &ErrMsg =
"") {
33 case cgdata_error::success:
36 case cgdata_error::eof:
39 case cgdata_error::bad_magic:
40 OS <<
"invalid codegen data (bad magic)";
42 case cgdata_error::bad_header:
43 OS <<
"invalid codegen data (file header is corrupt)";
45 case cgdata_error::empty_cgdata:
46 OS <<
"empty codegen data";
48 case cgdata_error::malformed:
49 OS <<
"malformed codegen data";
51 case cgdata_error::unsupported_version:
52 OS <<
"unsupported codegen data version";
68class CGDataErrorCategoryType :
public std::error_category {
69 const char *
name()
const noexcept
override {
return "llvm.cgdata"; }
71 std::string message(
int IE)
const override {
79 static CGDataErrorCategoryType ErrorCategory;
91const char *CodeGenDataSectNameCommon[] = {
92#define CG_DATA_SECT_ENTRY(Kind, SectNameCommon, SectNameCoff, Prefix) \
97const char *CodeGenDataSectNameCoff[] = {
98#define CG_DATA_SECT_ENTRY(Kind, SectNameCommon, SectNameCoff, Prefix) \
103const char *CodeGenDataSectNamePrefix[] = {
104#define CG_DATA_SECT_ENTRY(Kind, SectNameCommon, SectNameCoff, Prefix) Prefix,
114 bool AddSegmentInfo) {
115 std::string SectName;
118 SectName = CodeGenDataSectNamePrefix[CGSK];
121 SectName += CodeGenDataSectNameCoff[CGSK];
123 SectName += CodeGenDataSectNameCommon[CGSK];
128std::unique_ptr<CodeGenData> CodeGenData::Instance =
nullptr;
129std::once_flag CodeGenData::OnceFlag;
132 std::call_once(CodeGenData::OnceFlag, []() {
133 Instance = std::unique_ptr<CodeGenData>(
new CodeGenData());
137 return *(Instance.get());
140namespace IndexedCGData {
143 using namespace support;
145 static_assert(std::is_standard_layout_v<llvm::IndexedCGData::Header>,
146 "The header should be standard layout type since we use offset "
147 "of fields to read.");
149 H.Magic = endian::readNext<uint64_t, endianness::little, unaligned>(Curr);
152 H.Version = endian::readNext<uint32_t, endianness::little, unaligned>(Curr);
155 H.DataKind = endian::readNext<uint32_t, endianness::little, unaligned>(Curr);
162 "Please update the size computation below if a new field has "
163 "been added to the header, if not add a case statement to "
164 "fall through to the latest version.");
166 H.OutlinedHashTreeOffset =
167 endian::readNext<uint64_t, endianness::little, unaligned>(Curr);
177void warn(
Twine Message, std::string Whence, std::string Hint) {
180 errs() << Whence <<
": ";
181 errs() << Message <<
"\n";
static std::string getCGDataErrString(cgdata_error Err, const std::string &ErrMsg="")
std::string message() const override
Return the error message as a string.
static CodeGenData & getInstance()
Lightweight error class with error context and mandatory checking.
bool isA() const
Check whether one error is a subclass of another.
Tagged union holding either a T or a Error.
StringRef - Represent a constant reference to a string, i.e.
std::string str() const
str - Get the contents as an std::string.
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
static raw_ostream & warning()
Convenience method for printing "warning: " to stderr.
static raw_ostream & note()
Convenience method for printing "note: " to stderr.
A raw_ostream that writes to an std::string.
void warn(Error E, StringRef Whence="")
This is an optimization pass for GlobalISel generic memory operations.
void handleAllErrors(Error E, HandlerTs &&... Handlers)
Behaves the same as handleErrors, except that by contract all errors must be handled by the given han...
const std::error_category & cgdata_category()
raw_fd_ostream & errs()
This returns a reference to a raw_ostream for standard error.
std::string getCodeGenDataSectionName(CGDataSectKind CGSK, Triple::ObjectFormatType OF, bool AddSegmentInfo=true)