diff --git a/core.mak b/core.mak index 48f81519..dfb0c6c6 100644 --- a/core.mak +++ b/core.mak @@ -110,10 +110,11 @@ $(TB_OBJS): $(@:$(OBJ_DIR)/%.o=%.c) $(TCC_DIR)/config.h: $(TCC_DIR)/configure cd $(TCC_DIR)/ && ./configure -$(TCC_DIR)/tccdefs_.h: $(TCC_DIR)/include/tccdefs.h - $(MAKE) -C $(TCC_DIR) tccdefs_.h +$(TCC_DIR)/tccdefs_.h: $(TCC_DIR)/include/tccdefs.h $(TCC_DIR)/config.h + # $(MAKE) -C $(TCC_DIR) tccdefs_.h + echo '""' > $(TCC_DIR)/tccdefs_.h -$(TCC_OBJS): $(@:$(OBJ_DIR)/%.o=%.c) $(TCC_DIR) $(TCC_DIR)/config.h +$(TCC_OBJS): $(@:$(OBJ_DIR)/%.o=%.c) $(TCC_DIR) $(TCC_DIR)/tccdefs_.h $(TCC_DIR)/config.h @mkdir -p $$(dirname $(@)) $(CC) -c $(OPT) $(@:$(OBJ_DIR)/%.o=%.c) -o $(@) $(CFLAGS) diff --git a/main/minivm.c b/main/minivm.c index 8617b030..e541ea2a 100644 --- a/main/minivm.c +++ b/main/minivm.c @@ -56,6 +56,7 @@ int main(int argc, char **argv) { .use_tb_opt = false, .use_num = VM_USE_NUM_F64, .target = VM_TARGET_TB, + .tb_use_tailcall = true, #endif }; vm_blocks_t val_blocks = {0}; @@ -105,6 +106,8 @@ int main(int argc, char **argv) { config->tb_regs_node = enable; } else if (!strcmp(arg, "force-bitcast")) { config->tb_force_bitcast = enable; + } else if (!strcmp(arg, "tailcall")) { + config->tb_use_tailcall = enable; } else { fprintf(stderr, "error: unknown flag --tb-%s want --tb-recompile, --tb-cast-regs, or --tb-raw-regs", arg); return 1; diff --git a/vm/backend/exec.c b/vm/backend/exec.c index 788b73f3..a1aaaaa2 100644 --- a/vm/backend/exec.c +++ b/vm/backend/exec.c @@ -73,13 +73,13 @@ void *vm_cache_comp(const char *comp, const char **srcs, const char *entry) { fwrite(src_buf->buf, src_buf->len, 1, out); fclose(out); vm_io_buffer_t *cmd_buf = vm_io_buffer_new(); - // vm_io_buffer_format(cmd_buf, "%s -shared -O2 -foptimize-sibling-calls -fPIC %s -o %s -w -pipe", comp, c_file, so_file); - vm_io_buffer_format(cmd_buf, "%s -shared -g2 -foptimize-sibling-calls -fPIC %s -o %s -w -pipe", comp, c_file, so_file); + vm_io_buffer_format(cmd_buf, "%s -shared -O2 -foptimize-sibling-calls -fPIC %s -o %s -w -pipe", comp, c_file, so_file); + // vm_io_buffer_format(cmd_buf, "%s -shared -g2 -foptimize-sibling-calls -fPIC %s -o %s -w -pipe", comp, c_file, so_file); int res = system(cmd_buf->buf); if (res) { return NULL; } - // remove(c_file); + remove(c_file); } void *handle = dlopen(so_file, RTLD_LAZY); void *sym = dlsym(handle, entry); diff --git a/vm/backend/tb.c b/vm/backend/tb.c index 331ebab0..9e205d9f 100644 --- a/vm/backend/tb.c +++ b/vm/backend/tb.c @@ -534,7 +534,7 @@ branch_uses_reg:; false ); - if (VM_NO_TAILCALL) { + if (state->config->tb_use_tailcall) { TB_MultiOutput out = vm_tb_inst_call( state, next_proto, @@ -565,7 +565,7 @@ branch_uses_reg:; false ); - if (VM_NO_TAILCALL) { + if (state->config->tb_use_tailcall) { TB_MultiOutput out = vm_tb_inst_call( state, next_proto, @@ -599,7 +599,7 @@ branch_uses_reg:; } } - if (VM_NO_TAILCALL) { + if (state->config->tb_use_tailcall) { TB_MultiOutput out = vm_tb_inst_call( state, next_proto, diff --git a/vm/config.h b/vm/config.h index 2e69a37b..01683b12 100644 --- a/vm/config.h +++ b/vm/config.h @@ -5,7 +5,6 @@ #include #define VM_USE_DUMP 1 -#define VM_NO_TAILCALL 1 #define VM_FORMAT_FLOAT "%.14g" struct vm_config_t; @@ -64,6 +63,7 @@ struct vm_config_t { bool tb_regs_cast: 1; bool tb_regs_node: 1; bool tb_force_bitcast: 1; + bool tb_use_tailcall; }; #endif