[dmd-internals] Help with dl_* functions in DMD
Martin Nowak via dmd-internals
dmd-internals at puremagic.com
Sun Dec 27 13:33:33 PST 2015
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
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 819 bytes
Desc: OpenPGP digital signature
URL: <http://lists.puremagic.com/pipermail/dmd-internals/attachments/20151227/c9fa6477/attachment.sig>
More information about the dmd-internals
mailing list