Commit 4ef1c091 authored by Francisco Jerez's avatar Francisco Jerez
Browse files

clover: Move back to using build_error to signal compilation failure.

This partially reverts 7e0180d5

.
Having two different exception subclasses for compilation and linking
makes it more difficult to share or move code between the two
codepaths, because the exact same function under the same error
condition would need to throw one exception or the other depending on
what top-level API is being implemented with it.  There is little
benefit anyway because clCompileProgram() and clLinkProgram() can tell
whether they are linking or compiling a program.
Reviewed-by: Serge Martin's avatarSerge Martin <edb+mesa@sigluy.net>
Tested-by: Jan Vesely's avatarJan Vesely <jan.vesely@rutgers.edu>
parent 70fe6267
......@@ -186,8 +186,6 @@ clBuildProgram(cl_program d_prog, cl_uint num_devs,
} catch (error &e) {
if (e.get() == CL_INVALID_COMPILER_OPTIONS)
return CL_INVALID_BUILD_OPTIONS;
if (e.get() == CL_COMPILE_PROGRAM_FAILURE)
return CL_BUILD_PROGRAM_FAILURE;
return e.get();
}
......@@ -227,6 +225,9 @@ clCompileProgram(cl_program d_prog, cl_uint num_devs,
prog.build(devs, opts, headers);
return CL_SUCCESS;
} catch (build_error &e) {
return CL_COMPILE_PROGRAM_FAILURE;
} catch (error &e) {
return e.get();
}
......
......@@ -65,11 +65,10 @@ namespace clover {
cl_int code;
};
class compile_error : public error {
class build_error : public error {
public:
compile_error(const std::string &what = "") :
error(CL_COMPILE_PROGRAM_FAILURE, what) {
}
build_error(const std::string &what = "") :
error(CL_BUILD_PROGRAM_FAILURE, what) {}
};
template<typename O>
......
......@@ -98,7 +98,7 @@ namespace {
const auto elf = elf::get(code);
const auto symtab = elf::get_symbol_table(elf.get());
if (!symtab)
fail(r_log, compile_error(), "Unable to find symbol table.");
fail(r_log, build_error(), "Unable to find symbol table.");
return elf::get_symbol_offsets(elf.get(), symtab);
}
......@@ -110,7 +110,7 @@ namespace {
std::string err;
auto t = ::llvm::TargetRegistry::lookupTarget(target.triple, err);
if (!t)
fail(r_log, compile_error(), err);
fail(r_log, build_error(), err);
std::unique_ptr<TargetMachine> tm {
t->createTargetMachine(target.triple, target.cpu, "", {},
......@@ -118,7 +118,7 @@ namespace {
::llvm::CodeModel::Default,
::llvm::CodeGenOpt::Default) };
if (!tm)
fail(r_log, compile_error(),
fail(r_log, build_error(),
"Could not create TargetMachine: " + target.triple);
::llvm::SmallVector<char, 1024> data;
......@@ -133,7 +133,7 @@ namespace {
(ft == TargetMachine::CGFT_AssemblyFile);
if (tm->addPassesToEmitFile(pm, fos, ft))
fail(r_log, compile_error(), "TargetMachine can't emit this file");
fail(r_log, build_error(), "TargetMachine can't emit this file");
pm.run(mod);
}
......
......@@ -70,7 +70,7 @@ namespace {
raw_string_ostream os { *reinterpret_cast<std::string *>(data) };
::llvm::DiagnosticPrinterRawOStream printer { os };
di.print(printer);
throw compile_error();
throw build_error();
}
}
......@@ -173,7 +173,7 @@ namespace {
// Compile the code
clang::EmitLLVMOnlyAction act(&ctx);
if (!c.ExecuteAction(act))
throw compile_error();
throw build_error();
return act.takeModule();
}
......@@ -241,7 +241,7 @@ namespace {
for (auto &m : modules) {
if (compat::link_in_module(*linker,
parse_module_library(m, ctx, r_log)))
throw compile_error();
throw build_error();
}
return std::move(mod);
......
......@@ -48,7 +48,7 @@ namespace {
if (!(ts >> offset)) {
r_log = "invalid kernel start address";
throw compile_error();
throw build_error();
}
while (ts >> tok) {
......@@ -72,7 +72,7 @@ namespace {
args.push_back({ module::argument::sampler, 0 });
else {
r_log = "invalid kernel argument";
throw compile_error();
throw build_error();
}
}
......@@ -86,7 +86,7 @@ namespace {
if (!tgsi_text_translate(source, prog, ARRAY_SIZE(prog))) {
r_log = "translate failed";
throw compile_error();
throw build_error();
}
unsigned sz = tgsi_num_tokens(prog) * sizeof(tgsi_token);
......@@ -100,7 +100,7 @@ clover::tgsi::compile_program(const std::string &source, std::string &r_log) {
const size_t body_pos = source.find("COMP\n");
if (body_pos == std::string::npos) {
r_log = "invalid source";
throw compile_error();
throw build_error();
}
const char *body = &source[body_pos];
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment