From c7e6e8d9a54e79ba12a966f96f0a7a7be106e0a1 Mon Sep 17 00:00:00 2001 From: Sameer Rahmani Date: Sat, 22 Jan 2022 19:10:57 +0000 Subject: [PATCH] Create a very basic tablegen instance --- include/serene/errors/errors.td | 25 ++++++++++++++++++- tools/tbl-srn/CMakeLists.txt | 6 ++++- tools/tbl-srn/main.cpp | 20 +++++++++------ tools/tbl-srn/{ => serene}/errors-backend.cpp | 8 ++++-- tools/tbl-srn/{ => serene}/errors-backend.h | 0 5 files changed, 48 insertions(+), 11 deletions(-) rename tools/tbl-srn/{ => serene}/errors-backend.cpp (84%) rename tools/tbl-srn/{ => serene}/errors-backend.h (100%) diff --git a/include/serene/errors/errors.td b/include/serene/errors/errors.td index bfd4a27..fd765d1 100644 --- a/include/serene/errors/errors.td +++ b/include/serene/errors/errors.td @@ -1 +1,24 @@ -def Err; + +class Error { + string title = _title; + string description = _desc; +} + +def Err : Error<"Err1 titel"> { + let description = [{ + err1 + multiline + desc + }]; +} + +def Err2 : Error { + let title = "err 2 titel"; + let description = "err2 desc"; +} + +def Err3 : Error<"err3", [{ +err3 +multiline +desc +}]>; diff --git a/tools/tbl-srn/CMakeLists.txt b/tools/tbl-srn/CMakeLists.txt index 97bbdd8..8958ef0 100644 --- a/tools/tbl-srn/CMakeLists.txt +++ b/tools/tbl-srn/CMakeLists.txt @@ -16,8 +16,12 @@ set(LLVM_LINK_COMPONENTS Support TableGen) +#TODO: Make sure that we don't include the project wide header files +# path here +include_directories(${PROJECT_SOURCE_DIR}/tools/tbl-srn) + add_executable(tbl-srn - errors-backend.cpp + serene/errors-backend.cpp main.cpp ) diff --git a/tools/tbl-srn/main.cpp b/tools/tbl-srn/main.cpp index 4f2e411..31cf776 100644 --- a/tools/tbl-srn/main.cpp +++ b/tools/tbl-srn/main.cpp @@ -23,7 +23,7 @@ * instances. */ -#include +#include "serene/errors-backend.h" #include #include @@ -34,19 +34,25 @@ namespace cl = llvm::cl; namespace serene { -enum ActionType { ErrorsBackend }; +enum ActionType { PrintRecords, ErrorsBackend }; -cl::opt - action(cl::desc("Action to perform:"), - cl::values(clEnumValN( - ErrorsBackend, "errors-backend", - "Generate a C++ file containing errors in the input file"))); +cl::opt action( + cl::desc("Action to perform:"), + + cl::values( + clEnumValN(ErrorsBackend, "errors-backend", + "Generate a C++ file containing errors in the input file"), + clEnumValN(PrintRecords, "print-records", + "Print all records to stdout (default)"))); bool llvmTableGenMain(llvm::raw_ostream &os, llvm::RecordKeeper &records) { switch (action) { case ErrorsBackend: emitErrors(records, os); break; + case PrintRecords: + os << records; + break; } return false; } diff --git a/tools/tbl-srn/errors-backend.cpp b/tools/tbl-srn/serene/errors-backend.cpp similarity index 84% rename from tools/tbl-srn/errors-backend.cpp rename to tools/tbl-srn/serene/errors-backend.cpp index 3e0d206..d1252b6 100644 --- a/tools/tbl-srn/errors-backend.cpp +++ b/tools/tbl-srn/serene/errors-backend.cpp @@ -16,7 +16,8 @@ * along with this program. If not, see . */ -#include +// The "serene/" part is due to a convention that we use in the project +#include "serene/errors-backend.h" #include @@ -39,7 +40,10 @@ public: void ErrorsBackend::run(llvm::raw_ostream &os) { llvm::emitSourceFileHeader("Serene's Errors collection", os); - + for (const auto &classPair : records.getClasses()) { + llvm::Record *classRec = classPair.second.get(); + os << classRec << "--\n"; + } (void)records; } diff --git a/tools/tbl-srn/errors-backend.h b/tools/tbl-srn/serene/errors-backend.h similarity index 100% rename from tools/tbl-srn/errors-backend.h rename to tools/tbl-srn/serene/errors-backend.h