Skip to content

Add MIR_get_global_item#383

Open
iacore wants to merge 2 commits intovnmakarov:v0_masterfrom
iacore:fix-4
Open

Add MIR_get_global_item#383
iacore wants to merge 2 commits intovnmakarov:v0_masterfrom
iacore:fix-4

Conversation

@iacore
Copy link
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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