July 18, 2016 Re: Is there a way to "see" source code generated by templates after a compile? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Stefan Koch | On Monday, 18 July 2016 at 17:35:29 UTC, Stefan Koch wrote:
>
> I did it for function templates just now.
> It will the instantiated bodys to std-out.
Okay here is the frist really hacky draft patch
In dtemplate.d line 6691 right at the end of semantic3 insert the following code :
if (auto a = toAlias2) {
scope hgs = HdrGenState();
scope ob = OutBuffer();
scope ppv = new PrettyPrintVisitor(&ob, &hgs);
if (auto fd = a.isFuncDeclaration()) {
printf("FunctionTemplate: %s\n{", toChars);
if (auto fb = fd.fbody)
fb.accept(ppv);
}
printf("%.*s\n}\n", ob.size, cast(char*)ob.data);
}
}
Without warranty of any kind of course :)
|
July 19, 2016 Re: Is there a way to "see" source code generated by templates after a compile? | ||||
---|---|---|---|---|
| ||||
Posted in reply to WhatMeWorry | On Sunday, 17 July 2016 at 05:57:52 UTC, WhatMeWorry wrote:
>
>
> I don't suppose there's a way to "see" source code generated by templates after a compile but before execution? Or does the compiler generate it to a lower level on the fly; thus losing the source code?
>
> I'm assuming no because if there were a way, I'd of come across it by now :)
>
>
I've just stumbled across this on dmd documentation. Haven't had time to play with it yet.
-allinst
generate code for all template instantiations
|
July 20, 2016 Re: Is there a way to "see" source code generated by templates after a compile? | ||||
---|---|---|---|---|
| ||||
Posted in reply to WhatMeWorry | On Tuesday, 19 July 2016 at 20:19:53 UTC, WhatMeWorry wrote:
> On Sunday, 17 July 2016 at 05:57:52 UTC, WhatMeWorry wrote:
>>
>>
>> I don't suppose there's a way to "see" source code generated by templates after a compile but before execution? Or does the compiler generate it to a lower level on the fly; thus losing the source code?
>>
>> I'm assuming no because if there were a way, I'd of come across it by now :)
>>
>>
>
>
> I've just stumbled across this on dmd documentation. Haven't had time to play with it yet.
>
> -allinst
>
> generate code for all template instantiations
This is not what you are looking for. This option makes dmd put seemingly unused code in the binary. It does not output human-readable template instantations. It was meant to help workaround linking errors at the time when the lazy template instantiation mechanism was not so robust as nowadays.
|
Copyright © 1999-2021 by the D Language Foundation