Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add MIR_get_global_item #383

Open
wants to merge 2 commits into
base: v0_master
Choose a base branch
from
Open

Add MIR_get_global_item #383

wants to merge 2 commits into from

Conversation

iacore
Copy link
Contributor

@iacore iacore commented Nov 30, 2023

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

Why was it missing???
@iacore iacore marked this pull request as ready for review November 30, 2023 19:19
@vnmakarov
Copy link
Owner

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
Copy link
Contributor Author

iacore commented Nov 30, 2023

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

mir/c2mir/c2mir-driver.c

Lines 786 to 793 in 643bb0c

for (module = DLIST_HEAD (MIR_module_t, *MIR_get_module_list (main_ctx)); module != NULL;
module = DLIST_NEXT (MIR_module_t, module)) {
for (func = DLIST_HEAD (MIR_item_t, module->items); func != NULL;
func = DLIST_NEXT (MIR_item_t, func))
if (func->item_type == MIR_func_item && strcmp (func->u.func->name, "main") == 0)
main_func = func;
MIR_load_module (main_ctx, module);
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants