diff --git a/gibbon-rts/rts-c/gibbon_rts.c b/gibbon-rts/rts-c/gibbon_rts.c index 25b1eaea6..ea6e3ce96 100644 --- a/gibbon-rts/rts-c/gibbon_rts.c +++ b/gibbon-rts/rts-c/gibbon_rts.c @@ -1796,13 +1796,19 @@ void gib_show_usage(char** argv) printf("\n"); printf("This binary was generated by the Gibbon compiler.\n"); printf("\n"); - printf("Usage: %s [OPTS] [size] [iters]\n", argv[0]); + printf("Usage: %s [OPTIONS...]\n", argv[0]); printf("\n"); printf("Options:\n"); - printf(" --buffer-size Set the buffer size (default %" PRId64 ").\n", gib_global_biginf_init_chunk_size); - printf(" --bench-input Set the input file read for benchmarking. Applies only\n"); - printf(" IF the program was *compiled* with --bench-fun. \n"); + printf(" --biginf-buffer-size Set the buffer size (default %" PRId64 ").\n", gib_global_biginf_init_chunk_size); + printf(" --inf-buffer-size Set the buffer size (default %" PRId64 ").\n", gib_global_inf_init_chunk_size); + printf(" --bench-input Set the input file read for benchmarking. Applies only\n"); + printf(" IF the program was *compiled* with --bench-fun. \n"); + printf("\n"); + printf(" --array-input Set the file from which to read the array input.\n"); + printf(" --array-input-length Set the size of the array input file.\n"); + printf(" --iterate Set the number of iterations to perform (default 1).\n"); + printf(" --size-param Set the size param (default 1).\n"); return; } @@ -1914,7 +1920,7 @@ int gib_init(int argc, char **argv) } #endif - int got_numargs = 0; // How many numeric arguments have we got. + int got_numargs = argc; // How many numeric arguments have we got. int i; for (i = 1; i < argc; ++i) @@ -1923,13 +1929,21 @@ int gib_init(int argc, char **argv) gib_show_usage(argv); exit(0); } - else if (strcmp(argv[i], "--biginf-buffer-size") == 0 && i < argc - 1) - { + else if (strcmp(argv[i], "--biginf-buffer-size") == 0 && i < argc - 1){ + if (i+1 >= argc) { + fprintf(stderr, "Not enough arguments after --biginf-buffer-size, expected .\n"); + gib_show_usage(argv); + exit(1); + } gib_global_biginf_init_chunk_size = atoll(argv[i + 1]); i++; } - else if (strcmp(argv[i], "--inf-buffer-size") == 0 && i < argc - 1) - { + else if (strcmp(argv[i], "--inf-buffer-size") == 0 && i < argc - 1){ + if (i+1 >= argc) { + fprintf(stderr, "Not enough arguments after --inf-buffer-size, expected .\n"); + gib_show_usage(argv); + exit(1); + } gib_global_inf_init_chunk_size = atoll(argv[i + 1]); i++; } @@ -1952,28 +1966,49 @@ int gib_init(int argc, char **argv) i++; } else if (strcmp(argv[i], "--array-input-length") == 0 && i < argc - 1) { + if (i+1 >= argc) { + fprintf(stderr, "Not enough arguments after --array-input-length, expected .\n"); + gib_show_usage(argv); + exit(1); + } gib_global_arrayfile_length_param = atoll(argv[i+1]); i++; } else if (strcmp(argv[i], "--bench-prog") == 0 && i < argc - 1) { + if (i+1 >= argc) { + fprintf(stderr, "Not enough arguments after --bench-prog, expected .\n"); + gib_show_usage(argv); + exit(1); + } int len = strlen(argv[i+1]); gib_global_bench_prog_param = (char*) gib_alloc((len+1)*sizeof(char)); strncpy(gib_global_bench_prog_param,argv[i+1],len); i++; } + else if ((strcmp(argv[i], "--iterate") == 0)) { + if (i+1 >= argc) { + fprintf(stderr, "Not enough arguments after --iterate, expected .\n"); + gib_show_usage(argv); + exit(1); + } + gib_global_iters_param = atoll(argv[i+1]); + i++; + } + else if ((strcmp(argv[i], "--size-param") == 0)) { + if (i+1 >= argc) { + fprintf(stderr, "Not enough arguments after --size-param, expected .\n"); + gib_show_usage(argv); + exit(1); + } + gib_global_size_param = atoll(argv[i+1]); + i++; + } // If present, we expect the two arguments to be - else if (got_numargs >= 2) { + else{ fprintf(stderr, "Extra arguments left over: "); for(; i < argc; i++) fprintf(stderr, "%s ", argv[i]); gib_show_usage(argv); exit(1); - } else { - if (got_numargs == 0) { - gib_global_size_param = atoll(argv[i]); - got_numargs ++; - } else { - gib_global_iters_param = atoll(argv[i]); - } } }