Skip to content

Commit

Permalink
update tb, fix usages
Browse files Browse the repository at this point in the history
  • Loading branch information
ShawSumma committed Dec 26, 2023
1 parent a8e58ab commit 7a6ae39
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 13 deletions.
2 changes: 1 addition & 1 deletion main/minivm.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ int main(int argc, char **argv) {
// GC_disable();
vm_config_t val_config = (vm_config_t){
.use_tb_opt = false,
.use_num = VM_USE_NUM_F64,
.use_num = VM_USE_NUM_I64,
};
vm_blocks_t val_blocks = {0};
vm_blocks_t *blocks = &val_blocks;
Expand Down
2 changes: 1 addition & 1 deletion vendor/common/log.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ typedef void (*log_LockFn)(bool lock, void *udata);

enum { LOG_TRACE, LOG_DEBUG, LOG_INFO, LOG_WARN, LOG_ERROR, LOG_FATAL };

#if 1
#if 0
#define log_trace(...) log_log(LOG_TRACE, __FILE__, __LINE__, __VA_ARGS__)
#define log_debug(...) log_log(LOG_DEBUG, __FILE__, __LINE__, __VA_ARGS__)
#define log_info(...) log_log(LOG_INFO, __FILE__, __LINE__, __VA_ARGS__)
Expand Down
2 changes: 0 additions & 2 deletions vendor/tb/src/tb_builder.c
Original file line number Diff line number Diff line change
Expand Up @@ -300,8 +300,6 @@ void tb_inst_store(TB_Function* f, TB_DataType dt, TB_Node* addr, TB_Node* val,
n = tb_alloc_node(f, TB_STORE, TB_TYPE_MEMORY, 4, sizeof(TB_NodeMemAccess));
TB_NODE_SET_EXTRA(n, TB_NodeMemAccess, .align = alignment);
}
// printf("store gvn = %zu\n", (size_t) n->gvn);
// asm("int3");
set_input(f, n, f->trace.bot_ctrl, 0);
set_input(f, n, append_mem(f, n), 1);
set_input(f, n, addr, 2);
Expand Down
18 changes: 10 additions & 8 deletions vm/backend/tb.c
Original file line number Diff line number Diff line change
Expand Up @@ -241,15 +241,15 @@ TB_Node *vm_tb_func_body_once(vm_tb_state_t *state, TB_Node **regs, vm_block_t *
if (block->pass != NULL) {
return block->pass;
}
TB_Node *old_ctrl = tb_inst_get_control(state->fun);
TB_Trace old_ctrl = tb_inst_get_trace(state->fun);
TB_Node *ret = tb_inst_region(state->fun);
block->pass = ret;
char name[24];
snprintf(name, 23, "vm.%zi", block->id);
tb_inst_set_region_name(state->fun, ret, -1, name);
tb_inst_set_control(state->fun, ret);
vm_tb_func_body_once_as(state, regs, block);
tb_inst_set_control(state->fun, old_ctrl);
tb_inst_set_trace(state->fun, old_ctrl);
return ret;
}

Expand Down Expand Up @@ -1176,14 +1176,14 @@ void vm_tb_func_body_once_as(vm_tb_state_t *state, TB_Node **regs, vm_block_t *b
branch_uses_reg:;

TB_PrototypeParam next_rets[2] = {
{TB_TYPE_PTR},
{VM_TB_TYPE_VALUE},
{TB_TYPE_I32},
};

TB_PrototypeParam *next_params = vm_malloc(sizeof(TB_PrototypeParam) * next_nargs);

for (size_t argno = 0; argno < next_nargs; argno++) {
next_params[argno] = (TB_PrototypeParam){TB_TYPE_PTR};
next_params[argno] = (TB_PrototypeParam){VM_TB_TYPE_VALUE};
}

TB_FunctionPrototype *next_proto = tb_prototype_create(
Expand Down Expand Up @@ -1637,16 +1637,18 @@ void *vm_tb_rfunc_comp(vm_rblock_t *rblock) {
}
}
#endif
static bool arena_init = false;
TB_Arena arena;
tb_arena_create(&arena, 1 << 16);
TB_Arena *parena = &arena;
tb_arena_create(parena, 1 << 16);
TB_FeatureSet features = (TB_FeatureSet){0};
#if VM_USE_DUMP
if (state->config->dump_x86) {
TB_FunctionOutput *out = tb_pass_codegen(passes, &arena, &features, true);
TB_FunctionOutput *out = tb_pass_codegen(passes, parena, &features, true);
fprintf(stdout, "\n--- x86asm ---\n");
tb_output_print_asm(out, stdout);
} else {
tb_pass_codegen(passes, &arena, &features, false);
tb_pass_codegen(passes, parena, &features, false);
}
#else
tb_pass_codegen(passes, &arena, &features, false);
Expand All @@ -1656,7 +1658,7 @@ void *vm_tb_rfunc_comp(vm_rblock_t *rblock) {
TB_JIT *jit = tb_jit_begin(state->module, 1 << 16);
void *ret = tb_jit_place_function(jit, state->fun);

tb_arena_destroy(&arena);
tb_arena_destroy(parena);

rblock->jit = ret;

Expand Down
2 changes: 1 addition & 1 deletion vm/lua/ast.c
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,7 @@ vm_ast_node_t vm_lang_lua_conv(vm_lang_lua_t src, TSNode node) {
break;
}
case VM_USE_NUM_I32: {
step_expr = vm_ast_build_literal(i64, 1);
step_expr = vm_ast_build_literal(i32, 1);
break;
}
case VM_USE_NUM_I64: {
Expand Down

0 comments on commit 7a6ae39

Please sign in to comment.