clover/llvm: Use helper function to abort compilation with error message.
Reviewed-by: Serge Martin <edb+mesa@sigluy.net> Tested-by: Jan Vesely <jan.vesely@rutgers.edu>
This commit is contained in:
@@ -88,6 +88,12 @@ namespace {
|
|||||||
using namespace ::llvm;
|
using namespace ::llvm;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template<typename E> void
|
||||||
|
fail(std::string &r_log, E &&e, const std::string &s) {
|
||||||
|
r_log += s;
|
||||||
|
throw e;
|
||||||
|
}
|
||||||
|
|
||||||
void debug_log(const std::string &msg, const std::string &suffix) {
|
void debug_log(const std::string &msg, const std::string &suffix) {
|
||||||
const char *dbg_file = debug_get_option("CLOVER_DEBUG_FILE", "stderr");
|
const char *dbg_file = debug_get_option("CLOVER_DEBUG_FILE", "stderr");
|
||||||
if (!strcmp("stderr", dbg_file)) {
|
if (!strcmp("stderr", dbg_file)) {
|
||||||
@@ -577,20 +583,16 @@ namespace {
|
|||||||
LLVMCodeGenFileType file_type,
|
LLVMCodeGenFileType file_type,
|
||||||
LLVMMemoryBufferRef *out_buffer,
|
LLVMMemoryBufferRef *out_buffer,
|
||||||
std::string &r_log) {
|
std::string &r_log) {
|
||||||
LLVMBool err;
|
|
||||||
char *err_message = NULL;
|
char *err_message = NULL;
|
||||||
|
|
||||||
err = LLVMTargetMachineEmitToMemoryBuffer(tm, mod, file_type,
|
try {
|
||||||
&err_message, out_buffer);
|
if (LLVMTargetMachineEmitToMemoryBuffer(tm, mod, file_type,
|
||||||
|
&err_message, out_buffer))
|
||||||
if (err) {
|
fail(r_log, compile_error(), err_message);
|
||||||
r_log = std::string(err_message);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
} catch (...) {
|
||||||
LLVMDisposeMessage(err_message);
|
LLVMDisposeMessage(err_message);
|
||||||
|
throw;
|
||||||
if (err) {
|
|
||||||
throw compile_error();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -606,20 +608,21 @@ namespace {
|
|||||||
const char *buffer_data;
|
const char *buffer_data;
|
||||||
LLVMModuleRef mod_ref = wrap(mod);
|
LLVMModuleRef mod_ref = wrap(mod);
|
||||||
|
|
||||||
if (LLVMGetTargetFromTriple(t.triple.c_str(), &target, &error_message)) {
|
try {
|
||||||
r_log = std::string(error_message);
|
if (LLVMGetTargetFromTriple(t.triple.c_str(), &target, &error_message))
|
||||||
|
fail(r_log, compile_error(), error_message);
|
||||||
|
|
||||||
|
} catch (...) {
|
||||||
LLVMDisposeMessage(error_message);
|
LLVMDisposeMessage(error_message);
|
||||||
throw compile_error();
|
throw;
|
||||||
}
|
}
|
||||||
|
|
||||||
LLVMTargetMachineRef tm = LLVMCreateTargetMachine(
|
LLVMTargetMachineRef tm = LLVMCreateTargetMachine(
|
||||||
target, t.triple.c_str(), t.cpu.c_str(), "",
|
target, t.triple.c_str(), t.cpu.c_str(), "",
|
||||||
LLVMCodeGenLevelDefault, LLVMRelocDefault, LLVMCodeModelDefault);
|
LLVMCodeGenLevelDefault, LLVMRelocDefault, LLVMCodeModelDefault);
|
||||||
|
if (!tm)
|
||||||
if (!tm) {
|
fail(r_log, compile_error(),
|
||||||
r_log = "Could not create TargetMachine: " + t.triple;
|
"Could not create TargetMachine: " + t.triple);
|
||||||
throw compile_error();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (dump_asm) {
|
if (dump_asm) {
|
||||||
LLVMSetTargetMachineAsmVerbosity(tm, true);
|
LLVMSetTargetMachineAsmVerbosity(tm, true);
|
||||||
@@ -673,20 +676,19 @@ namespace {
|
|||||||
try {
|
try {
|
||||||
while ((section = elf_nextscn(elf, section))) {
|
while ((section = elf_nextscn(elf, section))) {
|
||||||
const char *name;
|
const char *name;
|
||||||
if (gelf_getshdr(section, &symtab_header) != &symtab_header) {
|
if (gelf_getshdr(section, &symtab_header) != &symtab_header)
|
||||||
r_log = "Failed to read ELF section header.";
|
fail(r_log, compile_error(),
|
||||||
throw compile_error();
|
"Failed to read ELF section header.");
|
||||||
}
|
|
||||||
name = elf_strptr(elf, section_str_index, symtab_header.sh_name);
|
name = elf_strptr(elf, section_str_index, symtab_header.sh_name);
|
||||||
if (!strcmp(name, ".symtab")) {
|
if (!strcmp(name, ".symtab")) {
|
||||||
symtab = section;
|
symtab = section;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (!symtab) {
|
if (!symtab)
|
||||||
r_log = "Unable to find symbol table.";
|
fail(r_log, compile_error(), "Unable to find symbol table.");
|
||||||
throw compile_error();
|
|
||||||
}
|
|
||||||
} catch (compile_error &e) {
|
} catch (compile_error &e) {
|
||||||
elf_end(elf);
|
elf_end(elf);
|
||||||
throw e;
|
throw e;
|
||||||
|
Reference in New Issue
Block a user