iadd code to detect efl_super(XXX_class_get())

This commit is contained in:
Marcel Hollerbach 2020-06-17 15:53:51 +02:00
parent 15c292b861
commit fda52b9fad
6 changed files with 89 additions and 22 deletions

View File

@ -448,7 +448,8 @@ foreach package : subprojects
src, pub_eo_file_target, priv_eo_file_target,
include_directories: efl_one_include_dirs,
dependencies: external_deps + efl_one_eo_deps,
c_args : package_c_args,
c_args : [ '-fplugin=' + myplugin.full_path()] + package_c_args,
depends_on : myplugin
)
# dependency for all the .eo file targets
efl_one_eo_deps += declare_dependency(

View File

@ -35,7 +35,7 @@
#include "ggc.h"
#include "timevar.h"
#include "params.h"
//#include "params.h"
#if BUILDING_GCC_VERSION <= 4009
#include "pointer-set.h"
@ -847,19 +847,19 @@ static inline gimple gimple_build_assign_with_ops(enum tree_code subcode, tree l
return gimple_build_assign(lhs, subcode, op1, op2 PASS_MEM_STAT);
}
template <>
/*template <>
template <>
inline bool is_a_helper<const ggoto *>::test(const_gimple gs)
{
return gs->code == GIMPLE_GOTO;
}
}*/
template <>
/*template <>
template <>
inline bool is_a_helper<const greturn *>::test(const_gimple gs)
{
return gs->code == GIMPLE_RETURN;
}
}*/
static inline gasm *as_a_gasm(gimple stmt)
{

View File

@ -19,7 +19,7 @@ myplugin_dep = custom_target('myplugin',
compiler_plugin = declare_dependency()
test_1 = executable('test-1', 'test-1.c', myplugin_dep,
c_args: [ '-fdump-passes', '-fplugin=' + myplugin.full_path() ],
c_args: [ '-fdump-tree-gimple', '-fplugin=' + myplugin.full_path(), ],
native: true,
)
test('test_1', test_1)

View File

@ -23,6 +23,7 @@ static void super2_add(gimple_stmt_iterator *gsi)
int frequency;
basic_block bb;
stmt = gimple_build_call(super2_function_decl, 0);
super2_func = as_a_gcall(stmt);
gsi_insert_after(gsi, super2_func, GSI_CONTINUE_LINKING);
@ -36,12 +37,71 @@ static void super2_add(gimple_stmt_iterator *gsi)
super2_func, bb->count, frequency);
}
struct Caller {
bool valid;
const char *called_api;
const char *klass;
};
typedef struct _Fetch_Result {
bool valid;
const char *api_name;
const_gimple first_argument;
} Fetch_Result;
static Fetch_Result
_fetch_first_argument(const_gimple arg, unsigned int narg)
{
Fetch_Result ret = {false, NULL, {}};
if (gimple_call_num_args(arg) < narg + 1) return ret;
tree first_argument = gimple_call_arg(arg, narg);
if (!first_argument) return ret;
if (TREE_CODE(first_argument) != SSA_NAME) return ret;
ret.first_argument = SSA_NAME_DEF_STMT(first_argument);
if (!ret.first_argument) return ret;
if (!is_gimple_call(ret.first_argument)) return ret;
tree tmp = gimple_call_fndecl(ret.first_argument);
if (!tmp) return ret;
ret.api_name = IDENTIFIER_POINTER(DECL_NAME(tmp));
ret.valid = true;
return ret;
}
/**
* Check that the first argument is a call to efl_super, and fetch the class function from it.
* As a result, this gives a boolean flag if the result is valid or not.
* If false, called_api and klass are invalid
* If true, klass is the class this is supering on, and called_api contains the API call
*
*/
static Caller fetch_efl_super_class(const_gimple stmt)
{
Caller ret = {false, NULL, NULL};
//check that we have efl_super as the first argument
Fetch_Result first = _fetch_first_argument(stmt, 0);
if (!first.valid) return ret;
tree called_api_tree = gimple_call_fndecl(first.first_argument);
ret.called_api = IDENTIFIER_POINTER(DECL_NAME(called_api_tree));
if (!!strncmp(first.api_name, "efl_super", 9)) return ret;
//copy the name we have inside efl_super
Fetch_Result argument_efl_super = _fetch_first_argument(first.first_argument, 1);
if (!argument_efl_super.valid) return ret;
ret.klass = argument_efl_super.api_name;
ret.valid = true;
return ret;
}
static unsigned int eo_execute(void)
{
basic_block bb, entry_bb;
gimple_stmt_iterator gsi;
//fprintf(stderr, "Function %s called\n", get_name(cfun->decl));
//fprintf(stderr, "Function %s eval\n", get_name(cfun->decl));
gcc_assert(single_succ_p(ENTRY_BLOCK_PTR_FOR_FN(cfun)));
entry_bb = single_succ(ENTRY_BLOCK_PTR_FOR_FN(cfun));
@ -51,16 +111,15 @@ static unsigned int eo_execute(void)
for (gsi = gsi_start_bb(bb); !gsi_end_p(gsi); gsi_next(&gsi))
{
stmt = gsi_stmt(gsi);
if (is_gimple_call(stmt)){
tree current_fn_decl = gimple_call_fndecl(stmt);
if (!current_fn_decl)
continue;
const char* name = IDENTIFIER_POINTER(DECL_NAME(current_fn_decl));
if (!strncmp(name, "efl_super", 9)) {
fprintf(stderr, "Found function %s\n", name);
super2_add(&gsi);
}
}
if (!stmt || !is_gimple_call(stmt)) continue;
struct Caller c = fetch_efl_super_class(stmt);
if (!c.klass)
continue;
fprintf(stderr, "Found call of %s as super of %s\n", c.called_api, c.klass);
//FIXME work
}
}
return 0;

View File

@ -1,11 +1,19 @@
#include <stdio.h>
void efl_super2(void){}
int efl_super(void) {
void *empty_class_get(void){
return NULL;
}
void* efl_super(void *v){
printf("asdfasdf %p\n", v);
return v;
}
void efl_super2(void *v, const char *asdf){
printf("asdfasdfasdf222 %p %s\n", v, asdf);
}
int main(void)
{
efl_super();
efl_super2(efl_super(empty_class_get()), "asdf");
return 0;
}

View File

@ -355,7 +355,6 @@ _obj_accessor_get_at(void *data, Efl_Ui_Position_Manager_Request_Range range, Ei
return result;
}
EOLIAN static Efl_Object*
_efl_ui_collection_efl_object_constructor(Eo *obj, Efl_Ui_Collection_Data *pd EINA_UNUSED)
{