10 #include "llvm/TableGen/Error.h"
11 #include "llvm/TableGen/Record.h"
22 if (
const auto *stringInit = dyn_cast<llvm::StringInit>(def))
23 return stringInit->getValue();
24 const llvm::Record *record = cast<llvm::DefInit>(def)->getDef();
27 const llvm::RecordVal *type = record->getValue(
"type");
28 if (!type || !type->getValue()) {
29 llvm::PrintFatalError(
"Builder DAG arguments must be either strings or "
30 "defs which inherit from CArg");
32 return record->getValueAsString(
"type");
38 if (isa<llvm::StringInit>(
def))
40 const llvm::Record *record = cast<llvm::DefInit>(
def)->getDef();
41 std::optional<StringRef> value =
42 record->getValueAsOptionalString(
"defaultValue");
43 return value && !value->empty() ? value : std::nullopt;
53 const llvm::DagInit *dag =
def->getValueAsDag(
"dagParams");
54 auto *defInit = dyn_cast<llvm::DefInit>(dag->getOperator());
55 if (!defInit || !defInit->getDef()->getName().equals(
"ins"))
56 PrintFatalError(
def->getLoc(),
"expected 'ins' in builders");
58 bool seenDefaultValue =
false;
59 for (
unsigned i = 0, e = dag->getNumArgs(); i < e; ++i) {
60 const llvm::StringInit *paramName = dag->getArgName(i);
61 const llvm::Init *paramValue = dag->getArg(i);
62 Parameter param(paramName ? paramName->getValue()
63 : std::optional<StringRef>(),
69 seenDefaultValue =
true;
70 }
else if (seenDefaultValue) {
72 "expected an argument with default value after other "
73 "arguments with default values");
75 parameters.emplace_back(param);
81 std::optional<StringRef> body =
def->getValueAsOptionalString(
"body");
82 return body && !body->empty() ? body : std::nullopt;
86 std::optional<StringRef> message =
87 def->getValueAsOptionalString(
"odsCppDeprecated");
88 return message && !message->empty() ? message : std::nullopt;
This class represents a single parameter to a builder method.
std::optional< StringRef > getDefaultValue() const
Return an optional string containing the default value to use for this parameter.
StringRef getCppType() const
Return a string containing the C++ type of this parameter.
const llvm::Record * def
The TableGen definition of this builder.
std::optional< StringRef > getDeprecatedMessage() const
Return the deprecation message of the builder.
std::optional< StringRef > getBody() const
Return an optional string containing the body of the builder.
Builder(const llvm::Record *record, ArrayRef< SMLoc > loc)
Construct a builder from the given Record instance.
Include the generated interface declarations.