Esempio n. 1
0
File: main.cpp Progetto: dinogun/omr
int main(int argc, char const * const * const argv) {
    assert(argc == 2);
    assert(initializeJit());

    // parse the input Tril file
    FILE* inputFile = fopen(argv[1], "r");
    assert(inputFile != NULL);
    ASTNode* trees = parseFile(inputFile);
    fclose(inputFile);

    printf("parsed trees:\n");
    printTrees(stdout, trees, 0);

    // assume that the file contians a single method and compile it
    Tril::DefaultCompiler incordecCompiler{trees};
    assert(incordecCompiler.compile() == 0);
    auto incordec = incordecCompiler.getEntryPoint<IncOrDecFunction*>();

    int32_t value = 1;
    printf("%d -> %d\n", value, incordec(&value));
    value = 2;
    printf("%d -> %d\n", value, incordec(&value));
    value = -1;
    printf("%d -> %d\n", value, incordec(&value));
    value = -2;
    printf("%d -> %d\n", value, incordec(&value));

    shutdownJit();
    return 0;
}
int main (int argc, char*argv[])
{
   	if(argc!=3)
	{
		printf("More argument needed");
		return 0;
	}
	 
	FILE *input=fopen(argv[1],"r");
	FILE *search=fopen(argv[2],"r");
    	int insert,tree,treeNum=1;
	BST *root=NULL;
	rootList *rootl=NULL; 
	while(1)
	{
		fscanf(input,"%d",&insert);
		if(feof(input))break;
		
		if(insert==-1)
		{
			insert_rootList(&rootl,root);
                	root=NULL;
			treeNum++;
		}
		else
		{
			insert_BST(&root,insert,treeNum);
		}
		
	}
	
	printTrees(rootl);
	fclose(input);	
	fclose(search);
	//free_list(&rootl);
    return 0;

}
int main(int argc, char ** argv) {
	float probability, randPoint;
	probability = 1;
	randPoint = probability + RAND_MAX * probability;

	char *trees;

	long i, len;

	trees = (char *) malloc(forestWidth * forestHeight * sizeof(char));
	memset(trees, EMPTY, forestWidth * forestHeight);

	for (i=0,len=forestWidth*forestHeight;i<len;++i) {
		if (rand() < randPoint) {
			trees[i] = TREE;
		}
	}

	Queue *current, *next;
	current = queue_init(forestHeight);
	next = queue_init(forestHeight);
	
	printf("\x1B[2J");
	printTrees(trees, forestWidth, forestHeight);

	for (i=0;i<forestHeight;++i) {
		if (trees[i*forestWidth] == TREE) {
			trees[i*forestWidth] = FIRE;
			queue_push(current, i*forestWidth);
		}
	}

	printTrees(trees, forestWidth, forestHeight);

	while (queue_length(current)) {
		queue_clear(next);
		while (queue_length(current)) {
			long index = queue_pop(current);
			long dx, dy, minx, miny, maxx, maxy, x, y;
			y = index / forestWidth;
			x = index % forestWidth;
			minx = x > 0 ? -1 : 0;
			miny = y > 0 ? -1 : 0;
			maxx = x < forestWidth -1 ? 1 : 0;
			maxy = y < forestHeight -1 ? 1 : 0;
			trees[index] = EMPTY;
			for (dx=minx;dx<=maxx;++dx) {
				for (dy=miny;dy<=maxy;++dy) {
					if (dx && !dy || dy && !dx) {
						long adj = index + dx + dy * forestWidth;
						if (trees[adj] == TREE) {
							trees[adj] = FIRE;
							queue_push(next, adj);
						}
					}
				}
			}
		}
		printTrees(trees, forestWidth, forestHeight);
		swap((void **)&current, (void **)&next);
	}
}
Esempio n. 4
0
int main(int argc, char const * const * const argv) {
    assert(argc == 2);
    assert(initializeJit());

    // parse the input Tril file
    FILE* inputFile = fopen(argv[1], "r");
    assert(inputFile != NULL);
    ASTNode* trees = parseFile(inputFile);
    fclose(inputFile);

    printf("parsed trees:\n");
    printTrees(stdout, trees, 0);

    // assume that the file contians a single method and compile it
    Tril::DefaultCompiler mandelbrotCompiler{trees};
    assert(mandelbrotCompiler.compile() == 0);
    auto mandelbrot = mandelbrotCompiler.getEntryPoint<MandelbrotFunction*>();

    const auto size = 80;                   // number of rows/columns in the output table
    const auto iterations = 1000;           // number of iterations to be performed
    int32_t table[size][size] = {{0}};          // the output table

    mandelbrot(iterations, size, &table[0][0]);

    // iterate over each cell in the table and print a corresponding character
    for (auto y = 0; y < size; ++y) {
        for (auto x = 0; x < size; ++x) {

#if defined(FULL_COLOUR)
            // if the current cell is *outside* the Mandelbrot set, print a '#',
            // other wise print ' ' (blank space)
            auto c = table[y][x] < iterations ? '#' : ' ';

            // map the modulus of the cell's value to a terminal color
            int colors[] = {1, 1, 5, 4, 6, 2, 3, 3, 3, 3};
            auto color = colors[table[y][x] % 10];

            // print the selected character in the calculated color
            // using ANSI escape codes
            printf(" \e[0;3%dm%c\e[0m ", color, c);
#elif defined(SIMPLE_COLOUR)
            // if the current cell is *inside* the Mandelbrot set, print a '#',
            // other wise print ' ' (blank space)
            auto c = table[y][x] >= 1000 ? '#' : ' ';

            // map the cell's x-coordinate to a color
            int colors[] = {0, 1, 3, 2, 6, 4, 5, 5, 5};
            auto color = colors[x / 10];

            // print the selected character in the calculated color
            // using ANSI escape codes
            printf(" \e[0;3%dm%c\e[0m ", color , c);
#else
            // if the current cell is *inside* the Mandelbrot set, print a '#',
            // other wise print ' ' (blank space)
            auto c = table[y][x] >= 1000 ? '#' : ' ';

            // print the selected character
            printf(" %c ", c );
#endif

        }
        printf("\n");
    }

   shutdownJit();
   return 0;
}
Esempio n. 5
0
int main (int argc, char*argv[]){

	//If there are not enough command line arguments
	if(argc != 3)
	{
		printf("Not enough command line arguments. Exiting program...\n");
		return 1;
	}

	//Opens the files for reading
	FILE* input = fopen(argv[1], "r");
	FILE* search = fopen(argv[2], "r");

	//If the files DNE
	if(input == NULL || search == NULL)
	{
		printf("Not all files exist. Exiting program...\n");
		return 1;
	}

	BST* root = NULL;
	rootList* head = NULL;


	//Inserts values into the BST
	int insertValue, treeNum = 1;
	while(fscanf(input, "%d", &insertValue) != EOF)
	{
		if(insertValue == -1)
		{
			++treeNum;
			insert_rootList(&head, root);
			root = NULL;
		}
		else
		{
			insert_BST(&root, insertValue, treeNum);
		}

	}

	printTrees(head);

	//Prints out the trees and searches for values within the trees
	//Calls the free functions
	int searchValue;
	printf("Number %-7s%-7s%-7s\n", "Found", "Tree", "Level");
	while(fscanf(search, "%d", &searchValue) != EOF)
	{
		BFS(head, searchValue);
	}

	//Closes files
	fclose(input);
	fclose(search);

	//Calls the free functions
	free_list(&head);

    return 0;
}