From 1025cfd38d2f1ca7095de9f808b52cae0f083802 Mon Sep 17 00:00:00 2001 From: vidsinghal Date: Sun, 8 Oct 2023 13:14:26 -0400 Subject: [PATCH] fix the handling of gibbon runtime args and usage help --- gibbon-rts/rts-c/gibbon_rts.c | 65 ++++++++++++++++++++--------------- 1 file changed, 38 insertions(+), 27 deletions(-) diff --git a/gibbon-rts/rts-c/gibbon_rts.c b/gibbon-rts/rts-c/gibbon_rts.c index 25b1eaea6..852728b0a 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 timing iterations to perform (default 1).\n"); + printf(" --size-param A parameter for size available as a language primitive which allows user to specify the size at runtime (default 1).\n"); return; } @@ -1864,6 +1870,14 @@ int dbgprintf(const char *format, ...) return code; } +void check_args(int i, int argc, char**argv, char* parameter){ + if (i+1 >= argc) { + fprintf(stderr, "Not enough arguments after %s, expected .\n", parameter); + gib_show_usage(argv); + exit(1); + } +} + /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ * RTS initialization and clean up @@ -1914,7 +1928,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,57 +1937,54 @@ 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) { + check_args(i, argc, argv, "--biginf-buffer-size"); 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) { + check_args(i, argc, argv, "--inf-buffer-size"); gib_global_inf_init_chunk_size = atoll(argv[i + 1]); i++; } else if ((strcmp(argv[i], "--bench-input") == 0)) { - if (i+1 >= argc) { - fprintf(stderr, "Not enough arguments after --bench-input, expected .\n"); - gib_show_usage(argv); - exit(1); - } + check_args(i, argc, argv, "--bench-input"); gib_global_benchfile_param = argv[i+1]; i++; } else if ((strcmp(argv[i], "--array-input") == 0)) { - if (i+1 >= argc) { - fprintf(stderr, "Not enough arguments after --array-input, expected .\n"); - gib_show_usage(argv); - exit(1); - } + check_args(i, argc, argv, "--array-input"); gib_global_arrayfile_param = argv[i+1]; i++; } else if (strcmp(argv[i], "--array-input-length") == 0 && i < argc - 1) { + check_args(i, argc, argv, "--array-input-length"); gib_global_arrayfile_length_param = atoll(argv[i+1]); i++; } else if (strcmp(argv[i], "--bench-prog") == 0 && i < argc - 1) { + check_args(i, argc, argv, "--bench-prog"); 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)) { + check_args(i, argc, argv, "--iterate"); + gib_global_iters_param = atoll(argv[i+1]); + i++; + } + else if ((strcmp(argv[i], "--size-param") == 0)) { + check_args(i, argc, argv, "--size-param"); + 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]); - } } }