| File: | build/source/mlir/lib/TableGen/Interfaces.cpp |
| Warning: | line 78, column 27 Called C++ object pointer is null |
Press '?' to see keyboard shortcuts
Keyboard shortcuts:
| 1 | //===- Interfaces.cpp - Interface classes ---------------------------------===// | |||
| 2 | // | |||
| 3 | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. | |||
| 4 | // See https://llvm.org/LICENSE.txt for license information. | |||
| 5 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | |||
| 6 | // | |||
| 7 | //===----------------------------------------------------------------------===// | |||
| 8 | ||||
| 9 | #include "mlir/TableGen/Interfaces.h" | |||
| 10 | #include "llvm/ADT/StringExtras.h" | |||
| 11 | #include "llvm/Support/FormatVariadic.h" | |||
| 12 | #include "llvm/TableGen/Error.h" | |||
| 13 | #include "llvm/TableGen/Record.h" | |||
| 14 | ||||
| 15 | using namespace mlir; | |||
| 16 | using namespace mlir::tblgen; | |||
| 17 | ||||
| 18 | //===----------------------------------------------------------------------===// | |||
| 19 | // InterfaceMethod | |||
| 20 | //===----------------------------------------------------------------------===// | |||
| 21 | ||||
| 22 | InterfaceMethod::InterfaceMethod(const llvm::Record *def) : def(def) { | |||
| 23 | llvm::DagInit *args = def->getValueAsDag("arguments"); | |||
| 24 | for (unsigned i = 0, e = args->getNumArgs(); i != e; ++i) { | |||
| 25 | arguments.push_back( | |||
| 26 | {llvm::cast<llvm::StringInit>(args->getArg(i))->getValue(), | |||
| 27 | args->getArgNameStr(i)}); | |||
| 28 | } | |||
| 29 | } | |||
| 30 | ||||
| 31 | StringRef InterfaceMethod::getReturnType() const { | |||
| 32 | return def->getValueAsString("returnType"); | |||
| 33 | } | |||
| 34 | ||||
| 35 | // Return the name of this method. | |||
| 36 | StringRef InterfaceMethod::getName() const { | |||
| 37 | return def->getValueAsString("name"); | |||
| 38 | } | |||
| 39 | ||||
| 40 | // Return if this method is static. | |||
| 41 | bool InterfaceMethod::isStatic() const { | |||
| 42 | return def->isSubClassOf("StaticInterfaceMethod"); | |||
| 43 | } | |||
| 44 | ||||
| 45 | // Return the body for this method if it has one. | |||
| 46 | std::optional<StringRef> InterfaceMethod::getBody() const { | |||
| 47 | auto value = def->getValueAsString("body"); | |||
| 48 | return value.empty() ? std::optional<StringRef>() : value; | |||
| 49 | } | |||
| 50 | ||||
| 51 | // Return the default implementation for this method if it has one. | |||
| 52 | std::optional<StringRef> InterfaceMethod::getDefaultImplementation() const { | |||
| 53 | auto value = def->getValueAsString("defaultBody"); | |||
| 54 | return value.empty() ? std::optional<StringRef>() : value; | |||
| 55 | } | |||
| 56 | ||||
| 57 | // Return the description of this method if it has one. | |||
| 58 | std::optional<StringRef> InterfaceMethod::getDescription() const { | |||
| 59 | auto value = def->getValueAsString("description"); | |||
| 60 | return value.empty() ? std::optional<StringRef>() : value; | |||
| 61 | } | |||
| 62 | ||||
| 63 | ArrayRef<InterfaceMethod::Argument> InterfaceMethod::getArguments() const { | |||
| 64 | return arguments; | |||
| 65 | } | |||
| 66 | ||||
| 67 | bool InterfaceMethod::arg_empty() const { return arguments.empty(); } | |||
| 68 | ||||
| 69 | //===----------------------------------------------------------------------===// | |||
| 70 | // Interface | |||
| 71 | //===----------------------------------------------------------------------===// | |||
| 72 | ||||
| 73 | Interface::Interface(const llvm::Record *def) : def(def) { | |||
| 74 | assert(def->isSubClassOf("Interface") &&(static_cast <bool> (def->isSubClassOf("Interface") && "must be subclass of TableGen 'Interface' class") ? void (0) : __assert_fail ("def->isSubClassOf(\"Interface\") && \"must be subclass of TableGen 'Interface' class\"" , "mlir/lib/TableGen/Interfaces.cpp", 75, __extension__ __PRETTY_FUNCTION__ )) | |||
| ||||
| 75 | "must be subclass of TableGen 'Interface' class")(static_cast <bool> (def->isSubClassOf("Interface") && "must be subclass of TableGen 'Interface' class") ? void (0) : __assert_fail ("def->isSubClassOf(\"Interface\") && \"must be subclass of TableGen 'Interface' class\"" , "mlir/lib/TableGen/Interfaces.cpp", 75, __extension__ __PRETTY_FUNCTION__ )); | |||
| 76 | ||||
| 77 | auto *listInit = dyn_cast<llvm::ListInit>(def->getValueInit("methods")); | |||
| 78 | for (llvm::Init *init : listInit->getValues()) | |||
| ||||
| 79 | methods.emplace_back(cast<llvm::DefInit>(init)->getDef()); | |||
| 80 | } | |||
| 81 | ||||
| 82 | // Return the name of this interface. | |||
| 83 | StringRef Interface::getName() const { | |||
| 84 | return def->getValueAsString("cppInterfaceName"); | |||
| 85 | } | |||
| 86 | ||||
| 87 | // Return the C++ namespace of this interface. | |||
| 88 | StringRef Interface::getCppNamespace() const { | |||
| 89 | return def->getValueAsString("cppNamespace"); | |||
| 90 | } | |||
| 91 | ||||
| 92 | // Return the methods of this interface. | |||
| 93 | ArrayRef<InterfaceMethod> Interface::getMethods() const { return methods; } | |||
| 94 | ||||
| 95 | // Return the description of this method if it has one. | |||
| 96 | std::optional<StringRef> Interface::getDescription() const { | |||
| 97 | auto value = def->getValueAsString("description"); | |||
| 98 | return value.empty() ? std::optional<StringRef>() : value; | |||
| 99 | } | |||
| 100 | ||||
| 101 | // Return the interfaces extra class declaration code. | |||
| 102 | std::optional<StringRef> Interface::getExtraClassDeclaration() const { | |||
| 103 | auto value = def->getValueAsString("extraClassDeclaration"); | |||
| 104 | return value.empty() ? std::optional<StringRef>() : value; | |||
| 105 | } | |||
| 106 | ||||
| 107 | // Return the traits extra class declaration code. | |||
| 108 | std::optional<StringRef> Interface::getExtraTraitClassDeclaration() const { | |||
| 109 | auto value = def->getValueAsString("extraTraitClassDeclaration"); | |||
| 110 | return value.empty() ? std::optional<StringRef>() : value; | |||
| 111 | } | |||
| 112 | ||||
| 113 | // Return the shared extra class declaration code. | |||
| 114 | std::optional<StringRef> Interface::getExtraSharedClassDeclaration() const { | |||
| 115 | auto value = def->getValueAsString("extraSharedClassDeclaration"); | |||
| 116 | return value.empty() ? std::optional<StringRef>() : value; | |||
| 117 | } | |||
| 118 | ||||
| 119 | // Return the body for this method if it has one. | |||
| 120 | std::optional<StringRef> Interface::getVerify() const { | |||
| 121 | // Only OpInterface supports the verify method. | |||
| 122 | if (!isa<OpInterface>(this)) | |||
| 123 | return std::nullopt; | |||
| 124 | auto value = def->getValueAsString("verify"); | |||
| 125 | return value.empty() ? std::optional<StringRef>() : value; | |||
| 126 | } | |||
| 127 | ||||
| 128 | bool Interface::verifyWithRegions() const { | |||
| 129 | return def->getValueAsBit("verifyWithRegions"); | |||
| 130 | } | |||
| 131 | ||||
| 132 | //===----------------------------------------------------------------------===// | |||
| 133 | // AttrInterface | |||
| 134 | //===----------------------------------------------------------------------===// | |||
| 135 | ||||
| 136 | bool AttrInterface::classof(const Interface *interface) { | |||
| 137 | return interface->getDef().isSubClassOf("AttrInterface"); | |||
| 138 | } | |||
| 139 | ||||
| 140 | //===----------------------------------------------------------------------===// | |||
| 141 | // OpInterface | |||
| 142 | //===----------------------------------------------------------------------===// | |||
| 143 | ||||
| 144 | bool OpInterface::classof(const Interface *interface) { | |||
| 145 | return interface->getDef().isSubClassOf("OpInterface"); | |||
| 146 | } | |||
| 147 | ||||
| 148 | //===----------------------------------------------------------------------===// | |||
| 149 | // TypeInterface | |||
| 150 | //===----------------------------------------------------------------------===// | |||
| 151 | ||||
| 152 | bool TypeInterface::classof(const Interface *interface) { | |||
| 153 | return interface->getDef().isSubClassOf("TypeInterface"); | |||
| 154 | } |