vnmakarov / mir

A lightweight JIT compiler based on MIR (Medium Internal Representation) and C11 JIT compiler and interpreter based on MIR

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Generated machine code fails if `MIR_finish` is called

giann opened this issue · comments

I have functions pointer returned by MIR_gen. If I try to call them after calling MIR_finish they will crash. Is this intended/normal?

Sorry for the delay with the answer.

Yes, the crash is expected. MIR_finish means finish all work with mir and all generated code.

MIR_finish frees all memory allocated by MIR including memory for the generated code.

Alright so followup question: i'm generating a function in which a constant is a reference to another function that also needs to be generated. How can i do that? Do i use several contexts?

No. you do not need use different contexts. They are mostly for independent parallel working MIR usage.

The best and simplest way to see how to do this is to look at mir-tests/run-test.c code.

Basically put the functions into one or two different modules, load module(s), link them using regular or lazy generator interface.

For the regular interface, linking will do all loaded functions generation and MIR_gen will return address of already generated function code.

For lazy interface, MIR_gen will generate code for given function only and code for functions called from given function will be generated on-the-fly (on the 1st call) and called automatically after that.