|
@@ -282,7 +282,7 @@ static void hl_read_opcode( hl_reader *r, hl_function *f, hl_opcode *o ) {
|
|
o->p1 = INDEX();
|
|
o->p1 = INDEX();
|
|
o->p2 = INDEX();
|
|
o->p2 = INDEX();
|
|
o->p3 = READ();
|
|
o->p3 = READ();
|
|
- o->extra = (int*)hl_malloc(&r->code->alloc,sizeof(int) * o->p3);
|
|
|
|
|
|
+ o->extra = (int*)hl_malloc(&r->code->falloc,sizeof(int) * o->p3);
|
|
for(i=0;i<o->p3;i++)
|
|
for(i=0;i<o->p3;i++)
|
|
o->extra[i] = INDEX();
|
|
o->extra[i] = INDEX();
|
|
}
|
|
}
|
|
@@ -292,7 +292,7 @@ static void hl_read_opcode( hl_reader *r, hl_function *f, hl_opcode *o ) {
|
|
int i;
|
|
int i;
|
|
o->p1 = UINDEX();
|
|
o->p1 = UINDEX();
|
|
o->p2 = UINDEX();
|
|
o->p2 = UINDEX();
|
|
- o->extra = (int*)hl_malloc(&r->code->alloc,sizeof(int) * o->p2);
|
|
|
|
|
|
+ o->extra = (int*)hl_malloc(&r->code->falloc,sizeof(int) * o->p2);
|
|
for(i=0;i<o->p2;i++)
|
|
for(i=0;i<o->p2;i++)
|
|
o->extra[i] = UINDEX();
|
|
o->extra[i] = UINDEX();
|
|
o->p3 = UINDEX();
|
|
o->p3 = UINDEX();
|
|
@@ -309,7 +309,7 @@ static void hl_read_opcode( hl_reader *r, hl_function *f, hl_opcode *o ) {
|
|
o->p1 = INDEX();
|
|
o->p1 = INDEX();
|
|
o->p2 = INDEX();
|
|
o->p2 = INDEX();
|
|
o->p3 = INDEX();
|
|
o->p3 = INDEX();
|
|
- o->extra = (int*)hl_malloc(&r->code->alloc,sizeof(int) * size);
|
|
|
|
|
|
+ o->extra = (int*)hl_malloc(&r->code->falloc,sizeof(int) * size);
|
|
for(i=0;i<size;i++)
|
|
for(i=0;i<size;i++)
|
|
o->extra[i] = INDEX();
|
|
o->extra[i] = INDEX();
|
|
}
|
|
}
|
|
@@ -323,11 +323,11 @@ static void hl_read_function( hl_reader *r, hl_function *f ) {
|
|
f->findex = UINDEX();
|
|
f->findex = UINDEX();
|
|
f->nregs = UINDEX();
|
|
f->nregs = UINDEX();
|
|
f->nops = UINDEX();
|
|
f->nops = UINDEX();
|
|
- f->regs = (hl_type**)hl_malloc(&r->code->alloc, f->nregs * sizeof(hl_type*));
|
|
|
|
|
|
+ f->regs = (hl_type**)hl_malloc(&r->code->falloc, f->nregs * sizeof(hl_type*));
|
|
for(i=0;i<f->nregs;i++)
|
|
for(i=0;i<f->nregs;i++)
|
|
f->regs[i] = hl_get_type(r);
|
|
f->regs[i] = hl_get_type(r);
|
|
CHK_ERROR();
|
|
CHK_ERROR();
|
|
- f->ops = (hl_opcode*)hl_malloc(&r->code->alloc, f->nops * sizeof(hl_opcode));
|
|
|
|
|
|
+ f->ops = (hl_opcode*)hl_malloc(&r->code->falloc, f->nops * sizeof(hl_opcode));
|
|
for(i=0;i<f->nops;i++)
|
|
for(i=0;i<f->nops;i++)
|
|
hl_read_opcode(r, f, f->ops+i);
|
|
hl_read_opcode(r, f, f->ops+i);
|
|
}
|
|
}
|
|
@@ -369,41 +369,41 @@ static char **hl_read_strings( hl_reader *r, int nstrings, int **out_lens ) {
|
|
static int *hl_read_debug_infos( hl_reader *r, int nops ) {
|
|
static int *hl_read_debug_infos( hl_reader *r, int nops ) {
|
|
int curfile = -1, curline = 0;
|
|
int curfile = -1, curline = 0;
|
|
hl_code *code = r->code;
|
|
hl_code *code = r->code;
|
|
- int *debug = (int*)hl_malloc(&code->alloc, sizeof(int) * nops * 2);
|
|
|
|
- int i = 0;
|
|
|
|
- while( i < nops ) {
|
|
|
|
- int c = READ();
|
|
|
|
- if( c & 1 ) {
|
|
|
|
- c >>= 1;
|
|
|
|
- curfile = (c << 8) | READ();
|
|
|
|
- if( curfile >= code->ndebugfiles )
|
|
|
|
- ERROR("Invalid debug file");
|
|
|
|
- } else if( c & 2 ) {
|
|
|
|
- int delta = c >> 6;
|
|
|
|
- int count = (c >> 2) & 15;
|
|
|
|
- if( i + count > nops )
|
|
|
|
- ERROR("Outside range");
|
|
|
|
- while( count-- ) {
|
|
|
|
- debug[i<<1] = curfile;
|
|
|
|
- debug[(i<<1)|1] = curline;
|
|
|
|
- i++;
|
|
|
|
- }
|
|
|
|
- curline += delta;
|
|
|
|
- } else if( c & 4 ) {
|
|
|
|
- curline += c >> 3;
|
|
|
|
- debug[i<<1] = curfile;
|
|
|
|
- debug[(i<<1)|1] = curline;
|
|
|
|
- i++;
|
|
|
|
- } else {
|
|
|
|
- unsigned char b2 = READ();
|
|
|
|
- unsigned char b3 = READ();
|
|
|
|
- curline = (c >> 3) | (b2 << 5) | (b3 << 13);
|
|
|
|
- debug[i<<1] = curfile;
|
|
|
|
- debug[(i<<1)|1] = curline;
|
|
|
|
- i++;
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- return debug;
|
|
|
|
|
|
+ int *debug = (int*)hl_malloc(&code->alloc, sizeof(int) * nops * 2);
|
|
|
|
+ int i = 0;
|
|
|
|
+ while( i < nops ) {
|
|
|
|
+ int c = READ();
|
|
|
|
+ if( c & 1 ) {
|
|
|
|
+ c >>= 1;
|
|
|
|
+ curfile = (c << 8) | READ();
|
|
|
|
+ if( curfile >= code->ndebugfiles )
|
|
|
|
+ ERROR("Invalid debug file");
|
|
|
|
+ } else if( c & 2 ) {
|
|
|
|
+ int delta = c >> 6;
|
|
|
|
+ int count = (c >> 2) & 15;
|
|
|
|
+ if( i + count > nops )
|
|
|
|
+ ERROR("Outside range");
|
|
|
|
+ while( count-- ) {
|
|
|
|
+ debug[i<<1] = curfile;
|
|
|
|
+ debug[(i<<1)|1] = curline;
|
|
|
|
+ i++;
|
|
|
|
+ }
|
|
|
|
+ curline += delta;
|
|
|
|
+ } else if( c & 4 ) {
|
|
|
|
+ curline += c >> 3;
|
|
|
|
+ debug[i<<1] = curfile;
|
|
|
|
+ debug[(i<<1)|1] = curline;
|
|
|
|
+ i++;
|
|
|
|
+ } else {
|
|
|
|
+ unsigned char b2 = READ();
|
|
|
|
+ unsigned char b3 = READ();
|
|
|
|
+ curline = (c >> 3) | (b2 << 5) | (b3 << 13);
|
|
|
|
+ debug[i<<1] = curfile;
|
|
|
|
+ debug[(i<<1)|1] = curline;
|
|
|
|
+ i++;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ return debug;
|
|
}
|
|
}
|
|
|
|
|
|
hl_code *hl_code_read( const unsigned char *data, int size ) {
|
|
hl_code *hl_code_read( const unsigned char *data, int size ) {
|
|
@@ -416,6 +416,7 @@ hl_code *hl_code_read( const unsigned char *data, int size ) {
|
|
hl_alloc_init(&alloc);
|
|
hl_alloc_init(&alloc);
|
|
c = hl_zalloc(&alloc,sizeof(hl_code));
|
|
c = hl_zalloc(&alloc,sizeof(hl_code));
|
|
c->alloc = alloc;
|
|
c->alloc = alloc;
|
|
|
|
+ hl_alloc_init(&c->falloc);
|
|
if( READ() != 'H' || READ() != 'L' || READ() != 'B' )
|
|
if( READ() != 'H' || READ() != 'L' || READ() != 'B' )
|
|
EXIT("Invalid header");
|
|
EXIT("Invalid header");
|
|
r->code = c;
|
|
r->code = c;
|
|
@@ -479,3 +480,7 @@ hl_code *hl_code_read( const unsigned char *data, int size ) {
|
|
CHK_ERROR();
|
|
CHK_ERROR();
|
|
return c;
|
|
return c;
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+void hl_code_free( hl_code *c ) {
|
|
|
|
+ hl_free(&c->falloc);
|
|
|
|
+}
|