Commit a1799a29 authored by Julian Kranz's avatar Julian Kranz

Endianness

parent 55fdddfc
......@@ -818,14 +818,14 @@ structure C1 = struct
foldl recAdd recStripped fs
end
| emitExp s (UPDATEexp (rs,t as RECORDvtype (boxed,fsTys),fs,e)) =
let
fun genFieldExpr (f,ty) = case List.find (fn (fid,_) => SymbolTable.eq_symid (f,fid)) fs of
NONE => (f,SELECTexp (rs,RECORDvtype (boxed,fsTys),f,e))
| SOME (_,e) => (f,e)
in
emitExp s (RECORDexp (rs,t,List.map genFieldExpr fsTys))
end
| emitExp s (UPDATEexp (rs,_,fs,e)) = raise CodeGenBug
let
fun genFieldExpr (f,ty) = case List.find (fn (fid,_) => SymbolTable.eq_symid (f,fid)) fs of
NONE => (f,SELECTexp (rs,RECORDvtype (boxed,fsTys),f,e))
| SOME (_,e) => (f,e)
in
emitExp s (RECORDexp (rs,t,List.map genFieldExpr fsTys))
end
| emitExp s (UPDATEexp (rs,_,fs,e)) = raise CodeGenBug
| emitExp s (LITexp (t,VEClit pat)) =
let
fun genNum (c,acc) = IntInf.fromInt 2*acc+(if c= #"1" then 1 else 0)
......@@ -866,12 +866,12 @@ structure C1 = struct
(*| emitPrim s (RSEEKprim, [e],_) = seq [str "gdsl_rseek(s, ", emitExp s e, str ")"]*)
| emitPrim s (DIVprim, [e1, e2],_) = seq [str "(", emitExp s e1, str ")/(", emitExp s e2, str ")"]
| emitPrim s (IPGETprim, [],_) = str "gdsl_get_ip_offset(s)"
| 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 (CONSUME8prim, [],_) = (addConsume s 8; str "consume(s, 1)")
| emitPrim s (CONSUME16prim, [],_) = (addConsume s 16; str "consume(s, 2)")
| emitPrim s (CONSUME32prim, [],_) = (addConsume s 32; str "consume(s, 4)")
| emitPrim s (UNCONSUME8prim, [],_) = str "unconsume(s, 1)"
| emitPrim s (UNCONSUME16prim, [],_) = str "unconsume(s, 1)"
| emitPrim s (UNCONSUME32prim, [],_) = str "unconsume(s, 1)"
| emitPrim s (UNCONSUME16prim, [],_) = str "unconsume(s, 2)"
| emitPrim s (UNCONSUME32prim, [],_) = str "unconsume(s, 4)"
| 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 ")"]
......@@ -1249,6 +1249,7 @@ structure C1 = struct
C1Templates.mkHook ("reset_heap", str (prefix ^ "reset_heap")),
C1Templates.mkHook ("heap_residency", str (prefix ^ "heap_residency")),
C1Templates.mkHook ("merge_rope", str (prefix ^ "merge_rope")),
C1Templates.mkHook ("endianess", str (prefix ^ "endianess")),
C1Templates.mkHook ("rope_to_string", str (prefix ^ "rope_to_string")),
C1Templates.mkHook ("rope_length", str (prefix ^ "rope_length")),
C1Templates.mkHook ("destroy", str (prefix ^ "destroy")),
......
......@@ -214,10 +214,14 @@ char*
static inline int_t consume(state_t s, char size) {
if(s->ip + size > s->ip_limit) {
s->err_str = "GDSL runtime: end of code input stream";
longjmp(s->err_tgt, 1);
};
int_t result = 0;
char size_left = size;
while(size_left) {
char be_buf_left = -((size_t)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;
......@@ -226,7 +230,7 @@ static inline int_t consume(state_t s, char size) {
be_buf_left += s->token_size;
}
for(; be_buf_left && size_left; be_buf_left--) {
result |= *(s->buf_be++) << (--size_left*8);
result |= *(s->buf_be++) << (--size_left * 8);
s->ip++;
}
}
......@@ -234,7 +238,7 @@ static inline int_t consume(state_t s, char size) {
}
static inline void unconsume(state_t s, char size) {
char be_buf_consumed = ((size_t)s->buf_be) & (s->token_size - 1);
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;
......@@ -242,7 +246,7 @@ static inline void unconsume(state_t s, char size) {
s->buf_be += (s->token_size - size);
s->ip -= size;
} else {
char be_buf_left = -((size_t)s->buf_be) & (s->token_size - 1);
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;
......@@ -255,26 +259,6 @@ static inline void unconsume(state_t s, char size) {
}
}
#define GEN_CONSUME(size) \
static inline int_t consume ## size(state_t s) { \
return consume(s, (size) / 8); \
}
//#define GEN_CONSUME(size) \
//static inline int_t consume ## size(state_t s) { \
// if (s->ip+( size >>3)>s->ip_limit) { \
// s->err_str = "GDSL runtime: end of code input stream";\
// longjmp(s->err_tgt,1); \
// }; \
// uint ## size ## _t* ptr = (uint ## size ## _t*) s->ip; \
// int_t res = (unsigned) *ptr; \
// s->ip+= size >> 3; \
// return res; \
//}
@consumes@
static int_t vec_to_signed(state_t s, vec_t v) {
unsigned int bit_size = sizeof(int_t)*8;
if (v.size>bit_size) {
......@@ -339,6 +323,8 @@ void
s->ip_limit = buf+buf_len;
s->ip_start = buf;
s->ip_base = base;
char be_buf_left = -((size_t)s->buf_be) & (s->token_size - 1);
s->buf_be += be_buf_left;
}
size_t
......@@ -385,6 +371,8 @@ void
free (heap);
heap = prev;
}
s->buf_be = (unsigned char*)(((size_t)s->buf_be | (s->token_size - 1)) - s->token_size + 1);
free(s->buf_be);
free(s);
}
......@@ -414,6 +402,7 @@ state_t
* Todo: Handle alignment error
*/
s->buf_be = (unsigned char*)malloc(s->token_size);
s->buf_be += 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