Question Re: predef.h

Mirsad Todorovac mtodorov at alu.hr
Mon Feb 20 15:38:37 CET 2006


Thanks, Frank,

On Mon, 20 Feb 2006, Frank Heckenbach wrote:

> Mirsad Todorovac wrote:
>
>> NOW; I was asked from GCC team whether the RotateLeft/RotateRight bug is
>> still present in their middle-end/back-end, and I am unable to tell
>> without trying to recompile implementation attempt in PASCAL with newest
>> backend (3.4.5, as it seem that GPC still does not support 4.0.2 :-(
>
> No, it doesn't yet. That's kind of a FAQ here ...

Yes, I realize there must be problems here, but I ma certain the Team is 
more than able to keep up with the task :-)

>> I am not sure if the mechanism of definition of primitives is the same as
>> the previous one in predef.h, so I am asking because you of course  know
>> more.
>
> Yes, it's the same. The file was just renamed because it really
> isn't a C header file (similar to other files such as tree.def in
> the backend).

Now, I was digging into it, and the new version keep complaining about the 
invalid operands to RotateLeft/RotateRight when argument is even a ''Byte''

The predef.def lines look like (inherited from Pred/Succ, and worked 
before, in 2003 versions):

PREDEF_ROUTINE (RotateLeft,         "xv,r|",         ER_CONST,      GNU_PASCAL)
PREDEF_ROUTINE (RotateRight,        "xv,r|",         ER_CONST,      GNU_PASCAL)

In fact, I was going through the source quite a bit before and now, and I 
still can't seem to catch all the tricks of this "signature" string ...

Essentially, the implementation is simple as LROTATE_EXPR and RROTATE_EXPR 
are supported by the backend already:

I see that now build_binary_op is depracated and abandoned in favor of 
build_pascal_binary_op. Is that the problem (also build_binary_op has 
misteriously lost last (default 0) argument).

Any help with this? Thank you!

Mirsad

P.S: Here is the implementation attempt:

-----
   case p_RotateLeft:
   case p_RotateRight:
     {
       int  left = (r_num == p_RotateLeft);
       int  precision      = TYPE_PRECISION (type);
       tree precision_node = build_int_2 (precision, 0);

       if (code == REAL_TYPE)
         error ("argument 1 of `%s' must be of integer type", r_name);
       else if (code2 == REAL_TYPE)
         error ("argument 2 of `%s' must be of integer type", r_name);
       if (argcount == 1)
         val2 = integer_one_node;
       else
         val2 = build_binary_op (TRUNC_MOD_EXPR, val2, precision_node);

       retval = convert (type, build_binary_op (left ? LROTATE_EXPR : RROTATE_EXPR, val, val2));
     }
     break;

And the demo breaks:

mtodorov at domac:~/rotltest$ cat rotl_bb.pas
program rotlnnn (output);

var  i0, i:     Byte;
      j:         Byte;

begin
   i0 := 1;
   j := BitSizeof (i0) + 1;
   i := RotateLeft (i0, j);
   if i <> RotateLeft (i0, 1) then
     WriteLn ('failed : i: Byte = 1; j: Byte = ', j, '; RotateLeft(i, j) = ', i)
   else
     WriteLn ('OK')
end.
mtodorov at domac:~/rotltest$ gpc rotl_bb.pas
rotl_bb.pas: In main program:
rotl_bb.pas:13: error: invalid operands to `RotateLeft'
rotl_bb.pas:14: error: invalid operands to `RotateLeft'
mtodorov at domac:~/rotltest$







More information about the Gpc mailing list