On 12/20/2015 09:11 PM, Jacob Carlborg via dmd-internals wrote:
> I’m trying to generate code using the dl_* functions in DMD. The 
> corresponding D code would be the following:
> 
> struct TLS
> {
>     int* function (TLS*) thunk;
>     size_t key;
>     size_t offset;
> }
> 
> extern (C) __gshared TLS bar;
> 
> extern (C) int main (int i, char**)
> {
>     auto foo = *bar.thunk(&bar);
> 
>     return 0;
> }
> 
> The code that DMD is generating, for the above “main” functions, is:
> 
> pushq %rbp
> movq  %rsp, %rbp
> movq  _bar(%rip), %rdi
> movq  %rdi, %rax
> callq         *_main(%rax)
> movl  _main(%rax), %ecx
> xorl          %eax, %eax
> popq  %rbp
> retq

What do you want to achieve? In general specific instructions such as
for TLS access should be implemented by the corresponding cd* function,
not in the intermediate representation.
The IR might be the right place for a low-level lowering though.

> Basically I have no idea what I’m doing and I don’t really understand how 
> these el_* functions are working. Anyone could give me some help with this?

The simply construct an IR tree, no magic here.

OPind  (dereference a pointer)
OPadd  (+ int or pointer)
OPaddr (& take an address)
OPconst (a constant value)
OPcallns (call a function)

You can find the documentation here.
https://github.com/D-Programming-Language/dmd/blob/fc9edc34c7d7403b8c69b49abfe4c5ec2ae66061/src/backend/oper.h#L22

Attachment: signature.asc
Description: OpenPGP digital signature

_______________________________________________
dmd-internals mailing list
[email protected]
http://lists.puremagic.com/mailman/listinfo/dmd-internals

Reply via email to