Commit 67d236fc authored by Julian Kranz's avatar Julian Kranz

GDSL Multiplexer: Portability

parent f127fa13
......@@ -50,6 +50,7 @@ struct frontend {
extern size_t gdsl_multiplex_frontends_list(struct frontend_desc **descs);
extern char gdsl_multiplex_frontend_get(struct frontend *backend, struct frontend_desc desc);
extern void gdsl_multiplex_descs_free(struct frontend_desc *descs, size_t descs_length);
extern void gdsl_multiplex_frontend_close(struct frontend *frontend);
#endif /* GDSL_MULTIPLEX_H_ */
......@@ -131,6 +131,12 @@ char gdsl_multiplex_frontend_get(struct frontend *frontend, struct frontend_desc
return GDSL_MULTIPLEX_ERROR_NONE;
}
void gdsl_multiplex_descs_free(struct frontend_desc *descs, size_t descs_length) {
for (size_t i = 0; i < descs_length; ++i)
free(descs[i].name);
free(descs);
}
void gdsl_multiplex_frontend_close(struct frontend *backend) {
dlclose(backend->dl);
}
......@@ -43,24 +43,24 @@ int main(int argc, char** argv) {
uint8_t *buffer;
size_t size = readhex_hex_read(stdin, &buffer);
struct frontend backend;
if(gdsl_multiplex_frontend_get(&backend, frontends[frontend_ind])) {
struct frontend frontend;
if(gdsl_multiplex_frontend_get(&frontend, frontends[frontend_ind])) {
fprintf(stderr, "Unable to open frontend.\n");
return 1;
}
state_t state = backend.generic.init();
backend.generic.set_code(state, (char*)buffer, size, 0);
state_t state = frontend.generic.init();
frontend.generic.set_code(state, (char*)buffer, size, 0);
if(setjmp(*backend.generic.err_tgt(state))) {
fprintf(stderr, "decode failed: %s\n", backend.generic.get_error_message(state));
if(setjmp(*frontend.generic.err_tgt(state))) {
fprintf(stderr, "decode failed: %s\n", frontend.generic.get_error_message(state));
retval = 1;
goto cleanup;
}
obj_t insn = backend.decoder.decode(state, backend.decoder.config_default(state));
obj_t insn = frontend.decoder.decode(state, frontend.decoder.config_default(state));
printf("[");
size_t decoded = backend.generic.get_ip_offset(state);
size_t decoded = frontend.generic.get_ip_offset(state);
for (size_t i = 0; i < decoded; ++i) {
if(i)
printf(" ");
......@@ -68,32 +68,29 @@ int main(int argc, char** argv) {
}
printf("] ");
string_t fmt = backend.generic.merge_rope(state, backend.decoder.pretty(state, insn));
string_t fmt = frontend.generic.merge_rope(state, frontend.decoder.pretty(state, insn));
puts(fmt);
printf("---------------------------\n");
if(setjmp(*backend.generic.err_tgt(state))) {
fprintf(stderr, "translate failed: %s\n", backend.generic.get_error_message(state));
if(setjmp(*frontend.generic.err_tgt(state))) {
fprintf(stderr, "translate failed: %s\n", frontend.generic.get_error_message(state));
retval = 1;
goto cleanup;
}
obj_t rreil = backend.translator.translate(state, insn);
obj_t rreil = frontend.translator.translate(state, insn);
fmt = backend.generic.merge_rope(state, backend.translator.pretty(state, rreil));
fmt = frontend.generic.merge_rope(state, frontend.translator.pretty(state, rreil));
puts(fmt);
cleanup:
backend.generic.destroy(state);
frontend.generic.destroy(state);
free(buffer);
// for (size_t i = 0; i < frontends_count; ++i)
// free(frontends[i]);
// free(frontends);
gdsl_multiplex_frontend_close(&backend);
gdsl_multiplex_descs_free(frontends, frontends_count);
gdsl_multiplex_frontend_close(&frontend);
return retval;
}
......
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