added: verification of llvm module after compilation

This commit is contained in:
Sven Vogel 2024-06-05 21:38:46 +02:00
parent 14c5ba320c
commit 30230249ae
1 changed files with 10 additions and 0 deletions

View File

@ -4,6 +4,7 @@
#include <llvm-c/Target.h> #include <llvm-c/Target.h>
#include <llvm-c/TargetMachine.h> #include <llvm-c/TargetMachine.h>
#include <llvm-c/Types.h> #include <llvm-c/Types.h>
#include <llvm-c/Analysis.h>
#include <llvm/backend.h> #include <llvm/backend.h>
#include <llvm/parser.h> #include <llvm/parser.h>
#include <llvm/llvm-ir/types.h> #include <llvm/llvm-ir/types.h>
@ -203,6 +204,15 @@ static BackendError build_module(LLVMBackendCompileUnit* unit,
// TODO: implement functions // TODO: implement functions
err = impl_functions(unit, global_scope, module->functions); err = impl_functions(unit, global_scope, module->functions);
char* error = NULL;
LLVMVerifyModule(unit->module, LLVMAbortProcessAction, &error);
if (error) {
print_message(Error, "Unable to compile due to: %s", error);
LLVMDisposeMessage(error);
err = new_backend_impl_error(Implementation, NULL, "LLVM backend verification error, see stdout");
}
return err; return err;
} }