s/build_error/compile_error in order to match the stored OpenCL status code.
Make program::build catch and log every OpenCL error.
Make tgsi error triggering uniform with the llvm one.
Reviewed-by: Francisco Jerez <currojerez@riseup.net>
const std::string &opts,
std::string &r_log);
- module compile_program_tgsi(const std::string &source);
+ module compile_program_tgsi(const std::string &source,
+ std::string &r_log);
}
#endif
cl_int code;
};
- class build_error : public error {
+ class compile_error : public error {
public:
- build_error(const std::string &what = "") :
+ compile_error(const std::string &what = "") :
error(CL_COMPILE_PROGRAM_FAILURE, what) {
}
};
try {
auto module = (dev.ir_format() == PIPE_SHADER_IR_TGSI ?
- compile_program_tgsi(_source) :
+ compile_program_tgsi(_source, log) :
compile_program_llvm(_source, headers,
dev.ir_format(),
dev.ir_target(), build_opts(dev),
log));
_binaries.insert({ &dev, module });
_logs.insert({ &dev, log });
- } catch (const build_error &) {
+ } catch (const error &) {
_logs.insert({ &dev, log });
throw;
}
name, llvm::MemoryBuffer::getMemBuffer(source));
if (!c.ExecuteAction(act))
- throw build_error(log);
+ throw compile_error(log);
}
module
r_log = log;
if (!ExecSuccess)
- throw build_error();
+ throw compile_error();
// Get address spaces map to be able to find kernel argument address space
memcpy(address_spaces, c.getTarget().getAddressSpaceMap(),
LLVMDisposeMessage(err_message);
if (err) {
- throw build_error();
+ throw compile_error();
}
}
if (LLVMGetTargetFromTriple(triple.c_str(), &target, &error_message)) {
r_log = std::string(error_message);
LLVMDisposeMessage(error_message);
- throw build_error();
+ throw compile_error();
}
LLVMTargetMachineRef tm = LLVMCreateTargetMachine(
if (!tm) {
r_log = "Could not create TargetMachine: " + triple;
- throw build_error();
+ throw compile_error();
}
if (dump_asm) {
const char *name;
if (gelf_getshdr(section, &symtab_header) != &symtab_header) {
r_log = "Failed to read ELF section header.";
- throw build_error();
+ throw compile_error();
}
name = elf_strptr(elf, section_str_index, symtab_header.sh_name);
if (!strcmp(name, ".symtab")) {
}
if (!symtab) {
r_log = "Unable to find symbol table.";
- throw build_error();
+ throw compile_error();
}
- } catch (build_error &e) {
+ } catch (compile_error &e) {
elf_end(elf);
throw e;
}
stream.flush();
*(std::string*)data = message;
- throw build_error();
+ throw compile_error();
}
}
namespace {
void
- read_header(const std::string &header, module &m) {
+ read_header(const std::string &header, module &m, std::string &r_log) {
std::istringstream ls(header);
std::string line;
if (!(ts >> name))
continue;
- if (!(ts >> offset))
- throw build_error("invalid kernel start address");
+ if (!(ts >> offset)) {
+ r_log = "invalid kernel start address";
+ throw compile_error();
+ }
while (ts >> tok) {
if (tok == "scalar")
args.push_back({ module::argument::image3d_wr, 4 });
else if (tok == "sampler")
args.push_back({ module::argument::sampler, 0 });
- else
- throw build_error("invalid kernel argument");
+ else {
+ r_log = "invalid kernel argument";
+ throw compile_error();
+ }
}
m.syms.push_back({ name, 0, offset, args });
}
void
- read_body(const char *source, module &m) {
+ read_body(const char *source, module &m, std::string &r_log) {
tgsi_token prog[1024];
- if (!tgsi_text_translate(source, prog, Elements(prog)))
- throw build_error("translate failed");
+ if (!tgsi_text_translate(source, prog, Elements(prog))) {
+ r_log = "translate failed";
+ throw compile_error();
+ }
unsigned sz = tgsi_num_tokens(prog) * sizeof(tgsi_token);
std::vector<char> data( (char *)prog, (char *)prog + sz );
}
module
-clover::compile_program_tgsi(const std::string &source) {
+clover::compile_program_tgsi(const std::string &source, std::string &r_log) {
const size_t body_pos = source.find("COMP\n");
const char *body = &source[body_pos];
module m;
- read_header({ source.begin(), source.begin() + body_pos }, m);
- read_body(body, m);
+ read_header({ source.begin(), source.begin() + body_pos }, m, r_log);
+ read_body(body, m, r_log);
return m;
}