Skip to content

Commit

Permalink
fix the handling of gibbon runtime args and usage help
Browse files Browse the repository at this point in the history
  • Loading branch information
vidsinghal committed Oct 9, 2023
1 parent 209a90d commit 1f35fd1
Showing 1 changed file with 38 additions and 27 deletions.
65 changes: 38 additions & 27 deletions gibbon-rts/rts-c/gibbon_rts.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 <bytes> Set the buffer size (default %" PRId64 ").\n", gib_global_biginf_init_chunk_size);
printf(" --bench-input <path> Set the input file read for benchmarking. Applies only\n");
printf(" IF the program was *compiled* with --bench-fun. \n");
printf(" --biginf-buffer-size <bytes> Set the buffer size (default %" PRId64 ").\n", gib_global_biginf_init_chunk_size);
printf(" --inf-buffer-size <bytes> Set the buffer size (default %" PRId64 ").\n", gib_global_inf_init_chunk_size);
printf(" --bench-input <path> 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 <path> Set the file from which to read the array input.\n");
printf(" --array-input-length <int> Set the size of the array input file.\n");
printf(" --iterate <int> Set the number of timing iterations to perform (default 1).\n");
printf(" --size-param <int> A parameter for size available as a language primitive which allows user to specify the size at runtime (default 1).\n");
return;
}

Expand Down Expand Up @@ -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 <int>.\n", parameter);
gib_show_usage(argv);
exit(1);
}
}


/* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
* RTS initialization and clean up
Expand Down Expand 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)
Expand All @@ -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 <file>.\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 <file>.\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 <size> <iters>
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]);
}
}
}

Expand Down

0 comments on commit 1f35fd1

Please sign in to comment.