34 IO.enumCase(
SymbolType,
"NoType", IFSSymbolType::NoType);
35 IO.enumCase(
SymbolType,
"Func", IFSSymbolType::Func);
36 IO.enumCase(
SymbolType,
"Object", IFSSymbolType::Object);
37 IO.enumCase(
SymbolType,
"TLS", IFSSymbolType::TLS);
38 IO.enumCase(
SymbolType,
"Unknown", IFSSymbolType::Unknown);
40 if (!IO.outputting() && IO.matchEnumFallback())
49 case IFSEndiannessType::Big:
52 case IFSEndiannessType::Little:
62 .
Case(
"big", IFSEndiannessType::Big)
63 .
Case(
"little", IFSEndiannessType::Little)
64 .
Default(IFSEndiannessType::Unknown);
65 if (
Value == IFSEndiannessType::Unknown) {
66 return "Unsupported endianness";
78 case IFSBitWidthType::IFS32:
81 case IFSBitWidthType::IFS64:
91 .
Case(
"32", IFSBitWidthType::IFS32)
92 .
Case(
"64", IFSBitWidthType::IFS64)
93 .
Default(IFSBitWidthType::Unknown);
94 if (
Value == IFSBitWidthType::Unknown) {
95 return "Unsupported bit width";
105 IO.mapOptional(
"ObjectFormat",
Target.ObjectFormat);
106 IO.mapOptional(
"Arch",
Target.ArchString);
107 IO.mapOptional(
"Endianness",
Target.Endianness);
108 IO.mapOptional(
"BitWidth",
Target.BitWidth);
112 static const bool flow =
true;
118 IO.mapRequired(
"Name", Symbol.Name);
119 IO.mapRequired(
"Type", Symbol.Type);
121 if (Symbol.Type == IFSSymbolType::NoType) {
124 if (!Symbol.Size || *Symbol.Size)
125 IO.mapOptional(
"Size", Symbol.Size);
126 }
else if (Symbol.Type != IFSSymbolType::Func) {
127 IO.mapOptional(
"Size", Symbol.Size);
129 IO.mapOptional(
"Undefined", Symbol.Undefined,
false);
130 IO.mapOptional(
"Weak", Symbol.Weak,
false);
131 IO.mapOptional(
"Warning", Symbol.Warning);
135 static const bool flow =
true;
141 if (!IO.mapTag(
"!ifs-v1",
true))
142 IO.setError(
"Not a .tbe YAML file.");
143 IO.mapRequired(
"IfsVersion", Stub.
IfsVersion);
144 IO.mapOptional(
"SoName", Stub.
SoName);
145 IO.mapOptional(
"Target", Stub.
Target);
146 IO.mapOptional(
"NeededLibs", Stub.
NeededLibs);
147 IO.mapRequired(
"Symbols", Stub.
Symbols);
154 if (!IO.mapTag(
"!ifs-v1",
true))
155 IO.setError(
"Not a .tbe YAML file.");
156 IO.mapRequired(
"IfsVersion", Stub.
IfsVersion);
157 IO.mapOptional(
"SoName", Stub.
SoName);
159 IO.mapOptional(
"NeededLibs", Stub.
NeededLibs);
160 IO.mapRequired(
"Symbols", Stub.
Symbols);
170 if (Line.starts_with(
"Target:")) {
171 if (Line ==
"Target:" || Line.contains(
"{")) {
180 yaml::Input YamlIn(Buf);
185 YamlIn >> *
static_cast<IFSStub *
>(Stub.get());
187 if (std::error_code Err = YamlIn.error()) {
192 return make_error<StringError>(
193 "IFS version " + Stub->IfsVersion.getAsString() +
" is unsupported.",
194 std::make_error_code(std::errc::invalid_argument));
195 if (Stub->Target.ArchString) {
200 std::make_error_code(std::errc::invalid_argument),
201 "IFS arch '" + *Stub->Target.ArchString +
"' is unsupported");
202 Stub->Target.Arch = eMachine;
204 for (
const auto &Item : Stub->Symbols) {
205 if (Item.Type == IFSSymbolType::Unknown)
207 std::make_error_code(std::errc::invalid_argument),
208 "IFS symbol type for symbol '" + Item.Name +
"' is unsupported");
210 return std::move(Stub);
214 yaml::Output YamlOut(
OS,
nullptr, 0);
215 std::unique_ptr<IFSStubTriple> CopyStub(
new IFSStubTriple(Stub));
217 CopyStub->Target.ArchString =
222 if (CopyStub->Target.Triple ||
223 (!CopyStub->Target.ArchString && !CopyStub->Target.Endianness &&
224 !CopyStub->Target.BitWidth))
225 YamlOut << *CopyStub;
227 YamlOut << *static_cast<IFSStub *>(CopyStub.get());
232 IFSStub &Stub, std::optional<IFSArch> OverrideArch,
233 std::optional<IFSEndiannessType> OverrideEndianness,
234 std::optional<IFSBitWidthType> OverrideBitWidth,
235 std::optional<std::string> OverrideTriple) {
236 std::error_code OverrideEC(1, std::generic_category());
239 return make_error<StringError>(
240 "Supplied Arch conflicts with the text stub", OverrideEC);
244 if (OverrideEndianness) {
247 return make_error<StringError>(
248 "Supplied Endianness conflicts with the text stub", OverrideEC);
252 if (OverrideBitWidth) {
254 return make_error<StringError>(
255 "Supplied BitWidth conflicts with the text stub", OverrideEC);
259 if (OverrideTriple) {
261 return make_error<StringError>(
262 "Supplied Triple conflicts with the text stub", OverrideEC);
270 std::error_code ValidationEC(1, std::generic_category());
274 return make_error<StringError>(
275 "Target triple cannot be used simultaneously with ELF target format",
289 return make_error<StringError>(
"Arch is not defined in the text stub",
293 return make_error<StringError>(
"BitWidth is not defined in the text stub",
297 return make_error<StringError>(
298 "Endianness is not defined in the text stub", ValidationEC);
305 Triple IFSTriple(TripleStr);
309 case Triple::ArchType::aarch64:
312 case Triple::ArchType::x86_64:
315 case Triple::ArchType::riscv64:
322 : IFSEndiannessType::Big;
324 IFSTriple.
isArch64Bit() ? IFSBitWidthType::IFS64 : IFSBitWidthType::IFS32;
329 bool StripEndianness,
bool StripBitWidth) {
330 if (StripTriple || StripArch) {
334 if (StripTriple || StripEndianness) {
337 if (StripTriple || StripBitWidth) {
349 const std::vector<std::string> &Exclude) {
354 if (StripUndefined) {
bool usesTriple(StringRef Buf)
Attempt to determine if a Text stub uses target triple.
This file declares an interface for reading and writing .ifs (text-based InterFace Stub) files.
This file defines an internal representation of an InterFace Stub.
This file implements the StringSwitch template, which mimics a switch() statement whose cases are str...
#define LLVM_YAML_IS_SEQUENCE_VECTOR(type)
Lightweight error class with error context and mandatory checking.
static ErrorSuccess success()
Create a success value.
Tagged union holding either a T or a Error.
Error takeError()
Take ownership of the stored error.
static Expected< GlobPattern > create(StringRef Pat, std::optional< size_t > MaxSubPatterns={})
MatchResult match(StringRef Buffer, const SourceMgr &SM) const
Matches the pattern string against the input buffer Buffer.
StringRef - Represent a constant reference to a string, i.e.
A switch()-like statement whose cases are string literals.
StringSwitch & Case(StringLiteral S, T Value)
Target - Wrapper for Target specific information.
Triple - Helper class for working with autoconf configuration names.
bool isLittleEndian() const
Tests whether the target triple is little endian.
ArchType getArch() const
Get the parsed architecture type of this triple.
bool isArch64Bit() const
Test whether the architecture is 64-bit.
LLVM Value Representation.
A forward iterator which reads text lines from a buffer.
This class implements an extremely fast bulk output stream that can only output to a stream.
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
uint16_t convertArchNameToEMachine(StringRef Arch)
Convert an architecture name into ELF's e_machine value.
StringRef convertEMachineToArchName(uint16_t EMachine)
Convert an ELF's e_machine value into an architecture name.
void stripIFSTarget(IFSStub &Stub, bool StripTriple, bool StripArch, bool StripEndianness, bool StripBitWidth)
Strips target platform information from the text stub.
Expected< std::unique_ptr< IFSStub > > readIFSFromBuffer(StringRef Buf)
Attempts to read an IFS interface file from a StringRef buffer.
Error validateIFSTarget(IFSStub &Stub, bool ParseTriple)
Validate the target platform inforation in the text stub.
IFSTarget parseTriple(StringRef TripleStr)
Parse llvm triple string into a IFSTarget struct.
Error writeIFSToOutputStream(raw_ostream &OS, const IFSStub &Stub)
Attempts to write an IFS interface file to a raw_ostream.
const VersionTuple IFSVersionCurrent(3, 0)
Error filterIFSSyms(IFSStub &Stub, bool StripUndefined, const std::vector< std::string > &Exclude={})
Error overrideIFSTarget(IFSStub &Stub, std::optional< IFSArch > OverrideArch, std::optional< IFSEndiannessType > OverrideEndianness, std::optional< IFSBitWidthType > OverrideBitWidth, std::optional< std::string > OverrideTriple)
Override the target platform inforation in the text stub.
This is an optimization pass for GlobalISel generic memory operations.
Error createStringError(std::error_code EC, char const *Fmt, const Ts &... Vals)
Create formatted StringError object.
void erase_if(Container &C, UnaryPredicate P)
Provide a container algorithm similar to C++ Library Fundamentals v2's erase_if which is equivalent t...
std::vector< IFSSymbol > Symbols
std::optional< std::string > SoName
std::vector< std::string > NeededLibs
std::optional< std::string > ArchString
std::optional< std::string > Triple
std::optional< IFSEndiannessType > Endianness
std::optional< IFSBitWidthType > BitWidth
std::optional< std::string > ObjectFormat
std::optional< IFSArch > Arch
static void mapping(IO &IO, IFSStubTriple &Stub)
static void mapping(IO &IO, IFSStub &Stub)
static void mapping(IO &IO, IFSSymbol &Symbol)
static void mapping(IO &IO, IFSTarget &Target)
static void enumeration(IO &IO, IFSSymbolType &SymbolType)
static StringRef input(StringRef Scalar, void *, IFSBitWidthType &Value)
static void output(const IFSBitWidthType &Value, void *, llvm::raw_ostream &Out)
static QuotingType mustQuote(StringRef)
static StringRef input(StringRef Scalar, void *, IFSEndiannessType &Value)
static QuotingType mustQuote(StringRef)
static void output(const IFSEndiannessType &Value, void *, llvm::raw_ostream &Out)