Calling an unknown function from low-level Cmm
Alexis King
lexi.lambda at gmail.com
Fri Feb 14 19:52:47 UTC 2020
Hi all,
I’m trying to understand how to properly call an unknown function from low-level Cmm code. If I’m just applying a function to a state token, it’s easy; I can just do
R1 = io;
jump stg_ap_v_fast [R1];
since the calling convention is consistent in that case. But what if my function takes actual arguments? I can’t do
R1 = fun;
R2 = arg;
jump stg_ap_p_fast [R1, R2];
because if the calling convention doesn’t pass any arguments in registers, that would be wrong. I could check if NO_ARG_REGS is defined and generate different code in that situation, but that seems extreme. One option I think would work would be to do
R1 = fun;
Sp_adj(-2);
Sp(1) = arg;
jump RET_LBL(stg_ap_p) [R1];
but that seems wasteful if I have the argument in a register already anyway. Am I missing something?
Thanks,
Alexis
More information about the ghc-devs
mailing list