Perform nested assembly loading. Use assembly loading instead of
[mono.git] / mono / metadata / loader.c
1 /*
2  * loader.c: Image Loader 
3  *
4  * Authors:
5  *   Paolo Molaro (lupus@ximian.com)
6  *   Miguel de Icaza (miguel@ximian.com)
7  *
8  * (C) 2001 Ximian, Inc.
9  *
10  * This file is used by the interpreter and the JIT engine to locate
11  * assemblies.  Used to load AssemblyRef and later to resolve various
12  * kinds of `Refs'.
13  *
14  * TODO:
15  *   This should keep track of the assembly versions that we are loading.
16  *
17  */
18 #include <config.h>
19 #include <glib.h>
20 #include <stdio.h>
21 #include <mono/metadata/metadata.h>
22 #include <mono/metadata/image.h>
23 #include <mono/metadata/cil-coff.h>
24 #include "cli.h"
25
26 MonoMethod *
27 mono_get_method (MonoImage *image, guint32 token)
28 {
29         MonoMethod *result = g_new0 (MonoMethod, 1);
30         int table = mono_metadata_token_table (token);
31         int index = mono_metadata_token_index (token);
32         cli_image_info_t *iinfo = image->image_info;
33         metadata_tableinfo_t *tables = iinfo->cli_metadata.tables;
34         const char *loc;
35         const char *sig = NULL;
36         int size;
37         guint32 cols[6];
38
39         /*
40          * We need a context with cli_image_info_t for this module and the assemblies
41          * loaded later to support method refs...
42          */
43         if (table != META_TABLE_METHOD) {
44                 g_assert (table == META_TABLE_MEMBERREF);
45                 mono_metadata_decode_row (&tables [table], index, cols, 3);
46                 g_assert ((cols [0] & 0x07) != 3);
47                 table = META_TABLE_METHOD;
48                 index = cols [0] >> 3;
49                 sig = mono_metadata_blob_heap (&iinfo->cli_metadata, cols [2]);
50                 result->name_idx = cols [1];
51         }
52         
53         mono_metadata_decode_row (&tables [table], index - 1, cols, 6);
54         result->name_idx = cols [3];
55         /* if this is a methodref from another module/assembly, this fails */
56         loc = cli_rva_map (iinfo, cols [0]);
57         g_assert (loc);
58         result->header = mono_metadata_parse_mh (&iinfo->cli_metadata, loc);
59         if (!sig) /* already taken from the methodref */
60                 sig = mono_metadata_blob_heap (&iinfo->cli_metadata, cols [4]);
61         sig = mono_metadata_decode_blob_size (sig, &size);
62         result->signature = mono_metadata_parse_method_signature (&iinfo->cli_metadata, 0, sig, NULL);
63
64         return result;
65 }
66
67 void
68 mono_free_method  (MonoMethod *method)
69 {
70         mono_metadata_free_method_signature (method->signature);
71         mono_metadata_free_mh (method->header);
72         g_free (method);
73 }