Create a very basic tablegen instance

This commit is contained in:
Sameer Rahmani 2022-01-22 19:10:57 +00:00
parent a085f0b7ea
commit c7e6e8d9a5
5 changed files with 48 additions and 11 deletions

View File

@ -1 +1,24 @@
def Err;
class Error<string _title = "", string _desc = ""> {
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
}]>;

View File

@ -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
)

View File

@ -23,7 +23,7 @@
* instances.
*/
#include <errors-backend.h>
#include "serene/errors-backend.h"
#include <llvm/Support/CommandLine.h>
#include <llvm/Support/InitLLVM.h>
@ -34,19 +34,25 @@
namespace cl = llvm::cl;
namespace serene {
enum ActionType { ErrorsBackend };
enum ActionType { PrintRecords, ErrorsBackend };
cl::opt<ActionType>
action(cl::desc("Action to perform:"),
cl::values(clEnumValN(
ErrorsBackend, "errors-backend",
"Generate a C++ file containing errors in the input file")));
cl::opt<ActionType> 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;
}

View File

@ -16,7 +16,8 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <errors-backend.h>
// The "serene/" part is due to a convention that we use in the project
#include "serene/errors-backend.h"
#include <llvm/Support/Format.h>
@ -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;
}