#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 cl::OptionCategory dialectGenCat("Options for -gen-bytecode");
static cl::opt<std::string>
selectedBcDialect("bytecode-dialect", cl::desc("The dialect to gen for"),
cl::cat(dialectGenCat), 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(const Record *def) { … }
void Generator::emitParseDispatch(StringRef kind,
ArrayRef<const Record *> vec) { … }
void Generator::emitParse(StringRef kind, const 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, const Record *>> vec) { … }
void Generator::emitPrintHelper(const 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) { … });