int main(int ac, char** av) { vm_t* vm; display_gl_t* display = NULL; int bound; int i; debugger_t* debugger = NULL; vm = vm_initialize(); if ( (parse_arguments(vm, ac, av) <= 0) || (check_core_endianess(vm) < 0)) { return -1; } bound = VM_MEMORY_SIZE / (vm->core_count - 1); for (i = 0; i < vm->core_count; ++i) { vm->cores[i]->bound.start = vm->cores[i]->start_address; vm->cores[i]->bound.size = bound; } memory_access_initialize(is_cpu_big_endian() != vm->big_endian); #if defined(_DEBUG) vm->full_screen = 0; #endif #ifdef RENDER_GL display = display_gl_initialize(1980, 1080, vm->full_screen); if (vm->step != -1) { debugger = debugger_init(vm->dbg_same_window ? display_gl_get_window(display) : NULL); } #endif while (vm->process_count && !display_gl_should_exit(display)) { int32 i; int update_display = 0; if (vm->cycle_barrier == vm->cycle_total) { for (i = 0; i < vm->core_count; ++i) { vm->cores[i]->bound.start = 0; vm->cores[i]->bound.size = vm->memory_size; } } if (vm->step != 0) { vm->cycle_current++; vm->cycle_total++; int32 process_count = vm->process_count; for (i = process_count; i > 0; --i) { process_t* process = vm->processes[i - 1]; process->cycle_wait--; if (process->cycle_wait <= 0) { vm_reset_process_io_op(process); vm_execute(vm, process); update_display = 1; if (vm->step > 0 && (vm->step_process == NULL || vm->step_process == process) ) { vm->step --; } } } if (vm->cycle_current > vm->cycle_to_die) { vm->cycle_current = 0; vm_kill_process_if_no_live(vm); vm_clean_dead_process(vm); } } else { update_display = 1; } #ifdef RENDER_GL update_display |= display_gl_update_input(display); if (update_display) { float y = 1; y = display_gl_text(display, 0, y, 0xffffffff, "cycle to die %d", vm->cycle_to_die); y = display_gl_text(display, 0, y, 0xffffffff, "live count %d ", vm->live_count); y = display_gl_text(display, 0, y, 0xffffffff, "process count %d ", vm->process_count); y = display_gl_text(display, 0, y, 0xffffffff, "cycle %d ", vm->cycle_total); y = display_gl_text(display, 0, y, 0xffffffff, "barrier %d ", vm->cycle_barrier); for (i = 0; i < vm->core_count; ++i) { core_t* core = vm->cores[i]; char* name = core->header ? core->header->name : "Unknow"; y = display_gl_text(display, 0, y, 0xffffffff, "%s %d", name, core->live_count); } display_gl_step(vm, display); display_gl_swap(display); } if (debugger && vm->step != 1) { debugger_render(debugger, vm); } #endif } print_winning_core(vm); if (debugger) { debugger_destroy(debugger); } #ifdef RENDER_GL display_gl_destroy(display); #endif vm_destroy(vm); }
debugger_destructor() { printf("debugger_destructor\n"); debugger_destroy(debugger_gp); }