#include "asm.h" #include "tpu.h" #include "util.h" #include #include #include #include #include #include #include static struct tis tis; int (*cleanup)(void) = NULL; const char *progname = "tis100"; static bool io_active(struct tis *tis) { struct tpu_io_port *io_port; int i; for (i = 0; i < TIS_MAX_IO_PORTS; i++) { io_port = tis->in_ports[i]; if (!io_port || !io_port->file) continue; if (io_port->port.attached && !io_port->port.writing && !feof(io_port->file)) return true; } return false; } int main(int argc, const char **argv) { struct tis_stats stats; bool idle, prev_idle; if (argc < 2) { fprintf(stderr, "Usage: tis100 FILE [IO..]\n"); exit(1); } tis_init(&tis); tis_load(&tis, argv); idle = false; while (!idle || !prev_idle || io_active(&tis)) { prev_idle = idle; idle = !tis_step(&tis); } if (tis.show_stats) { stats = tis_gen_stats(&tis); printf("=== stats ===\n"); printf(" cycles: %zu\n", stats.steps); printf(" nodes: %zu\n", stats.nodes); printf(" insts: %zu\n", stats.insts); printf(" idle: %2.1f%%\n", stats.idle * 100); printf("=============\n"); } tis_deinit(&tis); }