... | ... |
@@ -553,7 +553,7 @@ static void add_static_types(struct cli_bc *bc) |
553 | 553 |
bc->types[i].kind = DPointerType; |
554 | 554 |
bc->types[i].numElements = 1; |
555 | 555 |
bc->types[i].containedTypes = &containedTy[i]; |
556 |
- bc->types[i].size = bc->types[i].align = sizeof(void*); |
|
556 |
+ bc->types[i].size = bc->types[i].align = 8; |
|
557 | 557 |
} |
558 | 558 |
} |
559 | 559 |
|
... | ... |
@@ -1694,6 +1694,10 @@ static int cli_bytecode_prepare_interpreter(struct cli_bc *bc) |
1694 | 1694 |
case OP_BC_GEP1: |
1695 | 1695 |
case OP_BC_GEPZ: |
1696 | 1696 |
/*three[0] is the type*/ |
1697 |
+ if (bcfunc->types[inst->u.three[1]]&0x8000) |
|
1698 |
+ inst->interp_op = 5*(inst->interp_op/5); |
|
1699 |
+ else |
|
1700 |
+ inst->interp_op = 5*(inst->interp_op/5)+3; |
|
1697 | 1701 |
MAP(inst->u.three[1]); |
1698 | 1702 |
MAP(inst->u.three[2]); |
1699 | 1703 |
break; |
... | ... |
@@ -461,7 +461,7 @@ static inline int64_t ptr_compose(int32_t id, uint32_t offset) |
461 | 461 |
return (i << 32) | offset; |
462 | 462 |
} |
463 | 463 |
|
464 |
-static inline int32_t ptr_register_stack(struct ptr_infos *infos, |
|
464 |
+static inline int64_t ptr_register_stack(struct ptr_infos *infos, |
|
465 | 465 |
unsigned char *values, |
466 | 466 |
uint32_t off, uint32_t size) |
467 | 467 |
{ |
... | ... |
@@ -476,7 +476,7 @@ static inline int32_t ptr_register_stack(struct ptr_infos *infos, |
476 | 476 |
sinfos = &sinfos[n-1]; |
477 | 477 |
sinfos->base = values + off; |
478 | 478 |
sinfos->size = size; |
479 |
- return ptr_compose(-(n-1), 0); |
|
479 |
+ return ptr_compose(-n, 0); |
|
480 | 480 |
} |
481 | 481 |
|
482 | 482 |
static inline int64_t ptr_register_glob_fixedid(struct ptr_infos *infos, |
... | ... |
@@ -524,7 +524,7 @@ static inline void* ptr_torealptr(const struct ptr_infos *infos, int64_t ptr, |
524 | 524 |
return NULL; |
525 | 525 |
} |
526 | 526 |
if (ptrid < 0) { |
527 |
- ptrid = -ptrid; |
|
527 |
+ ptrid = -ptrid-1; |
|
528 | 528 |
if (UNLIKELY(ptrid >= infos->nstacks)) { |
529 | 529 |
bcfail("ptr", ptrid, infos->nstacks, __FILE__, __LINE__); |
530 | 530 |
return NULL; |
... | ... |
@@ -589,6 +589,7 @@ int cli_vm_execute(const struct cli_bc *bc, struct cli_bc_ctx *ctx, const struct |
589 | 589 |
char *old_values; |
590 | 590 |
struct ptr_infos ptrinfos; |
591 | 591 |
struct timeval tv0, tv1, timeout; |
592 |
+ int stackid = 0; |
|
592 | 593 |
|
593 | 594 |
memset(&ptrinfos, 0, sizeof(ptrinfos)); |
594 | 595 |
memset(&stack, 0, sizeof(stack)); |
... | ... |
@@ -789,6 +790,7 @@ int cli_vm_execute(const struct cli_bc *bc, struct cli_bc_ctx *ctx, const struct |
789 | 789 |
break; |
790 | 790 |
} |
791 | 791 |
values = stack_entry->values; |
792 |
+ /* TODO: unregister on ret */ |
|
792 | 793 |
TRACE_EXEC(inst->u.ops.funcid, inst->dest, inst->type, stack_depth); |
793 | 794 |
if (stack_depth > 10000) { |
794 | 795 |
cli_errmsg("bytecode: stack depth exceeded\n"); |
... | ... |
@@ -835,6 +837,7 @@ int cli_vm_execute(const struct cli_bc *bc, struct cli_bc_ctx *ctx, const struct |
835 | 835 |
} |
836 | 836 |
} |
837 | 837 |
func = func2; |
838 |
+ stackid = ptr_register_stack(&ptrinfos, values, 0, func->numBytes)>>32; |
|
838 | 839 |
CHECK_GT(func->numBB, 0); |
839 | 840 |
stop = jump(func, 0, &bb, &inst, &bb_inst); |
840 | 841 |
stack_depth++; |
... | ... |
@@ -955,6 +958,17 @@ int cli_vm_execute(const struct cli_bc *bc, struct cli_bc_ctx *ctx, const struct |
955 | 955 |
WRITE8(inst->dest, WORDS_BIGENDIAN); |
956 | 956 |
break; |
957 | 957 |
} |
958 |
+ DEFINE_OP(OP_BC_GEPZ) { |
|
959 |
+ int64_t ptr; |
|
960 |
+ if (!(inst->interp_op%5)) { |
|
961 |
+ WRITE64(inst->dest, ptr_compose(stackid, |
|
962 |
+ inst->u.unaryop)); |
|
963 |
+ } else { |
|
964 |
+ READ64(ptr, inst->u.unaryop); |
|
965 |
+ WRITE64(inst->dest, ptr); |
|
966 |
+ } |
|
967 |
+ break; |
|
968 |
+ } |
|
958 | 969 |
/* TODO: implement OP_BC_GEP1, OP_BC_GEP2, OP_BC_GEPN */ |
959 | 970 |
default: |
960 | 971 |
cli_errmsg("Opcode %u of type %u is not implemented yet!\n", |