Sujet : Re: transpiling to low level C
De : bc (at) *nospam* freeuk.com (bart)
Groupes : comp.lang.cDate : 17. Dec 2024, 20:42:51
Autres entêtes
Organisation : A noiseless patient Spider
Message-ID : <vjsk7q$1rrvs$2@dont-email.me>
References : 1 2 3 4 5 6 7 8 9 10 11
User-Agent : Mozilla Thunderbird
On 17/12/2024 19:07, Thiago Adams wrote:
Em 12/17/2024 3:37 PM, bart escreveu:
On 17/12/2024 18:16, Thiago Adams wrote:
>
>
also remove structs changing by unsigned char [] and cast parts of it to access members.
>
I think this the lower level possible in c.
>
This is what I do in my IL, where structs are just fixed blocks of so many bytes.
>
How do you do with struct parameters?
In the IL they are always passed notionally by value. This side of the IL (that is, the frontend compile that generates IL), knows nothing about the target, such as ABI details.
(In practice, some things are known, like the word size of the target, since that can change characteristics of the source language, like the size of 'int' or of 'void*'. It also needs to assume, or request from the backend, argument evaluation order, although my IL can reverse order if necessary.)
It is the backend, on the other size of the IL, that needs to deal with those details.
That can include making copies of structs that the ABI says are passed by value. But when targeting SYS V ABI (which I haven't attempted yet), it may need to know the internal layout of a struct.
You can however do experiments with using SYS V on Linux (must be 64 bits):
* Create test structs with, say, int32 or int64 elements
* Write a test function where such a struct is passed by value, and
then return a modified copy
* Rerun the test using a version of the function where a char[] version of the struct is passed and returned, and which contains the member access casts you suggested
* See if it gives the same results.
You might need a union of the two structs, or use memcpy to transfer contents, before and after calling the test function.