From ec6bd774dc69bcc8cf3d0a0c429ffe47d18f7ce3 Mon Sep 17 00:00:00 2001 From: Thomas Voss Date: Mon, 8 Jul 2024 22:59:34 +0200 Subject: Fallback to stderr if module printing fails with ENXIO --- src/codegen.c | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/src/codegen.c b/src/codegen.c index 2ec3be7..a45d458 100644 --- a/src/codegen.c +++ b/src/codegen.c @@ -1,4 +1,5 @@ #include +#include #include #include #include @@ -107,13 +108,16 @@ codegen(const char *file, bitset_t *cnst, fold_t *folds, scope_t *scps, error = NULL; if (LLVMVerifyModule(ctx.mod, LLVMReturnStatusAction, &error) == 1) err("codegen: %s", error); + LLVMDisposeMessage(error); if (lflag) { - if (LLVMPrintModuleToFile(llmod, oflag == NULL ? "/dev/stdout" : oflag, - &error) - == 1) - { - err("codegen: %s", error); + if (oflag == NULL) + oflag = "/dev/stdout"; + /* Stupid hack to make this work with Neovim */ + if (LLVMPrintModuleToFile(llmod, oflag, &error) == 1) { + if (errno != ENXIO) + err("codegen: %s: %s", oflag, error); + LLVMDumpModule(llmod); } } else { LLVMCodeGenFileType ft; @@ -135,7 +139,6 @@ codegen(const char *file, bitset_t *cnst, fold_t *folds, scope_t *scps, tmpfree(ctx.s); arena_free(ctx.a); LLVMDisposeBuilder(ctx.bob); - LLVMDisposeMessage(error); LLVMDisposeModule(ctx.mod); LLVMDisposeTargetData(ctx.td); LLVMDisposeTargetMachine(llmach); -- cgit v1.2.3