... | ... |
@@ -1000,7 +1000,7 @@ int cli_bytecode_load(struct cli_bc *bc, FILE *f, struct cli_dbio *dbio) |
1000 | 1000 |
return CL_SUCCESS; |
1001 | 1001 |
} |
1002 | 1002 |
|
1003 |
-int cli_bytecode_run(const struct cli_bc *bc, struct cli_bc_ctx *ctx) |
|
1003 |
+int cli_bytecode_run(const struct cli_all_bc *bcs, const struct cli_bc *bc, struct cli_bc_ctx *ctx) |
|
1004 | 1004 |
{ |
1005 | 1005 |
struct cli_bc_inst inst; |
1006 | 1006 |
struct cli_bc_func func; |
... | ... |
@@ -1012,24 +1012,24 @@ int cli_bytecode_run(const struct cli_bc *bc, struct cli_bc_ctx *ctx) |
1012 | 1012 |
cli_errmsg("bytecode has to be prepared either for interpreter or JIT!\n"); |
1013 | 1013 |
return CL_EARG; |
1014 | 1014 |
} |
1015 |
- memset(&func, 0, sizeof(func)); |
|
1016 |
- func.numInsts = 1; |
|
1017 |
- func.numValues = 1; |
|
1018 |
- func.numBytes = ctx->bytes; |
|
1019 |
- memset(ctx->values+ctx->bytes-8, 0, 8); |
|
1015 |
+ if (bc->state == bc_interp) { |
|
1016 |
+ memset(&func, 0, sizeof(func)); |
|
1017 |
+ func.numInsts = 1; |
|
1018 |
+ func.numValues = 1; |
|
1019 |
+ func.numBytes = ctx->bytes; |
|
1020 |
+ memset(ctx->values+ctx->bytes-8, 0, 8); |
|
1020 | 1021 |
|
1021 |
- inst.opcode = OP_CALL_DIRECT; |
|
1022 |
- inst.interp_op = OP_CALL_DIRECT*5; |
|
1023 |
- inst.dest = func.numArgs; |
|
1024 |
- inst.type = 0; |
|
1025 |
- inst.u.ops.numOps = ctx->numParams; |
|
1026 |
- inst.u.ops.funcid = ctx->funcid; |
|
1027 |
- inst.u.ops.ops = ctx->operands; |
|
1028 |
- inst.u.ops.opsizes = ctx->opsizes; |
|
1029 |
- if (bc->state == bc_interp) |
|
1022 |
+ inst.opcode = OP_CALL_DIRECT; |
|
1023 |
+ inst.interp_op = OP_CALL_DIRECT*5; |
|
1024 |
+ inst.dest = func.numArgs; |
|
1025 |
+ inst.type = 0; |
|
1026 |
+ inst.u.ops.numOps = ctx->numParams; |
|
1027 |
+ inst.u.ops.funcid = ctx->funcid; |
|
1028 |
+ inst.u.ops.ops = ctx->operands; |
|
1029 |
+ inst.u.ops.opsizes = ctx->opsizes; |
|
1030 | 1030 |
return cli_vm_execute(ctx->bc, ctx, &func, &inst); |
1031 |
- else |
|
1032 |
- return cli_vm_execute_jit(ctx->bc, ctx, &func, &inst); |
|
1031 |
+ } |
|
1032 |
+ return cli_vm_execute_jit(bcs, ctx, &bc->funcs[ctx->funcid]); |
|
1033 | 1033 |
} |
1034 | 1034 |
|
1035 | 1035 |
uint64_t cli_bytecode_context_getresult_int(struct cli_bc_ctx *ctx) |
... | ... |
@@ -70,7 +70,7 @@ void cli_bytecode_context_destroy(struct cli_bc_ctx *ctx); |
70 | 70 |
int cli_bytecode_init(struct cli_all_bc *allbc); |
71 | 71 |
int cli_bytecode_load(struct cli_bc *bc, FILE *f, struct cli_dbio *dbio); |
72 | 72 |
int cli_bytecode_prepare(struct cli_all_bc *allbc); |
73 |
-int cli_bytecode_run(const struct cli_bc *bc, struct cli_bc_ctx *ctx); |
|
73 |
+int cli_bytecode_run(const struct cli_all_bc *bcs, const struct cli_bc *bc, struct cli_bc_ctx *ctx); |
|
74 | 74 |
void cli_bytecode_destroy(struct cli_bc *bc); |
75 | 75 |
int cli_bytecode_done(struct cli_all_bc *allbc); |
76 | 76 |
|
... | ... |
@@ -418,8 +418,14 @@ public: |
418 | 418 |
}; |
419 | 419 |
} |
420 | 420 |
|
421 |
-int cli_vm_execute_jit(const struct cli_bc *bc, struct cli_bc_ctx *ctx, const struct cli_bc_func *func, const struct cli_bc_inst *inst) |
|
421 |
+int cli_vm_execute_jit(const struct cli_all_bc *bcs, struct cli_bc_ctx *ctx, |
|
422 |
+ const struct cli_bc_func *func) |
|
422 | 423 |
{ |
424 |
+ void *code = bcs->engine->compiledFunctions[func]; |
|
425 |
+ assert(code); |
|
426 |
+ // execute; |
|
427 |
+ uint32_t result = ((uint32_t (*)(void))code)(); |
|
428 |
+ *(uint32_t*)ctx->values = result; |
|
423 | 429 |
return 0; |
424 | 430 |
} |
425 | 431 |
|
... | ... |
@@ -467,6 +473,9 @@ int cli_bytecode_prepare_jit(struct cli_all_bc *bcs) |
467 | 467 |
} |
468 | 468 |
} |
469 | 469 |
|
470 |
+ for (unsigned i=0;i<bcs->count;i++) { |
|
471 |
+ bcs->all_bcs[i].state = bc_jit; |
|
472 |
+ } |
|
470 | 473 |
// compile all functions now, not lazily! |
471 | 474 |
for (Module::iterator I = M->begin(), E = M->end(); I != E; ++I) { |
472 | 475 |
Function *Fn = &*I; |
... | ... |
@@ -103,7 +103,7 @@ int cli_vm_execute(const struct cli_bc *bc, struct cli_bc_ctx *ctx, const struct |
103 | 103 |
extern "C" { |
104 | 104 |
#endif |
105 | 105 |
|
106 |
-int cli_vm_execute_jit(const struct cli_bc *bc, struct cli_bc_ctx *ctx, const struct cli_bc_func *func, const struct cli_bc_inst *inst); |
|
106 |
+int cli_vm_execute_jit(const struct cli_all_bc *bcs, struct cli_bc_ctx *ctx, const struct cli_bc_func *func); |
|
107 | 107 |
int cli_bytecode_prepare_jit(struct cli_all_bc *bc); |
108 | 108 |
int cli_bytecode_init_jit(struct cli_all_bc *bc); |
109 | 109 |
int cli_bytecode_done_jit(struct cli_all_bc *bc); |
... | ... |
@@ -67,7 +67,7 @@ static void runtest(const char *file, uint64_t expected) |
67 | 67 |
fail_unless(!!ctx, "cli_bytecode_context_alloc failed"); |
68 | 68 |
|
69 | 69 |
cli_bytecode_context_setfuncid(ctx, &bc, 0); |
70 |
- rc = cli_bytecode_run(&bc, ctx); |
|
70 |
+ rc = cli_bytecode_run(&bcs, &bc, ctx); |
|
71 | 71 |
fail_unless(rc == CL_SUCCESS, "cli_bytecode_run failed"); |
72 | 72 |
|
73 | 73 |
v = cli_bytecode_context_getresult_int(ctx); |