Пример #1
0
// ---------------------------------------------------------------------
//  make_updatable_input
// ---------------------------------------------------------------------
char* make_updatable_input(test_t* test) {
    int i,j;

    // allocate input matrices
    test->A = (int**)malloc(test->n*sizeof(int*));
    test->B = (int**)malloc(test->n*sizeof(int*));
    test->C = (int**)malloc(test->n*sizeof(int*));
    if (!test->A || !test->B || !test->C) 
        return "cannot initialize reactive input matrices";

    for (i=0; i<test->n; i++) {

        if (cmp_param(test->update_family, "_", 0, "arow")) {
            test->A[i] = (int*)dc_malloc(test->n*sizeof(int));
            test->B[i] = (int*)malloc(test->n*sizeof(int));
        }

        else if (cmp_param(test->update_family, "_", 0, "bcol")) {
            test->A[i] = (int*)malloc(test->n*sizeof(int));
            test->B[i] = (int*)dc_malloc(test->n*sizeof(int));
        }

        else if (cmp_param(test->update_family, "_", 0, "arow/bcol")) {
            test->A[i] = (int*)dc_malloc(test->n*sizeof(int));
            test->B[i] = (int*)dc_malloc(test->n*sizeof(int));
        }

        else return "unknown update family";

        test->C[i] = (int*)dc_malloc(test->n*sizeof(int));

        if (!test->A[i] || !test->B[i] || !test->C[i]) 
            return "cannot initialize reactive input matrices";
    }

    // init A and B: at the beginning, A and B contain 1 everywhere;
    // the output matrix C is initialized in matmat_new
    for (i=0; i<test->n; i++) 
        for (j=0; j<test->n; j++) 
            test->A[i][j] = test->B[i][j] = 1;

    // make checks
    #if CHECK
    if (test->check) {
    }
    #endif

    return NULL;
}
Пример #2
0
// ---------------------------------------------------------------------
// make_test
// ---------------------------------------------------------------------
test_t* make_test(size_t input_size, 
                  int seed, 
                  char* input_family, 
                  char* update_family, 
                  int check_correctness) {

    test_t* test = (test_t*)malloc(sizeof(test_t));
    if (test == NULL) return NULL;

    test->seed = seed;
    test->num_updates = 0;
    test->input_family = input_family;
    test->update_family = update_family;
    test->check = check_correctness;

    if (cmp_param(input_family, "_", 0, "square")) {
        if (!get_int_param(input_family, "_", 1, &test->R)) 
            return NULL;
        test->C = test->R;
    }
    else return NULL;

    test->Block = input_size;

    #if CONV || CHECK
    #endif

    return test;
}
Пример #3
0
// ---------------------------------------------------------------------
// do_updates
// ---------------------------------------------------------------------
char* do_updates(test_t* test) {

    // perform update sequence on matrix M
    int i, j, num_updates;

    srand(test->seed);

    // updates of individual random cells of the matrix
    if (cmp_param(test->update_family, "_", 0, "mrnd")) {
        if (!get_int_param(test->update_family, "_", 1, &num_updates)) 
            return "wrong update parameter";

        // perform random updates
        for (j=0; j<num_updates; j++) {
            int r = rand()%test->R;
            int c = rand()%test->C;
            test->M[r][c]++;
            test->num_updates++;
        }    
    }

    // updates of entire random columns of the matrix
    else if (cmp_param(test->update_family, "_", 0, "crnd")) {
        if (!get_int_param(test->update_family, "_", 1, &num_updates)) 
            return "wrong update parameter";

        // perform random updates
        for (j=0; j<num_updates; j++) {

            int c = rand()%test->C;

            dc_begin_at();
            for (i=0; i<test->R; i++) test->M[i][c]++;
            dc_end_at();
            test->num_updates++;
        }    
    }
    else return "unknown update family";
   
    // make correctness checks
    #if CHECK
    if (test->check) {
    }
    #endif
    
    return NULL;
}
Пример #4
0
Файл: main.c Проект: bl0b/tinyap
int do_args(int argc,char*argv[]) {
	int i;
	tinyap_t parser;

	tinyap_init();

	parser = tinyap_new();

	for(i=1;i<argc;i+=1) {
		if(cmp_param(1,"--grammar","-g")) {
			i+=1;
			tinyap_set_grammar(parser,argv[i]);
		} else if(cmp_param(1,"--input","-i")) {
			i+=1;
			tinyap_set_source_file(parser,argv[i]);
		} else if(cmp_param(1,"--output","-o")) {
			i+=1;
			if(tinyap_parsed_ok(parser)&&tinyap_get_output(parser)) {
				tinyap_serialize_to_file(tinyap_get_output(parser),argv[i]);
			/*} else {*/
				/*fprintf(stderr,"parse error at line %i, column %i\n%s\n",tinyap_get_error_row(parser),tinyap_get_error_col(parser),tinyap_get_error(parser));*/
			}
		/*} else if(cmp_param(0,"--relations","-R")) {*/
			/*tinyap_set_output(parser, relations_from_tree(tinyap_get_output(parser)));*/
		} else if(cmp_param(0,"--full-parse=on","-fp")) {
			tinyap_set_full_parse(parser, 1);
		} else if(cmp_param(0,"--simple-parse=on","-sp")) {
			tinyap_set_full_parse(parser, 1);
		} else if(cmp_param(0,"--parse","-p")) {
			tinyap_parse(parser);
			if(tinyap_parsed_ok(parser)&&tinyap_get_output(parser)) {
				/*tinyap_serialize_to_file(tinyap_get_output(parser),argv[i]);*/
				if(tinyap_verbose) {
					fprintf(stderr, "parsed %u bytes in %.3f seconds (%.3f kBps)\n",
							tinyap_get_source_buffer_length(parser),
							tinyap_get_parse_time(parser),
							tinyap_get_source_buffer_length(parser)/tinyap_get_parse_time(parser)*(1./1024));
				}
			} else {
				fprintf(stderr,"parse error at line %i, column %i\n%s\n",tinyap_get_error_row(parser),tinyap_get_error_col(parser),tinyap_get_error(parser));
				/*fprintf(stderr,"parse error at line %i, column %i\n%s\n", -1, -1, "TODO");*/
			}
		} else if(cmp_param(0,"--parse-as-grammar","-pag")) {
			tinyap_parse_as_grammar(parser);
			if(!(tinyap_parsed_ok(parser)&&tinyap_get_grammar_ast(parser))) {
				/*tinyap_serialize_to_file(tinyap_get_output(parser),argv[i]);*/
			/*} else {*/
				fprintf(stderr,"parse error at line %i, column %i\n%s\n",tinyap_get_error_row(parser),tinyap_get_error_col(parser),tinyap_get_error(parser));
				/*fprintf(stderr,"parse error at line %i, column %i\n%s\n", -1, -1, "TODO");*/
			}
		} else if(cmp_param(0,"--print-grammar","-pg")) {
			/*print_rules(tinyap_get_grammar_ast(parser));*/
			/*fputc('\n',stdout);*/

			wast_t grammar, short_gram;
			const char* up;

			grammar = make_wast(tinyap_list_get_element(tinyap_get_grammar_ast(parser), 0));
			short_gram = make_wast(tinyap_list_get_element(tinyap_get_ruleset(GRAMMAR_SHORT), 0));
			up = tinyap_unparse(short_gram, grammar);
			if(up) {
				fputs(up, stdout);
			} else {
				fputs("Couldn't unparse the AST ! :(\n", stderr);
			}
			free((char*)up);
			wa_del(grammar);

		} else if(cmp_param(0,"--verbose","-V")) {
			tinyap_set_verbose(1);
		} else if(cmp_param(0,"--quiet","-q")) {
			tinyap_set_verbose(0);
		} else if(cmp_param(0,"--version","-v")) {
			fprintf(stderr, TINYAP_ABOUT);
			fprintf(stderr, "version " TINYAP_VERSION "\n" );
		} else if(cmp_param(0,"--help","-h")) {

			fprintf(stderr, TINYAP_ABOUT);
			fprintf(stderr, "Usage : %s [--input,-i [inputFile]] [--output,-o [outputFile]] [--grammar,-g [grammarFile]] [--parse,-p] [--parse-as-grammar,-pag] [--walk, -w [pilotName]] [--help,-h] [--version, -v] [--verbose,-V] [--quiet,-q]\n",argv[0]);
			fprintf(stderr, "\n\t--version,-v\tdisplay version\n");
			fprintf(stderr, "\n\t--verbose,-V\toutput messages during parse\n");
			fprintf(stderr, "\n\t--quiet,-q\tdon't output messages during parse (default)\n");
			fprintf(stderr, "\n\t--grammar,-g name\tuse this grammar to parse input\n");
			fprintf(stderr, "\t\t\"" GRAMMAR_SHORT "\"\t(default) selects default meta-grammar\n");
			fprintf(stderr, "\t\tany other string is a filename to read grammar from\n");
			fprintf(stderr, "\n\t--print-grammar,-pg\toutput the current grammar in `explicit' dialect\n");
			fprintf(stderr, "\t\targument is the same as above\n");
			fprintf(stderr, "\n\t--input,-i name \ttext source to use\n");
			fprintf(stderr, "\t\t- (default)\tselects standard input\n");
			fprintf(stderr, "\t\tany other string is a filename to read from\n");
			fprintf(stderr, "\n\t--output,-o name\tredirect serialized AST output\n");
			fprintf(stderr, "\t\t- (default)\tselects standard output\n");
			fprintf(stderr, "\t\tany other string is a filename to write to\n");
			fprintf(stderr, "\n\t--parse,-p\t\tparse input text\n");
			fprintf(stderr, "\n\t--parse-as-grammar,-pag\tparse input text and use output AST as new grammar\n");
			fprintf(stderr, "\n\t--full-parse,-fp\t\tfind all possible parse trees\n");
			fprintf(stderr, "\n\t--simple-parse,-p\t\tfind first parse tree\n");
			fprintf(stderr, "\n\t--walk,-w name\t\twalk the current output tree using named ape\n\t\t\t\t(try prettyprint !)\n");
			fprintf(stderr, "\n\t--help,-h\t\tdisplay this text\n\n");
			exit(0);
		} else if(cmp_param(1,"--walk","-w")) {
			i+=1;
			wast_t wa = tinyap_make_wast(tinyap_list_get_element(tinyap_get_output(parser),0));
			tinyap_walk(wa,argv[i],NULL);
			tinyap_free_wast(wa);
		}
	}

	tinyap_delete(parser);

	/*if(tinyap_verbose) {*/
		/*fprintf(stderr, "maximum recursion level : %i\n", max_rec_level);*/
	/*}*/
	return 0;
}
Пример #5
0
// ---------------------------------------------------------------------
// do_updates
// ---------------------------------------------------------------------
char* do_updates(test_t* test) {

    // perform update sequence on matrix M
    
    int i, j, num_updates;

    srand(test->seed);

    // perform random updates on rows of A
    if (cmp_param(test->update_family, "_", 0, "arow")) {
        if (!get_int_param(test->update_family, "_", 1, &num_updates)) 
            return "wrong update parameter";

        for (j = 0; j < num_updates; j++) {
            int r = rand() % test->n;
            dc_begin_at();
            for (i=0; i<test->n; i++) test->A[r][i]++;
            dc_end_at();
            test->num_updates++;
        }    
    }

    // perform random updates on columns of B
    else if (cmp_param(test->update_family, "_", 0, "bcol")) {

        if (!get_int_param(test->update_family, "_", 1, &num_updates)) 
            return "wrong update parameter";

        for (j = 0; j < num_updates; j++) {
            int c = rand() % test->n;
            dc_begin_at();
            for (i = 0; i < test->n; i++) test->B[i][c]++;
            dc_end_at();
            test->num_updates++;
        }    
    }

    // perform random updates on rows of A and columns of B
    else if (cmp_param(test->update_family, "_", 0, "arow/bcol")) {

        if (!get_int_param(test->update_family, "_", 1, &num_updates)) 
            return "wrong update parameter";

        for (j = 0; j < num_updates; j++) {
            int x = rand() % test->n;
            dc_begin_at();
            if (rand() % 2 == 0)
                 for (i = 0; i < test->n; i++) test->A[x][i]++;
            else for (i = 0; i < test->n; i++) test->B[i][x]++;
            dc_end_at();
            test->num_updates++;
        }    
    }

    else return "unknown update family";

    // make correctness checks
    #if CHECK
    if (test->check) {
    }
    #endif
    
    return NULL;
}