Specify LDC to compile specific files

Michelle Long HappyDance321 at gmail.com
Tue Mar 5 20:48:18 UTC 2019


On Tuesday, 5 March 2019 at 18:52:45 UTC, Jacob Carlborg wrote:
> On 2019-03-05 17:40, Michelle Long wrote:
>
>> Know what the specific ABI issues are?
>
> LDC has a slightly modified version of druntime. When using 
> "new" on a class, the compiler lowers that to a function call 
> implemented in druntime. The DMD and LDC versions of this 
> function is different. LDC uses a function called 
> "_d_allocclass" and DMD a function called "_d_newclass". The 
> LDC function only allocates memory (I believe), without doing 
> any initialization.


If that is all then it should be no problem to compile a function 
with one compiler and "insert" it in to the code of another?

auto foo(T...)(T p) { .... }


This just then gets mapped to different machine code based on 
which compiler is used, but the outside world doesn't care... 
only the inputs and the outputs must make sense. Since the 
calling convention is the same, no allocations occur "on" the 
call, and if all the types past are compatible it should work.

For example

One should in theory be able to compile a simple module with a 
function in it using DMD and LDC then extract the machine code 
from one and replace it in the other and everything work 
fine(assuming any global addresses are corrected for).


If this is actually true for all(or most cases) then it should be 
a relatively easy problem to solve.

The main issue I imagine would be that to compile the functions 
marked one might still have to compile quite a bit of 
code(Ideally it would be lazily compiled so only those symbols 
used outside the function would be searched).

If this is essentially correct then one could ideally create a 
master compiler that one can set versions and pragmas to control 
what gets compiled where and the master compiler simply handles 
all the match making and everything just works. This allows one 
to mix debug and release and performance(ldc) with compile time 
performance(dmd) possibly with globally overriding for specifying 
a homogeneous process(e.g., all dmd debug). (and caching could be 
done to speed up compiling further since if a model or function 
does not change in source it won't change in binary output and no 
need to recompile)


The goal, of course, is again to provide targeted performance for 
those areas that matter such as math routines that do not need 
debugging features or dmd behavior. This then speeds up the 
overall program since it is more tailored for it's purpose rather 
than having to use a blanket set of rules that are not optimal in 
the real world.



More information about the Digitalmars-d-ide mailing list