From 4d0589d9f9b02b87703dfcf309e8e3382a256ab0 Mon Sep 17 00:00:00 2001 From: Andrea Shepard <andrea@persephoneslair.org> Date: Thu, 24 Nov 2016 04:15:41 +0000 Subject: [PATCH] Implement LLVM backend for h_nothing_p() --- src/parsers/nothing.c | 27 +++++++++++++++++++++++++++ src/t_parser.c | 1 + 2 files changed, 28 insertions(+) diff --git a/src/parsers/nothing.c b/src/parsers/nothing.c index 0a60108b..d95f3f24 100644 --- a/src/parsers/nothing.c +++ b/src/parsers/nothing.c @@ -1,3 +1,10 @@ +#ifdef HAMMER_LLVM_BACKEND +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wpedantic" +#include <llvm-c/Core.h> +#pragma GCC diagnostic pop +#include "../backends/llvm/llvm.h" +#endif #include "parser_internal.h" static HParseResult* parse_nothing() { @@ -16,12 +23,32 @@ static bool nothing_ctrvm(HRVMProg *prog, void* env) { return true; } +#ifdef HAMMER_LLVM_BACKEND + +static bool nothing_llvm(HLLVMParserCompileContext *ctxt, void* env) { + if (!ctxt) return false; + + /* This one just always returns NULL */ + LLVMBasicBlockRef entry = LLVMAppendBasicBlock(ctxt->func, "nothing_entry"); + LLVMBuildBr(ctxt->builder, entry); + LLVMPositionBuilderAtEnd(ctxt->builder, entry); + + LLVMBuildRet(ctxt->builder, LLVMConstNull(ctxt->llvm_parseresultptr)); + + return true; +} + +#endif /* defined(HAMMER_LLVM_BACKEND) */ + static const HParserVtable nothing_vt = { .parse = parse_nothing, .isValidRegular = h_true, .isValidCF = h_true, .desugar = desugar_nothing, .compile_to_rvm = nothing_ctrvm, +#ifdef HAMMER_LLVM_BACKEND + .llvm = nothing_llvm, +#endif .higher = false, }; diff --git a/src/t_parser.c b/src/t_parser.c index b7e2393b..30e9fc77 100644 --- a/src/t_parser.c +++ b/src/t_parser.c @@ -1049,5 +1049,6 @@ void register_parser_tests(void) { g_test_add_data_func("/core/parser/llvm/uint8", GINT_TO_POINTER(PB_LLVM), test_uint8); g_test_add_data_func("/core/parser/llvm/in", GINT_TO_POINTER(PB_LLVM), test_in); g_test_add_data_func("/core/parser/llvm/not_in", GINT_TO_POINTER(PB_LLVM), test_not_in); + g_test_add_data_func("/core/parser/llvm/nothing_p", GINT_TO_POINTER(PB_LLVM), test_nothing_p); #endif /* defined(HAMMER_LLVM_BACKEND) */ } -- GitLab