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

Add MIR_get_global_item #383

Open iacore opened 10 months ago

iacore commented 10 months ago

MIR_get_global_item was in mir.h but missing definition in mir.c. This patch tries to add its definition.

vnmakarov commented 10 months ago

I am not against to have MIR_get_global_item and MIR_get_module_item in API.

I don't like this MIR_get_global_item. The function actually finds the first item with the name. The item may be visible only in one module (has no export clause).

The search is not efficient. I remember there is somewhere in loading/linking code more efficient way to find an external item. It would be a good starting point to implement MIR_get_global_item.

Also these two functions should be documented in MIR.md

iacore commented 10 months ago

I have updated the issue description.

What's the correct way to look for a function definition in textual MIR loaded with MIR_scan_string?

I took the search code from https://github.com/vnmakarov/mir/blob/643bb0cdd12cd29029abb29ccf0edc5e94ba4103/c2mir/c2mir-driver.c#L786-L793