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

Endianness

parent 046fa80f
......@@ -7,6 +7,7 @@
#include <string.h>
#include <stdio.h>
#include <limits.h>
#include <endian.h>
/* generated declarations for records with fixed fields */
@records@
......@@ -209,6 +210,10 @@ char*
return s->err_str;
};
uint8_t htole8(uint8_t a) {
return a;
}
#define GEN_CONSUME(size) \
static inline int_t consume ## size(state_t s) { \
if (s->ip+( size >>3)>s->ip_limit) { \
......@@ -216,7 +221,7 @@ static inline int_t consume ## size(state_t s) { \
longjmp(s->err_tgt,1); \
}; \
uint ## size ## _t* ptr = (uint ## size ## _t*) s->ip; \
int_t res = (unsigned) *ptr; \
int_t res = htole ## size ((unsigned) *ptr); \
s->ip+= size >> 3; \
return res; \
}
......@@ -301,10 +306,10 @@ int_t
(state_t s, size_t i) {
size_t size = (size_t)(s->ip_limit - s->ip_start);
size_t start_offset = i - s->ip_base;
if(start_offset >= size)
return 1;
s->ip = s->ip_start + start_offset;
return 0;
if(start_offset >= size)
return 1;
s->ip = s->ip_start + start_offset;
return 0;
}
string_t
......
......@@ -82,7 +82,7 @@ int main(int argc, char** argv) {
fseek(f, offset, SEEK_SET);
size_t buffer_size = length + 15;
char *buffer = (char*)malloc(buffer_size);
char *buffer = (char*) malloc(buffer_size);
size_t buffer_length = fread(buffer, 1, buffer_size, f);
state_t state = gdsl_init();
......@@ -111,32 +111,31 @@ int main(int argc, char** argv) {
}
obj_t insn = gdsl_decode(state, gdsl_config_default(state));
// printf("[");
// size_t decoded = gdsl_get_ip_offset(state) - last_offset;
// for(size_t i = 0; i < decoded; ++i) {
// if(i)
// printf(" ");
// printf("%02x", ((uint8_t*)buffer)[last_offset + i]);
// }
// printf("] ");
printf("[");
size_t decoded = gdsl_get_ip_offset(state) - last_offset;
for(size_t i = 0; i < decoded; ++i) {
if(i) printf(" ");
printf("%02x", ((uint8_t*) buffer)[last_offset + i]);
}
printf("] ");
// string_t fmt = gdsl_merge_rope(state, gdsl_pretty(state, insn));
// puts(fmt);
string_t fmt = gdsl_merge_rope(state, gdsl_pretty(state, insn));
puts(fmt);
size_t residency = gdsl_heap_residency(state);
memory_dec += residency;
if(residency > memory_dec_max) memory_dec_max = residency;
// printf("---------------------------\n");
// printf("---------------------------\n");
if(setjmp(*gdsl_err_tgt(state))) {
fprintf(stderr, "translate failed: %s\n", gdsl_get_error_message(state));
break;
}
/*obj_t rreil = */gdsl_translate(state, insn);
obj_t rreil = gdsl_translate(state, insn);
// fmt = gdsl_merge_rope(state, gdsl_rreil_pretty(state, rreil));
// puts(fmt);
// fmt = gdsl_merge_rope(state, gdsl_rreil_pretty(state, rreil));
// puts(fmt);
residency = gdsl_heap_residency(state);
memory_dec_tran += residency;
......@@ -158,7 +157,7 @@ int main(int argc, char** argv) {
fprintf(stderr, "Instruction count: %zu\n", instructions);
fprintf(stderr, "Decoder: Total memoy: %zu, maximal memoy: %zu\n", memory_dec, memory_dec_max);
fprintf(stderr, "Decoder + Translator: Total memoy: %zu, maximal memoy: %zu\n", memory_dec_tran, memory_dec_tran_max);
fprintf(stderr, "time: %lf seconds\n", time / (double)(1000000000));
fprintf(stderr, "time: %lf seconds\n", time / (double) (1000000000));
return 0;
}
......
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