This is the mail archive of the gcc-help@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re : [Generic] CALL_EXPR tree code with object ref





----- Message d'origine ----
De : Ian Lance Taylor <iant@google.com>
À : charfi asma <charfiasma@yahoo.fr>
Cc : gcc-help@gcc.gnu.org
Envoyé le : Jeu 4 novembre 2010, 19h 48min 53s
Objet : Re: [Generic] CALL_EXPR tree code with object ref

charfi asma <charfiasma@yahoo.fr> writes:

> 1. I tried to follow the cp front end, but I get errors related to GTY.

What errors?

> I tried to include class.c, call.c or method.c to reuse the defined functions 
> like build_this_parm to add the param "this" to the call_exp, because when I 
> look at the gimple generated from the c++ call I find that I have to add "this" 
>
> to the 
>
> function decl and add it also to the call_expr (&c)

You for sure can't literally include class.c or any other C++ file.  You
need to read and understand what the code is doing, and write a version
of the code appropriate for your scenario.  For something like this,
think of GIMPLE as a simple programming language, and think about what
you want the code to look like.

> 2. I tried also to use the tree code defined in tree.def like COMPONENT_REF 
>(but 
>
>
> it is only used for FIELD_DECL and not TYPE_METHOD of a RECORD_TYPE)

It does not make sense to use a COMPONENT_REF on a TYPE_METHOD.  A
COMPONENT_REF is referring to a field in a struct, like "s.f".

You are getting hung up on the fact that RECORD_TYPE has a TYPE_METHODS
field.  I'm trying to tell you that the TYPE_METHODS field means nothing
to the middle-end.  It's there for the use of the frontend.  You need to
ignore TYPE_METHODS, and focus on what the code you want to generate.

> 3. I tried to use OBJ_TYPE_REF tree code defined in tree.def to get the ref to 

> an object but I can not find a build_obj_type_ref in the tree.c  to use it 
>(just 
>
>
> like build_call_exp ).

To build an OBJ_TYPE_REF just use build3.  See the C++ frontend for
examples.  But OBJ_TYPE_REF won't help you because the very first
parameter is the expression it is supposed to evaluate.  You need to
figure out how to write that expression for your language.

Ian

Hello,

thanks Ian for all your help.
I succeed in calling a method using a specific instance of a class by adding 
"this" param that refer to the object (the instance) in the parm list of that 
method (just like cp front end)

tree operation_type = build_method_type_directly (class_t, void_type_node, 
NULL_TREE); 

tree operation = build_decl(BUILTINS_LOCATION, FUNCTION_DECL, 
get_identifier("MyOperation"), operation_type);
tree parm = build_decl (BUILTINS_LOCATION, PARM_DECL, get_identifier("this"), 
build_pointer_type(class_t));

tree ptr_obj = build1(ADDR_EXPR, build_pointer_type(TREE_TYPE(object)),object);
tree __call_expr = build_call_expr(__field2, 1, ptr_obj); 

now I get nearly the same gimple that cp front end produce

1. My Gimple:

main ()
gimple_bind <
  <unnamed-signed:32> D.24;
  struct MyClass x;

  gimple_call <MyOperation, NULL, &x>
  gimple_assign <integer_cst, D.24, 1200, NULL>
  gimple_return <D.24>
>

MyOperation (struct MyClass * this)
gimple_bind <

>
/***********************************************************************/
2. cp gimple

int main() ()
gimple_bind <
  int D.1700;

  gimple_bind <
    struct MyClass c;

    gimple_call <MyOperation, NULL, &c>
    gimple_assign <integer_cst, D.1700, 0, NULL>
    gimple_return <D.1700>
  >
  gimple_assign <integer_cst, D.1700, 0, NULL>
  gimple_return <D.1700>
>

void MyClass::MyOperation() (struct MyClass * const this)
gimple_bind <
  GIMPLE_NOP
>
/***************************************************************************/
thank you again

Asma





Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]