Commit 55fdddfc authored by Julian Kranz's avatar Julian Kranz

Endianness

parent 04ba2eed
......@@ -869,9 +869,9 @@ structure C1 = struct
| emitPrim s (CONSUME8prim, [],_) = (addConsume s 8; str "consume8(s)")
| emitPrim s (CONSUME16prim, [],_) = (addConsume s 16; str "consume16(s)")
| emitPrim s (CONSUME32prim, [],_) = (addConsume s 32; str "consume32(s)")
| emitPrim s (UNCONSUME8prim, [],_) = str "s->ip-=1"
| emitPrim s (UNCONSUME16prim, [],_) = str "s->ip-=2"
| emitPrim s (UNCONSUME32prim, [],_) = str "s->ip-=4"
| emitPrim s (UNCONSUME8prim, [],_) = str "unconsume(s, 1)"
| emitPrim s (UNCONSUME16prim, [],_) = str "unconsume(s, 1)"
| emitPrim s (UNCONSUME32prim, [],_) = str "unconsume(s, 1)"
| emitPrim s (PRINTLNprim, [e],_) = seq [str "fputs(", emitExp s e, str ", s->handle)"]
| emitPrim s (RAISEprim, [e],_) = align [seq [str "s->err_str = ", emitExp s e, str ";"], str "longjmp(s->err_tgt,0)"]
| emitPrim s (ANDprim, [e1,e2],_) = seq [str "(", emitExp s e1, str ") & (", emitExp s e2, str ")"]
......
......@@ -217,7 +217,7 @@ static inline int_t consume(state_t s, char size) {
int_t result = 0;
char size_left = size;
while(size_left) {
char be_buf_left = -((unsigned char)s->buf_be) & (s->token_size - 1);
char be_buf_left = -((size_t)s->buf_be) & (s->token_size - 1);
if(!be_buf_left) {
s->buf_be -= s->token_size;
int i;
......@@ -227,12 +227,34 @@ static inline int_t consume(state_t s, char size) {
}
for(; be_buf_left && size_left; be_buf_left--) {
result |= *(s->buf_be++) << (--size_left*8);
s->ip++;
}
}
s->ip += size;
return result;
}
static inline void unconsume(state_t s, char size) {
char be_buf_consumed = ((size_t)s->buf_be) & (s->token_size - 1);
if(size < be_buf_consumed) {
s->buf_be -= size;
s->ip -= size;
} else if(size == be_buf_consumed) {
s->buf_be += (s->token_size - size);
s->ip -= size;
} else {
char be_buf_left = -((size_t)s->buf_be) & (s->token_size - 1);
s->buf_be += be_buf_left;
char size_left = size - be_buf_consumed;
s->ip -= be_buf_consumed;
char tokens = size_left / s->token_size;
s->ip -= (tokens + 1) * s->token_size;
char inner_token = size_left % s->token_size;
consume(s, s->token_size - inner_token);
}
}
#define GEN_CONSUME(size) \
static inline int_t consume ## size(state_t s) { \
return consume(s, (size) / 8); \
......@@ -388,8 +410,10 @@ state_t
s->le = 1;
s->token_size = 2;
s->buf_be = (unsigned char*)malloc(2*sizeof(int_t));
s->buf_be = (unsigned char*)((size_t)s->buf_be | (sizeof(int_t) - 1)) + 1;
/*
* Todo: Handle alignment error
*/
s->buf_be = (unsigned char*)malloc(s->token_size);
return s;
}
......
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