LLVM: lib/InterfaceStub/IFSHandler.cpp Source File (original) (raw)
1
2
3
4
5
6
7
8
20#include
21#include
22
23using namespace llvm;
25
27
28namespace llvm {
29namespace yaml {
30
31
32template <> struct ScalarEnumerationTraits<IFSSymbolType> {
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);
39
40 if (!IO.outputting() && IO.matchEnumFallback())
42 }
43};
44
49 case IFSEndiannessType::Big:
50 Out << "big";
51 break;
52 case IFSEndiannessType::Little:
53 Out << "little";
54 break;
55 default:
57 }
58 }
59
62 .Case("big", IFSEndiannessType::Big)
63 .Case("little", IFSEndiannessType::Little)
64 .Default(IFSEndiannessType::Unknown);
65 if (Value == IFSEndiannessType::Unknown) {
66 return "Unsupported endianness";
67 }
69 }
70
72};
73
78 case IFSBitWidthType::IFS32:
79 Out << "32";
80 break;
81 case IFSBitWidthType::IFS64:
82 Out << "64";
83 break;
84 default:
86 }
87 }
88
91 .Case("32", IFSBitWidthType::IFS32)
92 .Case("64", IFSBitWidthType::IFS64)
93 .Default(IFSBitWidthType::Unknown);
94 if (Value == IFSBitWidthType::Unknown) {
95 return "Unsupported bit width";
96 }
98 }
99
101};
102
105 IO.mapOptional("ObjectFormat", Target.ObjectFormat);
106 IO.mapOptional("Arch", Target.ArchString);
107 IO.mapOptional("Endianness", Target.Endianness);
108 IO.mapOptional("BitWidth", Target.BitWidth);
109 }
110
111
112 static const bool flow = true;
113};
114
115
118 IO.mapRequired("Name", Symbol.Name);
119 IO.mapRequired("Type", Symbol.Type);
120
121 if (Symbol.Type == IFSSymbolType::NoType) {
122
123
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);
128 }
129 IO.mapOptional("Undefined", Symbol.Undefined, false);
130 IO.mapOptional("Weak", Symbol.Weak, false);
131 IO.mapOptional("Warning", Symbol.Warning);
132 }
133
134
135 static const bool flow = true;
136};
137
138
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);
148 }
149};
150
151
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);
158 IO.mapOptional("Target", Stub.Target.Triple);
159 IO.mapOptional("NeededLibs", Stub.NeededLibs);
160 IO.mapRequired("Symbols", Stub.Symbols);
161 }
162};
163}
164}
165
166
170 if (Line.starts_with("Target:")) {
171 if (Line == "Target:" || Line.contains("{")) {
172 return false;
173 }
174 }
175 }
176 return true;
177}
178
180 yaml::Input YamlIn(Buf);
181 std::unique_ptr Stub(new IFSStubTriple());
183 YamlIn >> *Stub;
184 } else {
185 YamlIn >> *static_cast<IFSStub *>(Stub.get());
186 }
187 if (std::error_code Err = YamlIn.error()) {
189 }
190
192 return make_error(
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;
203 }
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");
209 }
210 return std::move(Stub);
211}
212
214 yaml::Output YamlOut(OS, nullptr, 0);
215 std::unique_ptr CopyStub(new IFSStubTriple(Stub));
217 CopyStub->Target.ArchString =
219 }
221
222 if (CopyStub->Target.Triple ||
223 (!CopyStub->Target.ArchString && !CopyStub->Target.Endianness &&
224 !CopyStub->Target.BitWidth))
225 YamlOut << *CopyStub;
226 else
227 YamlOut << *static_cast<IFSStub *>(CopyStub.get());
229}
230
232 IFSStub &Stub, std::optional OverrideArch,
233 std::optional OverrideEndianness,
234 std::optional OverrideBitWidth,
235 std::optionalstd::string OverrideTriple) {
236 std::error_code OverrideEC(1, std::generic_category());
237 if (OverrideArch) {
239 return make_error(
240 "Supplied Arch conflicts with the text stub", OverrideEC);
241 }
243 }
244 if (OverrideEndianness) {
247 return make_error(
248 "Supplied Endianness conflicts with the text stub", OverrideEC);
249 }
251 }
252 if (OverrideBitWidth) {
254 return make_error(
255 "Supplied BitWidth conflicts with the text stub", OverrideEC);
256 }
258 }
259 if (OverrideTriple) {
261 return make_error(
262 "Supplied Triple conflicts with the text stub", OverrideEC);
263 }
265 }
267}
268
270 std::error_code ValidationEC(1, std::generic_category());
274 return make_error(
275 "Target triple cannot be used simultaneously with ELF target format",
276 ValidationEC);
277 }
278 if (ParseTriple) {
283 }
285 }
287
289 return make_error("Arch is not defined in the text stub",
290 ValidationEC);
291 }
293 return make_error("BitWidth is not defined in the text stub",
294 ValidationEC);
295 }
297 return make_error(
298 "Endianness is not defined in the text stub", ValidationEC);
299 }
300 }
302}
303
305 Triple IFSTriple(TripleStr);
307
308 switch (IFSTriple.getArch()) {
309 case Triple::ArchType::aarch64:
311 break;
312 case Triple::ArchType::x86_64:
314 break;
315 case Triple::ArchType::riscv64:
317 break;
318 default:
320 }
322 : IFSEndiannessType::Big;
324 IFSTriple.isArch64Bit() ? IFSBitWidthType::IFS64 : IFSBitWidthType::IFS32;
325 return RetTarget;
326}
327
329 bool StripEndianness, bool StripBitWidth) {
330 if (StripTriple || StripArch) {
333 }
334 if (StripTriple || StripEndianness) {
336 }
337 if (StripTriple || StripBitWidth) {
339 }
340 if (StripTriple) {
342 }
345 }
346}
347
349 const std::vectorstd::string &Exclude) {
351 return false;
352 };
353
354 if (StripUndefined) {
357 };
358 }
359
362 if (!PatternOrErr)
366 };
367 }
368
370
372}
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)