bool yarn_exec_simple (yarn_executor_t executor, void* data, yarn_word_t thread_count, yarn_word_t ws_size, yarn_word_t index_size) { bool ret; bool del_on_exit = false; if (!g_is_init) { ret = yarn_init(); if (!ret) goto yarn_init_error; del_on_exit = true; } ret = init_dep(ws_size, index_size); if (!ret) goto dep_alloc_error; ret = yarn_epoch_reset(); if (!ret) goto epoch_reset_error; struct task_info info = {executor, data}; ret = yarn_tpool_exec(pool_worker_simple, (void*) &info, thread_count); if (!ret) goto exec_error; if (del_on_exit) yarn_destroy(); return true; exec_error: epoch_reset_error: dep_alloc_error: if(del_on_exit) yarn_destroy(); yarn_init_error: perror(__FUNCTION__); return false; }
int main(int argc, char **argv) { FILE *fp; size_t fsize; yarn_state *Y; char *buffer; char *memoryfile = NULL; int icount = -1; int status = YARN_STATUS_OK; if (argc <= 1) { printf("Must specify an object file to load.\n"); return 0; } for (int i=2; i<argc; i++) { if (strncmp("-m", argv[i], strlen("-m")) == 0) { memoryfile = argv[i]+2; } else if (strncmp("-c", argv[i], strlen("-c")) == 0) { icount = atoi(argv[i]+2); } } fp = fopen(argv[1], "r"); if (!fp) { printf("Invalid object file.\n"); return EXIT_FAILURE; } fseek(fp, 0L, SEEK_END); fsize = ftell(fp); fseek(fp, 0L, SEEK_SET); buffer = malloc(sizeof(char)*fsize); if (buffer == NULL) { printf("Unable to load object file.\n"); return EXIT_FAILURE; } fread(buffer,1,fsize,fp); fclose(fp); Y = yarn_init(256*sizeof(yarn_int)); if (Y == NULL) { printf("Unable to create Yarn state.\n"); return EXIT_FAILURE; } if (yarn_loadCode(Y,buffer,fsize) != 0) { printf("Unable to load Yarn object code.\n"); return EXIT_FAILURE; } while (status == YARN_STATUS_OK) { status = yarn_execute(Y, icount); printProgramStatus(Y); if (status == YARN_STATUS_PAUSE) { printf("Program paused, hit enter to continue."); getchar(); // Reset our status yarn_setStatus(Y, YARN_STATUS_OK); status = YARN_STATUS_OK; } } if (memoryfile != NULL) { fp = fopen(memoryfile, "w"); if (!fp) { printf("Invalid memory dump name.\n"); return EXIT_FAILURE; } fwrite(yarn_getMemoryPtr(Y), 1, yarn_getMemorySize(Y), fp); fclose(fp); printf("Wrote memory dump: %s\n",memoryfile); } yarn_destroy(Y); free(buffer); return 0; }