diff options
author | Thomas Voss <mail@thomasvoss.com> | 2024-07-08 22:59:34 +0200 |
---|---|---|
committer | Thomas Voss <mail@thomasvoss.com> | 2024-07-08 22:59:34 +0200 |
commit | ec6bd774dc69bcc8cf3d0a0c429ffe47d18f7ce3 (patch) | |
tree | 098fb3a85d386cb8dcff0fe184f000f23fd061d4 /src | |
parent | 40099e3d426be06c6ced41085c5592170852c77d (diff) |
Fallback to stderr if module printing fails with ENXIO
Diffstat (limited to 'src')
-rw-r--r-- | src/codegen.c | 15 |
1 files 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 <ctype.h> +#include <errno.h> #include <stdbool.h> #include <stdint.h> #include <stdio.h> @@ -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); |