Beispiel #1
0
	int
main(int argc, char *argv[])
{
	int i;

	struct node *h = NULL;
	for(i = 0; i < 10; i++)
		h = insert_last(h, i);

	print(h);

	h = reverse(h, NULL);
	print(h);

	h = reverse2(h);
	print(h);

	h = delete_first(h);
	print(h);

	h = delete_last(h);
	print(h);

	h = insert_first(h, 11);
	print(h);

	h = insert_last(h, 13);
	print(h);

	h = insert_after(h, newnode(14), 13);
	print(h);

	return 0;
}
void liveness(cfg_t* cfg)
{
        printf("I am orig\n");
        vertex_t*        u;
        vertex_t*        v;
        set_t*                prev;
        size_t                i;
        size_t                j;
        list_t*                worklist;
        list_t*                p;
        list_t*                h;

        worklist = NULL;

        for (i = 0; i < cfg->nvertex; ++i) {
                u = &cfg->vertex[i];

                insert_last(&worklist, u);
                u->listed = true;
        }

        while ((u = remove_first(&worklist)) != NULL) {
                u->listed = false;

                reset(u->set[OUT]);

                for (j = 0; j < u->nsucc; ++j)
                        or(u->set[OUT], u->set[OUT], u->succ[j]->set[IN]);

                prev = u->prev;
                u->prev = u->set[IN];
                u->set[IN] = prev;

                /* in our case liveness information... */
                propagate(u->set[IN], u->set[OUT], u->set[DEF], u->set[USE]);

                if (u->pred != NULL && !equal(u->prev, u->set[IN])) {
                        p = h = u->pred;
                        do {
                                v = p->data;
                                if (!v->listed) {
                                        v->listed = true;
                                        insert_last(&worklist, v);
                                }

                                p = p->succ;

                        } while (p != h);
                }
        }
}
Beispiel #3
0
void liveness(cfg_t* cfg)
{
	vertex_t*	u;
	size_t		i;
	list_t*		wlarray[NTHREADS];


	int index = 0;
	int rem = cfg->nvertex / NTHREADS;
	rem += cfg->nvertex - (rem * NTHREADS);
	for(i = 0; i < NTHREADS; i++) {
		wlarray[i] = NULL;
	}
	for (i = 0; i < cfg->nvertex; ++i) {
		u = &cfg->vertex[i];
		if (rem-- == 0) {
			index++;
			rem = cfg->nvertex / NTHREADS;
		}
		insert_last(&wlarray[index], u);
		u->listed = true;
	}
	pthread_t threads[NTHREADS];

	for (i= 0; i < NTHREADS; i++) {
		pthread_create(&threads[i], NULL, liveness_work, wlarray[i]);
	}
	for ( i = 0; i < NTHREADS; i++) {
			pthread_join(threads[i], NULL);
	}
}
Beispiel #4
0
/* init_search_path: make a list of directories to look for programs in. */
static void init_search_path(void)
{
	char*		dir_start;
	char*		path;
	char*		s;
	list_t*		p;
	bool		proceed;

	path = getenv("PATH");

	/* path may look like "/bin:/usr/bin:/usr/local/bin" 
	 * and this function makes a list with strings 
	 * "/bin" "usr/bin" "usr/local/bin"
	 *
	 */

	dir_start = malloc(1+strlen(path));
	if (dir_start == NULL) {
		error("out of memory.");
		exit(1);
	}

	strcpy(dir_start, path);

	path_dir_list = NULL;

	if (path == NULL || *path == 0) {
		path_dir_list = new_list("");
		return;
	}

	proceed = true;

	while (proceed) {
		s = dir_start;
		while (*s != ':' && *s != 0)
			s++;
		if (*s == ':')
			*s = 0;
		else
			proceed = false;

		insert_last(&path_dir_list, dir_start);

		dir_start = s + 1;
	}

	p = path_dir_list;

	if (p == NULL)
		return;

#if 0
	do {
		printf("%s\n", (char*)p->data);
		p = p->succ;	
	} while (p != path_dir_list);
#endif
}
Beispiel #5
0
/*
 * add item to list
 */
struct node* insert_last(struct node* h, int data)
{
	if(h == NULL)
		return newnode(data);

	h->next = insert_last(h->next, data);

	return h;
}
void connect(cfg_t* cfg, size_t pred, size_t succ)
{
        vertex_t*        u;
        vertex_t*        v;

        u = &cfg->vertex[pred];
        v = &cfg->vertex[succ];

        u->succ[u->nsucc++ ] = v;
        insert_last(&v->pred, u);
}
Beispiel #7
0
void* liveness_work(void* arg)
{
	vertex_t*	u = NULL;
	vertex_t*	v;
	set_t*		prev;
	size_t		j;
	list_t*		p;
	list_t*		h;
	list_t*		worklist = (list_t*) arg;
	while ((u = remove_first(&worklist)) != NULL) {
		pthread_mutex_lock(u->mutex); // Lock on current vertex
		u->listed = false;
		pthread_mutex_unlock(u->mutex); // Unlock

		reset(u->set[OUT]);

		for (j = 0; j < u->nsucc; ++j){
			pthread_mutex_lock((u->succ[j])->mutex); // Lock on successor
			or(u->set[OUT], u->set[OUT], u->succ[j]->set[IN]);
//			printf("Gathering from other vertexes\n");
			pthread_mutex_unlock((u->succ[j])->mutex); // Unlock
		}

		pthread_mutex_lock(u->mutex); // Lock current on vertex
		prev = u->prev;
		u->prev = u->set[IN];
		u->set[IN] = prev;

		/* in our case liveness information... */
		propagate(u->set[IN], u->set[OUT], u->set[DEF], u->set[USE]);
		pthread_mutex_unlock(u->mutex); // Unlock
//		printf("%p\n", (void*) u->pred);
		if (u->pred != NULL && !equal(u->prev, u->set[IN])) {
			p = h = u->pred;
			do {
				v = p->data;
				pthread_mutex_lock(v->mutex); // Lock on predecessor
//				printf("do-while...\n");
				if (!v->listed) {
//					printf("Not listed\n");
					v->listed = true;
					insert_last(&worklist, v);
				}
				pthread_mutex_unlock(v->mutex); // Unlock
				p = p->succ;

			} while (p != h);
		}
	}
//	printf("Thread done\n");
	return NULL;
}
Beispiel #8
0
void compact_after(list_node_type *node)
{
	vmm_data_type *node_data = (vmm_data_type *) node->data;
	
	list_node_type *next_node = node->next;
	vmm_data_type *next_node_data = (vmm_data_type *) next_node->data;
	
	u32int new_size = node_data->size + next_node_data->size;
	
	node_data->size = new_size;
	
	remove(vmm_free, next_node);
	
	insert_last(vmm_unused_nodes, next_node);
}
Beispiel #9
0
u32int *malloc_above(u32int size, u32int align, u32int above)
{
	list_node_type *malloc_node = search_free((size + align), above);
	
	vmm_data_type *malloc_data = malloc_node->data;
	
	u32int start_addr = malloc_data->virt_addr;
	u32int split_size = 0;
	
	while (start_addr < above)
	{
		start_addr++;
		split_size++;
	}
	
	while (start_addr % align != 0)
	{
		start_addr++;
		split_size++;
	}
	
	if (split_size > 0)
	{
		malloc_node = split_free(malloc_node, size);
		malloc_node = malloc_node->next;
	}
	
	list_node_type *split_node = split_free(malloc_node, size);
	
	remove(vmm_free, split_node);
	
	insert_last(vmm_used, split_node);
	
	vmm_data_type *malloc_node_data = (vmm_data_type *) malloc_node->data;
	u32int *malloc_ptr = (u32int *) malloc_node_data->virt_addr;
	
	return malloc_ptr;
}
void test_object() {
	printf("%s start.\n", __func__);
	create();
	
	insert(0, &arr_user[0]);
	insert_first(&arr_user[1]);
	insert_last(&arr_user[2]);
	insert(1, &arr_user[3]);
	
	printf("object is_empty=%d\n", is_empty());
	printf("object size=%d\n", size());
	
	int i;
	user *p;
	int len = size();
	for(i=0; i<len; i++) {
		p = (user*)get(i);
		printf("string get(%d)=[%d, %s]\n", i, p->id, p->name);
	}
	
	destory();
	printf("%s finish.\n", __func__);
}
void test_int() {
	printf("%s start.\n", __func__);
	int arr[4] = {1, 2, 3, 4};
	create();
	insert(0, &arr[0]);
	insert_first(&arr[1]);
	insert_last(&arr[2]);
	insert(1, &arr[3]);
	
	printf("int is_empty=%d\n", is_empty());
	printf("int size=%d\n", size());
	
	// 2, 4, 1, 3
	int i;
	int *p;
	int len = size();
	for(i=0; i<len; i++) {
		p = (int*)get(i);
		printf("int get(%d)=%d\n", i, *p);
	}
	destory();
	printf("%s finish.\n", __func__);
}
void test_string() {
	printf("%s start.\n", __func__);
	char* arr = {"one", "two", "three", "four"};
	create();
	insert(0, &arr[0]);
	insert_first(&arr[1]);
	insert_last(&arr[2]);
	insert(1, &arr[3]);
	
	printf("string is_empty=%d\n", is_empty());
	printf("string size=%d\n", size());
	
	// "two", "four", "one", "three"
	int i;
	char *p;
	int len = size();
	for(i=0; i<len; i++) {
		p = (char*)get(i);
		printf("string get(%d)=%s\n", i, p);
	}
	destory();
	printf("%s finish.\n", __func__);
}
Beispiel #13
0
main(){
	int ch, count=0, j=-1;
	node *ptr1, *ptr2;
	int ele;
	printf ("Enter elements of list 1\n");
	while(1)
	{
		scanf ("%d", &ele);
		if(ele!=-1)
		insert_last(ele, 0);
		else
		break;
	}
	printf ("Enter elements of list 2\n");
	while(1)
	{
		scanf ("%d", &ele);
		if(ele!=-1)
		insert_last(ele, 1);
		else
		break;
	}
    ptr1 = first[0];
	ptr2 = first[1];
	printf("List one\n");
	display(0);
	printf("List two\n");
	display(1);
	printf ("Common elements in the two lists:\n");
	
	/*for (;ptr1->next!=NULL; ptr1 = ptr1->next)
	{
		for (;ptr2->next!=NULL; ptr2 = ptr2->next)
		{
			if(ptr1->a==ptr2->a)
			{
				printf ("%d\n", ptr1->a);
				count++;
				break;
			}
		}
	}
	*/
	
	do{
		if (j!=-1)
		{
			ptr1 = ptr1->next;
		}
		ptr2 = first[1];
		j=0;
		do{						
			if (ptr2!=first[1] || j!=0)
			{
				ptr2 = ptr2->next;
			}
			if (ptr1->a==ptr2->a)
			{
				printf ("%d\n", ptr1->a);
				count++;
				break;
			}
			j++;		
		}while(ptr2->next!=NULL);
	}while(ptr1->next!=NULL);
	
	if (!count)
	{
		printf ("No elements common!\n");
	}
}
Beispiel #14
0
void vmm_initialize()
{
	// create a pointer to the current page directory
	u32int *page_directory = current_page_directory->virt_addr;
	
	// create a pointer to the place where the lists will start
	u32int vmm_starting_addr = 0xC0400000;
	
	// set up the pointers for the lists
	vmm_unused_nodes = (list_type *) vmm_starting_addr;
	vmm_used = (list_type *) ((u32int) vmm_unused_nodes + sizeof(list_type));
	vmm_free = (list_type *) ((u32int) vmm_used + sizeof(list_type));
	
	// clear the lists
	vmm_unused_nodes->first = NULL;
	vmm_unused_nodes->last = NULL;
	
	vmm_used->first = NULL;
	vmm_used->last = NULL;
	
	vmm_free->first = NULL;
	vmm_free->last = NULL;
	
	// for each item on the page directory (except the last 4 MB where the recursive mappings are)
	for (u32int i = 0; i < 1023; i++)
	{
		// if there's nothing on that index
		if ((page_directory[i] & 0x1) == 0)
		{
			// get a new node
			list_node_type *new_node = get_unused_node();
			
			// make a pointer to the new node data
			vmm_data_type *new_data = (vmm_data_type *) new_node->data;
			
			// populate the data
			new_data->virt_addr = i * 0x400000;
			new_data->size = 0x400000;
			
			// put the node on the list
			insert_last(vmm_free, new_node);
			
			// compact the list
			compact_all_free();
		}
		else
		{
			// figure out the virtual address for the page table
			u32int virt_addr_base = 0xFFC00000;
			u32int virt_addr_offset = i << 12;
			u32int page_table_addr = virt_addr_base + virt_addr_offset;
			
			// make a pointer to it
			u32int *page_table = (u32int *) page_table_addr;
			
			// for each entry on the page table
			for (u32int j = 0; j < 1024; j++)
			{
				// if there's nothing on that index
				if ((page_table[j] & 0x1) == 0)
				{
					// get a new node
					list_node_type *new_node = get_unused_node();
					
					// make a pointer to the new node data
					vmm_data_type *new_data = (vmm_data_type *) new_node->data;
					
					// populate the data
					new_data->virt_addr = ((i * 0x400000) + (j * 0x1000));
					new_data->size = 0x1000;
					
					// put the node on the list
					insert_last(vmm_free, new_node);
					
					// compact the list
					compact_all_free();
				}
			}
		}
	}
}