diff --git a/include/io.h b/include/io.h index 4cacc2b..1a65459 100644 --- a/include/io.h +++ b/include/io.h @@ -21,6 +21,7 @@ char *qb_find_path(char *filename); char *qb_config_file(char *path); size_t qb_find_type_size(char *type); +void *qb_string_to_void(char *type, char *value); // String Manipulation bool qb_is_space(char a); diff --git a/include/quibble_args.h b/include/quibble_args.h index 1ed9d3d..8af4cf6 100644 --- a/include/quibble_args.h +++ b/include/quibble_args.h @@ -32,6 +32,9 @@ quibble_kwarg *qb_parse_kwargs(char *config, int num_entries); int qb_find_arg_index(quibble_arg *arg, int n, char *variable); int qb_find_kwarg_index(quibble_kwarg *qk, int n, char *variable); +int qb_find_any_index(quibble_arg *args, int n, + quibble_kwarg *kwargs, int k_n, + char *variable); // prologue char *qb_create_prologue(char *config, char *name, diff --git a/include/quibble_program.h b/include/quibble_program.h index 3e6a1ef..486fb7a 100644 --- a/include/quibble_program.h +++ b/include/quibble_program.h @@ -34,6 +34,8 @@ typedef struct{ typedef struct{ quibble_arg *args; int num_args; + quibble_kwarg *kwargs; + int num_kwargs; char *body; char *name; } quibble_poem; diff --git a/src/io.c b/src/io.c index 78b2e53..81082cd 100644 --- a/src/io.c +++ b/src/io.c @@ -26,6 +26,9 @@ quibble_pixel *qb_create_pixel_array(int height, int width){ return qpa; } +void *qb_string_to_void(char *type, char *value){ +} + size_t qb_find_type_size(char *type){ if (type == NULL){ diff --git a/src/quibble_args.c b/src/quibble_args.c index 8bf6729..4749fe0 100644 --- a/src/quibble_args.c +++ b/src/quibble_args.c @@ -147,12 +147,42 @@ int qb_find_number_of_kwargs(char *config){ } +int qb_find_any_index(quibble_arg *args, int n, + quibble_kwarg *kwargs, int k_n, + char *variable){ + + if (n <= 0 && k_n <= 0){ + return -1; + } + + for (int i = 0; i < n; ++i){ + if (strcmp(args[i].variable, variable) == 0){ + return i; + } + } + + for (int i = 0; i < k_n; ++i){ + if (strcmp(kwargs[i].variable, variable) == 0){ + if (n > 0){ + return i+n; + } + else{ + return i; + } + } + } + + fprintf(stderr, "%s is not an argument or keyword argument!\n", variable); + exit(1); + + +} + int qb_find_arg_index(quibble_arg *qa, int n, char *variable){ if (n <= 0){ return -1; } - for (int i = 0; i < n; ++i){ if (strcmp(qa[i].variable, variable) == 0){ return i; diff --git a/src/quibble_poems.c b/src/quibble_poems.c index 851576f..90d1031 100644 --- a/src/quibble_poems.c +++ b/src/quibble_poems.c @@ -64,14 +64,19 @@ quibble_poem qb_parse_poem(char *poem){ final_poem.args = qb_parse_args(config, final_poem.num_args); + final_poem.num_kwargs = qb_find_number_of_kwargs(config); + final_poem.kwargs = + qb_parse_kwargs(config, final_poem.num_kwargs); + free(config); } else { final_poem.args = NULL; final_poem.num_args = 0; + final_poem.kwargs = NULL; + final_poem.num_kwargs = 0; } - int body_start = qb_find_next_char(poem, offset, '{')+1; int body_end = qb_find_matching_char(poem, poem_size, body_start-1, '{', '}'); @@ -108,24 +113,38 @@ char *qb_expand_poem(quibble_program qp, int poem_index){ strcat(tmp_body, "__kernel void "); strcat(tmp_body, qp.poem_list[poem_index].name); strcat(tmp_body, "("); - if (qp.poem_list[poem_index].num_args > 0){ - //strcat(tmp_body, ", "); - for (int i = 0; i < qp.poem_list[poem_index].num_args; ++i){ + for (int i = 0; i < qp.poem_list[poem_index].num_args; ++i){ - if (qp.poem_list[poem_index].args[i].type != NULL){ - strcat(tmp_body, qp.poem_list[poem_index].args[i].type); - strcat(tmp_body, " "); - } - strcat(tmp_body, qp.poem_list[poem_index].args[i].variable); - if (i == qp.poem_list[poem_index].num_args - 1){ - strcat(tmp_body, "){\n"); - } - else{ - strcat(tmp_body, ", "); - } + if (qp.poem_list[poem_index].args[i].type != NULL){ + strcat(tmp_body, qp.poem_list[poem_index].args[i].type); + strcat(tmp_body, " "); + } + strcat(tmp_body, qp.poem_list[poem_index].args[i].variable); + if (i == qp.poem_list[poem_index].num_args - 1 && + qp.poem_list[poem_index].num_kwargs <= 0){ + strcat(tmp_body, "){\n"); + } + else{ + strcat(tmp_body, ", "); } } - else { + for (int i = 0; i < qp.poem_list[poem_index].num_kwargs; ++i){ + + if (qp.poem_list[poem_index].kwargs[i].type != NULL){ + strcat(tmp_body, qp.poem_list[poem_index].kwargs[i].type); + strcat(tmp_body, " "); + } + strcat(tmp_body, qp.poem_list[poem_index].kwargs[i].variable); + if (i == qp.poem_list[poem_index].num_kwargs - 1){ + strcat(tmp_body, "){\n"); + } + else{ + strcat(tmp_body, ", "); + } + } + + if (qp.poem_list[poem_index].num_kwargs <= 0 && + qp.poem_list[poem_index].num_args <= 0){ strcat(tmp_body, "){\n"); } @@ -276,6 +295,7 @@ void qb_free_poem(quibble_poem qp){ free(qp.body); free(qp.name); qb_free_arg_array(qp.args, qp.num_args); + qb_free_kwarg_array(qp.kwargs, qp.num_kwargs); } void qb_print_poem(quibble_poem qp){ diff --git a/src/quibble_program.c b/src/quibble_program.c index 039b2cc..e0afd86 100644 --- a/src/quibble_program.c +++ b/src/quibble_program.c @@ -742,6 +742,17 @@ void qb_configure_program(quibble_program *qp, int platform, int device){ for (int i = 0; i < qp->num_poems; ++i){ kernels[i] = clCreateKernel(qp->program, qp->poem_list[i].name, &err); + if (qp->poem_list[i].num_kwargs > 0){ + for (int j = 0; j < qp->poem_list[i].num_kwargs; ++j){ + void *data = qb_string_to_void( + qp->poem_list[i].kwargs[j].type, + qp->poem_list[i].kwargs[j].value + ); + qb_set_arg(qp, qp->poem_list[i].name, + qp->poem_list[i].kwargs[j].variable, + data); + } + } cl_check(err); } @@ -777,8 +788,10 @@ void qb_set_arg(quibble_program *qp, char *poem, char *arg, void *data){ qb_find_type_arg(arg, &type, &variable); - int arg_index = qb_find_arg_index(qp->poem_list[poem_index].args, + int arg_index = qb_find_any_index(qp->poem_list[poem_index].args, qp->poem_list[poem_index].num_args, + qp->poem_list[poem_index].kwargs, + qp->poem_list[poem_index].num_kwargs, variable); size_t object_size = qb_find_type_size(type);