[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[dotgnu-pnet-commits] pnet ChangeLog engine/jitc.c engine/jitc_alloc....
From: |
Klaus Treichel |
Subject: |
[dotgnu-pnet-commits] pnet ChangeLog engine/jitc.c engine/jitc_alloc.... |
Date: |
Tue, 17 Oct 2006 12:24:18 +0000 |
CVSROOT: /cvsroot/dotgnu-pnet
Module name: pnet
Changes by: Klaus Treichel <ktreichel> 06/10/17 12:24:18
Modified files:
. : ChangeLog
engine : jitc.c jitc_alloc.c jitc_array.c jitc_call.c
jitc_delegate.c jitc_except.c jitc_obj.c
jitc_pinvoke.c jitc_ptr.c lib_misc.c
Log message:
2006-10-17 Klaus Treichel <address@hidden>
* engine/jitc.c: Add signature for allocating simple arrays.
Return and
pass TypeRef values by reference in internal calls. Do some more
reorganization of the source files.
* engine/jitc_alloc.c: Move the prototypes for memory
allocation from
jitc.c to this file.
* engine/jitc_array.c: Move the coder functions for array
handling from
jitc_ptr.c to this file. Move the function for creation of an
Object *
array from jitc_delegate.c to this file. Optimize creation of
simple
arrays. Adjust the calls to _ILJitThrowSystem to the new
signature.
* engine/jitc_call.c: Adjust the calls to _ILJitThrowSystem to
the new
signature. Fix the function for packing varargs.
* engine/jitc_delegate.c: Move the function to create an object
array to
jitc_array.c and adjust the name change in the calls.
* engine/jitc_except.c: Move the declaration of the internal
exceptions
from jitc.c to this file. Change _ILJitThrowInternal so that
the first arg
is a ILJitFunction instead of the ILJITCoder *.
* engine/jitc_obj.c: Adjust the calls to _ILJitThrowSystem to
the new
signature. Implement the arglist opcode.
* engine/jitc_pinvoke.c: Adjust the calls to _ILJitThrowSystem
to the new
signature.
* engine/jitc_ptr.c: Move the coder functions for arrays to
jitc_array.c.
* engine/lib_misc.c: The System.RuntimeArgumentHandle is passed
by value
if the jit coder is used.
CVSWeb URLs:
http://cvs.savannah.gnu.org/viewcvs/pnet/ChangeLog?cvsroot=dotgnu-pnet&r1=1.3375&r2=1.3376
http://cvs.savannah.gnu.org/viewcvs/pnet/engine/jitc.c?cvsroot=dotgnu-pnet&r1=1.57&r2=1.58
http://cvs.savannah.gnu.org/viewcvs/pnet/engine/jitc_alloc.c?cvsroot=dotgnu-pnet&r1=1.5&r2=1.6
http://cvs.savannah.gnu.org/viewcvs/pnet/engine/jitc_array.c?cvsroot=dotgnu-pnet&r1=1.2&r2=1.3
http://cvs.savannah.gnu.org/viewcvs/pnet/engine/jitc_call.c?cvsroot=dotgnu-pnet&r1=1.29&r2=1.30
http://cvs.savannah.gnu.org/viewcvs/pnet/engine/jitc_delegate.c?cvsroot=dotgnu-pnet&r1=1.6&r2=1.7
http://cvs.savannah.gnu.org/viewcvs/pnet/engine/jitc_except.c?cvsroot=dotgnu-pnet&r1=1.12&r2=1.13
http://cvs.savannah.gnu.org/viewcvs/pnet/engine/jitc_obj.c?cvsroot=dotgnu-pnet&r1=1.22&r2=1.23
http://cvs.savannah.gnu.org/viewcvs/pnet/engine/jitc_pinvoke.c?cvsroot=dotgnu-pnet&r1=1.5&r2=1.6
http://cvs.savannah.gnu.org/viewcvs/pnet/engine/jitc_ptr.c?cvsroot=dotgnu-pnet&r1=1.16&r2=1.17
http://cvs.savannah.gnu.org/viewcvs/pnet/engine/lib_misc.c?cvsroot=dotgnu-pnet&r1=1.14&r2=1.15
Patches:
Index: ChangeLog
===================================================================
RCS file: /cvsroot/dotgnu-pnet/pnet/ChangeLog,v
retrieving revision 1.3375
retrieving revision 1.3376
diff -u -b -r1.3375 -r1.3376
--- ChangeLog 15 Oct 2006 09:32:27 -0000 1.3375
+++ ChangeLog 17 Oct 2006 12:24:18 -0000 1.3376
@@ -1,3 +1,38 @@
+2006-10-17 Klaus Treichel <address@hidden>
+
+ * engine/jitc.c: Add signature for allocating simple arrays. Return and
+ pass TypeRef values by reference in internal calls. Do some more
+ reorganization of the source files.
+
+ * engine/jitc_alloc.c: Move the prototypes for memory allocation from
+ jitc.c to this file.
+
+ * engine/jitc_array.c: Move the coder functions for array handling from
+ jitc_ptr.c to this file. Move the function for creation of an Object *
+ array from jitc_delegate.c to this file. Optimize creation of simple
+ arrays. Adjust the calls to _ILJitThrowSystem to the new signature.
+
+ * engine/jitc_call.c: Adjust the calls to _ILJitThrowSystem to the new
+ signature. Fix the function for packing varargs.
+
+ * engine/jitc_delegate.c: Move the function to create an object array to
+ jitc_array.c and adjust the name change in the calls.
+
+ * engine/jitc_except.c: Move the declaration of the internal exceptions
+ from jitc.c to this file. Change _ILJitThrowInternal so that the first
arg
+ is a ILJitFunction instead of the ILJITCoder *.
+
+ * engine/jitc_obj.c: Adjust the calls to _ILJitThrowSystem to the new
+ signature. Implement the arglist opcode.
+
+ * engine/jitc_pinvoke.c: Adjust the calls to _ILJitThrowSystem to the
new
+ signature.
+
+ * engine/jitc_ptr.c: Move the coder functions for arrays to
jitc_array.c.
+
+ * engine/lib_misc.c: The System.RuntimeArgumentHandle is passed by value
+ if the jit coder is used.
+
2006-10-15 Klaus Treichel <address@hidden>
* engine/jitc.c, engine/jitc_call.c, engine/verify_call.c,
Index: engine/jitc.c
===================================================================
RCS file: /cvsroot/dotgnu-pnet/pnet/engine/jitc.c,v
retrieving revision 1.57
retrieving revision 1.58
diff -u -b -r1.57 -r1.58
--- engine/jitc.c 15 Oct 2006 09:32:28 -0000 1.57
+++ engine/jitc.c 17 Oct 2006 12:24:18 -0000 1.58
@@ -127,7 +127,7 @@
/*
* Definition of signatures of internal functions used by jitted code.
- * They have to be kept in sync wirh the corresponding engine funcions.
+ * They have to be kept in sync with the corresponding engine funcions.
*/
/*
@@ -141,6 +141,13 @@
static ILJitType _ILJitSignature_ILJitAlloc = 0;
/*
+ * System_Array *_ILJitSArrayAlloc(ILClass *arrayClass,
+ *
ILUInt32 numElements,
+ *
ILUInt32 elementSize)
+ */
+static ILJitType _ILJitSignature_ILJitSArrayAlloc = 0;
+
+/*
* System_Array *_ILJitGetExceptionStackTrace(ILExecThread *thread)
*/
static ILJitType _ILJitSignature_ILJitGetExceptionStackTrace = 0;
@@ -299,6 +306,11 @@
#include "jitc_locals.c"
#include "jitc_stack.c"
#include "jitc_labels.c"
+#include "jitc_except.c"
+#include "jitc_alloc.c"
+#include "jitc_array.c"
+#include "jitc_call.c"
+#include "jitc_delegate.c"
#undef IL_JITC_DECLARATIONS
/*
@@ -442,22 +454,6 @@
#endif
/*
- * Declaration of the engine internal exceptions.
- */
-#define _IL_JIT_OK 0
-#define _IL_JIT_OUT_OF_MEMORY 1
-#define _IL_JIT_INVALID_CAST 2
-#define _IL_JIT_INDEX_OUT_OF_RANGE 3
-#define _IL_JIT_MISSING_METHOD 4
-#define _IL_JIT_DLL_NOT_FOUND 5
-#define _IL_JIT_ENTRYPOINT_NOT_FOUND 6
-
-/*
- * Emit the code to throw a system exception.
- */
-static void _ILJitThrowSystem(ILJITCoder *jitCoder, ILUInt32 exception);
-
-/*
* Initialize a ILJitTypes base structure
*/
#define _ILJitTypesInitBase(jitTypes, jitType) \
@@ -2156,6 +2152,16 @@
}
args[0] = _IL_JIT_TYPE_VPTR;
+ args[1] = _IL_JIT_TYPE_UINT32;
+ args[2] = _IL_JIT_TYPE_UINT32;
+ returnType = _IL_JIT_TYPE_VPTR;
+ if(!(_ILJitSignature_ILJitSArrayAlloc =
+ jit_type_create_signature(IL_JIT_CALLCONV_CDECL, returnType,
args, 3, 1)))
+ {
+ return 0;
+ }
+
+ args[0] = _IL_JIT_TYPE_VPTR;
args[1] = _IL_JIT_TYPE_VPTR;
args[2] = _IL_JIT_TYPE_VPTR;
returnType = _IL_JIT_TYPE_INT32;
@@ -2907,7 +2913,7 @@
jitParams[0] = thread;
/* Check if the return type is a value type. */
- if(ILType_IsValueType(type))
+ if(ILType_IsValueType(type) && (returnType != _ILJitTypedRef))
{
++totalParams;
jitParamTypes[1] = _IL_JIT_TYPE_VPTR;
@@ -2926,7 +2932,7 @@
{
paramType = jit_type_get_param(signature, current);
- if(jit_type_is_struct(paramType))
+ if(jit_type_is_struct(paramType) && (paramType !=
_ILJitTypedRef))
{
jitParamTypes[param] = _IL_JIT_TYPE_VPTR;
#ifdef IL_JIT_THREAD_IN_SIGNATURE
@@ -3105,9 +3111,6 @@
}
#include "jitc_profile.c"
-#include "jitc_alloc.c"
-#include "jitc_array.c"
-#include "jitc_delegate.c"
#include "jitc_pinvoke.c"
/*
@@ -3869,6 +3872,10 @@
{
return _IL_JIT_TYPE_NINT;
}
+ if(!strcmp(className->name, "TypedRef"))
+ {
+ return _ILJitTypedRef;
+ }
}
return 0;
}
@@ -4136,6 +4143,11 @@
#include "jitc_locals.c"
#include "jitc_stack.c"
#include "jitc_labels.c"
+#include "jitc_alloc.c"
+#include "jitc_array.c"
+#include "jitc_except.c"
+#include "jitc_call.c"
+#include "jitc_delegate.c"
#undef IL_JITC_FUNCTIONS
/*
@@ -4149,6 +4161,7 @@
#include "jitc_var.c"
#include "jitc_stack.c"
#include "jitc_ptr.c"
+#include "jitc_array.c"
#include "jitc_branch.c"
#include "jitc_except.c"
#include "jitc_conv.c"
Index: engine/jitc_alloc.c
===================================================================
RCS file: /cvsroot/dotgnu-pnet/pnet/engine/jitc_alloc.c,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -b -r1.5 -r1.6
--- engine/jitc_alloc.c 28 Jul 2006 17:41:54 -0000 1.5
+++ engine/jitc_alloc.c 17 Oct 2006 12:24:18 -0000 1.6
@@ -18,6 +18,27 @@
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
+#ifdef IL_JITC_DECLARATIONS
+
+/*
+ * Generate the code to allocate the memory for an object with the given size.
+ * Returns the ILJitValue with the pointer to the new object.
+ */
+static ILJitValue _ILJitAllocGen(ILJitFunction jitFunction,
+ ILClass
*classInfo,
+ ILUInt32 size);
+
+/*
+ * Generate the code to allocate the memory for an object.
+ * Returns the ILJitValue with the pointer to the new object.
+ */
+static ILJitValue _ILJitAllocObjectGen(ILJitFunction jitFunction,
+
ILClass *classInfo);
+
+#endif /* IL_JITC_DECLARATIONS */
+
+#ifdef IL_JITC_FUNCTIONS
+
/*
* Allocate memory for an object that contains object references.
*/
@@ -105,7 +126,8 @@
* Generate the code to allocate the memory for an object with the given size.
* Returns the ILJitValue with the pointer to the new object.
*/
-static ILJitValue _ILJitAllocGen(ILJitFunction jitFunction, ILClass *classInfo,
+static ILJitValue _ILJitAllocGen(ILJitFunction jitFunction,
+ ILClass
*classInfo,
ILUInt32 size)
{
ILJitValue newObj;
@@ -149,7 +171,8 @@
* Generate the code to allocate the memory for an object.
* Returns the ILJitValue with the pointer to the new object.
*/
-static ILJitValue _ILJitAllocObjectGen(ILJitFunction jitFunction, ILClass
*classInfo)
+static ILJitValue _ILJitAllocObjectGen(ILJitFunction jitFunction,
+
ILClass *classInfo)
{
/* Make sure the class has been layouted. */
if(!(classInfo->userData) ||
@@ -164,3 +187,5 @@
((ILClassPrivate
*)(classInfo->userData))->size);
}
+#endif /* IL_JITC_FUNCTIONS */
+
Index: engine/jitc_array.c
===================================================================
RCS file: /cvsroot/dotgnu-pnet/pnet/engine/jitc_array.c,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -b -r1.2 -r1.3
--- engine/jitc_array.c 10 Oct 2006 17:10:45 -0000 1.2
+++ engine/jitc_array.c 17 Oct 2006 12:24:18 -0000 1.3
@@ -18,86 +18,277 @@
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
+#ifdef IL_JITC_DECLARATIONS
+
/*
- * Prototype for inlining functioncalls.
- *
- * ILJitValue func(ILJITCoder *, ILMethod *, ILCoderMethodInfo *,
ILJitStackItem *, ILInt32)
+ * The simple array header size.
*/
+#define _IL_JIT_SARRAY_HEADERSIZE sizeof(System_Array)
/*
- * Create a new simple array (1 dimension and zero based)
+ * Validate the array index.
*/
-static ILJitValue _ILJitSArrayNew(ILJITCoder *jitCoder, ILClass *arrayClass,
ILJitValue length)
+#define JITC_START_CHECK_ARRAY_INDEX(jitCoder, length, index) \
+ { \
+ jit_label_t __label = jit_label_undefined; \
+ jit_label_t __okLabel = jit_label_undefined; \
+ ILJitValue __length = (length); \
+ ILJitValue __index = (index); \
+ ILJitValue __temp; \
+ \
+ AdjustSign(jitCoder->jitFunction, &(__length), 1, 0); \
+ AdjustSign(jitCoder->jitFunction, &(__index), 1, 0); \
+ \
+ __temp = jit_insn_lt(jitCoder->jitFunction, __index, __length);
\
+ jit_insn_branch_if_not(jitCoder->jitFunction, __temp, &__label);
+
+#define JITC_END_CHECK_ARRAY_INDEX(jitCoder) \
+ jit_insn_branch(jitCoder->jitFunction, &__okLabel); \
+ jit_insn_label(jitCoder->jitFunction, &__label); \
+ _ILJitThrowSystem(jitCoder->jitFunction,
_IL_JIT_INDEX_OUT_OF_RANGE); \
+ jit_insn_label(jitCoder->jitFunction, &__okLabel); \
+ }
+
+/*
+ * Create an Object array with the given size.
+ */
+static ILJitValue _ILJitSObjectArrayCreate(ILJitFunction jitFunction,
+
ILExecThread *_thread,
+
ILJitValue thread,
+
ILUInt32 numElements);
+
+/*
+ * Get an array element at the specified indexes from a complex array.
+ */
+static ILJitValue _ILJitMArrayGet(ILJITCoder *jitCoder,
+ ILMethod
*method,
+
ILCoderMethodInfo *methodInfo,
+
ILJitStackItem *args,
+ ILInt32
numArgs);
+
+/*
+ * Get the address of an array element at the specified indexes in a complex
+ * array.
+ */
+static ILJitValue _ILJitMArrayAddress(ILJITCoder *jitCoder,
+
ILMethod *method,
+
ILCoderMethodInfo *methodInfo,
+
ILJitStackItem *args,
+
ILInt32 numArgs);
+
+/*
+ * Set an array element at the specified indexes in a complex array.
+ */
+static ILJitValue _ILJitMArraySet(ILJITCoder *jitCoder,
+ ILMethod
*method,
+
ILCoderMethodInfo *methodInfo,
+
ILJitStackItem *args,
+ ILInt32
numArgs);
+
+#endif /* IL_JITC_DECLARATIONS */
+
+#ifdef IL_JITC_FUNCTIONS
+
+/*
+ * Allocate a simple array which elements comntain object references.
+ */
+static System_Array *_ILJitSArrayAlloc(ILClass *arrayClass,
+
ILUInt32 numElements,
+
ILUInt32 elementSize)
{
- ILExecThread *thread = ILExecThreadCurrent();
- /* Get the array element type. */
- ILType *elementType = ILType_ElemType(ILClassGetSynType(arrayClass));
- /* Get the size of one array element. */
- ILUInt32 elementSize = ILSizeOfType(thread, elementType);
- ILJitValue headerSize =
jit_value_create_nint_constant(jitCoder->jitFunction,
-
_IL_JIT_TYPE_UINT32,
-
sizeof(System_Array));
+ ILUInt64 totalSize;
+ System_Array *ptr;
+
+ totalSize = (((ILUInt64)elementSize) * ((ILUInt64)numElements)) +
_IL_JIT_SARRAY_HEADERSIZE;
+ if(totalSize > (ILUInt64)IL_MAX_INT32)
+ {
+ /* The array is too large. */
+ /* Throw an "OutOfMemoryException" */
+ ILRuntimeExceptionThrowOutOfMemory();
+ return (System_Array *)0;
+ }
+ ptr = (System_Array *)_ILJitAlloc(arrayClass, (ILUInt32)totalSize);
+ ptr->length = numElements;
+ return ptr;
+}
+
+/*
+ * Allocate a simple array which elements do not comntain object references.
+ */
+static System_Array *_ILJitSArrayAllocAtomic(ILClass *arrayClass,
+
ILUInt32 numElements,
+
ILUInt32 elementSize)
+{
+ ILUInt64 totalSize;
+ System_Array *ptr;
+
+ totalSize = (((ILUInt64)elementSize) * ((ILUInt64)numElements)) +
_IL_JIT_SARRAY_HEADERSIZE;
+ if(totalSize > (ILUInt64)IL_MAX_INT32)
+ {
+ /* The array is too large. */
+ /* Throw an "OutOfMemoryException" */
+ ILRuntimeExceptionThrowOutOfMemory();
+ return (System_Array *)0;
+ }
+ ptr = (System_Array *)_ILJitAllocAtomic(arrayClass,
(ILUInt32)totalSize);
+ ptr->length = numElements;
+ return ptr;
+}
+
+/*
+ * Create a new simple array (1 dimension and zero based) with a constant size.
+ */
+static ILJitValue _ILJitSArrayNewWithConstantSize(ILJitFunction jitFunction,
+
ILExecThread *thread,
+
ILClass *arrayClass,
+
ILUInt32 length)
+{
+ /* The array element type. */
+ ILType *elementType;
+ /* The size of one array element. */
+ ILUInt32 elementSize;
+ ILUInt64 totalSize;
+ /* Number of elements in the array. */
+ ILJitValue arrayLength;
+ /* Total amount of memory needed for the array. */
ILJitValue arraySize;
ILJitValue newArray;
ILClass *elementClass;
ILClassPrivate *classPrivate;
ILJitValue args[2];
- if(jit_value_is_constant(length))
+ /* Make sure the synthetic array class is layouted. */
+ if(!(arrayClass->userData))
+ {
+ /* We have to layout the class first. */
+ if(!_LayoutClass(thread, arrayClass))
+ {
+ printf("Failed to layout class: %s\n",
ILClass_Name(arrayClass));
+ return (ILJitValue)0;
+ }
+ }
+
+ elementType = ILType_ElemType(ILClassGetSynType(arrayClass));
+
+ elementClass = ILClassFromType(ILProgramItem_Image(arrayClass),
+ 0,
elementType, 0);
+ elementClass = ILClassResolve(elementClass);
+ classPrivate = (ILClassPrivate *)(elementClass->userData);
+
+ if(!classPrivate)
+ {
+ if(!_LayoutClass(thread, elementClass))
{
- ILUInt64 totalSize = ((ILUInt64)elementSize) *
((ILUInt64)jit_value_get_nint_constant(length));
+ printf("Failed to layout class: %s\n",
ILClass_Name(elementClass));
+ return (ILJitValue)0;
+ }
+ classPrivate = (ILClassPrivate *)(elementClass->userData);
+ }
+ /* Get the size of one array element. */
+ elementSize = ILSizeOfType(thread, elementType);
+
+ totalSize = (((ILUInt64)elementSize) * ((ILUInt64)length)) +
_IL_JIT_SARRAY_HEADERSIZE;
if(totalSize > (ILUInt64)IL_MAX_INT32)
{
/* The array is too large. */
- ILJitValue array =
jit_value_create_nint_constant(jitCoder->jitFunction,
+ ILJitValue array = jit_value_create_nint_constant(jitFunction,
_IL_JIT_TYPE_VPTR, 0);
- _ILJitThrowSystem(jitCoder, _IL_JIT_OUT_OF_MEMORY);
+ _ILJitThrowSystem(jitFunction, _IL_JIT_OUT_OF_MEMORY);
return array;
}
- arraySize =
jit_value_create_nint_constant(jitCoder->jitFunction,
+ arraySize = jit_value_create_nint_constant(jitFunction,
_IL_JIT_TYPE_UINT32,
(ILUInt32)totalSize);
+
+ arrayLength = jit_value_create_nint_constant(jitFunction,
+
_IL_JIT_TYPE_UINT32,
+
length);
+
+ /* We call the alloc functions. */
+ /* They thow an out of memory exception so we don't need to care. */
+ args[0] = jit_value_create_nint_constant(jitFunction,
+
_IL_JIT_TYPE_VPTR,
+
(jit_nint)arrayClass);
+ args[1] = arraySize;
+
+ /* if(!(classPrivate->managedInstance)) */
+ if(ILType_IsPrimitive(elementType) &&
+ elementType != ILType_TypedRef)
+ {
+ newArray = jit_insn_call_native(jitFunction,
+
"_ILJitAllocAtomic",
+
_ILJitAllocAtomic,
+
_ILJitSignature_ILJitAlloc,
+
args, 2, 0);
}
else
{
- ILJitValue temp;
- jit_label_t label = jit_label_undefined;
- ILJitValue maxSize =
jit_value_create_long_constant(jitCoder->jitFunction,
-
_IL_JIT_TYPE_UINT64,
-
IL_MAX_INT32);
+ /* The element contains object references. */
+ newArray = jit_insn_call_native(jitFunction,
+
"_ILJitAlloc",
+
_ILJitAlloc,
+
_ILJitSignature_ILJitAlloc,
+
args, 2, 0);
+ }
+ /* Set the length in the array. */
+ jit_insn_store_relative(jitFunction,
+ newArray,
+ offsetof(System_Array,
length),
+ arrayLength);
+ return newArray;
+}
- arraySize =
jit_value_create_long_constant(jitCoder->jitFunction,
-
_IL_JIT_TYPE_UINT64,
-
elementSize);
- arraySize = jit_insn_mul(jitCoder->jitFunction, arraySize,
-
_ILJitValueConvertImplicit(jitCoder->jitFunction,
-
length,
-
_IL_JIT_TYPE_UINT64));
+/*
+ * Create a new simple array (1 dimension and zero based)
+ */
+static ILJitValue _ILJitSArrayNew(ILJITCoder *jitCoder, ILClass *arrayClass,
ILJitValue length)
+{
+ ILExecThread *thread = ILExecThreadCurrent();
- /* Check if the total arraysize is > IL_MAX_INT32. */
- temp = jit_insn_gt(jitCoder->jitFunction, arraySize, maxSize);
- jit_insn_branch_if_not(jitCoder->jitFunction, temp, &label);
- /* And throw an OutOfMemoryException then. */
- _ILJitThrowSystem(jitCoder, _IL_JIT_OUT_OF_MEMORY);
- jit_insn_label(jitCoder->jitFunction, &label);
+ if(jit_value_is_constant(length))
+ {
+ ILUInt32 numElements = jit_value_get_nint_constant(length);
- /* Downconvert the array size to an UINT32. */
- arraySize = _ILJitValueConvertImplicit(jitCoder->jitFunction,
arraySize, _IL_JIT_TYPE_UINT32);
+ return _ILJitSArrayNewWithConstantSize(jitCoder->jitFunction,
+
thread,
+
arrayClass,
+
numElements);
}
+ else
+ {
+ ILJitValue headerSize =
jit_value_create_nint_constant(jitCoder->jitFunction,
+
_IL_JIT_TYPE_UINT32,
+
_IL_JIT_SARRAY_HEADERSIZE);
+ /* The array element type. */
+ ILType *elementType;
+ /* The size of one array element. */
+ ILUInt32 elementSize;
+ /* Total amount of memory needed for the array. */
+ ILJitValue arraySize;
+ ILJitValue newArray;
+ ILClass *elementClass;
+ ILClassPrivate *classPrivate;
+ ILJitValue temp;
+ jit_label_t label = jit_label_undefined;
+ ILJitValue args[3];
+
/* Make sure the synthetic array class is layouted. */
if(!(arrayClass->userData))
{
/* We have to layout the class first. */
if(!_LayoutClass(thread, arrayClass))
{
+ printf("Failed to layout class: %s\n",
ILClass_Name(arrayClass));
return (ILJitValue)0;
}
}
- /* Make sure that the length has the correct type. */
- length = _ILJitValueConvertImplicit(jitCoder->jitFunction, length,
_IL_JIT_TYPE_UINT32);
+ elementType = ILType_ElemType(ILClassGetSynType(arrayClass));
+
+ /* Get the size of one array element. */
+ elementSize = ILSizeOfType(thread, elementType);
elementClass = ILClassFromType(ILProgramItem_Image(arrayClass),
0,
elementType, 0);
@@ -108,18 +299,48 @@
{
if(!_LayoutClass(thread, elementClass))
{
+ printf("Failed to layout class: %s\n",
ILClass_Name(elementClass));
return (ILJitValue)0;
}
classPrivate = (ILClassPrivate *)(elementClass->userData);
}
-#if !defined(IL_CONFIG_REDUCE_CODE) && !defined(IL_WITHOUT_TOOLS) &&
defined(_IL_JIT_ENABLE_DEBUG)
+
+ #if !defined(IL_CONFIG_REDUCE_CODE) && !defined(IL_WITHOUT_TOOLS) &&
defined(_IL_JIT_ENABLE_DEBUG)
if(jitCoder->flags & IL_CODER_FLAG_STATS)
{
ILMutexLock(globalTraceMutex);
fprintf(stdout, "New Array of type: %s\n",
ILClass_Name(elementClass));
ILMutexUnlock(globalTraceMutex);
}
-#endif
+ #endif
+
+ #if 0
+ ILJitValue maxSize =
jit_value_create_long_constant(jitCoder->jitFunction,
+
_IL_JIT_TYPE_UINT64,
+
IL_MAX_INT32);
+
+ arraySize =
jit_value_create_long_constant(jitCoder->jitFunction,
+
_IL_JIT_TYPE_UINT64,
+
elementSize);
+ arraySize = jit_insn_mul(jitCoder->jitFunction,
+ arraySize,
+
_ILJitValueConvertImplicit(jitCoder->jitFunction,
+
length,
+
_IL_JIT_TYPE_UINT64));
+
+ /* Check if the total arraysize is > IL_MAX_INT32. */
+ temp = jit_insn_gt(jitCoder->jitFunction, arraySize, maxSize);
+ jit_insn_branch_if_not(jitCoder->jitFunction, temp, &label);
+ /* And throw an OutOfMemoryException then. */
+ _ILJitThrowSystem(jitCoder->jitFunction, _IL_JIT_OUT_OF_MEMORY);
+ jit_insn_label(jitCoder->jitFunction, &label);
+
+ /* Downconvert the array size to an UINT32. */
+ arraySize = _ILJitValueConvertImplicit(jitCoder->jitFunction,
arraySize, _IL_JIT_TYPE_UINT32);
+
+ /* Make sure that the length has the correct type. */
+ length = _ILJitValueConvertImplicit(jitCoder->jitFunction,
length, _IL_JIT_TYPE_UINT32);
+
/* We call the alloc functions. */
/* They thow an out of memory exception so we don't need to care. */
args[0] = jit_value_create_nint_constant(jitCoder->jitFunction,
@@ -127,29 +348,89 @@
(jit_nint)arrayClass);
args[1] = jit_insn_add(jitCoder->jitFunction, arraySize, headerSize);
- if(classPrivate->managedInstance)
+ /* if(!(classPrivate->managedInstance)) */
+ if(ILType_IsPrimitive(elementType) &&
+ elementType != ILType_TypedRef)
{
- /* The element contains object references. */
newArray = jit_insn_call_native(jitCoder->jitFunction,
-
"_ILJitAlloc",
-
_ILJitAlloc,
+
"_ILJitAllocAtomic",
+
_ILJitAllocAtomic,
_ILJitSignature_ILJitAlloc,
args, 2, 0);
}
else
{
+ /* The element contains object references. */
newArray = jit_insn_call_native(jitCoder->jitFunction,
-
"_ILJitAllocAtomic",
-
_ILJitAllocAtomic,
+
"_ILJitAlloc",
+
_ILJitAlloc,
_ILJitSignature_ILJitAlloc,
args, 2, 0);
}
/* Set the length in the array. */
- jit_insn_store_relative(jitCoder->jitFunction, newArray,
+ jit_insn_store_relative(jitCoder->jitFunction,
+ newArray,
offsetof(System_Array,
length), length);
+ #else
+ /* We call the alloc functions. */
+ /* They thow an out of memory exception so we don't need to
care. */
+ args[0] = jit_value_create_nint_constant(jitCoder->jitFunction,
+
_IL_JIT_TYPE_VPTR,
+
(jit_nint)arrayClass);
+ args[1] = _ILJitValueConvertImplicit(jitCoder->jitFunction,
+
length,
+
_IL_JIT_TYPE_UINT32);
+ args[2] = jit_value_create_nint_constant(jitCoder->jitFunction,
+
_IL_JIT_TYPE_UINT32,
+
elementSize);
+
+ /* if(!(classPrivate->managedInstance)) */
+ if(ILType_IsPrimitive(elementType) &&
+ elementType != ILType_TypedRef)
+ {
+ newArray = jit_insn_call_native(jitCoder->jitFunction,
+
"_ILJitSArrayAllocAtomic",
+
_ILJitSArrayAllocAtomic,
+
_ILJitSignature_ILJitSArrayAlloc,
+
args, 3, 0);
+ }
+ else
+ {
+ /* The element contains object references. */
+ newArray = jit_insn_call_native(jitCoder->jitFunction,
+
"_ILJitSArrayAlloc",
+
_ILJitSArrayAlloc,
+
_ILJitSignature_ILJitSArrayAlloc,
+
args, 3, 0);
+ }
+ #endif
return newArray;
+ }
}
+/*
+ * Create an Object array with the given size.
+ */
+static ILJitValue _ILJitSObjectArrayCreate(ILJitFunction jitFunction,
+
ILExecThread *_thread,
+
ILJitValue thread,
+
ILUInt32 numElements)
+{
+ ILMethod *ctor;
+
+ /* Find the constructor for the array. */
+ ctor = ILExecThreadLookupMethod(_thread, "[oSystem.Object;", ".ctor",
+
"(Ti)V");
+ if(!ctor)
+ {
+ return 0;
+ }
+
+ return _ILJitSArrayNewWithConstantSize(jitFunction,
+
_thread,
+
ILMethod_Owner(ctor),
+
numElements);
+}
/*
* Calculate the absolute Index of an element in the array.
@@ -215,7 +496,7 @@
jit_insn_branch(jitCoder->jitFunction, &okLabel);
jit_insn_label(jitCoder->jitFunction, &arrayOutOfBoundsLabel);
/* Throw a System.IndexOutOfRange exception. */
- _ILJitThrowSystem(jitCoder, _IL_JIT_INDEX_OUT_OF_RANGE);
+ _ILJitThrowSystem(jitCoder->jitFunction, _IL_JIT_INDEX_OUT_OF_RANGE);
jit_insn_label(jitCoder->jitFunction, &okLabel);
return absoluteIndex;
@@ -348,3 +629,369 @@
return 0;
}
+/*
+ * Get the base pointer to the array data.
+ */
+static ILJitValue GetArrayBase(ILJITCoder *coder, ILJitValue array)
+{
+ return jit_insn_add_relative(coder->jitFunction, array,
sizeof(System_Array));
+}
+
+/*
+ * Get the array length.
+ */
+static ILJitValue GetArrayLength(ILJITCoder *coder, ILJitValue array)
+{
+ ILJitValue len;
+
+ len = jit_insn_load_relative(coder->jitFunction, array, 0,
+
_IL_JIT_TYPE_INT32);
+ return len;
+}
+
+static void ValidateArrayIndex(ILJITCoder *coder, ILJitValue length,
+
ILJitValue index)
+{
+ jit_label_t label = jit_label_undefined;
+ ILJitValue temp;
+
+ /* Make both values unsigned. We can save one compare this way. */
+ AdjustSign(coder->jitFunction, &length, 1, 0);
+ AdjustSign(coder->jitFunction, &index, 1, 0);
+
+ temp = jit_insn_lt(coder->jitFunction, index, length);
+ jit_insn_branch_if(coder->jitFunction, temp, &label);
+ /* Throw a System.IndexOutOfRange exception. */
+ _ILJitThrowSystem(coder->jitFunction, _IL_JIT_INDEX_OUT_OF_RANGE);
+ jit_insn_label(coder->jitFunction, &label);
+}
+
+/*
+ * Handle the ldelem* instructions.
+ */
+static void LoadArrayElem(ILJITCoder *coder, ILJitType type)
+{
+ _ILJitStackItemNew(index);
+ _ILJitStackItemNew(array);
+ ILJitValue length;
+ ILJitValue value;
+ ILJitValue arrayBase;
+
+ _ILJitStackPop(coder, index);
+ _ILJitStackPop(coder, array);
+ _ILJitStackItemCheckNull(coder, array);
+ length = GetArrayLength(coder, _ILJitStackItemValue(array));
+ JITC_START_CHECK_ARRAY_INDEX(coder, length, _ILJitStackItemValue(index))
+ arrayBase = GetArrayBase(coder, _ILJitStackItemValue(array));
+ value = jit_insn_load_elem(coder->jitFunction,
+ arrayBase,
+
_ILJitStackItemValue(index),
+ type);
+ _ILJitStackPushValue(coder, value);
+ JITC_END_CHECK_ARRAY_INDEX(coder)
+}
+
+/*
+ * Handle the stelem* instructions.
+ */
+static void StoreArrayElem(ILJITCoder *coder, ILJitType type)
+{
+ _ILJitStackItemNew(value);
+ _ILJitStackItemNew(index);
+ _ILJitStackItemNew(array);
+ ILJitValue length;
+ ILJitValue arrayBase;
+ ILJitValue temp;
+ ILJitType valueType;
+
+ _ILJitStackPop(coder, value);
+ _ILJitStackPop(coder, index);
+ _ILJitStackPop(coder, array);
+ valueType = jit_value_get_type(_ILJitStackItemValue(value));
+ _ILJitStackItemCheckNull(coder, array);
+ length = GetArrayLength(coder, _ILJitStackItemValue(array));
+ ValidateArrayIndex(coder, length, _ILJitStackItemValue(index));
+ arrayBase = GetArrayBase(coder, _ILJitStackItemValue(array));
+
+ /* Convert the value to the array type when needed. */
+ if(valueType != type)
+ {
+ int valueIsStruct = (jit_type_is_struct(valueType) ||
jit_type_is_union(valueType));
+ int destIsStruct = (jit_type_is_struct(type) ||
jit_type_is_union(type));
+
+ if(valueIsStruct || destIsStruct)
+ {
+ int valueSize = jit_type_get_size(valueType);
+ int destSize = jit_type_get_size(type);
+
+ if(destSize == valueSize)
+ {
+ /* The sizes match so we can safely use store
element. */
+ temp = _ILJitStackItemValue(value);
+ }
+ else
+ {
+ /* We assume that destSize is smaller than
valueSize because */
+ /* the values have to be assignment compatible.
*/
+ /* But we have to use memcpy instead. */
+ _ILJitStackItemNew(dest);
+ ILJitValue destPtr =
jit_insn_load_elem_address(coder->jitFunction,
+
arrayBase,
+
_ILJitStackItemValue(index),
+
type);
+ ILJitValue srcPtr =
jit_insn_address_of(coder->jitFunction,
+
_ILJitStackItemValue(value));
+ ILJitValue size =
jit_value_create_nint_constant(coder->jitFunction,
+
_IL_JIT_TYPE_NINT,
+
(jit_nint)destSize);
+
+ _ILJitStackItemInitWithNotNullValue(dest,
destPtr);
+ _ILJitStackItemMemCpy(coder, dest, srcPtr,
size);
+ return;
+ }
+ }
+ else
+ {
+ temp = _ILJitValueConvertImplicit(coder->jitFunction,
+
_ILJitStackItemValue(value),
+
type);
+ }
+ }
+ else
+ {
+ temp = _ILJitStackItemValue(value);
+ }
+ jit_insn_store_elem(coder->jitFunction,
+ arrayBase,
+ _ILJitStackItemValue(index),
+ temp);
+}
+
+#endif /* IL_JITC_FUNCTIONS */
+
+#ifdef IL_JITC_CODE
+
+/*
+ * Handle an array access opcode.
+ */
+static void JITCoder_ArrayAccess(ILCoder *coder, int opcode,
+ ILEngineType
indexType, ILType *elemType)
+{
+ ILJITCoder *jitCoder = _ILCoderToILJITCoder(coder);
+ _ILJitStackItemNew(array);
+ _ILJitStackItemNew(index);
+ ILJitValue len;
+ ILJitValue value;
+ ILJitValue arrayBase;
+
+ switch(opcode)
+ {
+ case IL_OP_LDELEMA:
+ {
+ _ILJitStackPop(jitCoder, index);
+ _ILJitStackPop(jitCoder, array);
+
+ _ILJitStackItemCheckNull(jitCoder, array);
+ len = GetArrayLength(jitCoder,
_ILJitStackItemValue(array));
+ ValidateArrayIndex(jitCoder, len,
_ILJitStackItemValue(index));
+ arrayBase = GetArrayBase(jitCoder,
_ILJitStackItemValue(array));
+
+ ILJitType type = _ILJitGetReturnType(elemType,
jitCoder->process);
+
+ value =
jit_insn_load_elem_address(jitCoder->jitFunction,
+
arrayBase,
+
_ILJitStackItemValue(index),
+
type);
+ _ILJitStackPushNotNullValue(jitCoder, value);
+ }
+ break;
+
+ case IL_OP_LDELEM_I1:
+ {
+ /* Load a signed byte from an array */
+ LoadArrayElem(jitCoder, _IL_JIT_TYPE_SBYTE);
+ }
+ break;
+
+ case IL_OP_LDELEM_I2:
+ {
+ /* Load a signed short from an array */
+ LoadArrayElem(jitCoder, _IL_JIT_TYPE_INT16);
+ }
+ break;
+
+ case IL_OP_LDELEM_I4:
+ #ifdef IL_NATIVE_INT32
+ case IL_OP_LDELEM_I:
+ #endif
+ {
+ /* Load an integer from an array */
+ LoadArrayElem(jitCoder, _IL_JIT_TYPE_INT32);
+ }
+ break;
+
+ case IL_OP_LDELEM_I8:
+ #ifdef IL_NATIVE_INT64
+ case IL_OP_LDELEM_I:
+ #endif
+ {
+ /* Load a long from an array */
+ LoadArrayElem(jitCoder, _IL_JIT_TYPE_INT64);
+ }
+ break;
+
+ case IL_OP_LDELEM_U1:
+ {
+ /* Load an unsigned byte from an array */
+ LoadArrayElem(jitCoder, _IL_JIT_TYPE_BYTE);
+ }
+ break;
+
+ case IL_OP_LDELEM_U2:
+ {
+ /* Load an unsigned short from an array */
+ LoadArrayElem(jitCoder, _IL_JIT_TYPE_UINT16);
+ }
+ break;
+
+ case IL_OP_LDELEM_U4:
+ {
+ /* Load an unsigned integer from an array */
+ LoadArrayElem(jitCoder, _IL_JIT_TYPE_UINT32);
+ }
+ break;
+
+ case IL_OP_LDELEM_R4:
+ {
+ /* Load a 32-bit float from an array */
+ LoadArrayElem(jitCoder, _IL_JIT_TYPE_SINGLE);
+ }
+ break;
+
+ case IL_OP_LDELEM_R8:
+ {
+ /* Load a 64-bit float from an array */
+ LoadArrayElem(jitCoder, _IL_JIT_TYPE_DOUBLE);
+ }
+ break;
+
+ case IL_OP_LDELEM_REF:
+ {
+ /* Load a pointer from an array */
+ LoadArrayElem(jitCoder, _IL_JIT_TYPE_VPTR);
+ }
+ break;
+
+ case IL_OP_LDELEM:
+ {
+ ILJitType type = _ILJitGetReturnType(elemType,
jitCoder->process);
+ LoadArrayElem(jitCoder, type);
+ }
+ break;
+
+ case IL_OP_STELEM_I1:
+ {
+ /* Store a byte value to an array */
+ StoreArrayElem(jitCoder, _IL_JIT_TYPE_SBYTE);
+ }
+ break;
+
+ case IL_OP_STELEM_I2:
+ {
+ /* Store a short value to an array */
+ StoreArrayElem(jitCoder, _IL_JIT_TYPE_INT16);
+ }
+ break;
+
+ case IL_OP_STELEM_I4:
+ #ifdef IL_NATIVE_INT32
+ case IL_OP_STELEM_I:
+ #endif
+ {
+ /* Store an integer value to an array */
+ StoreArrayElem(jitCoder, _IL_JIT_TYPE_INT32);
+ }
+ break;
+
+ case IL_OP_STELEM_I8:
+ #ifdef IL_NATIVE_INT64
+ case IL_OP_STELEM_I:
+ #endif
+ {
+ /* Store a long value to an array */
+ StoreArrayElem(jitCoder, _IL_JIT_TYPE_INT64);
+ }
+ break;
+
+ case IL_OP_STELEM_R4:
+ {
+ /* Store a 32-bit floating point value to an array */
+ StoreArrayElem(jitCoder, _IL_JIT_TYPE_SINGLE);
+ }
+ break;
+
+ case IL_OP_STELEM_R8:
+ {
+ /* Store a 64-bit floating point value to an array */
+ StoreArrayElem(jitCoder, _IL_JIT_TYPE_DOUBLE);
+ }
+ break;
+
+ case IL_OP_STELEM_REF:
+ {
+ /* Store a pointer to an array */
+ /* TODO: Check if the types are assignmentcompatible. */
+ StoreArrayElem(jitCoder, _IL_JIT_TYPE_VPTR);
+ }
+ break;
+
+ case IL_OP_STELEM:
+ {
+ /* Store a pointer to an array */
+ /* TODO: Check if the types are assignmentcompatible. */
+ ILJitType type = _ILJitGetReturnType(elemType,
jitCoder->process);
+ StoreArrayElem(jitCoder, type);
+ }
+ break;
+ }
+}
+
+/*
+ * Get the length of an array.
+ */
+static void JITCoder_ArrayLength(ILCoder *coder)
+{
+ ILJITCoder *jitCoder = _ILCoderToILJITCoder(coder);
+ _ILJitStackItemNew(array);
+ ILJitValue length;
+
+ /* Pop the array off the evaluation stack. */
+ _ILJitStackPop(jitCoder, array);
+
+ _ILJitStackItemCheckNull(jitCoder, array);
+ length = GetArrayLength(jitCoder, _ILJitStackItemValue(array));
+ _ILJitStackPushValue(jitCoder, length);
+}
+
+/*
+ * Construct a new array, given a type and length value.
+ */
+static void JITCoder_NewArray(ILCoder *coder, ILType *arrayType,
+ ILClass *arrayClass,
ILEngineType lengthType)
+{
+ ILJITCoder *jitCoder = _ILCoderToILJITCoder(coder);
+ _ILJitStackItemNew(length);
+ ILJitValue returnValue;
+
+ /* Pop the length off the evaluation stack. */
+ _ILJitStackPop(jitCoder, length);
+
+ returnValue = _ILJitSArrayNew(jitCoder,
+ arrayClass,
+
_ILJitStackItemValue(length));
+
+ _ILJitStackPushNotNullValue(jitCoder, returnValue);
+}
+
+#endif /* IL_JITC_CODE */
+
Index: engine/jitc_call.c
===================================================================
RCS file: /cvsroot/dotgnu-pnet/pnet/engine/jitc_call.c,v
retrieving revision 1.29
retrieving revision 1.30
diff -u -b -r1.29 -r1.30
--- engine/jitc_call.c 15 Oct 2006 09:32:28 -0000 1.29
+++ engine/jitc_call.c 17 Oct 2006 12:24:18 -0000 1.30
@@ -18,7 +18,11 @@
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
-#ifdef IL_JITC_CODE
+#ifdef IL_JITC_DECLARATIONS
+
+#endif /* IL_JITC_DECLARATIONS */
+
+#ifdef IL_JITC_FUNCTIONS
/*
* Get the call signature from the methodInfo or the ILCoderMethoInfo.
@@ -131,7 +135,7 @@
args, 3, 0);
jit_insn_branch_if(jitCoder->jitFunction, jitFunction, &label);
- _ILJitThrowSystem(jitCoder, _IL_JIT_MISSING_METHOD);
+ _ILJitThrowSystem(jitCoder->jitFunction, _IL_JIT_MISSING_METHOD);
jit_insn_label(jitCoder->jitFunction, &label);
return jitFunction;
@@ -163,7 +167,7 @@
vtable, vtableIndex,
_IL_JIT_TYPE_VPTR);
jit_insn_branch_if(jitCoder->jitFunction, jitFunction, &label);
- _ILJitThrowSystem(jitCoder, _IL_JIT_MISSING_METHOD);
+ _ILJitThrowSystem(jitCoder->jitFunction, _IL_JIT_MISSING_METHOD);
jit_insn_label(jitCoder->jitFunction, &label);
return jitFunction;
@@ -183,8 +187,9 @@
* This is not included in VarArgs as this is needed by non-vararg operations
* like BeginInvoke.
*/
-void _ILJitPackVarArgs(ILJITCoder *jitCoder,
- ILUInt32 firstParam,
ILUInt32 numArgs,
+ILInt32 _ILJitPackVarArgs(ILJITCoder *jitCoder,
+ ILUInt32 firstParam,
+ ILUInt32 numArgs,
ILType *callSiteSig)
{
ILExecThread *_thread = ILExecThreadCurrent();
@@ -192,47 +197,26 @@
ILType *paramType;
ILType *enumType;
ILClass *info;
- ILMethod *ctor;
ILUInt32 typeSize;
- ILJitFunction jitCtor;
ILJitValue thread = _ILJitCoderGetThread(jitCoder);
- ILJitValue arrayLength =
jit_value_create_nint_constant(jitCoder->jitFunction,
-
_IL_JIT_TYPE_UINT32,
-
(jit_nint)numArgs);
ILJitValue array;
- ILJitValue arrayBase;
+ ILInt32 arrayBase;
ILJitValue boxObject;
ILJitValue boxValue;
ILJitValue boxObjectSize;
ILJitValue ptr;
- jit_label_t labelException = jit_label_undefined;
- jit_label_t label = jit_label_undefined;
ILJitStackItem *stackItems;
- ILJitValue args[3];
/* Allocate an array to hold all of the arguments */
- /* Find the constructor for the array. */
- ctor = ILExecThreadLookupMethod(_thread, "[oSystem.Object;", ".ctor",
-
"(Ti)V");
- jitCtor = ILJitFunctionFromILMethod(ctor);
- if(!jitCtor)
- {
- /* We have to layout the class first. */
- if(!_LayoutClass(_thread, ILMethod_Owner(ctor)))
+ array = _ILJitSObjectArrayCreate(jitCoder->jitFunction, _thread,
thread, numArgs);
+ if(!array)
{
- return;
- }
- jitCtor = ILJitFunctionFromILMethod(ctor);
+ return 0;
}
- args[0] = thread;
- args[1] = arrayLength;
- array = jit_insn_call(jitCoder->jitFunction, 0, jitCtor,
- 0, args, 2, 0);
- jit_insn_branch_if_not(jitCoder->jitFunction, array, &labelException);
- arrayBase = jit_insn_add_relative(jitCoder->jitFunction,
- array,
-
sizeof(void *));
+
+ arrayBase = _IL_JIT_SARRAY_HEADERSIZE;
+
/* Adjust the stack just to the first vararg. */
stackItems = _ILJitStackItemGetAndPop(jitCoder, numArgs);
@@ -249,121 +233,20 @@
paramType = ILType_Ref(paramType);
enumType = ILTypeGetEnumType(paramType);
- if(ILType_IsPrimitive(enumType))
- {
- /* Box a primitive value after aligning it
properly */
- switch(ILType_ToElement(enumType))
- {
- case IL_META_ELEMTYPE_I1:
- {
- boxValue =
jit_insn_load_relative(jitCoder->jitFunction,
-
_ILJitStackItemValue(stackItems[param]),
-
0, _IL_JIT_TYPE_SBYTE);
- }
- break;
-
- case IL_META_ELEMTYPE_U1:
- case IL_META_ELEMTYPE_BOOLEAN:
- {
- boxValue =
jit_insn_load_relative(jitCoder->jitFunction,
-
_ILJitStackItemValue(stackItems[param]),
-
0, _IL_JIT_TYPE_BYTE);
- }
- break;
-
- case IL_META_ELEMTYPE_I2:
- {
- boxValue =
jit_insn_load_relative(jitCoder->jitFunction,
-
_ILJitStackItemValue(stackItems[param]),
-
0, _IL_JIT_TYPE_INT16);
- }
- break;
- case IL_META_ELEMTYPE_U2:
- case IL_META_ELEMTYPE_CHAR:
- {
- boxValue =
jit_insn_load_relative(jitCoder->jitFunction,
-
_ILJitStackItemValue(stackItems[param]),
-
0, _IL_JIT_TYPE_UINT16);
- }
- break;
-
- case IL_META_ELEMTYPE_I4:
-#ifdef IL_NATIVE_INT32
- case IL_META_ELEMTYPE_I:
-#endif
- {
- boxValue =
jit_insn_load_relative(jitCoder->jitFunction,
-
_ILJitStackItemValue(stackItems[param]),
-
0, _IL_JIT_TYPE_INT32);
- }
- break;
-
- case IL_META_ELEMTYPE_U4:
-#ifdef IL_NATIVE_INT32
- case IL_META_ELEMTYPE_U:
-#endif
- {
- boxValue =
jit_insn_load_relative(jitCoder->jitFunction,
-
_ILJitStackItemValue(stackItems[param]),
-
0, _IL_JIT_TYPE_UINT32);
- }
- break;
-
- case IL_META_ELEMTYPE_I8:
-#ifdef IL_NATIVE_INT64
- case IL_META_ELEMTYPE_I:
-#endif
- {
- boxValue =
jit_insn_load_relative(jitCoder->jitFunction,
-
_ILJitStackItemValue(stackItems[param]),
-
0, _IL_JIT_TYPE_INT64);
- }
- break;
-
- case IL_META_ELEMTYPE_U8:
-#ifdef IL_NATIVE_INT64
- case IL_META_ELEMTYPE_U:
-#endif
- {
- boxValue =
jit_insn_load_relative(jitCoder->jitFunction,
-
_ILJitStackItemValue(stackItems[param]),
-
0, _IL_JIT_TYPE_UINT64);
- }
- break;
-
- case IL_META_ELEMTYPE_R4:
- {
- boxValue =
jit_insn_load_relative(jitCoder->jitFunction,
-
_ILJitStackItemValue(stackItems[param]),
-
0, _IL_JIT_TYPE_SINGLE);
- }
- break;
-
- case IL_META_ELEMTYPE_R8:
+ if(ILType_IsPrimitive(enumType))
{
- boxValue =
jit_insn_load_relative(jitCoder->jitFunction,
-
_ILJitStackItemValue(stackItems[param]),
-
0, _IL_JIT_TYPE_DOUBLE);
- }
- break;
+ ILJitType jitType =
_ILJitGetReturnType(enumType,
+
jitCoder->process);
- case IL_META_ELEMTYPE_R:
+ if(!jitType)
{
- boxValue =
jit_insn_load_relative(jitCoder->jitFunction,
-
_ILJitStackItemValue(stackItems[param]),
-
0, _IL_JIT_TYPE_NFLOAT);
+ return 0;
}
- break;
- default:
- {
boxValue =
jit_insn_load_relative(jitCoder->jitFunction,
_ILJitStackItemValue(stackItems[param]),
-
0, _IL_JIT_TYPE_VPTR);
- }
- break;
- }
+
0, jitType);
}
else if(ILType_IsValueType(paramType))
{
@@ -375,7 +258,9 @@
boxValue =
jit_insn_load_relative(jitCoder->jitFunction,
_ILJitStackItemValue(stackItems[param]),
0, _IL_JIT_TYPE_VPTR);
- jit_insn_store_relative(jitCoder->jitFunction,
arrayBase, 0,
+ jit_insn_store_relative(jitCoder->jitFunction,
+
array,
+
arrayBase,
boxValue);
boxValue = 0;
}
@@ -385,128 +270,28 @@
it up within a "System.IntPtr" object */
boxValue =
jit_insn_load_relative(jitCoder->jitFunction,
_ILJitStackItemValue(stackItems[param]),
-
0, _IL_JIT_TYPE_VPTR);
+
0,
+
_IL_JIT_TYPE_VPTR);
paramType = ILType_Int;
}
}
else
{
enumType = ILTypeGetEnumType(paramType);
- if(ILType_IsPrimitive(enumType))
- {
- int x;
- x = ILType_ToElement(enumType);
- /* Box a primitive value after aligning it
properly */
- switch(ILType_ToElement(paramType))
- {
- case IL_META_ELEMTYPE_I1:
- {
- boxValue =
jit_insn_convert(jitCoder->jitFunction,
-
_ILJitStackItemValue(stackItems[param]),
-
_IL_JIT_TYPE_SBYTE, 0);
- }
- break;
-
- case IL_META_ELEMTYPE_U1:
- case IL_META_ELEMTYPE_BOOLEAN:
- {
- boxValue =
jit_insn_convert(jitCoder->jitFunction,
-
_ILJitStackItemValue(stackItems[param]),
-
_IL_JIT_TYPE_BYTE, 0);
- }
- break;
-
- case IL_META_ELEMTYPE_I2:
- {
- boxValue =
jit_insn_convert(jitCoder->jitFunction,
-
_ILJitStackItemValue(stackItems[param]),
-
_IL_JIT_TYPE_INT16, 0);
- }
- break;
-
- case IL_META_ELEMTYPE_U2:
- case IL_META_ELEMTYPE_CHAR:
- {
- boxValue =
jit_insn_convert(jitCoder->jitFunction,
-
_ILJitStackItemValue(stackItems[param]),
-
_IL_JIT_TYPE_UINT16, 0);
- }
- break;
-
- case IL_META_ELEMTYPE_I4:
-#ifdef IL_NATIVE_INT32
- case IL_META_ELEMTYPE_I:
-#endif
- {
- boxValue =
jit_insn_convert(jitCoder->jitFunction,
-
_ILJitStackItemValue(stackItems[param]),
-
_IL_JIT_TYPE_INT32, 0);
- }
- break;
-
- case IL_META_ELEMTYPE_U4:
-#ifdef IL_NATIVE_INT32
- case IL_META_ELEMTYPE_U:
-#endif
- {
- boxValue =
jit_insn_convert(jitCoder->jitFunction,
-
_ILJitStackItemValue(stackItems[param]),
-
_IL_JIT_TYPE_UINT32, 0);
- }
- break;
-
- case IL_META_ELEMTYPE_I8:
-#ifdef IL_NATIVE_INT64
- case IL_META_ELEMTYPE_I:
-#endif
- {
- boxValue =
jit_insn_convert(jitCoder->jitFunction,
-
_ILJitStackItemValue(stackItems[param]),
-
_IL_JIT_TYPE_INT64, 0);
- }
- break;
-
- case IL_META_ELEMTYPE_U8:
-#ifdef IL_NATIVE_INT64
- case IL_META_ELEMTYPE_U:
-#endif
- {
- boxValue =
jit_insn_convert(jitCoder->jitFunction,
-
_ILJitStackItemValue(stackItems[param]),
-
_IL_JIT_TYPE_UINT64, 0);
- }
- break;
-
- case IL_META_ELEMTYPE_R4:
+ if(ILType_IsPrimitive(enumType))
{
- boxValue =
jit_insn_convert(jitCoder->jitFunction,
-
_ILJitStackItemValue(stackItems[param]),
-
_IL_JIT_TYPE_SINGLE, 0);
- }
- break;
+ ILJitType jitType =
_ILJitGetReturnType(enumType,
+
jitCoder->process);
- case IL_META_ELEMTYPE_R8:
+ if(!jitType)
{
- boxValue =
jit_insn_convert(jitCoder->jitFunction,
-
_ILJitStackItemValue(stackItems[param]),
-
_IL_JIT_TYPE_DOUBLE, 0);
+ return 0;
}
- break;
- case IL_META_ELEMTYPE_R:
- {
- boxValue =
jit_insn_convert(jitCoder->jitFunction,
+ boxValue =
_ILJitValueConvertImplicit(jitCoder->jitFunction,
_ILJitStackItemValue(stackItems[param]),
-
_IL_JIT_TYPE_NFLOAT, 0);
- }
-
- default:
- {
- boxValue =
_ILJitStackItemValue(stackItems[param]);
- }
- break;
- }
+
jitType);
}
else if(ILType_IsValueType(paramType))
{
@@ -516,16 +301,18 @@
else if(ILTypeIsReference(paramType))
{
/* Object reference type: pass it directly */
- jit_insn_store_relative(jitCoder->jitFunction,
arrayBase, 0,
+ jit_insn_store_relative(jitCoder->jitFunction,
+
array,
+
arrayBase,
_ILJitStackItemValue(stackItems[param]));
}
else
{
/* Assume that everything else is a pointer,
and wrap
it up within a "System.IntPtr" object */
- boxValue =
jit_insn_convert(jitCoder->jitFunction,
+ boxValue =
_ILJitValueConvertImplicit(jitCoder->jitFunction,
_ILJitStackItemValue(stackItems[param]),
-
_IL_JIT_TYPE_VPTR, 0);
+
_IL_JIT_TYPE_VPTR);
paramType = ILType_Int;
}
}
@@ -533,40 +320,48 @@
{
/* We have to box the argument. */
info = ILClassFromType
-
(ILContextNextImage(_thread->process->context, 0),
+
(ILContextNextImage(jitCoder->process->context, 0),
0, paramType, 0);
info = ILClassResolve(info);
typeSize = ILSizeOfType(_thread, paramType);
boxObjectSize =
jit_value_create_nint_constant(jitCoder->jitFunction,
-
_IL_JIT_TYPE_UINT32, typeSize);
+
_IL_JIT_TYPE_UINT32,
+
typeSize);
boxObject = _ILJitAllocGen(jitCoder->jitFunction, info,
typeSize);
if(boxValue)
{
- jit_insn_store_relative(jitCoder->jitFunction,
boxObject, 0,
+ jit_insn_store_relative(jitCoder->jitFunction,
+
boxObject,
+
0,
boxValue);
}
else
{
- jit_insn_memcpy(jitCoder->jitFunction,
boxObject, ptr, boxObjectSize);
+ jit_insn_memcpy(jitCoder->jitFunction,
+ boxObject,
+ ptr,
+ boxObjectSize);
}
- jit_insn_store_relative(jitCoder->jitFunction,
arrayBase, 0,
+ jit_insn_store_relative(jitCoder->jitFunction,
+ array,
+
arrayBase,
boxObject);
}
- arrayBase = jit_insn_add_relative(jitCoder->jitFunction,
-
arrayBase,
-
sizeof(void *));
+ /* Advance to the next slot in the array. */
+ arrayBase += sizeof(ILObject *);
}
- jit_insn_branch(jitCoder->jitFunction, &label);
- jit_insn_label(jitCoder->jitFunction, &labelException);
- _ILJitThrowCurrentException(jitCoder);
- jit_insn_label(jitCoder->jitFunction, &label);
-
/* push the array on the stack */
_ILJitStackPushNotNullValue(jitCoder, array);
+
+ return 1;
}
+#endif /* IL_JITC_FUNCTIONS */
+
+#ifdef IL_JITC_CODE
+
static void JITCoder_UpConvertArg(ILCoder *coder, ILEngineStackItem *args,
ILUInt32 numArgs,
ILUInt32 param,
ILType *paramType)
@@ -768,8 +563,6 @@
&callSignature);
#endif
- /* TODO: create call signature for vararg calls. */
-
if(info->tailCall == 1)
{
#ifdef IL_JIT_THREAD_IN_SIGNATURE
@@ -1850,6 +1643,7 @@
static void JITCoder_JumpMethod(ILCoder *coder, ILMethod *methodInfo)
{
+ /* TODO */
}
static void JITCoder_ReturnInsn(ILCoder *coder, ILEngineType engineType,
Index: engine/jitc_delegate.c
===================================================================
RCS file: /cvsroot/dotgnu-pnet/pnet/engine/jitc_delegate.c,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -b -r1.6 -r1.7
--- engine/jitc_delegate.c 13 Jul 2006 18:16:05 -0000 1.6
+++ engine/jitc_delegate.c 17 Oct 2006 12:24:18 -0000 1.7
@@ -18,52 +18,31 @@
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
+#ifdef IL_JITC_DECLARATIONS
+
/*
- * Create an Object array with the given size.
+ * Build the Invoke method for the delegate.
*/
-static ILJitValue _ILJitObjectArrayCreate(ILJitFunction jitFunction,
-
ILExecThread *_thread,
-
ILJitValue thread,
-
ILUInt32 numElements)
-{
- ILMethod *ctor;
- ILJitFunction jitCtor;
- ILJitValue array;
- ILJitValue arrayLength = jit_value_create_nint_constant(jitFunction,
-
_IL_JIT_TYPE_UINT32,
-
(jit_nint)numElements);
- ILJitValue args[2];
+static int _ILJitCompileDelegateInvoke(ILJitFunction func);
- /* Find the constructor for the array. */
- ctor = ILExecThreadLookupMethod(_thread, "[oSystem.Object;", ".ctor",
-
"(Ti)V");
- if(!ctor)
- {
- return 0;
- }
+/*
+ * Build the BeginInvoke method for a delegate.
+ */
+static int _ILJitCompileDelegateBeginInvoke(ILJitFunction func);
- jitCtor = ILJitFunctionFromILMethod(ctor);
- if(!jitCtor)
- {
- /* We have to layout the class first. */
- if(!_LayoutClass(_thread, ILMethod_Owner(ctor)))
- {
- return 0;
- }
- jitCtor = ILJitFunctionFromILMethod(ctor);
- }
-#ifdef IL_JIT_THREAD_IN_SIGNATURE
- args[0] = thread;
- args[1] = arrayLength;
- array = jit_insn_call(jitFunction, 0, jitCtor,
- 0, args, 2, 0);
-#else
- args[0] = arrayLength;
- array = jit_insn_call(jitFunction, 0, jitCtor,
- 0, args, 1, 0);
-#endif
- return array;
-}
+/*
+ * Build the EndInvoke method for a delegate.
+ */
+static int _ILJitCompileDelegateEndInvoke(ILJitFunction func);
+
+/*
+ * Build the Invoke method for the multicast delegate.
+ */
+static int _ILJitCompileMultiCastDelegateInvoke(ILJitFunction func);
+
+#endif /* IL_JITC_DECLARATIONS */
+
+#ifdef IL_JITC_FUNCTIONS
/*
* Pack the delegate invoke arguments into an "Object[]" array and return the
@@ -90,7 +69,7 @@
ILJitValue ptr;
/* Allocate an array to hold all of the arguments */
- array = _ILJitObjectArrayCreate(jitFunction, _thread, thread, numArgs);
+ array = _ILJitSObjectArrayCreate(jitFunction, _thread, thread, numArgs);
if(!array)
{
return 0;
@@ -721,7 +700,7 @@
}
/* Allocate an array to hold the out arguments */
- array = _ILJitObjectArrayCreate(func, _thread, thread, numOutParams);
+ array = _ILJitSObjectArrayCreate(func, _thread, thread, numOutParams);
if(!array)
{
return JIT_RESULT_COMPILE_ERROR;
@@ -880,3 +859,5 @@
return JIT_RESULT_OK;
}
+#endif /* IL_JITC_FUNCTIONS */
+
Index: engine/jitc_except.c
===================================================================
RCS file: /cvsroot/dotgnu-pnet/pnet/engine/jitc_except.c,v
retrieving revision 1.12
retrieving revision 1.13
diff -u -b -r1.12 -r1.13
--- engine/jitc_except.c 10 Oct 2006 17:10:45 -0000 1.12
+++ engine/jitc_except.c 17 Oct 2006 12:24:18 -0000 1.13
@@ -18,7 +18,28 @@
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
-#ifdef IL_JITC_CODE
+#ifdef IL_JITC_DECLARATIONS
+
+/*
+ * Declaration of the engine internal exceptions.
+ */
+#define _IL_JIT_OK 0
+#define _IL_JIT_OUT_OF_MEMORY 1
+#define _IL_JIT_INVALID_CAST 2
+#define _IL_JIT_INDEX_OUT_OF_RANGE 3
+#define _IL_JIT_MISSING_METHOD 4
+#define _IL_JIT_DLL_NOT_FOUND 5
+#define _IL_JIT_ENTRYPOINT_NOT_FOUND 6
+
+/*
+ * Emit the code to throw a system exception.
+ */
+static void _ILJitThrowSystem(ILJitFunction jitFunction,
+ ILUInt32 exception);
+
+#endif /* IL_JITC_DECLARATIONS */
+
+#ifdef IL_JITC_FUNCTIONS
/*
* Find the "stackTrace" field within "System.Exception" and then set.
@@ -52,7 +73,8 @@
/*
* Emit the code to throw a system exception.
*/
-static void _ILJitThrowSystem(ILJITCoder *jitCoder, ILUInt32 exception)
+static void _ILJitThrowSystem(ILJitFunction jitFunction,
+ ILUInt32 exception)
{
static const char * const exceptionClasses[] = {
"Ok",
@@ -68,7 +90,7 @@
if(exception == _IL_JIT_OUT_OF_MEMORY)
{
- jit_insn_call_native(jitCoder->jitFunction,
+ jit_insn_call_native(jitFunction,
"ILRuntimeExceptionThrowOutOfMemory",
ILRuntimeExceptionThrowOutOfMemory,
_ILJitSignature_ILRuntimeExceptionThrowOutOfMemory,
@@ -98,10 +120,10 @@
return;
}
}
- info = jit_value_create_nint_constant(jitCoder->jitFunction,
+ info = jit_value_create_nint_constant(jitFunction,
_IL_JIT_TYPE_VPTR,
(jit_nint)classInfo);
- jit_insn_call_native(jitCoder->jitFunction,
+ jit_insn_call_native(jitFunction,
"ILRuntimeExceptionThrowClass",
ILRuntimeExceptionThrowClass,
_ILJitSignature_ILRuntimeExceptionThrowClass,
@@ -227,6 +249,9 @@
jit_insn_label(jitCoder->jitFunction, &label);
}
+#endif /* IL_JITC_FUNCTIONS */
+
+#ifdef IL_JITC_CODE
/*
* Set up exception handling for the current method.
Index: engine/jitc_obj.c
===================================================================
RCS file: /cvsroot/dotgnu-pnet/pnet/engine/jitc_obj.c,v
retrieving revision 1.22
retrieving revision 1.23
diff -u -b -r1.22 -r1.23
--- engine/jitc_obj.c 13 Oct 2006 15:04:03 -0000 1.22
+++ engine/jitc_obj.c 17 Oct 2006 12:24:18 -0000 1.23
@@ -183,7 +183,7 @@
temp = jit_insn_eq(jitCoder->jitFunction, type, info);
jit_insn_branch_if(jitCoder->jitFunction, temp, &label1);
/* Throw an InvalidCastException */
- _ILJitThrowSystem(jitCoder, _IL_JIT_INVALID_CAST);
+ _ILJitThrowSystem(jitCoder->jitFunction, _IL_JIT_INVALID_CAST);
jit_insn_label(jitCoder->jitFunction, &label1);
valuePtr = jit_insn_load_relative(jitCoder->jitFunction, ptr,
offsetof(ILTypedRef, value),
@@ -302,7 +302,7 @@
_ILJitStackPush(jitCoder, object);
jit_insn_branch_if(jitCoder->jitFunction, returnValue, &label);
/* Throw an InvalidCastException. */
- _ILJitThrowSystem(jitCoder, _IL_JIT_INVALID_CAST);
+ _ILJitThrowSystem(jitCoder->jitFunction, _IL_JIT_INVALID_CAST);
}
else
@@ -1099,6 +1099,29 @@
static void JITCoder_ArgList(ILCoder *coder)
{
+ ILJITCoder *jitCoder = _ILCoderToILJITCoder(coder);
+ ILJitType signature = jit_function_get_signature(jitCoder->jitFunction);
+ ILInt32 numArgs = jit_type_num_params(signature);
+ _ILJitStackItemNew(stackItem);
+
+#if !defined(IL_CONFIG_REDUCE_CODE) && !defined(IL_WITHOUT_TOOLS)
+ if (jitCoder->flags & IL_CODER_FLAG_STATS)
+ {
+ ILMutexLock(globalTraceMutex);
+ fprintf(stdout,
+ "ArgList: Arg = %i\n",
+ numArgs - 1);
+ ILMutexUnlock(globalTraceMutex);
+ }
+#endif
+
+ /* We have to push the last argument for this function on the stack. */
+#ifdef IL_JIT_THREAD_IN_SIGNATURE
+ _ILJitStackItemLoadArg(jitCoder, stackItem, numArgs - 2);
+#else
+ _ILJitStackItemLoadArg(jitCoder, stackItem, numArgs - 1);
+#endif
+ _ILJitStackPush(jitCoder, stackItem);
}
#endif /* IL_JITC_CODE */
Index: engine/jitc_pinvoke.c
===================================================================
RCS file: /cvsroot/dotgnu-pnet/pnet/engine/jitc_pinvoke.c,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -b -r1.5 -r1.6
--- engine/jitc_pinvoke.c 25 Sep 2006 18:34:07 -0000 1.5
+++ engine/jitc_pinvoke.c 17 Oct 2006 12:24:18 -0000 1.6
@@ -117,11 +117,11 @@
{
if(jitMethodInfo->fnInfo.func == _IL_JIT_PINVOKE_DLLNOTFOUND)
{
- _ILJitThrowSystem(jitCoder, _IL_JIT_DLL_NOT_FOUND);
+ _ILJitThrowSystem(jitCoder->jitFunction,
_IL_JIT_DLL_NOT_FOUND);
}
else if(jitMethodInfo->fnInfo.func ==
_IL_JIT_PINVOKE_ENTRYPOINTNOTFOUND)
{
- _ILJitThrowSystem(jitCoder,
_IL_JIT_ENTRYPOINT_NOT_FOUND);
+ _ILJitThrowSystem(jitCoder->jitFunction,
_IL_JIT_ENTRYPOINT_NOT_FOUND);
}
return JIT_RESULT_OK;
}
@@ -443,11 +443,11 @@
{
if(jitMethodInfo->fnInfo.func == _IL_JIT_PINVOKE_DLLNOTFOUND)
{
- _ILJitThrowSystem(jitCoder, _IL_JIT_DLL_NOT_FOUND);
+ _ILJitThrowSystem(jitCoder->jitFunction,
_IL_JIT_DLL_NOT_FOUND);
}
else if(jitMethodInfo->fnInfo.func ==
_IL_JIT_PINVOKE_ENTRYPOINTNOTFOUND)
{
- _ILJitThrowSystem(jitCoder,
_IL_JIT_ENTRYPOINT_NOT_FOUND);
+ _ILJitThrowSystem(jitCoder->jitFunction,
_IL_JIT_ENTRYPOINT_NOT_FOUND);
}
return 0;
}
Index: engine/jitc_ptr.c
===================================================================
RCS file: /cvsroot/dotgnu-pnet/pnet/engine/jitc_ptr.c,v
retrieving revision 1.16
retrieving revision 1.17
diff -u -b -r1.16 -r1.17
--- engine/jitc_ptr.c 13 Oct 2006 15:04:03 -0000 1.16
+++ engine/jitc_ptr.c 17 Oct 2006 12:24:18 -0000 1.17
@@ -21,168 +21,6 @@
#ifdef IL_JITC_CODE
/*
- * Get the base pointer to the array data.
- */
-static ILJitValue GetArrayBase(ILJITCoder *coder, ILJitValue array)
-{
- return jit_insn_add_relative(coder->jitFunction, array,
sizeof(System_Array));
-}
-
-/*
- * Get the array length.
- */
-static ILJitValue GetArrayLength(ILJITCoder *coder, ILJitValue array)
-{
- ILJitValue len;
-
- len = jit_insn_load_relative(coder->jitFunction, array, 0,
-
_IL_JIT_TYPE_INT32);
- return len;
-}
-
-/*
- * Validate the array index.
- */
-#define JITC_START_CHECK_ARRAY_INDEX(jitCoder, length, index) \
- { \
- jit_label_t __label = jit_label_undefined; \
- jit_label_t __okLabel = jit_label_undefined; \
- ILJitValue __length = (length); \
- ILJitValue __index = (index); \
- ILJitValue __temp; \
- \
- AdjustSign(jitCoder->jitFunction, &(__length), 1, 0); \
- AdjustSign(jitCoder->jitFunction, &(__index), 1, 0); \
- \
- __temp = jit_insn_lt(jitCoder->jitFunction, __index, __length);
\
- jit_insn_branch_if_not(jitCoder->jitFunction, __temp, &__label);
-
-#define JITC_END_CHECK_ARRAY_INDEX(jitCoder) \
- jit_insn_branch(jitCoder->jitFunction, &__okLabel); \
- jit_insn_label(jitCoder->jitFunction, &__label); \
- _ILJitThrowSystem(jitCoder, _IL_JIT_INDEX_OUT_OF_RANGE); \
- jit_insn_label(jitCoder->jitFunction, &__okLabel); \
- }
-
-static void ValidateArrayIndex(ILJITCoder *coder, ILJitValue length,
-
ILJitValue index)
-{
- jit_label_t label = jit_label_undefined;
- ILJitValue temp;
-
- /* Make both values unsigned. We can save one compare this way. */
- AdjustSign(coder->jitFunction, &length, 1, 0);
- AdjustSign(coder->jitFunction, &index, 1, 0);
-
- temp = jit_insn_lt(coder->jitFunction, index, length);
- jit_insn_branch_if(coder->jitFunction, temp, &label);
- /* Throw a System.IndexOutOfRange exception. */
- _ILJitThrowSystem(coder, _IL_JIT_INDEX_OUT_OF_RANGE);
- jit_insn_label(coder->jitFunction, &label);
-}
-
-/*
- * Handle the ldelem* instructions.
- */
-static void LoadArrayElem(ILJITCoder *coder, ILJitType type)
-{
- _ILJitStackItemNew(index);
- _ILJitStackItemNew(array);
- ILJitValue length;
- ILJitValue value;
- ILJitValue arrayBase;
-
- _ILJitStackPop(coder, index);
- _ILJitStackPop(coder, array);
- _ILJitStackItemCheckNull(coder, array);
- length = GetArrayLength(coder, _ILJitStackItemValue(array));
- JITC_START_CHECK_ARRAY_INDEX(coder, length, _ILJitStackItemValue(index))
- arrayBase = GetArrayBase(coder, _ILJitStackItemValue(array));
- value = jit_insn_load_elem(coder->jitFunction,
- arrayBase,
-
_ILJitStackItemValue(index),
- type);
- _ILJitStackPushValue(coder, value);
- JITC_END_CHECK_ARRAY_INDEX(coder)
-}
-
-/*
- * Handle the stelem* instructions.
- */
-static void StoreArrayElem(ILJITCoder *coder, ILJitType type)
-{
- _ILJitStackItemNew(value);
- _ILJitStackItemNew(index);
- _ILJitStackItemNew(array);
- ILJitValue length;
- ILJitValue arrayBase;
- ILJitValue temp;
- ILJitType valueType;
-
- _ILJitStackPop(coder, value);
- _ILJitStackPop(coder, index);
- _ILJitStackPop(coder, array);
- valueType = jit_value_get_type(_ILJitStackItemValue(value));
- _ILJitStackItemCheckNull(coder, array);
- length = GetArrayLength(coder, _ILJitStackItemValue(array));
- ValidateArrayIndex(coder, length, _ILJitStackItemValue(index));
- arrayBase = GetArrayBase(coder, _ILJitStackItemValue(array));
-
- /* Convert the value to the array type when needed. */
- if(valueType != type)
- {
- int valueIsStruct = (jit_type_is_struct(valueType) ||
jit_type_is_union(valueType));
- int destIsStruct = (jit_type_is_struct(type) ||
jit_type_is_union(type));
-
- if(valueIsStruct || destIsStruct)
- {
- int valueSize = jit_type_get_size(valueType);
- int destSize = jit_type_get_size(type);
-
- if(destSize == valueSize)
- {
- /* The sizes match so we can safely use store
element. */
- temp = _ILJitStackItemValue(value);
- }
- else
- {
- /* We assume that destSize is smaller than
valueSize because */
- /* the values have to be assignment compatible.
*/
- /* But we have to use memcpy instead. */
- _ILJitStackItemNew(dest);
- ILJitValue destPtr =
jit_insn_load_elem_address(coder->jitFunction,
-
arrayBase,
-
_ILJitStackItemValue(index),
-
type);
- ILJitValue srcPtr =
jit_insn_address_of(coder->jitFunction,
-
_ILJitStackItemValue(value));
- ILJitValue size =
jit_value_create_nint_constant(coder->jitFunction,
-
_IL_JIT_TYPE_NINT,
-
(jit_nint)destSize);
-
- _ILJitStackItemInitWithNotNullValue(dest,
destPtr);
- _ILJitStackItemMemCpy(coder, dest, srcPtr,
size);
- return;
- }
- }
- else
- {
- temp = _ILJitValueConvertImplicit(coder->jitFunction,
-
_ILJitStackItemValue(value),
-
type);
- }
- }
- else
- {
- temp = _ILJitStackItemValue(value);
- }
- jit_insn_store_elem(coder->jitFunction,
- arrayBase,
- _ILJitStackItemValue(index),
- temp);
-}
-
-/*
* Handle the ldind* instructions.
*/
static void LoadRelative(ILJITCoder *coder, ILJitType type)
@@ -258,191 +96,6 @@
}
/*
- * Handle an array access opcode.
- */
-static void JITCoder_ArrayAccess(ILCoder *coder, int opcode,
- ILEngineType
indexType, ILType *elemType)
-{
- ILJITCoder *jitCoder = _ILCoderToILJITCoder(coder);
- _ILJitStackItemNew(array);
- _ILJitStackItemNew(index);
- ILJitValue len;
- ILJitValue value;
- ILJitValue arrayBase;
-
- switch(opcode)
- {
- case IL_OP_LDELEMA:
- {
- _ILJitStackPop(jitCoder, index);
- _ILJitStackPop(jitCoder, array);
-
- _ILJitStackItemCheckNull(jitCoder, array);
- len = GetArrayLength(jitCoder,
_ILJitStackItemValue(array));
- ValidateArrayIndex(jitCoder, len,
_ILJitStackItemValue(index));
- arrayBase = GetArrayBase(jitCoder,
_ILJitStackItemValue(array));
-
- ILJitType type = _ILJitGetReturnType(elemType,
jitCoder->process);
-
- value =
jit_insn_load_elem_address(jitCoder->jitFunction,
-
arrayBase,
-
_ILJitStackItemValue(index),
-
type);
- _ILJitStackPushNotNullValue(jitCoder, value);
- }
- break;
-
- case IL_OP_LDELEM_I1:
- {
- /* Load a signed byte from an array */
- LoadArrayElem(jitCoder, _IL_JIT_TYPE_SBYTE);
- }
- break;
-
- case IL_OP_LDELEM_I2:
- {
- /* Load a signed short from an array */
- LoadArrayElem(jitCoder, _IL_JIT_TYPE_INT16);
- }
- break;
-
- case IL_OP_LDELEM_I4:
- #ifdef IL_NATIVE_INT32
- case IL_OP_LDELEM_I:
- #endif
- {
- /* Load an integer from an array */
- LoadArrayElem(jitCoder, _IL_JIT_TYPE_INT32);
- }
- break;
-
- case IL_OP_LDELEM_I8:
- #ifdef IL_NATIVE_INT64
- case IL_OP_LDELEM_I:
- #endif
- {
- /* Load a long from an array */
- LoadArrayElem(jitCoder, _IL_JIT_TYPE_INT64);
- }
- break;
-
- case IL_OP_LDELEM_U1:
- {
- /* Load an unsigned byte from an array */
- LoadArrayElem(jitCoder, _IL_JIT_TYPE_BYTE);
- }
- break;
-
- case IL_OP_LDELEM_U2:
- {
- /* Load an unsigned short from an array */
- LoadArrayElem(jitCoder, _IL_JIT_TYPE_UINT16);
- }
- break;
-
- case IL_OP_LDELEM_U4:
- {
- /* Load an unsigned integer from an array */
- LoadArrayElem(jitCoder, _IL_JIT_TYPE_UINT32);
- }
- break;
-
- case IL_OP_LDELEM_R4:
- {
- /* Load a 32-bit float from an array */
- LoadArrayElem(jitCoder, _IL_JIT_TYPE_SINGLE);
- }
- break;
-
- case IL_OP_LDELEM_R8:
- {
- /* Load a 64-bit float from an array */
- LoadArrayElem(jitCoder, _IL_JIT_TYPE_DOUBLE);
- }
- break;
-
- case IL_OP_LDELEM_REF:
- {
- /* Load a pointer from an array */
- LoadArrayElem(jitCoder, _IL_JIT_TYPE_VPTR);
- }
- break;
-
- case IL_OP_LDELEM:
- {
- ILJitType type = _ILJitGetReturnType(elemType,
jitCoder->process);
- LoadArrayElem(jitCoder, type);
- }
- break;
-
- case IL_OP_STELEM_I1:
- {
- /* Store a byte value to an array */
- StoreArrayElem(jitCoder, _IL_JIT_TYPE_SBYTE);
- }
- break;
-
- case IL_OP_STELEM_I2:
- {
- /* Store a short value to an array */
- StoreArrayElem(jitCoder, _IL_JIT_TYPE_INT16);
- }
- break;
-
- case IL_OP_STELEM_I4:
- #ifdef IL_NATIVE_INT32
- case IL_OP_STELEM_I:
- #endif
- {
- /* Store an integer value to an array */
- StoreArrayElem(jitCoder, _IL_JIT_TYPE_INT32);
- }
- break;
-
- case IL_OP_STELEM_I8:
- #ifdef IL_NATIVE_INT64
- case IL_OP_STELEM_I:
- #endif
- {
- /* Store a long value to an array */
- StoreArrayElem(jitCoder, _IL_JIT_TYPE_INT64);
- }
- break;
-
- case IL_OP_STELEM_R4:
- {
- /* Store a 32-bit floating point value to an array */
- StoreArrayElem(jitCoder, _IL_JIT_TYPE_SINGLE);
- }
- break;
-
- case IL_OP_STELEM_R8:
- {
- /* Store a 64-bit floating point value to an array */
- StoreArrayElem(jitCoder, _IL_JIT_TYPE_DOUBLE);
- }
- break;
-
- case IL_OP_STELEM_REF:
- {
- /* Store a pointer to an array */
- /* TODO: Check if the types are assignmentcompatible. */
- StoreArrayElem(jitCoder, _IL_JIT_TYPE_VPTR);
- }
- break;
-
- case IL_OP_STELEM:
- {
- /* Store a pointer to an array */
- /* TODO: Check if the types are assignmentcompatible. */
- ILJitType type = _ILJitGetReturnType(elemType,
jitCoder->process);
- StoreArrayElem(jitCoder, type);
- }
- break;
- }
-}
-
-/*
* Handle a pointer indirection opcode.
*/
static void JITCoder_PtrAccess(ILCoder *coder, int opcode)
@@ -674,100 +327,6 @@
}
/*
- * Get the length of an array.
- */
-static void JITCoder_ArrayLength(ILCoder *coder)
-{
- ILJITCoder *jitCoder = _ILCoderToILJITCoder(coder);
- _ILJitStackItemNew(array);
- ILJitValue length;
-
- /* Pop the array off the evaluation stack. */
- _ILJitStackPop(jitCoder, array);
-
- _ILJitStackItemCheckNull(jitCoder, array);
- length = GetArrayLength(jitCoder, _ILJitStackItemValue(array));
- _ILJitStackPushValue(jitCoder, length);
-}
-
-/*
- * Construct a new array, given a type and length value.
- */
-static void JITCoder_NewArray(ILCoder *coder, ILType *arrayType,
- ILClass *arrayClass,
ILEngineType lengthType)
-{
- ILJITCoder *jitCoder = _ILCoderToILJITCoder(coder);
- _ILJitStackItemNew(length);
- ILJitValue returnValue;
-
-#if 1
- ILJitValue args[2];
- ILMethod *ctor;
- ILJitFunction jitFunction;
- jit_label_t label = jit_label_undefined;
- ILInternalInfo fnInfo;
-
- /* Pop the length off the evaluation stack. */
- _ILJitStackPop(jitCoder, length);
-
- /* Find the allocation constructor within the array class.
- We know that the class only has one method, so it must
- be the constructor that we are looking for */
- ctor = (ILMethod *)ILClassNextMemberByKind
- (arrayClass, 0,
IL_META_MEMBERKIND_METHOD);
-
- jitFunction = ILJitFunctionFromILMethod(ctor);
- if(!jitFunction)
- {
- /* We have to layout the class first. */
- if(!_LayoutClass(ILExecThreadCurrent(), arrayClass))
- {
- return;
- }
- jitFunction = ILJitFunctionFromILMethod(ctor);
- }
- if(_ILJitFunctionIsInternal(jitCoder, ctor, &fnInfo, 1))
- {
- ILJitValue thread = _ILJitCoderGetThread(jitCoder);
-
- returnValue = _ILJitCallInternal(jitCoder->jitFunction,
-
thread,
-
ctor,
-
fnInfo.func, 0,
-
&_ILJitStackItemValue(length), 1);
- }
- else
- {
- #ifdef IL_JIT_THREAD_IN_SIGNATURE
- args[0] = _ILJitCoderGetThread(jitCoder);
- args[1] = _ILJitStackItemValue(length);
-
- /* Output code to call the array type's constructor */
- returnValue = jit_insn_call(jitCoder->jitFunction, 0,
jitFunction,
- 0,
args, 2, 0);
- #else
- args[0] = _ILJitStackItemValue(length);
- /* Output code to call the array type's constructor */
- returnValue = jit_insn_call(jitCoder->jitFunction, 0,
jitFunction,
- 0,
args, 1, 0);
- #endif
- }
- jit_insn_branch_if(jitCoder->jitFunction, returnValue, &label);
- _ILJitThrowCurrentException(jitCoder);
- jit_insn_label(jitCoder->jitFunction, &label);
-#else
- /* Pop the length off the evaluation stack. */
- _ILJitStackPop(jitCoder, length);
-
- returnValue = _ILJitSArrayNew(jitCoder,
- arrayClass,
-
_ILJitStackItemValue(length));
-#endif
-
- _ILJitStackPushNotNullValue(jitCoder, returnValue);
-}
-
-/*
* Check the top of stack value for NULL.
*/
static void JITCoder_CheckNull(ILCoder *coder)
Index: engine/lib_misc.c
===================================================================
RCS file: /cvsroot/dotgnu-pnet/pnet/engine/lib_misc.c,v
retrieving revision 1.14
retrieving revision 1.15
diff -u -b -r1.14 -r1.15
--- engine/lib_misc.c 13 Apr 2003 22:12:15 -0000 1.14
+++ engine/lib_misc.c 17 Oct 2006 12:24:18 -0000 1.15
@@ -207,7 +207,11 @@
void *_this, void *argList)
{
ArgIterator *iter = (ArgIterator *)_this;
+#ifdef IL_USE_JIT
+ iter->un.argIter.args = (System_Array *)((ILObject *)argList);
+#else
iter->un.argIter.args = (System_Array *)(*((ILObject **)argList));
+#endif
iter->un.argIter.posn = 0;
}
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [dotgnu-pnet-commits] pnet ChangeLog engine/jitc.c engine/jitc_alloc....,
Klaus Treichel <=