[M3devel] stdcall naming discrepancy?

Tony Hosking hosking at cs.purdue.edu
Mon Feb 4 15:52:31 CET 2008


Any chance that standard_structs in Target.i3 is causing the front- 
end to pass structs by reference (standard structs=TRUE)?  Also,  
looking at pop_struct in parse.c it seems to want to pass them by  
reference (standard_structs=FALSE)?  In any case, what does the  
integrated back-end do with pop_struct?  I bet it is passing by  
value...  whereas parse.c passes by ref.  Blurgh!  Looks like we need  
to smarten things up for calls to non-M3 stdcall procedures.

On Feb 4, 2008, at 1:23 AM, Jay wrote:

> (and codegen..)
>
> C:\dev2\j\m3\t>type t.c
>
> typedef struct {
>  int a,b,c,d,e,f;
> } Foo_t;
>
> void __stdcall Sleep(Foo_t foo);
>
> extern Foo_t a;
>
> void F1()
> {
>  Sleep(a);
> }
>
> C:\dev2\j\m3\t>gcc -c -S t.c
>
> C:\dev2\j\m3\t>type t.s
>         .file   "t.c"
>         .text
> .globl _F1
>         .def    _F1;    .scl    2;      .type   32;     .endef
> _F1:
>         pushl   %ebp
>         movl    %esp, %ebp
>         subl    $24, %esp
>         movl    _a, %eax
>         movl    %eax, (%esp)
>         movl    _a+4, %eax
>         movl    %eax, 4(%esp)
>         movl    _a+8, %eax
>         movl    %eax, 8(%esp)
>         movl    _a+12, %eax
>         movl    %eax, 12(%esp)
>         movl    _a+16, %eax
>         movl    %eax, 16(%esp)
>         movl    _a+20, %eax
>         movl    %eax, 20(%esp)
>         call    _Sleep at 24
>         subl    $24, %esp
>         leave
>         ret
> C:\dev2\j\m3\t>
>
> (NOTE: This is NOT the correct declaration of Sleep, but ok for  
> testing purposes.)
>
> C:\dev2\j\m3\t>type t.i3
> INTERFACE T;
>
> TYPE Foo_t = RECORD
>  a,b,c,d,e,f : INTEGER;
> END;
>
> <*EXTERNAL Sleep:WINAPI*>
> PROCEDURE Sleep (dwMilliseconds1: Foo_t);
> END T.
>
> C:\dev2\j\m3\t>type t.m3
>
> MODULE T;
> VAR
>  Foo: Foo_t;
>
> BEGIN
>  Sleep(Foo);
> END T.
>
>
> LM1:
>  movl 8(%ebp), %eax
>  xorl $1, %eax
>  testb %al, %al
>  jne L2
>  .stabn 68,0,6,LM2-_T_M3
> LM2:
>  movl $_MM_T+52, %eax
>  movl %eax, %edx
>  subl $8, %esp
>  subl $24, %esp
>  movl %esp, %eax
>  movl %eax, %edi
>  movl %edx, %esi
>  cld
>  movl $6, %eax
>  movl %eax, %ecx
>  rep
>  movsl
>  call _Sleep at 4
>  addl $8, %esp
> L2:
>  movl $_MM_T, %eax
> LBE2:
>  leal -8(%ebp), %esp
>  popl %esi
>  popl %edi
>  leave
>  ret
>
> ?
>
>  - Jay
>
> Connect and share in new ways with Windows Live. Get it now!




More information about the M3devel mailing list