...
|
...
|
@@ -1468,7 +1468,12 @@ void cli_bytecode_destroy(struct cli_bc *bc)
|
1468
|
1468
|
}
|
1469
|
1469
|
|
1470
|
1470
|
#define MAP(val) do { operand_t o = val; \
|
|
1471
|
+ if (o & 0x80000000) {\
|
|
1472
|
+ o &= 0x7fffffff;\
|
|
1473
|
+ o = bcfunc->numValues + bcfunc->numConstants + o;\
|
|
1474
|
+ }\
|
1471
|
1475
|
if (o > totValues) {\
|
|
1476
|
+ printf("%d\n", _FIRST_GLOBAL);\
|
1472
|
1477
|
cli_errmsg("bytecode: operand out of range: %u > %u, for instruction %u in function %u\n", o, totValues, j, i);\
|
1473
|
1478
|
return CL_EBYTECODE;\
|
1474
|
1479
|
}\
|
...
|
...
|
@@ -1480,7 +1485,7 @@ static int cli_bytecode_prepare_interpreter(struct cli_bc *bc)
|
1480
|
1480
|
|
1481
|
1481
|
for (i=0;i<bc->num_func;i++) {
|
1482
|
1482
|
struct cli_bc_func *bcfunc = &bc->funcs[i];
|
1483
|
|
- unsigned totValues = bcfunc->numValues + bcfunc->numConstants;
|
|
1483
|
+ unsigned totValues = bcfunc->numValues + bcfunc->numConstants + bc->num_globals;
|
1484
|
1484
|
unsigned *map = cli_malloc(sizeof(*map)*totValues);
|
1485
|
1485
|
for (j=0;j<bcfunc->numValues;j++) {
|
1486
|
1486
|
uint16_t ty = bcfunc->types[j];
|
...
|
...
|
@@ -1495,6 +1500,13 @@ static int cli_bytecode_prepare_interpreter(struct cli_bc *bc)
|
1495
|
1495
|
map[bcfunc->numValues+j] = bcfunc->numBytes;
|
1496
|
1496
|
bcfunc->numBytes += 8;
|
1497
|
1497
|
}
|
|
1498
|
+ for (j=0;j<bc->num_globals;j++) {
|
|
1499
|
+ uint16_t ty = bc->globaltys[j];
|
|
1500
|
+ unsigned align = typealign(bc, ty);
|
|
1501
|
+ bcfunc->numBytes = (bcfunc->numBytes + align-1)&(~(align-1));
|
|
1502
|
+ map[bcfunc->numValues+bcfunc->numConstants+j] = bcfunc->numBytes;
|
|
1503
|
+ bcfunc->numBytes += typesize(bc, ty);
|
|
1504
|
+ }
|
1498
|
1505
|
for (j=0;j<bcfunc->numInsts;j++) {
|
1499
|
1506
|
struct cli_bc_inst *inst = &bcfunc->allinsts[j];
|
1500
|
1507
|
inst->dest = map[inst->dest];
|