From 46c574b694557ae6e94330268a8e85d3289277c7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Th=C3=A9otime=20DONNENFELD?= <theotime.donnenfeld@ensiie.fr> Date: Sun, 21 Oct 2018 16:17:42 +0200 Subject: [PATCH] Added first version of pragmas --- functions/pragma.c | 90 ++++++++++++++++++++++++++++++++++++++++++++++ functions/pragma.h | 9 +++++ plugin.cpp | 15 ++------ 3 files changed, 101 insertions(+), 13 deletions(-) create mode 100644 functions/pragma.c create mode 100644 functions/pragma.h diff --git a/functions/pragma.c b/functions/pragma.c new file mode 100644 index 0000000..95085db --- /dev/null +++ b/functions/pragma.c @@ -0,0 +1,90 @@ +#include "pragma.h" + +static void my_pragma_action(cpp_reader *ARG_UNUSED(dummy)) +{ + printf("****** Pragam detected: ******\n"); + enum cpp_ttype token; + tree x; + const char* elt; + token = pragma_lex (&x); + bool close_paren_needed_p = false; + bool correct_pragma_names = true; + bool is_in_array=false; + if (cfun){ + printf("!!Pragma placed inside function!!\n"); + correct_pragma_names = false; + return; + } + + + if (token == CPP_OPEN_PAREN){ + close_paren_needed_p = true; + token = pragma_lex (&x); + } + + if (token == CPP_NAME){ + tree args = NULL_TREE; + + do + { + if (TREE_STRING_LENGTH (x) > 0) + args = tree_cons (NULL_TREE, x, args); + + printf("Arg found : %s\n", IDENTIFIER_POINTER(x)); + is_in_array = false; + for (int ix = 0; pragma_func_names.iterate (ix, &elt); ix++){ + if(strcmp(elt,IDENTIFIER_POINTER(x))){ + is_in_array = true; + } + } + if(is_in_array) + pragma_func_names_temp.safe_push(IDENTIFIER_POINTER(x)); + token = pragma_lex (&x); + //Cleans COMAS + while (token == CPP_COMMA){ + token = pragma_lex (&x); + + } + + + }while (token == CPP_NAME); + + if(close_paren_needed_p){ + if (token == CPP_CLOSE_PAREN){ + token = pragma_lex (&x); + + } + else{ + printf("Missing closed parenthesis\n"); + correct_pragma_names = false; + return; + } + } + + } + else{ + printf("Invalid pragma - not starting with name or open parenthesis\n"); + return; + } + + if (token != CPP_EOF) + { + printf("Error : arg read but EOL not reached"); + correct_pragma_names = false; + return; + } + + while(pragma_func_names_temp.length() != 0 && correct_pragma_names){ + pragma_func_names.safe_push(pragma_func_names_temp.pop()); + } + + printf("\n\n"); +} + + +static void register_my_pragma(void *event_data, void *data) +{ + c_register_pragma ("instrumente", "function", my_pragma_action); +} + + diff --git a/functions/pragma.h b/functions/pragma.h new file mode 100644 index 0000000..625efe5 --- /dev/null +++ b/functions/pragma.h @@ -0,0 +1,9 @@ +#ifndef __PRAGMADD__H +#define __PRAGMADD__H + +vec<const char*> pragma_func_names; +vec<const char*> pragma_func_names_temp; +static void register_my_pragma(void *event_data, void *data); +static void my_pragma_action(cpp_reader *ARG_UNUSED(dummy)); + +#endif diff --git a/plugin.cpp b/plugin.cpp index ae48b07..566b6b3 100755 --- a/plugin.cpp +++ b/plugin.cpp @@ -22,6 +22,8 @@ #include "./functions/graph.c" #include "./functions/MPI_functions.h" #include "./functions/MPI_functions.c" +#include "./functions/pragma.h" +#include "./functions/pragma.c" int plugin_is_GPL_compatible; @@ -53,19 +55,6 @@ const pass_data cleanup_pass_data = }; -static void my_pragma_action(cpp_reader *ARG_UNUSED(dummy)) -{ - printf("****** Pragma detected: ******\n"); - printf("\n"); -} - - -static void register_my_pragma(void *event_data, void *data) -{ - c_register_pragma ("instrumente", "function", my_pragma_action); -} - - class split_count_pass : public gimple_opt_pass { public: -- GitLab