10 #include "llvm/TableGen/Error.h"
11 #include "llvm/TableGen/Record.h"
19 using llvm::StringInit;
27 if (
const auto *stringInit = dyn_cast<StringInit>(def))
28 return stringInit->getValue();
29 const Record *record = cast<DefInit>(def)->getDef();
32 const llvm::RecordVal *type = record->getValue(
"type");
33 if (!type || !type->getValue()) {
34 llvm::PrintFatalError(
"Builder DAG arguments must be either strings or "
35 "defs which inherit from CArg");
37 return record->getValueAsString(
"type");
43 if (isa<StringInit>(
def))
45 const Record *record = cast<DefInit>(
def)->getDef();
46 std::optional<StringRef> value =
47 record->getValueAsOptionalString(
"defaultValue");
48 return value && !value->empty() ? value : std::nullopt;
57 const DagInit *dag = def->getValueAsDag(
"dagParams");
58 auto *defInit = dyn_cast<DefInit>(dag->getOperator());
59 if (!defInit || defInit->getDef()->getName() !=
"ins")
60 PrintFatalError(def->getLoc(),
"expected 'ins' in builders");
62 bool seenDefaultValue =
false;
63 for (
unsigned i = 0, e = dag->getNumArgs(); i < e; ++i) {
64 const StringInit *paramName = dag->getArgName(i);
65 const Init *paramValue = dag->getArg(i);
66 Parameter param(paramName ? paramName->getValue()
67 : std::optional<StringRef>(),
72 if (param.getDefaultValue()) {
73 seenDefaultValue =
true;
74 }
else if (seenDefaultValue) {
76 "expected an argument with default value after other "
77 "arguments with default values");
79 parameters.emplace_back(param);
85 std::optional<StringRef> body =
def->getValueAsOptionalString(
"body");
86 return body && !body->empty() ? body : std::nullopt;
90 std::optional<StringRef> message =
91 def->getValueAsOptionalString(
"odsCppDeprecated");
92 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.
Builder(const llvm::Record *record, ArrayRef< SMLoc > loc)
Construct a builder from the given Record instance.
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.
Include the generated interface declarations.