|
|
@ -1475,10 +1475,15 @@ void cli_bytecode_destroy(struct cli_bc *bc) |
|
|
|
#define MAP(val) do { operand_t o = val; \ |
|
|
|
#define MAP(val) do { operand_t o = val; \ |
|
|
|
if (o & 0x80000000) {\
|
|
|
|
if (o & 0x80000000) {\
|
|
|
|
o &= 0x7fffffff;\
|
|
|
|
o &= 0x7fffffff;\
|
|
|
|
o = bcfunc->numValues + bcfunc->numConstants + o;\
|
|
|
|
if (o > bc->num_globals) {\
|
|
|
|
|
|
|
|
cli_errmsg("bytecode: global out of range: %u > %u, for instruction %u in function %u\n",\
|
|
|
|
|
|
|
|
o, bc->num_globals, j, i);\
|
|
|
|
|
|
|
|
return CL_EBYTECODE;\
|
|
|
|
|
|
|
|
}\
|
|
|
|
|
|
|
|
val = 0x80000000 | gmap[o];\
|
|
|
|
|
|
|
|
break;\
|
|
|
|
}\
|
|
|
|
}\
|
|
|
|
if (o > totValues) {\
|
|
|
|
if (o > totValues) {\
|
|
|
|
printf("%d\n", _FIRST_GLOBAL);\
|
|
|
|
|
|
|
|
cli_errmsg("bytecode: operand out of range: %u > %u, for instruction %u in function %u\n", o, totValues, j, i);\
|
|
|
|
cli_errmsg("bytecode: operand out of range: %u > %u, for instruction %u in function %u\n", o, totValues, j, i);\
|
|
|
|
return CL_EBYTECODE;\
|
|
|
|
return CL_EBYTECODE;\
|
|
|
|
}\
|
|
|
|
}\
|
|
|
@ -1487,11 +1492,26 @@ void cli_bytecode_destroy(struct cli_bc *bc) |
|
|
|
static int cli_bytecode_prepare_interpreter(struct cli_bc *bc) |
|
|
|
static int cli_bytecode_prepare_interpreter(struct cli_bc *bc) |
|
|
|
{ |
|
|
|
{ |
|
|
|
unsigned i, j, k; |
|
|
|
unsigned i, j, k; |
|
|
|
|
|
|
|
unsigned *gmap; |
|
|
|
|
|
|
|
bc->numGlobalBytes = 0; |
|
|
|
|
|
|
|
gmap = cli_malloc(bc->num_globals*sizeof(*gmap)); |
|
|
|
|
|
|
|
if (!gmap) |
|
|
|
|
|
|
|
return CL_EMEM; |
|
|
|
|
|
|
|
for (j=0;j<bc->num_globals;j++) { |
|
|
|
|
|
|
|
uint16_t ty = bc->globaltys[j]; |
|
|
|
|
|
|
|
unsigned align = typealign(bc, ty); |
|
|
|
|
|
|
|
assert(align); |
|
|
|
|
|
|
|
bc->numGlobalBytes = (bc->numGlobalBytes + align-1)&(~(align-1)); |
|
|
|
|
|
|
|
gmap[j] = bc->numGlobalBytes; |
|
|
|
|
|
|
|
bc->numGlobalBytes += typesize(bc, ty); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
for (i=0;i<bc->num_func;i++) { |
|
|
|
for (i=0;i<bc->num_func;i++) { |
|
|
|
struct cli_bc_func *bcfunc = &bc->funcs[i]; |
|
|
|
struct cli_bc_func *bcfunc = &bc->funcs[i]; |
|
|
|
unsigned totValues = bcfunc->numValues + bcfunc->numConstants + bc->num_globals; |
|
|
|
unsigned totValues = bcfunc->numValues + bcfunc->numConstants + bc->num_globals; |
|
|
|
unsigned *map = cli_malloc(sizeof(*map)*totValues); |
|
|
|
unsigned *map = cli_malloc(sizeof(*map)*totValues); |
|
|
|
|
|
|
|
if (!map) |
|
|
|
|
|
|
|
return CL_EMEM; |
|
|
|
bcfunc->numBytes = 0; |
|
|
|
bcfunc->numBytes = 0; |
|
|
|
for (j=0;j<bcfunc->numValues;j++) { |
|
|
|
for (j=0;j<bcfunc->numValues;j++) { |
|
|
|
uint16_t ty = bcfunc->types[j]; |
|
|
|
uint16_t ty = bcfunc->types[j]; |
|
|
@ -1507,14 +1527,6 @@ static int cli_bytecode_prepare_interpreter(struct cli_bc *bc) |
|
|
|
map[bcfunc->numValues+j] = bcfunc->numBytes; |
|
|
|
map[bcfunc->numValues+j] = bcfunc->numBytes; |
|
|
|
bcfunc->numBytes += 8; |
|
|
|
bcfunc->numBytes += 8; |
|
|
|
} |
|
|
|
} |
|
|
|
for (j=0;j<bc->num_globals;j++) { |
|
|
|
|
|
|
|
uint16_t ty = bc->globaltys[j]; |
|
|
|
|
|
|
|
unsigned align = typealign(bc, ty); |
|
|
|
|
|
|
|
assert(align); |
|
|
|
|
|
|
|
bcfunc->numBytes = (bcfunc->numBytes + align-1)&(~(align-1)); |
|
|
|
|
|
|
|
map[bcfunc->numValues+bcfunc->numConstants+j] = bcfunc->numBytes; |
|
|
|
|
|
|
|
bcfunc->numBytes += typesize(bc, ty); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
for (j=0;j<bcfunc->numInsts;j++) { |
|
|
|
for (j=0;j<bcfunc->numInsts;j++) { |
|
|
|
struct cli_bc_inst *inst = &bcfunc->allinsts[j]; |
|
|
|
struct cli_bc_inst *inst = &bcfunc->allinsts[j]; |
|
|
|
inst->dest = map[inst->dest]; |
|
|
|
inst->dest = map[inst->dest]; |
|
|
@ -1646,6 +1658,7 @@ static int cli_bytecode_prepare_interpreter(struct cli_bc *bc) |
|
|
|
} |
|
|
|
} |
|
|
|
free(map); |
|
|
|
free(map); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
free(gmap); |
|
|
|
bc->state = bc_interp; |
|
|
|
bc->state = bc_interp; |
|
|
|
return CL_SUCCESS; |
|
|
|
return CL_SUCCESS; |
|
|
|
} |
|
|
|
} |
|
|
|