vnmakarov / mir

A lightweight JIT compiler based on MIR (Medium Internal Representation) and C11 JIT compiler and interpreter based on MIR
MIT License
2.29k stars 145 forks source link

How to get offset of a variable to the stack bottom #349

Closed mttbx closed 1 year ago

mttbx commented 1 year ago

Hi, If I allocate an object on the stack. How can I know the offset of it to the stack bottom. Thus I can create a static const stack map to do gc.

vnmakarov commented 1 year ago

There is MIR_ALLOCA insn for this. It reserves stack memory of given size and returns address to it. The stack memory is automatically freed on the function exit.

MIR_ALLOCA is analogous to C alloca. The insn is actually used for implementing C alloca besides to stack allocation of structure or array type C variables.

mttbx commented 1 year ago

Thank you.