From 685794495e1206c8d49b06fb5531307969e5f3b4 Mon Sep 17 00:00:00 2001 From: Jasper Mattsson Date: Wed, 11 Nov 2020 02:23:37 +0200 Subject: [PATCH] Add missing MIR_get_global_item --- mir.c | 10 ++++++++++ mir.h | 1 + 2 files changed, 11 insertions(+) diff --git a/mir.c b/mir.c index 9ebb6a443d..532e482ec7 100644 --- a/mir.c +++ b/mir.c @@ -1464,6 +1464,16 @@ void MIR_finish_module (MIR_context_t ctx) { curr_module = NULL; } +MIR_item_t MIR_get_global_item (MIR_context_t ctx, const char *name) { + for (MIR_item_t item = DLIST_HEAD (MIR_item_t, environment_module.items); item != NULL; + item = DLIST_NEXT (MIR_item_t, item)) { + if (item->item_type == MIR_import_item && strcmp (item->u.import_id, name) == 0) { + return item->ref_def; + } + } + return NULL; +} + static void setup_global (MIR_context_t ctx, const char *name, void *addr, MIR_item_t def) { MIR_item_t item, tab_item; MIR_module_t saved = curr_module; diff --git a/mir.h b/mir.h index 4f1398515e..3b1818d524 100644 --- a/mir.h +++ b/mir.h @@ -553,6 +553,7 @@ extern void MIR_read_with_func (MIR_context_t ctx, int (*const reader_func) (MIR extern void MIR_scan_string (MIR_context_t ctx, const char *str); #endif +/* Get an exported item or an external function by its name */ extern MIR_item_t MIR_get_global_item (MIR_context_t ctx, const char *name); extern void MIR_load_module (MIR_context_t ctx, MIR_module_t m); extern void MIR_load_external (MIR_context_t ctx, const char *name, void *addr);