void main_process(char input[]) { inputType t; t = identifyType(input); verify_order(t); switch (t) { case DIRECTIVE: treat_directive(input); break; case COMMENT: treat_comment(input); break; case LABEL: //treat_label(input); break; case INSTRUCTION: treat_instruction(input); break; case ERROR: break; case NONE: break; } }
/*! Test sorting and searching implementations. */ void test(void) { int cnt; printf("testing various size arrays:"); for (cnt = 0; cnt < MAX_CNT; cnt = cnt * 4 / 3 + 1) { int repeat; printf(" %zu", cnt); for (repeat = 0; repeat < 10; repeat++) { static int values[MAX_CNT]; int i; /* Put values 0...CNT in random order in VALUES. */ for (i = 0; i < cnt; i++) values[i] = i; shuffle(values, cnt); /* Sort VALUES, then verify ordering. */ qsort(values, cnt, sizeof *values, compare_ints); verify_order(values, cnt); verify_bsearch(values, cnt); } } printf(" done\n"); printf("stdlib: PASS\n"); }
void dump_page_alloc(FILE* f) { if (!alloc_info) { fprintf(f, "not initialized yet\n"); fflush(f); return; } /* dump the buddy system */ fprintf (f, "Buddy system: max-order=%d, id - idx = %d\n", alloc_info->max_order, alloc_info->idx_2_id_adj); int i, e; char* page_start_addr = alloc_info->first_page; int page_sz_log = alloc_info->page_size_log2; for (i = 0, e = alloc_info->max_order; i <= e; i++) { rb_tree_t* free_blks = &alloc_info->free_blks[i]; if (rbt_is_empty(free_blks)) continue; fprintf(f, "Order = %3d: ", i); rb_iter_t iter, iter_e; for (iter = rbt_iter_begin(free_blks), iter_e = rbt_iter_end(free_blks); iter != iter_e; iter = rbt_iter_inc(free_blks, iter)) { rb_node_t* node = rbt_iter_deref(iter); page_idx_t page_idx = node->key; char* addr = page_start_addr + (page_idx << page_sz_log); fprintf(f, "pg_idx:%d (%p, len=%d), ", page_idx, addr, (int)node->value); verify_order(page_idx, i); } fputs("\n", f); } fprintf(f, "\nAllocated blocks:\n"); { rb_tree_t* rbt = &alloc_info->alloc_blks; rb_iter_t iter, iter_e; int idx = 0; for (iter = rbt_iter_begin(rbt), iter_e = rbt_iter_end(rbt); iter != iter_e; iter = rbt_iter_inc(rbt, iter)) { rb_node_t* nd = rbt_iter_deref(iter); int blk = nd->key; fprintf(f, "%3d: pg_idx:%d, size:%ld, order = %d\n", idx, blk, nd->value, alloc_info->page_info[blk].order); idx++; } } }