Plugin that parse tree

2011-01-23 Thread Daniel Marjamäki
Hello!

I want to write a plugin that parse the AST. Could I get some hint
about how to do it?

I have been reading this excellent article:
http://codesynthesis.com/~boris/blog/2010/05/10/parsing-cxx-with-gcc-plugin-part-2/

The problem is that I fail to follow those advices.

I fail to use 'global_namespace':
daniel@daniel:~/gcc/build/gcc$ ./xgcc -fplugin=./myplugin2.so -c test1.c
cc1: error: cannot load plugin ./myplugin2.so
./myplugin2.so: undefined symbol: global_namespace

Here is the code:

#include "gcc-plugin.h"
#include "cp/cp-tree.h"
#include 

int plugin_is_GPL_compatible;

static void traverse(tree ns)
{
}

void override_gate(void *gcc_data, void *user_data)
{
printf("myplugin1:override_gate\n");

// Process AST
traverse(global_namespace);
}

int
plugin_init (struct plugin_name_args *plugin_info,
 struct plugin_gcc_version *version)
{
printf("myplugin1\n");

register_callback(plugin_info->base_name,
  PLUGIN_OVERRIDE_GATE,
  &override_gate,
  0);

return 0;
}

Best regards,
Daniel Marjamäki


Re: Plugin that parse tree

2011-01-23 Thread Basile Starynkevitch
On Sun, 23 Jan 2011 11:58:21 +0100
Daniel Marjamäki  wrote:

> Hello!
> 
> I want to write a plugin that parse the AST. Could I get some hint
> about how to do it?


You could use GCC MELT for that purpose. See www.gcc-melt.org

Regards
-- 
Basile STARYNKEVITCH http://starynkevitch.net/Basile/
email: basilestarynkevitchnet mobile: +33 6 8501 2359
8, rue de la Faiencerie, 92340 Bourg La Reine, France
*** opinions {are only mine, sont seulement les miennes} ***


Re: Plugin that parse tree

2011-01-23 Thread Daniel Marjamäki
GCC-MELT is an interesting project. But it seems to be very difficult
to write lisp scripts. You don't have a C interface also, do you?

I would like to see how I can use plain C.

Regards,
Daniel


2011/1/23 Basile Starynkevitch :
> On Sun, 23 Jan 2011 11:58:21 +0100
> Daniel Marjamäki  wrote:
>
>> Hello!
>>
>> I want to write a plugin that parse the AST. Could I get some hint
>> about how to do it?
>
>
> You could use GCC MELT for that purpose. See www.gcc-melt.org
>
> Regards
> --
> Basile STARYNKEVITCH         http://starynkevitch.net/Basile/
> email: basilestarynkevitchnet mobile: +33 6 8501 2359
> 8, rue de la Faiencerie, 92340 Bourg La Reine, France
> *** opinions {are only mine, sont seulement les miennes} ***
>


Re: Plugin that parse tree

2011-01-23 Thread Basile Starynkevitch
On Sun, 23 Jan 2011 15:49:48 +0100
Daniel Marjamäki  wrote:

> GCC-MELT is an interesting project. But it seems to be very difficult
> to write lisp scripts. You don't have a C interface also, do you?

The few people who tried writing MELT code are founding on the contrary
that coding in MELT is easier than coding in C (even if I agree that
MELT is not very well documented).

The major MELT idea is on the contrary that coding in MELT, using the
powerful features provided by the MELT language (pattern matching,
functional/applicative & object programming styles), is much easier
than coding in C. And MELT philosophy is indeed that it is a
higher-level language than C (you don't have any pattern matching in C
for instance).

So I disagree with the idea that writing MELT code is difficult (and
harder than writing in C). But it is also matter of taste.
 
> I would like to see how I can use plain C.

In that case, MELT is not really for you. The selling point of MELT is
precisely to avoid the low level details of C and to give something
higher-level to you. If you really want to code in C, don't use MELT.

There is no interface from C to MELT, and there cannot be one... The
purpose of MELT is to avoid coding plugins in C!


>> I want to write a plugin that parse the AST. Could I get some hint
>> about how to do it?

The major issue is to understand all the details of GCC internal
representations (i.e. Trees, Gimples). Did you understand them?

Regards


-- 
Basile STARYNKEVITCH http://starynkevitch.net/Basile/
email: basilestarynkevitchnet mobile: +33 6 8501 2359
8, rue de la Faiencerie, 92340 Bourg La Reine, France
*** opinions {are only mine, sont seulement les miennes} ***


Re: Plugin that parse tree

2011-01-23 Thread Dave Korn
On 23/01/2011 10:58, Daniel Marjamäki wrote:

> I fail to use 'global_namespace':
> daniel@daniel:~/gcc/build/gcc$ ./xgcc -fplugin=./myplugin2.so -c test1.c
> cc1: error: cannot load plugin ./myplugin2.so

  You're running the C compiler (cc1) here, not the C++ one (cc1plus), because
you've passed a file with the plain .c extension to the driver.

> ./myplugin2.so: undefined symbol: global_namespace

  So it doesn't have this global variable that only exists in cc1plus.

  Either change your test file to .cpp, or add "-x c++" to the command-line.

  In general, as long as your plugin refers to global_namespace directly, it's
not going to be compatible with any of the other language sub-compilers apart
from cc1plus.  If you wanted it to work with any kind of language, I think
you'd need to look up global_namespace using dlsym (and handle the case when
it was not found), rather than linking against it directly.

cheers,
  DaveK



Re: Plugin that parse tree

2011-01-23 Thread Daniel Marjamäki
Hello!

>  Either change your test file to .cpp, or add "-x c++" to the command-line.

that worked. thank you.

I don't want to limit my plugin to C++. But to start with it is ok.

> The major issue is to understand all the details of GCC internal 
> representations (i.e. Trees, Gimples). Did you understand them?

I don't understand anything about the internal representations yet. I
don't even know which representation I am currently parsing.

I want to get started. If you have any advice it is welcome.

I have read the "Gcc internals" manual. It is well written but it
doesn't have much example code. Do you know about any simple example
code?

Regards,
Daniel


2011/1/23 Dave Korn :
> On 23/01/2011 10:58, Daniel Marjamäki wrote:
>
>> I fail to use 'global_namespace':
>> daniel@daniel:~/gcc/build/gcc$ ./xgcc -fplugin=./myplugin2.so -c test1.c
>> cc1: error: cannot load plugin ./myplugin2.so
>
>  You're running the C compiler (cc1) here, not the C++ one (cc1plus), because
> you've passed a file with the plain .c extension to the driver.
>
>> ./myplugin2.so: undefined symbol: global_namespace
>
>  So it doesn't have this global variable that only exists in cc1plus.
>
>  Either change your test file to .cpp, or add "-x c++" to the command-line.
>
>  In general, as long as your plugin refers to global_namespace directly, it's
> not going to be compatible with any of the other language sub-compilers apart
> from cc1plus.  If you wanted it to work with any kind of language, I think
> you'd need to look up global_namespace using dlsym (and handle the case when
> it was not found), rather than linking against it directly.
>
>    cheers,
>      DaveK
>
>


gcc-4.3-20110123 is now available

2011-01-23 Thread gccadmin
Snapshot gcc-4.3-20110123 is now available on
  ftp://gcc.gnu.org/pub/gcc/snapshots/4.3-20110123/
and on various mirrors, see http://gcc.gnu.org/mirrors.html for details.

This snapshot has been generated from the GCC 4.3 SVN branch
with the following options: svn://gcc.gnu.org/svn/gcc/branches/gcc-4_3-branch 
revision 169143

You'll find:

 gcc-4.3-20110123.tar.bz2 Complete GCC (includes all of below)

  MD5=b81f53d6c85ac04a4eb4e94b7a8108be
  SHA1=f60914d886171266e14a8f80161f803127452701

 gcc-core-4.3-20110123.tar.bz2C front end and core compiler

  MD5=097fb77eea8152528a046182ec8be83a
  SHA1=dc4fdb303023eff5439e8c9f8504c1a4ca41a5b9

 gcc-ada-4.3-20110123.tar.bz2 Ada front end and runtime

  MD5=1da5014fbb3e728a9e95e75301bcd37f
  SHA1=d881318c1fd060738e34dad01bbcd23a1a0d1f6e

 gcc-fortran-4.3-20110123.tar.bz2 Fortran front end and runtime

  MD5=9bdbd1abd96492683edeb9c4059022b5
  SHA1=47fc059c6128862eccb441157b5fa6230da256c0

 gcc-g++-4.3-20110123.tar.bz2 C++ front end and runtime

  MD5=dfbb5432b8cbb7a06d9936f5cca15daf
  SHA1=ed6207af164cf98b803bf029b959bf2163cf640b

 gcc-go-4.3-20110123.tar.bz2  Go front end and runtime

  MD5=f80ce6a690c9743c5e790bd509713c5b
  SHA1=7809c68ec8ca4c990adefb85931a3adfd00ca720

 gcc-java-4.3-20110123.tar.bz2Java front end and runtime

  MD5=e5780e6dd2e1c2c9c02072e521ba09e0
  SHA1=4ad031a5ebb18ffc769ce6bce1398901e44b741a

 gcc-objc-4.3-20110123.tar.bz2Objective-C front end and runtime

  MD5=c8edf114f091b93c385ff7935e493dd9
  SHA1=fc5315f656cd951dcf3546d77ae61885a9295dd9

 gcc-testsuite-4.3-20110123.tar.bz2   The GCC testsuite

  MD5=fec86b0ef7f6096dfe73eef4c79523c7
  SHA1=da4ba1b842cd61846bcfb6600525370cc0a23af2

Diffs from 4.3-20110116 are available in the diffs/ subdirectory.

When a particular snapshot is ready for public consumption the LATEST-4.3
link is updated and a message is sent to the gcc list.  Please do not use
a snapshot before it has been announced that way.


gcc plugin framework on Windows Question

2011-01-23 Thread asmwarrior

Hi, all, I have read the discussion here:
http://gcc.gnu.org/ml/gcc/2010-07/msg3.html

I'm not sure about the current status.

Is it possible to use this library:
http://code.google.com/p/dlfcn-win32/

This library just do a wrapper on the windows dll library.

any ideas?

thanks.

asmwarrior