Skip to content

Commit b8facf4

Browse files
authored
Merge pull request #228 from iu-parfunc/fix_gibbon_runtime_args
Fix the handling of gibbon runtime args and usage help
2 parents 209a90d + 2fd1098 commit b8facf4

File tree

1 file changed

+39
-27
lines changed

1 file changed

+39
-27
lines changed

gibbon-rts/rts-c/gibbon_rts.c

Lines changed: 39 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1796,13 +1796,20 @@ void gib_show_usage(char** argv)
17961796
printf("\n");
17971797
printf("This binary was generated by the Gibbon compiler.\n");
17981798
printf("\n");
1799-
printf("Usage: %s [OPTS] [size] [iters]\n", argv[0]);
1799+
printf("Usage: %s [OPTIONS...]\n", argv[0]);
18001800

18011801
printf("\n");
18021802
printf("Options:\n");
1803-
printf(" --buffer-size <bytes> Set the buffer size (default %" PRId64 ").\n", gib_global_biginf_init_chunk_size);
1804-
printf(" --bench-input <path> Set the input file read for benchmarking. Applies only\n");
1805-
printf(" IF the program was *compiled* with --bench-fun. \n");
1803+
printf(" --biginf-buffer-size <bytes> Set the buffer size (default %" PRId64 ").\n", gib_global_biginf_init_chunk_size);
1804+
printf(" --inf-buffer-size <bytes> Set the buffer size (default %" PRId64 ").\n", gib_global_inf_init_chunk_size);
1805+
printf(" --bench-input <path> Set the input file read for benchmarking. Applies only\n");
1806+
printf(" If the program was *compiled* with --bench-fun. \n");
1807+
printf("\n");
1808+
printf(" --array-input <path> Set the file from which to read the array input.\n");
1809+
printf(" --array-input-length <int> Set the size of the array input file.\n");
1810+
printf(" --iterate <int> Set the number of timing iterations to perform (default 1).\n");
1811+
// TODO: Rectify the definition of size-param
1812+
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");
18061813
return;
18071814
}
18081815

@@ -1864,6 +1871,14 @@ int dbgprintf(const char *format, ...)
18641871
return code;
18651872
}
18661873

1874+
void check_args(int i, int argc, char **argv, char *parameter){
1875+
if (i+1 >= argc) {
1876+
fprintf(stderr, "Not enough arguments after %s, expected <int>.\n", parameter);
1877+
gib_show_usage(argv);
1878+
exit(1);
1879+
}
1880+
}
1881+
18671882

18681883
/* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
18691884
* RTS initialization and clean up
@@ -1914,7 +1929,7 @@ int gib_init(int argc, char **argv)
19141929
}
19151930
#endif
19161931

1917-
int got_numargs = 0; // How many numeric arguments have we got.
1932+
int got_numargs = argc; // How many numeric arguments have we got.
19181933

19191934
int i;
19201935
for (i = 1; i < argc; ++i)
@@ -1923,57 +1938,54 @@ int gib_init(int argc, char **argv)
19231938
gib_show_usage(argv);
19241939
exit(0);
19251940
}
1926-
else if (strcmp(argv[i], "--biginf-buffer-size") == 0 && i < argc - 1)
1927-
{
1941+
else if (strcmp(argv[i], "--biginf-buffer-size") == 0 && i < argc - 1) {
1942+
check_args(i, argc, argv, "--biginf-buffer-size");
19281943
gib_global_biginf_init_chunk_size = atoll(argv[i + 1]);
19291944
i++;
19301945
}
1931-
else if (strcmp(argv[i], "--inf-buffer-size") == 0 && i < argc - 1)
1932-
{
1946+
else if (strcmp(argv[i], "--inf-buffer-size") == 0 && i < argc - 1) {
1947+
check_args(i, argc, argv, "--inf-buffer-size");
19331948
gib_global_inf_init_chunk_size = atoll(argv[i + 1]);
19341949
i++;
19351950
}
19361951
else if ((strcmp(argv[i], "--bench-input") == 0)) {
1937-
if (i+1 >= argc) {
1938-
fprintf(stderr, "Not enough arguments after --bench-input, expected <file>.\n");
1939-
gib_show_usage(argv);
1940-
exit(1);
1941-
}
1952+
check_args(i, argc, argv, "--bench-input");
19421953
gib_global_benchfile_param = argv[i+1];
19431954
i++;
19441955
}
19451956
else if ((strcmp(argv[i], "--array-input") == 0)) {
1946-
if (i+1 >= argc) {
1947-
fprintf(stderr, "Not enough arguments after --array-input, expected <file>.\n");
1948-
gib_show_usage(argv);
1949-
exit(1);
1950-
}
1957+
check_args(i, argc, argv, "--array-input");
19511958
gib_global_arrayfile_param = argv[i+1];
19521959
i++;
19531960
}
19541961
else if (strcmp(argv[i], "--array-input-length") == 0 && i < argc - 1) {
1962+
check_args(i, argc, argv, "--array-input-length");
19551963
gib_global_arrayfile_length_param = atoll(argv[i+1]);
19561964
i++;
19571965
}
19581966
else if (strcmp(argv[i], "--bench-prog") == 0 && i < argc - 1) {
1967+
check_args(i, argc, argv, "--bench-prog");
19591968
int len = strlen(argv[i+1]);
19601969
gib_global_bench_prog_param = (char*) gib_alloc((len+1)*sizeof(char));
19611970
strncpy(gib_global_bench_prog_param,argv[i+1],len);
19621971
i++;
19631972
}
1973+
else if ((strcmp(argv[i], "--iterate") == 0)) {
1974+
check_args(i, argc, argv, "--iterate");
1975+
gib_global_iters_param = atoll(argv[i+1]);
1976+
i++;
1977+
}
1978+
else if ((strcmp(argv[i], "--size-param") == 0)) {
1979+
check_args(i, argc, argv, "--size-param");
1980+
gib_global_size_param = atoll(argv[i+1]);
1981+
i++;
1982+
}
19641983
// If present, we expect the two arguments to be <size> <iters>
1965-
else if (got_numargs >= 2) {
1984+
else {
19661985
fprintf(stderr, "Extra arguments left over: ");
19671986
for(; i < argc; i++) fprintf(stderr, "%s ", argv[i]);
19681987
gib_show_usage(argv);
19691988
exit(1);
1970-
} else {
1971-
if (got_numargs == 0) {
1972-
gib_global_size_param = atoll(argv[i]);
1973-
got_numargs ++;
1974-
} else {
1975-
gib_global_iters_param = atoll(argv[i]);
1976-
}
19771989
}
19781990
}
19791991

0 commit comments

Comments
 (0)