#include #include #include #include #include #include "debug.h" #include "desc.h" #include "prim.h" #include "parse.h" #include "code.h" #include "mem.h" long readfile(char **string, FILE *f) { fseek(f, 0, SEEK_END); long fsize = ftell(f); fseek(f, 0, SEEK_SET); *string = (char*) malloc(fsize); fread(*string, fsize, 1, f); fclose(f); return fsize; } int main ( int argc, char *argv[] ) { init_mem(); init_desc(); init_prim(); char* input = "..\\tests\\Braun.bsapl"; if ( argc == 2 ) { input = argv[1]; } FILE* file = fopen(input, "r"); char* line = NULL; long len = 0; if ( file == 0 ) { printf( "Could not open file\n" ); exit(-1); } else { len = readfile(&line, file); if(len < 0) { printf( "No Input\n" ); } fclose( file ); if(len < 0) exit(-1); } #ifdef DEBUG printf("sizeof(int): %d, sizeof(long): %d, sizeof(void*): %d, sizeof(Thunk): %d\n\n", sizeof(int), sizeof(long), sizeof(void*), sizeof(Thunk)); #endif int nrfuns = parse(&line, len); #ifdef DEBUG printf("Number of functions parsed: %d\n", nrfuns); #endif if(nrfuns<=0) { exit(0); } // TODO: put it into a special "expression" space, instead of "code" char *exprstream = "A0 F4 main"; Code* expr = parseTerm(&exprstream); #ifdef BENCHMARK struct timeval t1, t2; gettimeofday(&t1, NULL); #endif push_a(NULL); exec(expr, stack_top_a, stack_top_a, stack_top_b); Thunk* res = pop_a(); #ifdef BENCHMARK gettimeofday(&t2, NULL); #endif print(res, true); #ifdef BENCHMARK // compute and print the elapsed time in millisec double elapsedTime = (t2.tv_sec - t1.tv_sec) * 1000.0; // sec to ms elapsedTime += (t2.tv_usec - t1.tv_usec) / 1000.0; // us to ms printf("\n\nexecution time: %G ms\n", elapsedTime); #endif #ifdef DEBUG print_stat(); #endif exit(0); }