diff options
author | Dietmar Maurer <dietmar@mono-cvs.ximian.com> | 2001-08-21 06:51:33 +0400 |
---|---|---|
committer | Dietmar Maurer <dietmar@mono-cvs.ximian.com> | 2001-08-21 06:51:33 +0400 |
commit | 726d99ab5b162500adf9e69a8e64ee35584409d6 (patch) | |
tree | dc664a4c000216535d0d4861a0663c6f548bc88e | |
parent | 18667dfc0d58565e609175d535cd260c72d2fb6e (diff) |
merged the cli and metadata directories - everything is now in metadata
svn path=/trunk/mono/; revision=529
-rw-r--r-- | configure.in | 1 | ||||
-rw-r--r-- | mono/Makefile.am | 2 | ||||
-rw-r--r-- | mono/cli/.cvsignore | 5 | ||||
-rw-r--r-- | mono/cli/ChangeLog | 150 | ||||
-rw-r--r-- | mono/cli/Makefile.am | 16 | ||||
-rw-r--r-- | mono/cli/class.c | 484 | ||||
-rw-r--r-- | mono/cli/class.h | 71 | ||||
-rw-r--r-- | mono/cli/loader.c | 453 | ||||
-rw-r--r-- | mono/cli/object.c | 179 | ||||
-rw-r--r-- | mono/cli/object.h | 49 | ||||
-rw-r--r-- | mono/cli/types.h | 28 | ||||
-rw-r--r-- | mono/interpreter/Makefile.am | 9 | ||||
-rw-r--r-- | mono/interpreter/icall.c | 31 | ||||
-rw-r--r-- | mono/interpreter/interp.c | 10 | ||||
-rw-r--r-- | mono/interpreter/interp.h | 6 | ||||
-rw-r--r-- | mono/metadata/Makefile.am | 18 | ||||
-rw-r--r-- | mono/metadata/class.c | 6 | ||||
-rw-r--r-- | mono/metadata/class.h | 2 | ||||
-rw-r--r-- | mono/metadata/icall.c | 31 | ||||
-rw-r--r-- | mono/metadata/loader.c | 31 | ||||
-rw-r--r-- | mono/metadata/loader.h (renamed from mono/cli/cli.h) | 7 | ||||
-rw-r--r-- | mono/metadata/object.c | 4 | ||||
-rw-r--r-- | mono/metadata/object.h | 2 |
23 files changed, 86 insertions, 1509 deletions
diff --git a/configure.in b/configure.in index 3df24b068d6..505a7f950a2 100644 --- a/configure.in +++ b/configure.in @@ -40,7 +40,6 @@ mono/Makefile mono/metadata/Makefile mono/dis/Makefile mono/cil/Makefile -mono/cli/Makefile mono/interpreter/Makefile mono/tests/Makefile mono/wrapper/Makefile diff --git a/mono/Makefile.am b/mono/Makefile.am index ce9de43f09b..4e595711c97 100644 --- a/mono/Makefile.am +++ b/mono/Makefile.am @@ -1 +1 @@ -SUBDIRS = metadata cil cli dis interpreter wrapper +SUBDIRS = metadata cil dis interpreter wrapper diff --git a/mono/cli/.cvsignore b/mono/cli/.cvsignore deleted file mode 100644 index 2982b1ba7fd..00000000000 --- a/mono/cli/.cvsignore +++ /dev/null @@ -1,5 +0,0 @@ -Makefile -Makefile.in -*.a -*.o -.deps diff --git a/mono/cli/ChangeLog b/mono/cli/ChangeLog deleted file mode 100644 index e5de4619ff8..00000000000 --- a/mono/cli/ChangeLog +++ /dev/null @@ -1,150 +0,0 @@ -2001-08-20 Dietmar Maurer <dietmar@ximian.com> - - * object.c (mono_new_string): impl. - - * loader.c (mono_init): impl. - - * object.c (mono_new_utf16_string): impl. - - * class.h: replaced 'struct MonoMethod' with 'MonoMethod' - - * cli.h: removed #include <mono/cli/object.h> - -Sat Aug 18 12:42:26 CEST 2001 Paolo Molaro <lupus@ximian.com> - - * class.c, class.h: load also the methods when loading a class. - -2001-08-10 Dietmar Maurer <dietmar@ximian.com> - - * object.c (mono_object_clone): impl. - -2001-08-09 Dietmar Maurer <dietmar@ximian.com> - - * object.c (mono_new_szarray): impl. - - * loader.c (mono_typedef_from_name): return the token, not the index - (mono_get_corlib): impl. - (mono_get_array_class_info): impl. - (method_from_memberref): add array support - (mono_get_method): support INTERNAL_CALL - - * class.c (mono_class_create_from_typedef): Array support, - code cleanup, store the token_type, not the token index, added - flag for value types. - (mono_type_to_tydedef): impl. - (mono_class_create_from_typespec): impl. - (mono_array_class_get): impl. - (mono_class_get): support TYPE_SPEC token. - -2001-08-06 Dietmar Maurer <dietmar@ximian.com> - - * cli.h: renamed MonoMethodManaged to MonoMethodNormal - - * loader.h: removed. - - * object.h: added MonoArrayObject and MonoStringObject - - * loader.c (mono_typedef_from_name): - s/typedef_from_name/(mono_typedef_from_name and made it public. - - * class.c (class_compute_field_layout): skip the FIELD signature - (mono_class_create_from_typedef): bug fix: field.last was wrong - (class_compute_field_layout): added some code to make it work for - classes with EXPLICIT_LAYOUT but no offsets specified (I observed - that behaviour on System.Array) - -2001-08-02 Dietmar Maurer <dietmar@ximian.com> - - * loader.c (mono_get_string_class_info): do a strcmp to check - if it is System.String instead of using magic numbers. - (mono_map_dll): impl. - (mono_get_method): bug fix: pass index - 1 to fill_pinvoke_info - - * class.c (mono_class_create_from_typedef): do a strcmp to check - if it is System.Object instead of using magic numbers. - -Wed Aug 1 22:48:29 CEST 2001 Paolo Molaro <lupus@ximian.com> - - * class.c, class.h: mono_field_type_size () moved to metadata. - Take correctly into account alignment when laying out - class fields. Fix 5 to 0 magc number (to check for System.Object). - -2001-08-01 Dietmar Maurer <dietmar@ximian.com> - - * loader.c (mono_get_string_class_info): impl. - (methoddef_from_memberref): added check for references into mscorlib - - * class.c (mono_class_create_from_typedef): better check for root - object - -Tue Jul 31 17:45:44 CEST 2001 Paolo Molaro <lupus@ximian.com> - - * class.c, cli.h, loader.c: massive namespace cleanup. - -2001-07-31 Dietmar Maurer <dietmar@ximian.com> - - * cli.h: added pinvoke flags to MonoMethodPInvoke, moved method - implementation flags to MonoMethod - -Mon Jul 30 20:05:23 CEST 2001 Paolo Molaro <lupus@ximian.com> - - * cli.h, loader.c: usa a char *name field in MonoMethod instead - of the name_idx token. - -Fri Jul 27 20:51:47 CEST 2001 Paolo Molaro <lupus@ximian.com> - - * class.h, class.c: add inited field to MonoClass. - -Fri Jul 27 13:51:11 CEST 2001 Paolo Molaro <lupus@ximian.com> - - * class.h, class.c: add a class_size member to MonoClass. We store - the static fields after the other class data. Offsets for static - fields are offsets from the MonoClass pointer. - Properly initialize class->instance_size and deal with static - fields when layouting them. - -2001-07-27 Dietmar Maurer <dietmar@ximian.com> - - * loader.c (ves_map_ffi_type): impl. - (fill_pinvoke_info): impl. - -Fri Jul 27 11:46:09 CEST 2001 Paolo Molaro <lupus@ximian.com> - - * loader.c: implemented lookup of methods in a different MonoImage - (needed to call the Syste.Object constructor, for example). Fixed the cache - code to only check for methods defined in the image. - -Thu Jul 26 15:31:01 CEST 2001 Paolo Molaro <lupus@ximian.com> - - * loader.c: forgot to insert the method in the cache, not nice - with a recursive fibonacci test case :-) - -Thu Jul 26 13:17:22 CEST 2001 Paolo Molaro <lupus@ximian.com> - - * class.c: updates to match changes in metadata. - Fix off by one errors. Implement creation of classes by typeref. - Remove custom cache and use the class cache in MonoImage. - * cli.h, loader.c: add MonoImage field to MonoMethod. Fill method cache - in MonoImage. Updates to match changes in metadata. - -2001-07-24 Miguel de Icaza <miguel@ximian.com> - - * class.c (mono_class_create_from_typedef): Take into account - parent classes for the size of a structure. - - Still not ideal, but better than before. - - For the case of the interpreter, Paolo is right, there is not much - use for a Field Map, as the way the Fields are located is through - a token. - - (mono_class_init): Remove, initialize automatically. - - (mono_class_get_field): new function, returns the information - about a field given a class and its token. - -2001-07-23 Miguel de Icaza <miguel@ximian.com> - - * object.h, object.c, class.h, class.c: Implemented the beginning - of the object system. x - diff --git a/mono/cli/Makefile.am b/mono/cli/Makefile.am deleted file mode 100644 index 695e494e3a9..00000000000 --- a/mono/cli/Makefile.am +++ /dev/null @@ -1,16 +0,0 @@ -lib_LIBRARIES = libmonocli.a - -INCLUDES = $(GLIB_CFLAGS) -I$(top_srcdir) - -libmonocli_a_SOURCES = \ - class.c \ - loader.c \ - object.c - -libmonocliincludedir = $(includir)/mono/cli - -libmonocliinclude_HEADERS = \ - class.h \ - cli.h \ - object.h \ - types.h diff --git a/mono/cli/class.c b/mono/cli/class.c deleted file mode 100644 index 20aefe97980..00000000000 --- a/mono/cli/class.c +++ /dev/null @@ -1,484 +0,0 @@ -/* - * class.c: Class management for the Mono runtime - * - * Author: - * Miguel de Icaza (miguel@ximian.com) - * - * (C) 2001 Ximian, Inc. - * - * Possible Optimizations: - * in mono_class_create, do not allocate the class right away, - * but wait until you know the size of the FieldMap, so that - * the class embeds directly the FieldMap after the vtable. - * - * - */ -#include <config.h> -#include <glib.h> -#include <stdio.h> -#include <mono/metadata/image.h> -#include <mono/metadata/cil-coff.h> -#include <mono/metadata/metadata.h> -#include <mono/metadata/tabledefs.h> -#include <mono/metadata/tokentype.h> -#include <mono/cli/cli.h> -#include <mono/cli/class.h> -#include <mono/cli/types.h> -#include <mono/cli/object.h> - -#define CSIZE(x) (sizeof (x) / 4) - -static void -typedef_from_typeref (MonoImage *image, guint32 type_token, MonoImage **rimage, guint32 *index) -{ - guint32 cols[MONO_TYPEDEF_SIZE]; - MonoMetadata *m = &image->metadata; - MonoTableInfo *t = &m->tables[MONO_TABLE_TYPEREF]; - guint32 idx, i; - const char *name, *nspace; - - mono_metadata_decode_row (t, (type_token&0xffffff)-1, cols, 3); - g_assert ((cols [0] & 0x3) == 2); - idx = cols [0] >> 2; - name = mono_metadata_string_heap (m, cols [1]); - nspace = mono_metadata_string_heap (m, cols [2]); - /* load referenced assembly */ - image = image->references [idx-1]->image; - m = &image->metadata; - t = &m->tables [MONO_TABLE_TYPEDEF]; - /* dumb search for now */ - for (i=0; i < t->rows; ++i) { - mono_metadata_decode_row (t, i, cols, MONO_TYPEDEF_SIZE); - - if (!strcmp (name, mono_metadata_string_heap (m, cols [1])) && - !strcmp (nspace, mono_metadata_string_heap (m, cols [2]))) { - *rimage = image; - *index = MONO_TOKEN_TYPE_DEF | (i + 1); - return; - } - } - g_assert_not_reached (); - -} - -/** - * class_compute_field_layout: - * @m: pointer to the metadata. - * @class: The class to initialize - * - * Initializes the class->fields. - * - * Currently we only support AUTO_LAYOUT, and do not even try to do - * a good job at it. This is temporary to get the code for Paolo. - */ -static void -class_compute_field_layout (MonoMetadata *m, MonoClass *class) -{ - const int top = class->field.count; - guint32 layout = class->flags & TYPE_ATTRIBUTE_LAYOUT_MASK; - MonoTableInfo *t = &m->tables [MONO_TABLE_FIELD]; - int i, j; - - /* - * Fetch all the field information. - */ - for (i = 0; i < top; i++){ - const char *sig; - guint32 cols [3]; - int idx = class->field.first + i; - - mono_metadata_decode_row (t, idx, cols, CSIZE (cols)); - sig = mono_metadata_blob_heap (m, cols [2]); - mono_metadata_decode_value (sig, &sig); - /* FIELD signature == 0x06 */ - g_assert (*sig == 0x06); - class->fields [i].type = mono_metadata_parse_field_type ( - m, sig + 1, &sig); - class->fields [i].flags = cols [0]; - } - /* - * Compute field layout and total size. - */ - switch (layout){ - case TYPE_ATTRIBUTE_AUTO_LAYOUT: - case TYPE_ATTRIBUTE_SEQUENTIAL_LAYOUT: - for (i = 0; i < top; i++){ - int size, align; - - size = mono_type_size (class->fields [i].type->type, &align); - if (class->fields [i].flags & FIELD_ATTRIBUTE_STATIC) { - class->fields [i].offset = class->class_size; - class->class_size += (class->class_size % align); - class->class_size += size; - } else { - class->fields [i].offset = class->instance_size; - class->instance_size += (class->instance_size % align); - class->instance_size += size; - } - } - break; - case TYPE_ATTRIBUTE_EXPLICIT_LAYOUT: - for (i = 0; i < top; i++){ - guint32 cols [2]; - int size, align; - int idx = class->field.first + i; - - t = &m->tables [MONO_TABLE_FIELDLAYOUT]; - - for (j = 0; j < t->rows; j++) { - - mono_metadata_decode_row (t, j, cols, CSIZE (cols)); - if (cols [1] == idx) { - g_warning ("TODO: Explicit layout not supported yet"); - } - } - - size = mono_type_size (class->fields [i].type->type, &align); - if (class->fields [i].flags & FIELD_ATTRIBUTE_STATIC) { - class->fields [i].offset = class->class_size; - class->class_size += (class->class_size % align); - class->class_size += size; - } else { - class->fields [i].offset = class->instance_size; - class->instance_size += (class->instance_size % align); - class->instance_size += size; - } - } - break; - } -} - -/** - * @image: context where the image is created - * @type_token: typedef token - */ -static MonoClass * -mono_class_create_from_typedef (MonoImage *image, guint32 type_token) -{ - MonoMetadata *m = &image->metadata; - MonoTableInfo *tt = &m->tables [MONO_TABLE_TYPEDEF]; - MonoClass stack_class; - MonoClass *class = &stack_class; - guint32 cols [MONO_TYPEDEF_SIZE], parent_token; - guint tidx = mono_metadata_token_index (type_token); - const char *name, *nspace; - - g_assert (mono_metadata_token_table (type_token) == MONO_TABLE_TYPEDEF); - - memset (class, 0, sizeof (MonoClass)); - - mono_metadata_decode_row (tt, tidx-1, cols, CSIZE (cols)); - name = mono_metadata_string_heap (m, cols[1]); - nspace = mono_metadata_string_heap (m, cols[2]); - /*g_print ("Init class %s\n", name);*/ - - /* if root of the hierarchy */ - if (!strcmp (nspace, "System") && !strcmp (name, "Object")) { - class->instance_size = sizeof (MonoObject); - class->parent = NULL; - } else { - parent_token = mono_metadata_token_from_dor (cols [3]); - class->parent = mono_class_get (image, parent_token); - class->instance_size = class->parent->instance_size; - class->valuetype = class->parent->valuetype; - } - if (!strcmp (nspace, "System") && !strcmp (name, "ValueType")) - class->valuetype = 1; - - g_assert (class->instance_size); - class->image = image; - class->type_token = type_token; - class->flags = cols [0]; - class->class_size = sizeof (MonoClass); - - /* - * Compute the field and method lists - */ - class->field.first = cols [MONO_TYPEDEF_FIELD_LIST] - 1; - class->method.first = cols [MONO_TYPEDEF_METHOD_LIST] - 1; - - if (tt->rows > tidx){ - guint32 cols_next [MONO_TYPEDEF_SIZE]; - - mono_metadata_decode_row (tt, tidx, cols_next, CSIZE (cols_next)); - class->field.last = cols_next [MONO_TYPEDEF_FIELD_LIST] - 1; - class->method.last = cols_next [MONO_TYPEDEF_METHOD_LIST] - 1; - } else { - class->field.last = m->tables [MONO_TABLE_FIELD].rows; - class->method.last = m->tables [MONO_TABLE_METHOD].rows; - } - - if (cols [MONO_TYPEDEF_FIELD_LIST] && - cols [MONO_TYPEDEF_FIELD_LIST] <= m->tables [MONO_TABLE_FIELD].rows) - class->field.count = class->field.last - class->field.first; - else - class->field.count = 0; - - if (cols [MONO_TYPEDEF_METHOD_LIST] <= m->tables [MONO_TABLE_METHOD].rows) - class->method.count = class->method.last - class->method.first; - else - class->method.count = 0; - - /* - * Computes the size used by the fields, and their locations - */ - if (class->field.count > 0){ - class->fields = g_new (MonoClassField, class->field.count); - class_compute_field_layout (m, class); - } - - /* reserve space to store vector pointer in arrays */ - if (!strcmp (nspace, "System") && !strcmp (name, "Array")) { - class->instance_size += 2 * sizeof (gpointer); - g_assert (class->field.count == 0); - g_assert (class->instance_size == sizeof (MonoArrayObject)); - } - - if (class->method.count > 0) { - int i; - class->methods = g_new (MonoMethod*, class->method.count); - for (i = class->method.first; i < class->method.last; ++i) - class->methods [i - class->method.first] = mono_get_method (image, - MONO_TOKEN_METHOD_DEF | (i + 1)); - } - - class = g_malloc0 (class->class_size); - *class = stack_class; - return class; -} - -static guint32 -mono_type_to_tydedef (MonoImage *image, MonoType *type, MonoImage **rimage) -{ - MonoImage *corlib, *res; - guint32 etype; - - res = corlib = mono_defaults.corlib; - - switch (type->type) { - case MONO_TYPE_BOOLEAN: - etype = mono_typedef_from_name (corlib, "Boolean", "System", NULL); - break; - case MONO_TYPE_CHAR: - etype = mono_typedef_from_name (corlib, "Char", "System", NULL); - break; - case MONO_TYPE_I1: - etype = mono_typedef_from_name (corlib, "Byte", "System", NULL); - break; - case MONO_TYPE_I2: - etype = mono_typedef_from_name (corlib, "Int16", "System", NULL); - break; - case MONO_TYPE_U2: - etype = mono_typedef_from_name (corlib, "UInt16", "System", NULL); - break; - case MONO_TYPE_I4: - etype = mono_typedef_from_name (corlib, "Int32", "System", NULL); - break; - case MONO_TYPE_U4: - etype = mono_typedef_from_name (corlib, "UInt32", "System", NULL); - break; - case MONO_TYPE_I8: - etype = mono_typedef_from_name (corlib, "Int64", "System", NULL); - break; - case MONO_TYPE_U8: - etype = mono_typedef_from_name (corlib, "UInt64", "System", NULL); - break; - case MONO_TYPE_R8: - etype = mono_typedef_from_name (corlib, "Double", "System", NULL); - break; - case MONO_TYPE_STRING: - etype = mono_typedef_from_name (corlib, "String", "System", NULL); - break; - case MONO_TYPE_CLASS: - etype = type->data.token; - res = image; - break; - default: - g_warning ("implement me %08x\n", type->type); - g_assert_not_reached (); - } - - *rimage = res; - return etype; -} - -/** - * @image: context where the image is created - * @type_spec: typespec token - * @at: an optional pointer to return the array type - */ -static MonoClass * -mono_class_create_from_typespec (MonoImage *image, guint32 type_spec) -{ - MonoMetadata *m = &image->metadata; - guint32 idx = mono_metadata_token_index (type_spec); - MonoTableInfo *t; - guint32 cols [MONO_TYPESPEC_SIZE]; - const char *ptr; - guint32 len, etype; - MonoType *type; - MonoClass *class; - MonoImage *rimage; - - t = &m->tables [MONO_TABLE_TYPESPEC]; - - mono_metadata_decode_row (t, idx-1, cols, MONO_TYPESPEC_SIZE); - ptr = mono_metadata_blob_heap (m, cols [MONO_TYPESPEC_SIGNATURE]); - len = mono_metadata_decode_value (ptr, &ptr); - type = mono_metadata_parse_type (m, ptr, &ptr); - - switch (type->type) { - case MONO_TYPE_ARRAY: - etype = mono_type_to_tydedef (image, type->data.array->type, &rimage); - class = mono_array_class_get (rimage, etype, type->data.array->rank); - break; - case MONO_TYPE_SZARRAY: - g_assert (!type->custom_mod); - etype = mono_type_to_tydedef (image, type->data.type, &rimage); - class = mono_array_class_get (rimage, etype, 1); - break; - default: - g_assert_not_reached (); - } - - mono_metadata_free_type (type); - - return class; -} - -MonoClass * -mono_array_class_get (MonoImage *image, guint32 etype, guint32 rank) -{ - MonoClass *class, *eclass; - static MonoClass *parent = NULL; - MonoArrayClass *aclass; - guint32 esize, key; - - g_assert (rank <= 255); - - if (!parent) { - parent = mono_class_get (mono_defaults.corlib, - mono_defaults.array_token); - g_assert (parent != NULL); - } - - eclass = mono_class_get (image, etype); - g_assert (eclass != NULL); - - image = eclass->image; - - esize = eclass->instance_size; - - g_assert (!eclass->type_token || - mono_metadata_token_table (eclass->type_token) == MONO_TABLE_TYPEDEF); - - key = ((rank & 0xff) << 24) | (eclass->type_token & 0xffffff); - if ((class = g_hash_table_lookup (image->array_cache, GUINT_TO_POINTER (key)))) - return class; - - if (eclass->valuetype) - esize -= sizeof (MonoObject); - - aclass = g_new0 (MonoArrayClass, 1); - class = (MonoClass *)aclass; - - class->image = image; - class->type_token = 0; - class->flags = TYPE_ATTRIBUTE_CLASS; - class->parent = parent; - class->instance_size = class->parent->instance_size; - class->class_size = sizeof (MonoArrayClass); - class->evaltype = eclass->valuetype; - - aclass->rank = rank; - aclass->etype_token = eclass->type_token; - aclass->esize = esize; - - g_hash_table_insert (image->array_cache, GUINT_TO_POINTER (key), class); - return class; -} - -/* - * Auxiliary routine to mono_class_get_field - * - * Takes a field index instead of a field token. - */ -static MonoClassField * -mono_class_get_field_idx (MonoClass *class, int idx) -{ - if (class->field.count){ - if ((idx >= class->field.first) && (idx < class->field.last)){ - return &class->fields [idx - class->field.first]; - } - } - - if (!class->parent) - return NULL; - - return mono_class_get_field_idx (class->parent, idx); -} - -/** - * mono_class_get_field: - * @class: the class to lookup the field. - * @field_token: the field token - * - * Returns: A MonoClassField representing the type and offset of - * the field, or a NULL value if the field does not belong to this - * class. - */ -MonoClassField * -mono_class_get_field (MonoClass *class, guint32 field_token) -{ - int idx = mono_metadata_token_index (field_token); - - if (mono_metadata_token_code (field_token) == MONO_TOKEN_MEMBER_REF) - g_error ("Unsupported Field Token is a MemberRef, implement me"); - - g_assert (mono_metadata_token_code (field_token) == MONO_TOKEN_FIELD_DEF); - - return mono_class_get_field_idx (class, idx - 1); -} - -/** - * mono_class_get: - * @image: the image where the class resides - * @type_token: the token for the class - * @at: an optional pointer to return the array element type - * - * Returns: the MonoClass that represents @type_token in @image - */ -MonoClass * -mono_class_get (MonoImage *image, guint32 type_token) -{ - MonoClass *class; - - switch (type_token & 0xff000000){ - case MONO_TOKEN_TYPE_DEF: - if ((class = g_hash_table_lookup (image->class_cache, - GUINT_TO_POINTER (type_token)))) - return class; - - class = mono_class_create_from_typedef (image, type_token); - break; - - case MONO_TOKEN_TYPE_REF: { - typedef_from_typeref (image, type_token, &image, &type_token); - return mono_class_get (image, type_token); - } - case MONO_TOKEN_TYPE_SPEC: - if ((class = g_hash_table_lookup (image->class_cache, - GUINT_TO_POINTER (type_token)))) - return class; - - class = mono_class_create_from_typespec (image, type_token); - break; - default: - g_assert_not_reached (); - } - - g_hash_table_insert (image->class_cache, GUINT_TO_POINTER (type_token), class); - - return class; -} - diff --git a/mono/cli/class.h b/mono/cli/class.h deleted file mode 100644 index 9cf8e2a35a1..00000000000 --- a/mono/cli/class.h +++ /dev/null @@ -1,71 +0,0 @@ -#ifndef _MONO_CLI_CLASS_H_ -#define _MONO_CLI_CLASS_H_ - -#include <mono/metadata/metadata.h> -#include <mono/metadata/image.h> -#include <mono/cli/cli.h> - -#define MONO_CLASS_IS_ARRAY(c) (c->type_token == 0) - -typedef struct { - MonoFieldType *type; - int offset; - guint32 flags; -} MonoClassField; - -typedef struct _MonoClass MonoClass; - -struct _MonoClass { - MonoImage *image; - guint32 type_token; - - guint inited : 1; - guint valuetype : 1; /* derives from System.ValueType */ - guint evaltype : 1; /* element type derives from System.ValueType */ - - MonoClass *parent; - - /* - * Computed object instance size, total. - */ - int instance_size; - int class_size; - - /* - * From the TypeDef table - */ - guint32 flags; - struct { - guint32 first, last; - int count; - } field, method; - - /* - * Field information: Type and location from object base - */ - MonoClassField *fields; - - MonoMethod **methods; - - /* - * After the methods, there is room for the static fields... - */ -}; - -typedef struct { - MonoClass class; - guint32 rank; /* array dimension */ - guint32 etype_token; /* element type token */ - guint32 esize; /* element size */ -} MonoArrayClass; - -MonoClass * -mono_class_get (MonoImage *image, guint32 type_token); - -MonoClass * -mono_array_class_get (MonoImage *image, guint32 etype, guint32 rank); - -MonoClassField * -mono_class_get_field (MonoClass *class, guint32 field_token); - -#endif /* _MONO_CLI_CLASS_H_ */ diff --git a/mono/cli/loader.c b/mono/cli/loader.c deleted file mode 100644 index 70637ce2277..00000000000 --- a/mono/cli/loader.c +++ /dev/null @@ -1,453 +0,0 @@ -/* - * loader.c: Image Loader - * - * Authors: - * Paolo Molaro (lupus@ximian.com) - * Miguel de Icaza (miguel@ximian.com) - * - * (C) 2001 Ximian, Inc. - * - * This file is used by the interpreter and the JIT engine to locate - * assemblies. Used to load AssemblyRef and later to resolve various - * kinds of `Refs'. - * - * TODO: - * This should keep track of the assembly versions that we are loading. - * - */ -#include <config.h> -#include <glib.h> -#include <gmodule.h> -#include <stdio.h> -#include <string.h> -#include <mono/metadata/metadata.h> -#include <mono/metadata/image.h> -#include <mono/metadata/assembly.h> -#include <mono/metadata/tokentype.h> -#include <mono/metadata/cil-coff.h> -#include <mono/metadata/tabledefs.h> -#include "cli.h" - -MonoDefaults mono_defaults; - -static char *dll_map[] = { - "libc", "libc.so.6", - "libm", "libm.so.6", - "cygwin1.dll", "libc.so.6", - NULL, NULL -}; - -static const char * -mono_map_dll (const char *name) -{ - int i = 0; - - while (dll_map [i]) { - if (!strcmp (dll_map [i], name)) - return dll_map [i + 1]; - i += 2; - } - - return name; -} - -guint32 -mono_typedef_from_name (MonoImage *image, const char *name, - const char *nspace, guint32 *mlist) -{ - MonoMetadata *m = &image->metadata; - MonoTableInfo *t = &m->tables [MONO_TABLE_TYPEDEF]; - guint32 i; - guint32 cols [MONO_TYPEDEF_SIZE]; - - for (i=0; i < t->rows; ++i) { - mono_metadata_decode_row (t, i, cols, MONO_TYPEDEF_SIZE); - if (strcmp (name, mono_metadata_string_heap (m, cols [MONO_TYPEDEF_NAME])) == 0 - && strcmp (nspace, mono_metadata_string_heap (m, cols [MONO_TYPEDEF_NAMESPACE])) == 0) { - if (mlist) - *mlist = cols [MONO_TYPEDEF_METHOD_LIST]; - return MONO_TOKEN_TYPE_DEF | (i + 1); - } - } - g_assert_not_reached (); - return 0; -} - -void -mono_init () -{ - static gboolean initialized = FALSE; - MonoAssembly *ass; - enum MonoImageOpenStatus status = MONO_IMAGE_OK; - - if (initialized) - return; - - /* find the corlib */ - ass = mono_assembly_open (CORLIB_NAME, NULL, &status); - g_assert (status == MONO_IMAGE_OK); - g_assert (ass != NULL); - mono_defaults.corlib = ass->image; - - mono_defaults.array_token = mono_typedef_from_name ( - mono_defaults.corlib, "Array", "System", NULL); - g_assert (mono_defaults.array_token != 0); - - mono_defaults.char_token = mono_typedef_from_name ( - mono_defaults.corlib, "Char", "System", NULL); - g_assert (mono_defaults.char_token != 0); - - mono_defaults.string_token = mono_typedef_from_name ( - mono_defaults.corlib, "String", "System", NULL); - - g_assert (mono_defaults.string_token != 0); - -} - -static MonoMethod * -method_from_memberref (MonoImage *image, guint32 index) -{ - MonoImage *mimage; - MonoMetadata *m = &image->metadata; - MonoTableInfo *tables = m->tables; - guint32 cols[6]; - guint32 nindex, class, i; - const char *mname, *name, *nspace; - MonoMethodSignature *sig, *msig; - const char *ptr; - - mono_metadata_decode_row (&tables [MONO_TABLE_MEMBERREF], index-1, cols, 3); - nindex = cols [MONO_MEMBERREF_CLASS] >> MEMBERREF_PARENT_BITS; - class = cols [MONO_MEMBERREF_CLASS] & MEMBERREF_PARENT_MASK; - /*g_print ("methodref: 0x%x 0x%x %s\n", class, nindex, - mono_metadata_string_heap (m, cols [MONO_MEMBERREF_NAME]));*/ - - mname = mono_metadata_string_heap (m, cols [MONO_MEMBERREF_NAME]); - - ptr = mono_metadata_blob_heap (m, cols [MONO_MEMBERREF_SIGNATURE]); - mono_metadata_decode_blob_size (ptr, &ptr); - sig = mono_metadata_parse_method_signature (m, 0, ptr, NULL); - - switch (class) { - case MEMBERREF_PARENT_TYPEREF: { - guint32 scopeindex, scopetable; - - mono_metadata_decode_row (&tables [MONO_TABLE_TYPEREF], nindex-1, cols, MONO_TYPEREF_SIZE); - scopeindex = cols [MONO_TYPEREF_SCOPE] >> RESOLTION_SCOPE_BITS; - scopetable = cols [MONO_TYPEREF_SCOPE] & RESOLTION_SCOPE_MASK; - /*g_print ("typeref: 0x%x 0x%x %s.%s\n", scopetable, scopeindex, - mono_metadata_string_heap (m, cols [MONO_TYPEREF_NAMESPACE]), - mono_metadata_string_heap (m, cols [MONO_TYPEREF_NAME]));*/ - switch (scopetable) { - case RESOLTION_SCOPE_ASSEMBLYREF: - /* - * To find the method we have the following info: - * *) name and namespace of the class from the TYPEREF table - * *) name and signature of the method from the MEMBERREF table - */ - nspace = mono_metadata_string_heap (m, cols [MONO_TYPEREF_NAMESPACE]); - name = mono_metadata_string_heap (m, cols [MONO_TYPEREF_NAME]); - - /* this will triggered by references to mscorlib */ - g_assert (image->references [scopeindex-1] != NULL); - - mimage = image->references [scopeindex-1]->image; - - m = &mimage->metadata; - tables = &m->tables [MONO_TABLE_METHOD]; - mono_typedef_from_name (mimage, name, nspace, &i); - /* mostly dumb search for now */ - for (i--; i < tables->rows; ++i) { - - mono_metadata_decode_row (tables, i, cols, MONO_METHOD_SIZE); - - if (!strcmp (mname, mono_metadata_string_heap (m, cols [MONO_METHOD_NAME]))) { - - ptr = mono_metadata_blob_heap (m, cols [MONO_METHOD_SIGNATURE]); - mono_metadata_decode_blob_size (ptr, &ptr); - msig = mono_metadata_parse_method_signature (m, 1, ptr, NULL); - - if (mono_metadata_signature_equal (&image->metadata, sig, - &mimage->metadata, msig)) { - mono_metadata_free_method_signature (sig); - mono_metadata_free_method_signature (msig); - return mono_get_method (mimage, MONO_TOKEN_METHOD_DEF | (i + 1)); - } - } - } - g_warning ("cant find method %s.%s::%s",nspace, name, mname); - g_assert_not_reached (); - break; - default: - g_assert_not_reached (); - } - break; - } - case MEMBERREF_PARENT_TYPESPEC: { - guint32 bcols [MONO_TYPESPEC_SIZE]; - guint32 len; - MonoType *type; - MonoMethod *result; - - mono_metadata_decode_row (&tables [MONO_TABLE_TYPESPEC], nindex - 1, - bcols, MONO_TYPESPEC_SIZE); - ptr = mono_metadata_blob_heap (m, bcols [MONO_TYPESPEC_SIGNATURE]); - len = mono_metadata_decode_value (ptr, &ptr); - type = mono_metadata_parse_type (m, ptr, &ptr); - - if (type->type != MONO_TYPE_ARRAY) - g_assert_not_reached (); - - result = (MonoMethod *)g_new0 (MonoMethod, 1); - result->image = image; - result->iflags = METHOD_IMPL_ATTRIBUTE_INTERNAL_CALL; - result->signature = sig; - - if (!strcmp (mname, ".ctor")) { - g_assert (sig->hasthis); - if (type->data.array->rank == sig->param_count) { - result->addr = mono_lookup_internal_call ("__array_ctor"); - return result; - } else if ((type->data.array->rank * 2) == sig->param_count) { - result->addr = mono_lookup_internal_call ("__array_bound_ctor"); - return result; - } else - g_assert_not_reached (); - } - - if (!strcmp (mname, "Set")) { - g_assert (sig->hasthis); - g_assert (type->data.array->rank + 1 == sig->param_count); - - result->addr = mono_lookup_internal_call ("__array_Set"); - return result; - } - - if (!strcmp (mname, "Get")) { - g_assert (sig->hasthis); - g_assert (type->data.array->rank == sig->param_count); - - result->addr = mono_lookup_internal_call ("__array_Get"); - return result; - } - - g_assert_not_reached (); - break; - } - default: - g_assert_not_reached (); - } - - return NULL; -} - -static ffi_type * -ves_map_ffi_type (MonoType *type) -{ - ffi_type *rettype; - - switch (type->type) { - case MONO_TYPE_I1: - rettype = &ffi_type_sint8; - break; - case MONO_TYPE_BOOLEAN: - case MONO_TYPE_U1: - rettype = &ffi_type_uint8; - break; - case MONO_TYPE_I2: - rettype = &ffi_type_sint16; - break; - case MONO_TYPE_U2: - case MONO_TYPE_CHAR: - rettype = &ffi_type_uint16; - break; - case MONO_TYPE_I4: - rettype = &ffi_type_sint32; - break; - case MONO_TYPE_U4: - rettype = &ffi_type_sint32; - break; - case MONO_TYPE_R4: - rettype = &ffi_type_float; - break; - case MONO_TYPE_R8: - rettype = &ffi_type_double; - break; - case MONO_TYPE_STRING: - rettype = &ffi_type_pointer; - break; - case MONO_TYPE_VOID: - rettype = &ffi_type_void; - break; - default: - g_warning ("not implemented"); - g_assert_not_reached (); - } - - return rettype; -} - -static void -fill_pinvoke_info (MonoImage *image, MonoMethodPInvoke *piinfo, int index) -{ - MonoMethod *mh = &piinfo->method; - MonoTableInfo *tables = image->metadata.tables; - MonoTableInfo *im = &tables [MONO_TABLE_IMPLMAP]; - MonoTableInfo *mr = &tables [MONO_TABLE_MODULEREF]; - guint32 im_cols [4]; - guint32 mr_cols [1]; - const char *import = NULL; - const char *scope = NULL; - char *full_name; - GModule *gmodule; - ffi_type **args, *rettype; - int i, acount; - - for (i = 0; i < im->rows; i++) { - - mono_metadata_decode_row (im, i, im_cols, 4); - - if ((im_cols[1] >> 1) == index + 1) { - - import = mono_metadata_string_heap (&image->metadata, - im_cols [2]); - - mono_metadata_decode_row (mr, im_cols [3] - 1, mr_cols, - 1); - - scope = mono_metadata_string_heap (&image->metadata, - mr_cols [0]); - } - } - - g_assert (import && scope); - - scope = mono_map_dll (scope); - full_name = g_module_build_path (NULL, scope); - gmodule = g_module_open (full_name, G_MODULE_BIND_LAZY); - g_free (full_name); - - g_assert (gmodule); - - piinfo->cif = g_new (ffi_cif , 1); - piinfo->piflags = im_cols [0]; - - g_module_symbol (gmodule, import, &mh->addr); - - g_assert (mh->addr); - - acount = mh->signature->param_count; - - args = g_new (ffi_type *, acount); - - for (i = 0; i < acount; i++) - args[i] = ves_map_ffi_type (mh->signature->params [i]->type); - - rettype = ves_map_ffi_type (mh->signature->ret->type); - - if (!ffi_prep_cif (piinfo->cif, FFI_DEFAULT_ABI, acount, rettype, - args) == FFI_OK) { - g_warning ("prepare pinvoke failed"); - g_assert_not_reached (); - } -} - -MonoMethod * -mono_get_method (MonoImage *image, guint32 token) -{ - MonoMethod *result; - MonoMetadata *m = &image->metadata; - int table = mono_metadata_token_table (token); - int index = mono_metadata_token_index (token); - MonoTableInfo *tables = m->tables; - const char *loc, *sig = NULL; - char *name; - int size; - guint32 cols[MONO_TYPEDEF_SIZE]; - - if (table == MONO_TABLE_METHOD && (result = g_hash_table_lookup (image->method_cache, GINT_TO_POINTER (token)))) - return result; - - if (table != MONO_TABLE_METHOD) { - g_assert (table == MONO_TABLE_MEMBERREF); - return method_from_memberref (image, index); - } - - mono_metadata_decode_row (&tables [table], index - 1, cols, 6); - - if (cols [1] & METHOD_IMPL_ATTRIBUTE_INTERNAL_CALL) { - MonoTableInfo *t = &m->tables [MONO_TABLE_TYPEDEF]; - MonoAssembly *corlib; - guint32 tdef; - guint32 tdcols [MONO_TYPEDEF_SIZE]; - - tdef = mono_metadata_typedef_from_method (m, index - 1) - 1; - - mono_metadata_decode_row (t, tdef, tdcols, MONO_TYPEDEF_SIZE); - - name = g_strconcat (mono_metadata_string_heap (m, tdcols [MONO_TYPEDEF_NAMESPACE]), ".", - mono_metadata_string_heap (m, tdcols [MONO_TYPEDEF_NAME]), "::", - mono_metadata_string_heap (m, cols [MONO_METHOD_NAME]), NULL); - - corlib = mono_assembly_open (CORLIB_NAME, NULL, NULL); - - /* all internal calls must be inside corlib */ - g_assert (corlib->image == image); - - result = (MonoMethod *)g_new0 (MonoMethod, 1); - - result->addr = mono_lookup_internal_call (name); - - g_free (name); - - g_assert (result->addr != NULL); - - } else if (cols [2] & METHOD_ATTRIBUTE_PINVOKE_IMPL) { - - result = (MonoMethod *)g_new0 (MonoMethodPInvoke, 1); - } else { - - result = (MonoMethod *)g_new0 (MonoMethodNormal, 1); - } - - result->image = image; - result->flags = cols [2]; - result->iflags = cols [1]; - result->name = mono_metadata_string_heap (m, cols [3]); - - if (!sig) /* already taken from the methodref */ - sig = mono_metadata_blob_heap (m, cols [4]); - size = mono_metadata_decode_blob_size (sig, &sig); - result->signature = mono_metadata_parse_method_signature (m, 0, sig, NULL); - - if (result->flags & METHOD_ATTRIBUTE_PINVOKE_IMPL) { - fill_pinvoke_info (image, (MonoMethodPInvoke *)result, - index - 1); - } else if (!(result->iflags & METHOD_IMPL_ATTRIBUTE_INTERNAL_CALL)) { - /* if this is a methodref from another module/assembly, this fails */ - loc = mono_cli_rva_map ((MonoCLIImageInfo *)image->image_info, cols [0]); - g_assert (loc); - ((MonoMethodNormal *)result)->header = - mono_metadata_parse_mh (m, loc); - } - - g_hash_table_insert (image->method_cache, GINT_TO_POINTER (token), result); - - return result; -} - -void -mono_free_method (MonoMethod *method) -{ - mono_metadata_free_method_signature (method->signature); - if (method->flags & METHOD_ATTRIBUTE_PINVOKE_IMPL) { - MonoMethodPInvoke *piinfo = (MonoMethodPInvoke *)method; - g_free (piinfo->cif->arg_types); - g_free (piinfo->cif); - } else if (!(method->iflags & METHOD_IMPL_ATTRIBUTE_INTERNAL_CALL)) { - mono_metadata_free_mh (((MonoMethodNormal *)method)->header); - } - - g_free (method); -} - diff --git a/mono/cli/object.c b/mono/cli/object.c deleted file mode 100644 index 6368977b903..00000000000 --- a/mono/cli/object.c +++ /dev/null @@ -1,179 +0,0 @@ -/* - * object.c: Object creation for the Mono runtime - * - * Author: - * Miguel de Icaza (miguel@ximian.com) - * - * (C) 2001 Ximian, Inc. - */ -#include <config.h> -#include <stdlib.h> -#include <stdio.h> -#include <mono/cli/cli.h> -#include <mono/cli/object.h> - -/** - * mono_object_allocate: - * @size: number of bytes to allocate - * - * This is a very simplistic routine until we have our GC-aware - * memory allocator. - * - * Returns: an allocated object of size @size, or NULL on failure. - */ -static void * -mono_object_allocate (size_t size) -{ - void *o = calloc (1, size); - - return o; -} - -/** - * mono_object_free: - * - * Frees the memory used by the object. Debugging purposes - * only, as we will have our GC system. - */ -void -mono_object_free (MonoObject *o) -{ - MonoClass *c = o->klass; - - memset (o, 0, c->instance_size); - free (o); -} - -/** - * mono_object_new: - * @image: Context where the type_token is hosted - * @type_token: a token of the type that we want to create - * - * Returns: A newly created object whose definition is - * looked up using @type_token in the @image image - */ -MonoObject * -mono_object_new (MonoImage *image, guint32 type_token) -{ - MonoClass *c; - MonoObject *o; - - c = mono_class_get (image, type_token); - o = mono_object_allocate (c->instance_size); - o->klass = c; - - return o; -} - -/** - * mono_object_clone: - * @obj: the object to clone - * - * Returns: A newly created object who is a shallow copy of @obj - */ -MonoObject * -mono_object_clone (MonoObject *obj) -{ - MonoObject *o; - int size; - - size = obj->klass->instance_size; - o = mono_object_allocate (size); - - memcpy (o, obj, size); - - return o; -} - -/* - * mono_new_szarray: - * @image: image where the object is being referenced - * @etype: element type token - * @n: number of array elements - * - * This routine creates a new szarray with @n elements of type @token - */ -MonoObject * -mono_new_szarray (MonoImage *image, guint32 etype, guint32 n) -{ - MonoClass *c; - MonoObject *o; - MonoArrayObject *ao; - MonoArrayClass *ac; - - c = mono_array_class_get (image, etype, 1); - g_assert (c != NULL); - - o = mono_object_allocate (c->instance_size); - o->klass = c; - - ao = (MonoArrayObject *)o; - ac = (MonoArrayClass *)c; - - ao->bounds = g_malloc0 (sizeof (MonoArrayBounds)); - ao->bounds [0].length = n; - ao->bounds [0].lower_bound = 0; - - ao->vector = g_malloc0 (n * ac->esize); - - return o; -} - -MonoObject * -mono_new_utf16_string (const char *text, gint32 len) -{ - MonoObject *s; - MonoArrayObject *ca; - - s = mono_object_new (mono_defaults.corlib, mono_defaults.string_token); - g_assert (s != NULL); - - ca = (MonoArrayObject *)mono_new_szarray (mono_defaults.corlib, mono_defaults.string_token, len); - g_assert (ca != NULL); - - ((MonoStringObject *)s)->c_str = ca; - ((MonoStringObject *)s)->length = len; - - memcpy (ca->vector, text, len * 2); - - return s; -} - -MonoObject * -mono_new_string (const char *text) -{ - MonoObject *o; - guint16 *ut; - int i, l; - - /* fixme: use some kind of unicode library here */ - - l = strlen (text); - ut = g_malloc (l*2); - - for (i = 0; i < l; i++) - ut [i] = text[i]; - - o = mono_new_utf16_string ((char *)ut, l); - - g_free (ut); - - return o; -} - -MonoObject * -mono_value_box (MonoImage *image, guint32 etype, gpointer val) -{ - MonoObject *res; - int size; - - res = mono_object_new (image, etype); - - g_assert (res->klass->valuetype); - - size = res->klass->instance_size - sizeof (MonoObject); - - memcpy ((char *)res + sizeof (MonoObject), val, size); - - return res; -} diff --git a/mono/cli/object.h b/mono/cli/object.h deleted file mode 100644 index 2675cee09f4..00000000000 --- a/mono/cli/object.h +++ /dev/null @@ -1,49 +0,0 @@ -#ifndef _MONO_CLI_OBJECT_H_ -#define _MONO_CLI_OBJECT_H_ - -#include <mono/cli/class.h> - -typedef struct { - MonoClass *klass; -} MonoObject; - -typedef struct { - guint32 length; - guint32 lower_bound; -} MonoArrayBounds; - -typedef struct { - MonoObject obj; - gpointer vector; - MonoArrayBounds *bounds; -} MonoArrayObject; - -typedef struct { - MonoObject obj; - MonoArrayObject *c_str; - gint32 length; -} MonoStringObject; - -MonoObject * -mono_object_new (MonoImage *image, guint32 type_token); - -MonoObject * -mono_new_szarray (MonoImage *image, guint32 etype, guint32 n); - -MonoObject * -mono_new_utf16_string (const char *text, gint32 len); - -MonoObject * -mono_new_string (const char *text); - -void -mono_object_free (MonoObject *o); - -MonoObject * -mono_value_box (MonoImage *image, guint32 type, gpointer val); - -MonoObject * -mono_object_clone (MonoObject *obj); - -#endif - diff --git a/mono/cli/types.h b/mono/cli/types.h deleted file mode 100644 index c5d1110bc61..00000000000 --- a/mono/cli/types.h +++ /dev/null @@ -1,28 +0,0 @@ -#ifndef _MONO_CLI_TYPES_H_ -#define _MONO_CLI_TYPES_H_ - -/* - * 32 bit computer definitions. - */ - -typedef char m_boolean; -typedef short m_char; -typedef char m_i1; -typedef unsigned char m_u1; -typedef short m_i2; -typedef unsigned short m_u2; -typedef int m_i4; -typedef unsigned int m_u4; -typedef long m_i8; -typedef unsigned long m_u8; -typedef float m_r4; -typedef double m_r8; -typedef int m_i; -typedef unsigned int m_u; -typedef void * m_string; -typedef void * m_object; -typedef void * m_class; -typedef void * m_ptr; -typedef void * m_fnptr; - -#endif diff --git a/mono/interpreter/Makefile.am b/mono/interpreter/Makefile.am index 9cc4ae66c7e..f7d1a888b75 100644 --- a/mono/interpreter/Makefile.am +++ b/mono/interpreter/Makefile.am @@ -1,8 +1,8 @@ INCLUDES = \ -I$(top_srcdir) \ -I$(top_srcdir)/libffi/include \ - $(GLIB_CFLAGS) \ - $(GMODULE_CFLAGS) + $(GMODULE_CFLAGS) \ + $(GLIB_CFLAGS) bin_PROGRAMS = mono-int @@ -14,8 +14,7 @@ mono_int_SOURCES = \ mono_int_LDADD = \ ../metadata/libmetadata.a \ - ../cli/libmonocli.a \ - ../../libffi/libffi.a \ - $(GMODULE_LIBS) \ $(GLIB_LIBS) \ + $(GMODULE_LIBS) \ + ../../libffi/libffi.a -lm diff --git a/mono/interpreter/icall.c b/mono/interpreter/icall.c index 95ba2d185d3..3d9ec500cc1 100644 --- a/mono/interpreter/icall.c +++ b/mono/interpreter/icall.c @@ -10,7 +10,7 @@ #include <config.h> #include <glib.h> -#include <mono/cli/cli.h> +#include <mono/metadata/loader.h> #include "interp.h" @@ -267,30 +267,17 @@ static gpointer icall_map [] = { NULL, NULL }; -gpointer -mono_lookup_internal_call (const char *name) +void +mono_init_icall () { - static GHashTable *icall_hash = NULL; - gpointer res; - - if (!icall_hash) { - char *n; - int i = 0; - - icall_hash = g_hash_table_new (g_str_hash , g_str_equal); - - while ((n = icall_map [i])) { - g_hash_table_insert (icall_hash, n, icall_map [i+1]); - i += 2; - } - } + char *n; + int i = 0; - if (!(res = g_hash_table_lookup (icall_hash, name))) { - g_warning ("cant resolve internal call to \"%s\"", name); - g_assert_not_reached (); + while ((n = icall_map [i])) { + mono_add_internal_call (n, icall_map [i+1]); + i += 2; } - - return res; + } diff --git a/mono/interpreter/interp.c b/mono/interpreter/interp.c index 8bb4edf224b..4cf62d6689e 100644 --- a/mono/interpreter/interp.c +++ b/mono/interpreter/interp.c @@ -34,8 +34,8 @@ #include <mono/metadata/tabledefs.h> #include <mono/metadata/blob.h> #include <mono/metadata/tokentype.h> -#include <mono/cli/cli.h> -#include <mono/cli/types.h> +#include <mono/metadata/loader.h> +//#include <mono/cli/types.h> #include "interp.h" #include "hacks.h" @@ -57,7 +57,6 @@ static void ves_exec_method (MonoInvocation *frame); typedef void (*ICallMethod) (MonoInvocation *frame); - static void ves_real_abort (int line, MonoMethod *mh, const unsigned char *ip, stackval *stack, stackval *sp) @@ -1365,7 +1364,7 @@ ves_exec_method (MonoInvocation *frame) else if (sp->type == VAL_DOUBLE) sp->data.f = - sp->data.f; else if (sp->type == VAL_NATI) - sp->data.p = (gpointer)(- (m_i)sp->data.p); + sp->data.p = (gpointer)(- (int)sp->data.p); BREAK; CASE (CEE_NOT) ++ip; @@ -1374,7 +1373,7 @@ ves_exec_method (MonoInvocation *frame) else if (sp->type == VAL_I64) sp->data.l = ~ sp->data.l; else if (sp->type == VAL_NATI) - sp->data.p = (gpointer)(~ (m_i)sp->data.p); + sp->data.p = (gpointer)(~ (int)sp->data.p); BREAK; CASE (CEE_CONV_I1) ves_abort(); BREAK; CASE (CEE_CONV_I2) ves_abort(); BREAK; @@ -2139,6 +2138,7 @@ main (int argc, char *argv []) file = argv [1]; mono_init (); + mono_init_icall (); assembly = mono_assembly_open (file, NULL, NULL); if (!assembly){ diff --git a/mono/interpreter/interp.h b/mono/interpreter/interp.h index eee29287add..b52580cf3ba 100644 --- a/mono/interpreter/interp.h +++ b/mono/interpreter/interp.h @@ -1,7 +1,7 @@ #include <glib.h> -#include <mono/cli/cli.h> -#include <mono/cli/object.h> +#include <mono/metadata/loader.h> +#include <mono/metadata/object.h> enum { VAL_I32 = 0, @@ -50,3 +50,5 @@ struct _MonoInvocation { MonoExceptionClause *ex_handler; }; +void mono_init_icall (); + diff --git a/mono/metadata/Makefile.am b/mono/metadata/Makefile.am index 73f778e992f..c0fe32cc47d 100644 --- a/mono/metadata/Makefile.am +++ b/mono/metadata/Makefile.am @@ -7,15 +7,20 @@ lib_LIBRARIES = libmetadata.a # assembliesdir = $(libdir) -INCLUDES = $(GLIB_CFLAGS) -I$(top_srcdir) \ - -DMONO_ASSEMBLIES=\""$(assembliesdir)"\" +INCLUDES = $(GLIB_CFLAGS) $(GMODULE_CFLAGS) -I$(top_srcdir) \ + -DMONO_ASSEMBLIES=\""$(assembliesdir)"\" \ + -I$(top_srcdir)/libffi/include + libmetadata_a_SOURCES = \ assembly.c \ image.c \ metadata.c \ private.h \ - rawbuffer.c + rawbuffer.c \ + loader.c \ + class.c \ + object.c libmetadataincludedir = $(includedir)/mono/metadata @@ -29,9 +34,12 @@ libmetadatainclude_HEADERS = \ rawbuffer.h \ row-indexes.h \ tabledefs.h \ - tokentype.h + tokentype.h \ + loader.h \ + class.h \ + object.h pedump_SOURCES = \ pedump.c $(libmetadata_a_SOURCES) -pedump_LDADD = $(GLIB_LIBS) +pedump_LDADD = $(GLIB_LIBS) $(GMODULE_LIBS) ../../libffi/libffi.a diff --git a/mono/metadata/class.c b/mono/metadata/class.c index 20aefe97980..e4576489681 100644 --- a/mono/metadata/class.c +++ b/mono/metadata/class.c @@ -21,10 +21,8 @@ #include <mono/metadata/metadata.h> #include <mono/metadata/tabledefs.h> #include <mono/metadata/tokentype.h> -#include <mono/cli/cli.h> -#include <mono/cli/class.h> -#include <mono/cli/types.h> -#include <mono/cli/object.h> +#include <mono/metadata/class.h> +#include <mono/metadata/object.h> #define CSIZE(x) (sizeof (x) / 4) diff --git a/mono/metadata/class.h b/mono/metadata/class.h index 9cf8e2a35a1..1ee7a5a70fd 100644 --- a/mono/metadata/class.h +++ b/mono/metadata/class.h @@ -3,7 +3,7 @@ #include <mono/metadata/metadata.h> #include <mono/metadata/image.h> -#include <mono/cli/cli.h> +#include <mono/metadata/loader.h> #define MONO_CLASS_IS_ARRAY(c) (c->type_token == 0) diff --git a/mono/metadata/icall.c b/mono/metadata/icall.c index 95ba2d185d3..3d9ec500cc1 100644 --- a/mono/metadata/icall.c +++ b/mono/metadata/icall.c @@ -10,7 +10,7 @@ #include <config.h> #include <glib.h> -#include <mono/cli/cli.h> +#include <mono/metadata/loader.h> #include "interp.h" @@ -267,30 +267,17 @@ static gpointer icall_map [] = { NULL, NULL }; -gpointer -mono_lookup_internal_call (const char *name) +void +mono_init_icall () { - static GHashTable *icall_hash = NULL; - gpointer res; - - if (!icall_hash) { - char *n; - int i = 0; - - icall_hash = g_hash_table_new (g_str_hash , g_str_equal); - - while ((n = icall_map [i])) { - g_hash_table_insert (icall_hash, n, icall_map [i+1]); - i += 2; - } - } + char *n; + int i = 0; - if (!(res = g_hash_table_lookup (icall_hash, name))) { - g_warning ("cant resolve internal call to \"%s\"", name); - g_assert_not_reached (); + while ((n = icall_map [i])) { + mono_add_internal_call (n, icall_map [i+1]); + i += 2; } - - return res; + } diff --git a/mono/metadata/loader.c b/mono/metadata/loader.c index 70637ce2277..eb020082d0f 100644 --- a/mono/metadata/loader.c +++ b/mono/metadata/loader.c @@ -26,7 +26,7 @@ #include <mono/metadata/tokentype.h> #include <mono/metadata/cil-coff.h> #include <mono/metadata/tabledefs.h> -#include "cli.h" +#include <mono/metadata/loader.h> MonoDefaults mono_defaults; @@ -104,6 +104,35 @@ mono_init () } +static GHashTable *icall_hash = NULL; + +void +mono_add_internal_call (const char *name, gpointer method) +{ + if (!icall_hash) + icall_hash = g_hash_table_new (g_str_hash , g_str_equal); + + g_hash_table_insert (icall_hash, g_strdup (name), method); +} + +gpointer +mono_lookup_internal_call (const char *name) +{ + gpointer res; + + if (!icall_hash) { + g_warning ("icall_hash not initialized"); + g_assert_not_reached (); + } + + if (!(res = g_hash_table_lookup (icall_hash, name))) { + g_warning ("cant resolve internal call to \"%s\"", name); + g_assert_not_reached (); + } + + return res; +} + static MonoMethod * method_from_memberref (MonoImage *image, guint32 index) { diff --git a/mono/cli/cli.h b/mono/metadata/loader.h index 0ad94ee144f..1f4e2dc2f10 100644 --- a/mono/cli/cli.h +++ b/mono/metadata/loader.h @@ -1,5 +1,5 @@ -#ifndef _MONO_CLI_CLI_H_ -#define _MONO_CLI_CLI_H_ 1 +#ifndef _MONO_METADATA_LOADER_H_ +#define _MONO_METADATA_LOADER_H_ 1 #include <ffi.h> #include <mono/metadata/metadata.h> @@ -51,6 +51,9 @@ mono_typedef_from_name (MonoImage *image, const char *name, MonoImage * mono_load_image (const char *fname, enum MonoImageOpenStatus *status); +void +mono_add_internal_call (const char *name, gpointer method); + gpointer mono_lookup_internal_call (const char *name); diff --git a/mono/metadata/object.c b/mono/metadata/object.c index 6368977b903..54585d24095 100644 --- a/mono/metadata/object.c +++ b/mono/metadata/object.c @@ -9,8 +9,8 @@ #include <config.h> #include <stdlib.h> #include <stdio.h> -#include <mono/cli/cli.h> -#include <mono/cli/object.h> +#include <mono/metadata/loader.h> +#include <mono/metadata/object.h> /** * mono_object_allocate: diff --git a/mono/metadata/object.h b/mono/metadata/object.h index 2675cee09f4..0a90ab19e03 100644 --- a/mono/metadata/object.h +++ b/mono/metadata/object.h @@ -1,7 +1,7 @@ #ifndef _MONO_CLI_OBJECT_H_ #define _MONO_CLI_OBJECT_H_ -#include <mono/cli/class.h> +#include <mono/metadata/class.h> typedef struct { MonoClass *klass; |