pro64-support
[Top] [All Lists]

RE: C to Whirl

To: pro64-support@xxxxxxxxxxx
Subject: RE: C to Whirl
From: "Huang, Tao" <tao.huang@xxxxxxxxx>
Date: Wed, 15 Aug 2001 22:24:10 +0800
Sender: owner-pro64-support@xxxxxxxxxxx
I had a try to fix this bug, the modification place can be described as below:

1)in function W2C_Enter_Global_Symbols() of file w2c_driver.cxx line 541 ~ 549 
change to:
        for (UINT ty = 1; ty < TY_Table_Size(); ty++)
         {
                TY_IDX ty_current = make_TY_IDX(ty);
                if (TY_Is_Structured(ty_current))
                 {
                        (void)W2CF_Symtab_Nameof_Ty(ty_current);
                        for (fld = TY_flist(Ty_Table[ty_current]); !fld.Is_Null 
(); fld = FLD_next(fld))
                        (void)W2CF_Symtab_Nameof_Fld(fld);
                } /* if a struct */
        } /* for all types */
        
        Reason: index variable need left shift 8 bits to transform to TY_IDX.

2) in function WN2C_Append_Symtab_Types() file wn2c.cxx line 1969 ~ 1988 change 
to:
           /* Declare structure types. */
          for (ty = 1; ty < TY_Table_Size(); ty++)
          {
              TY_IDX ty_current = make_TY_IDX(ty);
              if (TY_Is_Structured(ty_current)       &&
                  !TY_split(Ty_Table[ty_current])    &&
                  !TY_is_translated_to_c(ty_current) &&
                  !Stab_Reserved_Ty(ty_current))
              {
                 tmp_tokens = New_Token_Buffer();
                 TY2C_translate_unqualified(tmp_tokens, ty_current);
                 Append_Token_Special(tmp_tokens, ';');
                 Append_Indented_Newline(tmp_tokens, lines_between_decls);
                 if (tokens != NULL)
                    Append_And_Reclaim_Token_List(tokens, &tmp_tokens);
                 else
                    Write_And_Reclaim_Tokens(W2C_File[W2C_DOTH_FILE], 
                                             NULL, /* No srcpos map */
                                             &tmp_tokens);
           }
        }
        Reason: similiar to 1)

3) in function skip_till_next_field() in file ty2c.cxx line 280 ~ 288 change to:
         while (!next_fld.Is_Null () &&
            (FLD_ofst(this_fld) >= FLD_ofst(next_fld) ||
             PTR_OR_ALIGNED_WITH_STRUCT(FLD_type(next_fld),  struct_align) ||
            (!TY_Is_Pointer(FLD_type(next_fld)) &&
              FLD_ofst(next_fld) % TY_align(FLD_type(next_fld)) != 0) ||
            (!is_union && FLD_Is_Bitfield(next_fld,  FLD_next(next_fld),
                               struct_size - FLD_ofst(next_fld)))))

        The modification is to erase ! operator before stmt 
PTR_OR_ALIGNED_WITH_STRUCT(FLD_type(next_fld),  struct_align)

4) in function function TY2C_prepend_FLD_list() in file ./be/whirl2c/ty2c.cxx 
line 372 ~ 374 change to:
   if (PTR_OR_ALIGNED_WITH_STRUCT(FLD_type(fld), struct_align) ||
       (!is_union &&
        FLD_Is_Bitfield(fld, FLD_next(fld), remaining_bytes)))

       The modification is to erase ! operator before stmt 
PTR_OR_ALIGNED_WITH_STRUCT(FLD_type(next_fld),  struct_align)

After modification, the code seems like attached files.

There is still a mistake in structure variable number. That's because in this 
case there is ambigous name for a intrinsic call stat() and a intrinsic struct 
stat, so cause error in symbol table in function W2CF_Symtab_Nameof_St() of 
file w2cf_symtab.cxx.

At last, I'd like to thank for Rune, Peng tu, shin-ming liu for the help and 
advice.

-Tao Huang 
     
-----Original Message-----
From: Charles R. Hardnett [mailto:hardnett@xxxxxxxxxxxxx]
Sent: 2001?6?25? 21:48
To: pro64-support@xxxxxxxxxxx
Subject: C to Whirl




Hello,

I have a question that involves the C to Whirl generation. I am using
the whirl2C module, and noticed a bug with code such as the following:


        struct stat sbuf;
 
        if (sbuf.st_mode) {
          printf("hello");
        }


The above code comes out of pro64 after whirl2c translation to look
something like:

if((_UINT32)(*(struct stat0 {
    _UINT64 st_dev;
    _UINT32 st_ino;
    _INT32 __pad1;
    _UINT32 st_mode;
    _UINT32 st_nlink;
    _UINT32 st_uid;
    _UINT32 st_gid;
    _UINT64 st_rdev;
    _INT64 st_size;
    _INT64 st_atime;
    _INT64 st_mtime;
    _INT64 st_ctime;
    _INT32 st_blocks;
    _INT32 __pad2;
    _UINT32 st_blksize;
    _INT32 __pad3;
    _INT64 __unused[6LL];
  } *)(((_INT8 *) & sbuf) + 16LL)) != 0U)
  {
    printf((const _INT8 *)(_INT8(*)[6LL]) "hello");
  }                                                                             

The problem of course is cast contains a declaration of the struct,
and not just the name of the struct. I have tracked down the problem
to where this only occurs when a struct field is accessed within a
cond exp i.e. within while, if, for, etc.

I have also convinced myself that the problem is not in the whirl2c
conversion because it appears that whirl2C is only outputing the token
information that is stored in the WN for this object's
type. Therefore, it appears that the problem is the translation from C
to whirl by GFEC is most likely the culprit. 

My questions are: 

   1. Is there anyone else looking at the whirl2c module that may have
run into this problem?

   2. If not, does anyone have any good information on GFEC and how
its exprs are stored? operated on to create the whirl? I was looking
at the code this weekend, and could use any documentation anyone may
have on it.

Thanks,

Charles
  
-- 
--------------------------------------------------------------------
Charles R. Hardnett www.spelman.edu/~hardnett 





begin 600 problem.w2c.h
M+RH@26YC;'5D92!B=6EL=&EN('1Y<&5S(&%N9"!O<&5R871O<G,@*B\*(VEN
M8VQU9&4@/'=H:7)L,F,N:#X*"B\J(%1Y<&5S("HO"G-T<G5C="!S=&%T('L*
M("!?54E.5#8T('-T7V1E=CL*("!?54E.5#,R('-T7VEN;SL*("!?24Y4,S(@
M7U]P860Q.PH@(%]524Y4,S(@<W1?;6]D93L*("!?54E.5#,R('-T7VYL:6YK
M.PH@(%]524Y4,S(@<W1?=6ED.PH@(%]524Y4,S(@<W1?9VED.PH@(%]524Y4
M-C0@<W1?<F1E=CL*("!?24Y4-C0@<W1?<VEZ93L*("!?24Y4-C0@<W1?871I
M;64["B`@7TE.5#8T('-T7VUT:6UE.PH@(%])3E0V-"!S=%]C=&EM93L*("!?
M24Y4,S(@<W1?8FQO8VMS.PH@(%])3E0S,B!?7W!A9#(["B`@7U5)3E0S,B!S
M=%]B;&MS:7IE.PH@(%])3E0S,B!?7W!A9#,["B`@7TE.5#8T(%]?=6YU<V5D
M6S9,3%T["GT["@HO*B!&:6QE+6QE=F5L('-Y;6)O;&EC(&-O;G-T86YT<R`J
M+PIS=&%T:6,@7TE.5#@@86YO;ELV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]D*`H@(&-O;G-T(%])3E0X("H@7U]P871H+`H@(%]524Y4,S(@7U]M;V1E
M+`H@(%]524Y4-C0@7U]D978I"GL*("!R96=I<W1E<B!?24Y4,S(@7U]C;VUM
M83L*("`*("!?7V-O;6UA(#T@7U]X;6MN;V0H,"P@7U]P871H+"!?7VUO9&4L
M("9?7V1E=BD["B`@<F5T=7)N(%]?8V]M;6$["GT@+RH@;6MN;V0@*B\*"@I?
M24Y4,S(@;6%I;B@I"GL*("!R96=I<W1E<B!?24Y4,S(@<F5G.#L*("!S=')U
M8W0@<W1A=#$@<V)U9CL*("`*("!I9B@H7U5)3E0S,BDH*BAS=')U8W0@<W1A
M=#$@*BDH*"A?24Y4."`J*2`F('-B=68I("L@,39,3"DI("$](#!5*0H@('L*
M("`@('!R:6YT9B@H8V]N<W0@xxxxx#@@*BDH7TE.5#@H*BE;-DQ,72D@(FAE
H;&QO(BD["B`@?0H@(')E='5R;B!R96<X.PI]("\J(&UA:6X@*B\*"@==
`
end

<Prev in Thread] Current Thread [Next in Thread>