#include "mlir/Support/IndentedOstream.h"
#include "mlir/TableGen/GenInfo.h"
#include "llvm/ADT/MapVector.h"
#include "llvm/ADT/STLExtras.h"
#include "llvm/Support/CommandLine.h"
#include "llvm/Support/FormatVariadic.h"
#include "llvm/TableGen/Error.h"
#include "llvm/TableGen/Record.h"
#include <regex>
usingnamespacellvm;
static llvm::cl::OptionCategory dialectGenCat("Options for -gen-bytecode");
static llvm::cl::opt<std::string>
selectedBcDialect("bytecode-dialect",
llvm::cl::desc("The dialect to gen for"),
llvm::cl::cat(dialectGenCat), llvm::cl::CommaSeparated);
namespace {
class Generator { … };
}
static std::string format(StringRef templ,
std::map<std::string, std::string> &&map) { … }
static std::string capitalize(StringRef str) { … }
static std::string getCType(Record *def) { … }
void Generator::emitParseDispatch(StringRef kind, ArrayRef<Record *> vec) { … }
void Generator::emitParse(StringRef kind, Record &x) { … }
void printParseConditional(mlir::raw_indented_ostream &ios,
ArrayRef<Init *> args,
ArrayRef<std::string> argNames) { … }
void Generator::emitParseHelper(StringRef kind, StringRef returnType,
StringRef builder, ArrayRef<Init *> args,
ArrayRef<std::string> argNames,
StringRef failure,
mlir::raw_indented_ostream &ios) { … }
void Generator::emitPrint(StringRef kind, StringRef type,
ArrayRef<std::pair<int64_t, Record *>> vec) { … }
void Generator::emitPrintHelper(Record *memberRec, StringRef kind,
StringRef parent, StringRef name,
mlir::raw_indented_ostream &ios) { … }
void Generator::emitPrintDispatch(StringRef kind, ArrayRef<std::string> vec) { … }
namespace {
struct AttrOrType { … };
}
static bool emitBCRW(const RecordKeeper &records, raw_ostream &os) { … }
static mlir::GenRegistration
genBCRW("gen-bytecode", "Generate dialect bytecode readers/writers",
[](const RecordKeeper &records, raw_ostream &os) { … });