#include "AttrOrTypeFormatGen.h"
#include "FormatGen.h"
#include "mlir/Support/LLVM.h"
#include "mlir/TableGen/AttrOrTypeDef.h"
#include "mlir/TableGen/Format.h"
#include "mlir/TableGen/GenInfo.h"
#include "llvm/ADT/BitVector.h"
#include "llvm/ADT/StringExtras.h"
#include "llvm/ADT/StringSwitch.h"
#include "llvm/ADT/TypeSwitch.h"
#include "llvm/Support/MemoryBuffer.h"
#include "llvm/Support/SaveAndRestore.h"
#include "llvm/Support/SourceMgr.h"
#include "llvm/TableGen/Error.h"
#include "llvm/TableGen/TableGenBackend.h"
usingnamespacemlir;
usingnamespacemlir::tblgen;
formatv;
namespace {
class ParameterElement
: public VariableElementBase<VariableElement::Parameter> { … };
static bool paramIsOptional(ParameterElement *el) { … }
static bool paramNotOptional(ParameterElement *el) { … }
template <DirectiveElement::Kind DirectiveKind>
class ParamsDirectiveBase : public DirectiveElementBase<DirectiveKind> { … };
class ParamsDirective : public ParamsDirectiveBase<DirectiveElement::Params> { … };
class StructDirective : public ParamsDirectiveBase<DirectiveElement::Struct> { … };
}
static const char *const defaultParameterParser = …;
static const char *const defaultParameterPrinter = …;
static const char *const qualifiedParameterPrinter = …;
static const char *const parserErrorStr = …;
static const char *const variableParser = …;
namespace {
class DefFormat { … };
}
static void genAttrSelfTypeParser(MethodBody &os, const FmtContext &ctx,
const AttributeSelfTypeParameter ¶m) { … }
void DefFormat::genParser(MethodBody &os) { … }
void DefFormat::genElementParser(FormatElement *el, FmtContext &ctx,
MethodBody &os) { … }
void DefFormat::genLiteralParser(StringRef value, FmtContext &ctx,
MethodBody &os, bool isOptional) { … }
void DefFormat::genVariableParser(ParameterElement *el, FmtContext &ctx,
MethodBody &os) { … }
void DefFormat::genParamsParser(ParamsDirective *el, FmtContext &ctx,
MethodBody &os) { … }
void DefFormat::genStructParser(StructDirective *el, FmtContext &ctx,
MethodBody &os) { … }
void DefFormat::genCustomParser(CustomDirective *el, FmtContext &ctx,
MethodBody &os, bool isOptional) { … }
void DefFormat::genOptionalGroupParser(OptionalElement *el, FmtContext &ctx,
MethodBody &os) { … }
void DefFormat::genPrinter(MethodBody &os) { … }
void DefFormat::genElementPrinter(FormatElement *el, FmtContext &ctx,
MethodBody &os) { … }
void DefFormat::genLiteralPrinter(StringRef value, FmtContext &ctx,
MethodBody &os) { … }
void DefFormat::genVariablePrinter(ParameterElement *el, FmtContext &ctx,
MethodBody &os, bool skipGuard) { … }
template <typename ParameterRange>
static void guardOnAny(FmtContext &ctx, MethodBody &os, ParameterRange &¶ms,
bool inverted = false) { … }
void DefFormat::genCommaSeparatedPrinter(
ArrayRef<ParameterElement *> params, FmtContext &ctx, MethodBody &os,
function_ref<void(ParameterElement *)> extra) { … }
void DefFormat::genParamsPrinter(ParamsDirective *el, FmtContext &ctx,
MethodBody &os) { … }
void DefFormat::genStructPrinter(StructDirective *el, FmtContext &ctx,
MethodBody &os) { … }
void DefFormat::genCustomPrinter(CustomDirective *el, FmtContext &ctx,
MethodBody &os) { … }
void DefFormat::genOptionalGroupPrinter(OptionalElement *el, FmtContext &ctx,
MethodBody &os) { … }
void DefFormat::genWhitespacePrinter(WhitespaceElement *el, FmtContext &ctx,
MethodBody &os) { … }
namespace {
class DefFormatParser : public FormatParser { … };
}
LogicalResult DefFormatParser::verify(SMLoc loc,
ArrayRef<FormatElement *> elements) { … }
LogicalResult DefFormatParser::verifyCustomDirectiveArguments(
SMLoc loc, ArrayRef<FormatElement *> arguments) { … }
LogicalResult
DefFormatParser::verifyOptionalGroupElements(llvm::SMLoc loc,
ArrayRef<FormatElement *> elements,
FormatElement *anchor) { … }
LogicalResult DefFormatParser::markQualified(SMLoc loc,
FormatElement *element) { … }
FailureOr<DefFormat> DefFormatParser::parse() { … }
FailureOr<FormatElement *>
DefFormatParser::parseVariableImpl(SMLoc loc, StringRef name, Context ctx) { … }
FailureOr<FormatElement *>
DefFormatParser::parseDirectiveImpl(SMLoc loc, FormatToken::Kind kind,
Context ctx) { … }
FailureOr<FormatElement *> DefFormatParser::parseParamsDirective(SMLoc loc,
Context ctx) { … }
FailureOr<FormatElement *> DefFormatParser::parseStructDirective(SMLoc loc,
Context ctx) { … }
void mlir::tblgen::generateAttrOrTypeFormat(const AttrOrTypeDef &def,
MethodBody &parser,
MethodBody &printer) { … }