> That depends a bit on the compiler version and optimization level,
> but (in particular in the 3.x time frame) GCC may output assembler
> code on a function-by-function basis, without necessarily reading
> in the whole source file first.

Ok, actually it doesn't matter if it doesn't work all the time.  I'll
always be compiling with -Os anyway, so it sounds like I'm in
with a chance of the whole file being read first?

If so, where is my first opportunity, in 3.2.3, to see if there's a
"main" function in this file?

Hmm, it seems 3.2.x would *always* operate on a function-by-function
basis.  The unit-at-a-time mode was only introduced with 3.4 (I don't
recall if it was already present in 3.3).  I don't think there is any
way in 3.2.3 to check whether there is a "main" function in the file
before it is processed ...

Does that mean I could take advantage of this behaviour?  Currently
I have this change:

/* Store in OUTPUT a string (made with alloca) containing an
  assembler-name for a local static variable named NAME.
  LABELNO is an integer which is different for each call.  */

#ifdef TARGET_PDPMAC
#define ASM_FORMAT_PRIVATE_NAME(OUTPUT, NAME, LABELNO)  ^I^I\
{^I^I^I^I^I^I^I^I^I\
 (OUTPUT) = (char *) alloca (strlen ((NAME)) + 10);^I^I^I\
 sprintf ((OUTPUT), "__%d", (LABELNO));^I^I^I^I\
}

to give the static functions unique names within the file.

However, it has the unfortunate side-effect that this code:

#if defined(TARGET_DIGNUS) || defined(TARGET_PDPMAC)
#define ASM_DECLARE_FUNCTION_NAME(FILE, NAME, DECL)^I^I^I\
{^I^I^I^I^I^I^I^I^I\
 if (strlen (NAME) + 1 > mvs_function_name_length)^I^I^I\
   {^I^I^I^I^I^I^I^I^I\
     if (mvs_function_name)^I^I^I^I^I^I\
^Ifree (mvs_function_name);^I^I^I^I^I\
     mvs_function_name = 0;^I^I^I^I^I^I\
   }^I^I^I^I^I^I^I^I^I\
 if (!mvs_function_name)^I^I^I^I^I^I\
   {^I^I^I^I^I^I^I^I^I\
     mvs_function_name_length = strlen (NAME) * 2 + 1;^I^I^I\
     mvs_function_name = (char *) xmalloc (mvs_function_name_length);^I\
   }^I^I^I^I^I^I^I^I^I\
 strcpy (mvs_function_name, NAME);^I^I^I^I^I\
 mvs_need_to_globalize = 1;^I^I^I^I^I^I\
}
#endif

static void
i370_output_function_prologue (f, l)
    FILE *f;
    HOST_WIDE_INT l;
{
/* Don't print stack and args in PDPMAC as it makes the
  comment too long */
#ifdef TARGET_PDPMAC
 fprintf (f, "* %c-func %s prologue\n",
          mvs_need_entry ? 'X' : 'S',
          mvs_function_name);
#else

is producing this output:

* S-func __0 prologue
@@0      PDPPRLG CINDEX=1,FRAME=88,BASER=12,ENTRY=NO
        B     FEN1
        LTORG
FEN1     EQU   *
        DROP  12
        BALR  12,0
        USING *,12
PG1      EQU   *
        LR    11,1
        L     10,=A(PGT1)
* Function __0 code
* 46 world.c
        SLR   15,15
* Function __0 epilogue
        PDPEPIL
* Function __0 literal pool
        DS    0F
        LTORG
* Function __0 page table
        DS    0F
PGT1     EQU   *
        DC    A(PG1)

for this function:

static int aaa(void)
{
   return (0);
}

ie the "aaa" is being completely lost, being replaced by __0 everywhere.
Ideally the __0 would be aaa everywhere, with just the @@0 remaining
generated.

Indeed, I have just made this change:

C:\devel\gcc\gcc>cd config\i370

C:\devel\gcc\gcc\config\i370>cvs diff
cvs diff: Diffing .
Index: i370.c
===================================================================
RCS file: c:\cvsroot/gcc/gcc/config/i370/i370.c,v
retrieving revision 1.34
diff -r1.34 i370.c
84a85,87
/* original name of a static variable */
char origmvsstatic[150];

1457c1460
<            mvs_function_name);
---
           mvs_need_entry ? mvs_function_name : origmvsstatic);
1599c1602,1603
<   fprintf (f, "* Function %s code\n", mvs_function_name);
---
  fprintf (f, "* Function %s code\n",
           mvs_need_entry ? mvs_function_name : origmvsstatic);
1787c1791,1792
<   fprintf (file, "* Function %s epilogue\n", mvs_function_name);
---
  fprintf (file, "* Function %s epilogue\n",
           mvs_need_entry ? mvs_function_name : origmvsstatic);
1818c1823,1824
<   fprintf (file, "* Function %s literal pool\n", mvs_function_name);
---
  fprintf (file, "* Function %s literal pool\n",
           mvs_need_entry ? mvs_function_name : origmvsstatic);
1821c1827,1828
<   fprintf (file, "* Function %s page table\n", mvs_function_name);
---
  fprintf (file, "* Function %s page table\n",
           mvs_need_entry ? mvs_function_name : origmvsstatic);

C:\devel\gcc\gcc\config\i370>cvs diff -c i370.h
Index: i370.h
===================================================================
RCS file: c:\cvsroot/gcc/gcc/config/i370/i370.h,v
retrieving revision 1.35
diff -c -r1.35 i370.h
*** i370.h      18 Jul 2009 08:56:33 -0000      1.35
--- i370.h      20 Aug 2009 10:40:35 -0000
***************
*** 57,62 ****
--- 57,63 ----
 /* The source file module.  */

 extern char *mvs_module;
+ extern char origmvsstatic[];

/* Compile using char instructions (mvc, nc, oc, xc). On 4341 use this since
    these are more than twice as fast as load-op-store.
***************
*** 1832,1837 ****
--- 1833,1839 ----
 #define ASM_FORMAT_PRIVATE_NAME(OUTPUT, NAME, LABELNO)                \
 {                                                                     \
   (OUTPUT) = (char *) alloca (strlen ((NAME)) + 10);                  \
+   strcpy(origmvsstatic, NAME); \
   sprintf ((OUTPUT), "__%d", (LABELNO));                              \
 }
 #else

and it is working:

* S-func aaa prologue
@@0      PDPPRLG CINDEX=1,FRAME=88,BASER=12,ENTRY=NO
        B     FEN1
        LTORG
FEN1     EQU   *
        DROP  12
        BALR  12,0
        USING *,12
PG1      EQU   *
        LR    11,1
        L     10,=A(PGT1)
* Function aaa code
* 46 world.c
        SLR   15,15
* Function aaa epilogue
        PDPEPIL
* Function aaa literal pool
        DS    0F
        LTORG
* Function aaa page table
        DS    0F
PGT1     EQU   *
        DC    A(PG1)


But is that guaranteed?

Thanks.  Paul.

Reply via email to