[M3devel] a trouble with passing records by value..

Tony Hosking hosking at cs.purdue.edu
Tue Aug 31 15:15:32 CEST 2010


What happens if you take the address of t inside ActionLookup?
What happens if you take the address of t1 inside main?

On 31 Aug 2010, at 07:25, Jay K wrote:

> 
> Given something like this:
> 
> jbook2:p247 jay$ more 1.c
> #include <assert.h>
> 
> typedef struct { long code; long value; } T1;
> 
> void ActionLookup(T1 t, long code, long value);
> 
> void ActionLookup(T1 t, long code, long value)
> {
>   assert(t.code == code);
>   assert(t.value == value);
> }
> 
> int main()
> {
>   T1 t1 = {2,2};
>   ActionLookup(t1, 2, 2);
>   return 0;
> }
> j
> 
> 
> on some platforms, such as AMD64_DARWIN, T1 is passed in registers. Good.
> 
> 
> However, one of the unfortunate aspects of our Modula-3 system is that when you reference e.g. t1.value,
> the backend isn't told you are accessing the "value" "field" of "t1", and it figures out where that is,
> but rather 64bits at offset 64bits into t1. Therefore t1 must have an address. Therefore it can't be in registers.
> Darn.
> 
> 
> If m3cg were higher level this could be better.
> 
> 
> There should be a viable compromise where the parameter is passed in registers, and only "homed"
> to some stack location if its address is used -- e.g. to pass unused parameters in registers.
> But given the inefficiency of field accesses, I'm not sure it is worth trying?
> 
> 
> Maybe we should have M3CG include field references?
> 
> 
> There is this basic problem that the interface between m3front and m3cc isn't really at the
> right level for m3cc. But it is probably for m3front. m3front wants a lower level code generator.
> 
> 
>  - Jay
> 		 	   		  




More information about the M3devel mailing list