MCPcopy Create free account
hub / github.com/NVIDIA/cuda-tile / BytecodeVersionParser

Class BytecodeVersionParser

lib/Bytecode/Common/CommandLineOptions.cpp:23–63  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

21
22namespace {
23class BytecodeVersionParser : public llvm::cl::parser<BytecodeVersion> {
24public:
25 BytecodeVersionParser(llvm::cl::Option &o)
26 : llvm::cl::parser<BytecodeVersion>(o) {}
27
28 bool parse(llvm::cl::Option &o, StringRef /*argName*/, StringRef arg,
29 BytecodeVersion &v) {
30 StringRef versionStr = arg;
31
32 // Parse the `major.minor`.
33 uint8_t verMajor, verMinor;
34 if (versionStr.consumeInteger(10, verMajor) ||
35 !versionStr.consume_front(".") ||
36 versionStr.consumeInteger(10, verMinor))
37 return o.error("Invalid argument '" + arg + "'");
38
39 // Parse the `.tag`.
40 uint16_t tag = 0;
41 if (versionStr.consume_front(".") && versionStr.consumeInteger(10, tag))
42 return o.error("Invalid argument '" + arg + "'");
43 if (!versionStr.empty())
44 return o.error("Invalid argument '" + arg + "'");
45
46 std::optional<BytecodeVersion> version =
47 BytecodeVersion::fromVersion(verMajor, verMinor, tag);
48 if (!version) {
49 return o.error(
50 llvm::formatv(
51 "Invalid argument '{0}': the supported versions are [{1} - {2}]",
52 arg, BytecodeVersion::kMinSupportedVersion,
53 BytecodeVersion::kCurrentVersion)
54 .str());
55 }
56
57 // Set the version and return false to indicate success.
58 v = *version;
59 return false;
60 }
61
62 static void print(raw_ostream &os, const BytecodeVersion &v) { os << v; }
63};
64
65// Static storage for command line option value.
66static BytecodeVersion *bytecodeVersionPtr = nullptr;

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected