Michael Glickman <[EMAIL PROTECTED]> writes:

> That's interesting. I am not a Perl guru, but the question
> is really about the idea, not about its actual implementation.
> 
> What I guess you did, was parsing LD-script and creating
> C headers out of it. In this case, if you want to have
> a section for a file, you also need to parse a source
> code and change section declaration for each static function,
> while creating a prototype for each global function.
> Looks really bizaire, unless I am missing something, or don't
> undestand it properly.

Each compilation unit starts with this boilerplate:

  // File: compunit.c
  #define __COMPUNIT_C__
  #include "compunit.h"
  SECTION_DECL(sectname)

Function declarations always look like this:

  START_FUNCPROTO
  void somefunc(Char* x)
  END_FUNCPROTO
  {
    // body of function
  }

  START_STATIC_FUNCPROTO
  void some_staticfunc(Int16 x)
  END_FUNCPROTO
  {
    // body of static function
  }

The SECTION_DECL, START_FUNCPROTO and END_FUNCPROTO are macros that expand
to nothing. START_STATIC_FUNCPROTO expands to the `static' keyword. 

compunit.h has this basic boilerplate:

  #ifndef __COMPUNIT_H__
  #define __COMPUNIT_H__

  // All declarations, except function prototypes go here

  #include "compunit.p.h"
  #endif

The perl script takes a .c file and generates a .p.h file. It uses the
SECTION_DECL macro to figure out what the section name will be for the
functions in the compilation unit, and it uses the
START_FUNCPROTO/START_STATIC_FUNCPROTO and END_FUNCPROTO macros to
extract the function prototypes. The .p.h file ends up looking like:

  // This file automatically generated by genproto
  #ifndef __COMPUNIT_P_H__
  #define __COMPUNIT_P_H__

  #ifdef __COMPUNIT_C__
  // Static functions
  static void some_staticfunc(Int16 x) __attribute__ ((section ("sectname")));
  #endif

  // Global functions
  void somefunc(Char* x) __attribute__ ((section ("sectname")));

  #endif

The Makefile has a bunch of dependency rules to ensure that the .p.h
files depend on .c files, so that they are always up to date.

Once the basics are set up, all the programmer needs to do is remember
to wrap all function definitions inside START_FUNCPROTO/END_FUNCPROTO
and make sure that compunit.h includes compunit.p.h.

If you want a function to get put into the main section, just don't wrap
it in the START/END declarations. The only other real limitation is that
you can't have more than one section per compilation unit; not a big
deal, IMO.

To create the .def file, just grep the .c files for SECTION_DECL, and do
some text massaging (another perl script).

-- 
Dave Carrigan ([EMAIL PROTECTED])            | Yow! Is it 1974?  What's for
UNIX-Apache-Perl-Linux-Firewalls-LDAP-C-DNS | SUPPER?  Can I spend my COLLEGE
Seattle, WA, USA                            | FUND in one wild afternoon??
http://www.rudedog.org/                     | 

-- 
For information on using the Palm Developer Forums, or to unsubscribe, please see 
http://www.palmos.com/dev/tech/support/forums/

Reply via email to