[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[dotgnu-pnet-commits] [SCM] DotGNU Portable.NET engine, compilers and to
From: |
Klaus Treichel |
Subject: |
[dotgnu-pnet-commits] [SCM] DotGNU Portable.NET engine, compilers and tools (pnet) branch, master, updated. 38f20fb9b1211606a5a15b16c64f28accc344951 |
Date: |
Sat, 09 Apr 2011 07:40:18 +0000 |
This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "DotGNU Portable.NET engine, compilers and tools (pnet)".
The branch, master has been updated
via 38f20fb9b1211606a5a15b16c64f28accc344951 (commit)
from bbff92a0bb0d327feecb64712c85b498f0b72410 (commit)
Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.
- Log -----------------------------------------------------------------
http://git.savannah.gnu.org/cgit/pnet.git/commit/?id=38f20fb9b1211606a5a15b16c64f28accc344951
commit 38f20fb9b1211606a5a15b16c64f28accc344951
Author: Klaus Treichel <address@hidden>
Date: Sat Apr 9 09:39:30 2011 +0200
Add support for dynamic code generation.
Change delegate implementation from using internal calls to dynamic
generated code.
diff --git a/ChangeLog b/ChangeLog
index bbe361d..8b1eb68 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,69 @@
+2011-04-09 Klaus Treichel <address@hidden>
+
+ * engine/Makefile.am: Add coder.c and coder.h to the sources.
+
+ * engine/coder.c, engine/coder.h: Add code generation helper functions
+ and move some functions from the verifyer to here.
+ (_ILCoderBoxPtr) BoxPtr moved from verify_obj.c to here.
+ (_ILCoderBoxValue) BoxValue moved from verify_obj.c to here.
+ (_ILCoderGetParamType) GetParamType moved ftom verify_var.c to here.
+ (_ILCoderSetReturnType) Moved from verify_call.c to here and include
+ the handling of void return types too.
+
+ * engine/convert.c (GenMethod): Add method for processing dynamic code
+ generators.
+ (ConvertMethod): Adjust to changed ILInternalInfo structure and handle
+ dynamic code generators.
+
+ * engine/engine.h (ILGenCodeFunc): Define signature for dynamic code
+ generators.
+ (ILInternalInfo): Modify struct to handle dynamic code generators.
+
+ * engine/internal.c (_ILFindInternalCall): Adjust to changed
+ ILInternalInfo structure.
+
+ * engine/lib_array.c (_ILGetInternalArray): Adjust to changed
+ ILInternalInfo structure.
+
+ * engine/lib_delegate.c (_ILAsyncResult_SetOutParams): Add Check for
null
+ outParams and no invoke arguments.
+ (Delegate_ctor): Replace by dynamic code generator.
+ (Delegate_Invoke): likewise
+ (Delegate_BeginInvoke): likewise
+ (Delegate_EndInvoke): likewise
+ (_ILGetInternalDelegate): Return the new code generators instead of the
+ native functions for the constructor and the Invoke, BeginInvoke and
+ EndInvoke methods.
+
+ * engine/jitc.c: Move declaration of ILJITCoder, ILJitInlineFunc and
+ ILJitMethodInfo to engine/jitc.h.
+ (_ILJitFunctionIsInternal, _ILJitCompileInternal): Adjust to changed
+ ILInternalInfo structure.
+ (_ILJitSetMethodInfo): Adjust to changed ILInternalInfo structure.
+ Use the dynamic code gereration for the delegate methods now.
+
+ * engine/jitc.h: Move declaration of ILJITCoder, ILJitInlineFunc and
+ ILJitMethodInfo from engine/jitc.c to here.
+
+ * engine/jitc_call.c, engine/jitc_pinvoke.c, engine/jitc_setup.c,
+ engine/jitc_stack.c: Adjust to changed ILInternalInfo structure.
+
+ * engine/verify.c: Include coder.h
+
+ * engine/verify_call.c (SetReturnType): Move to coder.c
+ _ILCoderSetReturnType.
+ Change calls to SetReturnType and the handling of void return type to
+ call _ILCoderSetReturnType.
+ Change call to BoxPtr to call _ILCoderBoxPtr.
+
+ * engine/verify_obj.c (BoxPtr): Moved to coder.c _ILCoderBoxPtr.
+ (BoxValue): Moved to coder.c _ILCoderBoxValue.
+ Change call to BoxValue to call _ILCoderBoxValue.
+
+ * engine/verify_var.c (GetParamType): Moved to coder.c
+ _ILCoderGetParamType.
+ Change calls to GetParamType to call _ILCoderGetParamType.
+
2011-02-28 Klaus Treichel <address@hidden>
* csdoc/src2xml.c (Convert): Use memmove instead of strcpy to move
diff --git a/engine/Makefile.am b/engine/Makefile.am
index ba373d9..ac94e32 100644
--- a/engine/Makefile.am
+++ b/engine/Makefile.am
@@ -105,6 +105,8 @@ libILEngine_a_SOURCES = cctormgr.c \
cvm.c \
box.c \
call.c \
+ coder.c \
+ coder.h \
convert.c \
custom.c \
cvm_dasm.c \
diff --git a/engine/coder.c b/engine/coder.c
new file mode 100644
index 0000000..9a4be1f
--- /dev/null
+++ b/engine/coder.c
@@ -0,0 +1,264 @@
+/*
+ * coder.c - Common helper methods for code generation.
+ *
+ * Copyright (C) 2011 Southern Storm Software, Pty Ltd.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
+#include "engine_private.h"
+#include "coder.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/*
+ * Get the type of a parameter to the current method.
+ * Returns 0 if the parameter number is invalid.
+ */
+ILType *_ILCoderGetParamType(ILType *signature, ILMethod *method,
+ ILUInt32 num)
+{
+ if(ILType_HasThis(signature))
+ {
+ /* This method has a "this" parameter */
+ if(!num)
+ {
+ ILClass *owner;
+ ILType *synthetic;
+
+ owner = ILMethod_Owner(method);
+ if(ILClassIsValueType(owner))
+ {
+ /* The "this" parameter is a value type, which
is
+ being passed as a managed pointer. Return
+ ILType_Invalid to tell the caller that
special
+ handling is required */
+ return ILType_Invalid;
+ }
+ synthetic = ILClassGetSynType(owner);
+ if(synthetic)
+ {
+ return synthetic;
+ }
+ else
+ {
+ return ILType_FromClass(owner);
+ }
+ }
+ else
+ {
+ return ILTypeGetParam(signature, num);
+ }
+ }
+ else
+ {
+ return ILTypeGetParam(signature, num + 1);
+ }
+}
+
+/*
+ * Load the arguments from fromArg to toArg on the verification and
+ * coder stack.
+ * fromArg ... toArg must be valid argument numbers for the given
+ * method and signature.
+ */
+void _ILCoderLoadArgs(ILCoder *coder, ILEngineStackItem *stack,
+ ILMethod *method, ILType *signature,
+ ILUInt32 fromArg, ILUInt32 toArg)
+{
+ ILUInt32 current;
+ ILUInt32 stackTop;
+
+ stackTop = 0;
+ current = fromArg;
+ while(current <= toArg)
+ {
+ ILType *paramType;
+
+ paramType = _ILCoderGetParamType(signature, method, current);
+ stack[stackTop].typeInfo = paramType;
+ stack[stackTop].engineType = _ILTypeToEngineType(paramType);
+ ILCoderLoadArg(coder, current, paramType);
+ ++stackTop;
+ ++current;
+ }
+}
+
+/*
+ * Set return type information within a stack item.
+ */
+void _ILCoderSetReturnType(ILEngineStackItem *item, ILType *returnType)
+{
+ if(returnType != ILType_Void)
+ {
+ item->engineType = _ILTypeToEngineType(returnType);
+ if(item->engineType != ILEngineType_M)
+ {
+ item->typeInfo = returnType;
+ }
+ else
+ {
+ item->typeInfo =
ILType_Ref(ILTypeStripPrefixes(returnType));
+ }
+ }
+ else
+ {
+ item->engineType = ILEngineType_Invalid;
+ }
+}
+
+/*
+ * Process a "box" operation on a value. Returns zero if
+ * invalid parameters.
+ */
+int _ILCoderBoxValue(ILExecProcess *process, ILEngineType valueType,
+ ILType *typeInfo, ILClass *boxClass)
+{
+ ILUInt32 size;
+ ILType *rawType;
+
+ /* Determine the raw version of the boxing type */
+ rawType = ILTypeGetEnumType(ILClassToType(boxClass));
+
+ /* Get the size of the value type */
+ size = _ILSizeOfTypeLocked(process, rawType);
+
+ /* Determine how to box the value */
+ if(ILType_IsPrimitive(rawType))
+ {
+ if(valueType == ILEngineType_I4)
+ {
+ /* Determine if we are boxing a byte, short, or int
+ based on the raw type */
+ switch(ILType_ToElement(rawType))
+ {
+ case IL_META_ELEMTYPE_BOOLEAN:
+ case IL_META_ELEMTYPE_I1:
+ case IL_META_ELEMTYPE_U1:
+ {
+ ILCoderBoxSmaller(process->coder,
boxClass, valueType, ILType_Int8);
+ return 1;
+ }
+ /* Not reached */
+
+ case IL_META_ELEMTYPE_I2:
+ case IL_META_ELEMTYPE_U2:
+ case IL_META_ELEMTYPE_CHAR:
+ {
+ ILCoderBoxSmaller(process->coder,
boxClass, valueType, ILType_Int16);
+ return 1;
+ }
+ /* Not reached */
+
+ case IL_META_ELEMTYPE_I4:
+ case IL_META_ELEMTYPE_U4:
+ #ifdef IL_NATIVE_INT32
+ case IL_META_ELEMTYPE_I:
+ case IL_META_ELEMTYPE_U:
+ #endif
+ {
+ ILCoderBox(process->coder, boxClass,
valueType, size);
+ return 1;
+ }
+ /* Not reached */
+ }
+ }
+ else if(valueType == ILEngineType_I)
+ {
+ /* Box a native integer */
+ switch(ILType_ToElement(rawType))
+ {
+ case IL_META_ELEMTYPE_I:
+ case IL_META_ELEMTYPE_U:
+ {
+ ILCoderBox(process->coder, boxClass,
valueType, size);
+ return 1;
+ }
+ /* Not reached */
+ }
+ }
+ else if(valueType == ILEngineType_I8)
+ {
+ /* Box a 64-bit integer */
+ switch(ILType_ToElement(rawType))
+ {
+ case IL_META_ELEMTYPE_I8:
+ case IL_META_ELEMTYPE_U8:
+ {
+ ILCoderBox(process->coder, boxClass,
valueType, size);
+ return 1;
+ }
+ /* Not reached */
+ }
+ }
+ else if(valueType == ILEngineType_F)
+ {
+ /* Determine if we are boxing a float or double
+ based on the size of the value type */
+ if(rawType == ILType_Float32)
+ {
+ ILCoderBoxSmaller(process->coder, boxClass,
valueType, ILType_Float32);
+ return 1;
+ }
+ else if(rawType == ILType_Float64 ||
+ rawType == ILType_Float)
+ {
+ ILCoderBoxSmaller(process->coder, boxClass,
valueType, ILType_Float64);
+ return 1;
+ }
+ }
+ }
+ else if(valueType == ILEngineType_MV ||
+ valueType == ILEngineType_TypedRef)
+ {
+ if(ILTypeIdentical(typeInfo, ILClassToType(boxClass)))
+ {
+ ILCoderBox(process->coder, boxClass, valueType, size);
+ return 1;
+ }
+ }
+ return 0;
+}
+
+/*
+ * Process a "box" operation on a value. Returns zero if
+ * invalid parameters.
+ */
+int _ILCoderBoxPtr(ILExecProcess *process, ILType *typeInfo,
+ ILClass *boxClass, ILUInt32 pos)
+{
+ ILUInt32 size;
+ ILType *rawType;
+
+ /* Determine the raw version of the boxing type */
+ rawType = ILTypeGetEnumType(ILClassToType(boxClass));
+
+ /* Get the size of the value type */
+ size = _ILSizeOfTypeLocked(process, rawType);
+
+ if(ILTypeIdentical(typeInfo, ILClassToType(boxClass)))
+ {
+ ILCoderBoxPtr(process->coder, boxClass, size, pos);
+ return 1;
+ }
+
+ return 0;
+}
+
+#ifdef __cplusplus
+};
+#endif
diff --git a/engine/coder.h b/engine/coder.h
new file mode 100644
index 0000000..2bb0ba1
--- /dev/null
+++ b/engine/coder.h
@@ -0,0 +1,68 @@
+/*
+ * coder.h - Definitions for the code generation helpers.
+ *
+ * Copyright (C) 2011 Southern Storm Software, Pty Ltd.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
+#ifndef _ENGINE_CODER_H
+#define _ENGINE_CODER_H
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/*
+ * Get the type of a parameter to the current method.
+ * Returns 0 if the parameter number is invalid.
+ */
+ILType *_ILCoderGetParamType(ILType *signature, ILMethod *method,
+ ILUInt32 num);
+
+/*
+ * Load the arguments from fromArg to toArg on the verification and
+ * coder stack.
+ * fromArg ... toArg must be valid argument numbers for the given
+ * method and signature.
+ */
+void _ILCoderLoadArgs(ILCoder *coder, ILEngineStackItem *stack,
+ ILMethod *method, ILType *signature,
+ ILUInt32 fromArg, ILUInt32 toArg);
+
+/*
+ * Set return type information within a stack item.
+ */
+void _ILCoderSetReturnType(ILEngineStackItem *item, ILType *returnType);
+
+/*
+ * Process a "box" operation on a value. Returns zero if
+ * invalid parameters.
+ */
+int _ILCoderBoxValue(ILExecProcess *process, ILEngineType valueType,
+ ILType *typeInfo, ILClass *boxClass);
+
+/*
+ * Process a "box" operation on a value. Returns zero if
+ * invalid parameters.
+ */
+int _ILCoderBoxPtr(ILExecProcess *process, ILType *typeInfo,
+ ILClass *boxClass, ILUInt32 pos);
+
+#ifdef __cplusplus
+};
+#endif
+
+#endif /* _ENGINE_CODER_H */
diff --git a/engine/convert.c b/engine/convert.c
index 3b09bc9..e7ce687 100644
--- a/engine/convert.c
+++ b/engine/convert.c
@@ -36,6 +36,35 @@ extern "C" {
#define IL_CONVERT_TYPE_INIT 5
#define IL_CONVERT_DLL_NOT_FOUND 6
+/*
+ * Gererate code for functions where no il code is available.
+ */
+static unsigned char *GenMethod(ILCoder *coder, ILMethod *method,
+ ILGenCodeFunc
func,
+ int *errorCode,
const char **errorInfo)
+{
+ int result;
+ unsigned char *start;
+
+ do
+ {
+ ILCoderExceptions coderExceptions;
+
+ ILMemZero(&coderExceptions, sizeof(ILCoderExceptions));
+ result = (*func)(coder, method, &start, &coderExceptions);
+ } while (result == IL_CODER_END_RESTART);
+
+ if(result != IL_CODER_END_OK)
+ {
+ *errorCode = IL_CONVERT_OUT_OF_MEMORY;
+ return 0;
+ }
+
+ /* The method is converted now */
+ *errorCode = IL_CONVERT_OK;
+ return start;
+}
+
#ifdef IL_USE_JIT
/*
@@ -83,11 +112,27 @@ static unsigned char *ConvertMethod(ILExecThread *thread,
ILMethod *method,
}
else
{
- /* All other cases should be handled in the jit coder. */
+ ILJitMethodInfo *jitMethodInfo;
- METADATA_UNLOCK(_ILExecThreadProcess(thread));
- *errorCode = IL_CONVERT_OUT_OF_MEMORY;
- return 0;
+ jitMethodInfo = (ILJitMethodInfo *)method->userData;
+ if(jitMethodInfo->fnInfo.flags == _IL_INTERNAL_GENCODE)
+ {
+ if(GenMethod(coder, method,
jitMethodInfo->fnInfo.un.gen,
+ errorCode, errorInfo) == 0)
+ {
+ METADATA_UNLOCK(_ILExecThreadProcess(thread));
+ *errorCode = IL_CONVERT_OUT_OF_MEMORY;
+ return 0;
+ }
+ }
+ else
+ {
+ /* All other cases should be handled in the jit coder.
*/
+
+ METADATA_UNLOCK(_ILExecThreadProcess(thread));
+ *errorCode = IL_CONVERT_OUT_OF_MEMORY;
+ return 0;
+ }
}
/* The method is converted now */
@@ -230,11 +275,9 @@ static unsigned char *ConvertMethod(ILExecThread *thread,
ILMethod *method,
else
{
/* This is a "PInvoke", "internalcall", or "runtime" method */
+ ILMemZero(&fnInfo, sizeof(ILInternalInfo));
+ ILMemZero(&ctorfnInfo, sizeof(ILInternalInfo));
pinv = ILPInvokeFind(method);
- fnInfo.func = 0;
- fnInfo.marshal = 0;
- ctorfnInfo.func = 0;
- ctorfnInfo.marshal = 0;
isConstructor = ILMethod_IsConstructor(method);
switch(method->implementAttrs &
(IL_META_METHODIMPL_CODE_TYPE_MASK |
@@ -309,16 +352,16 @@ static unsigned char *ConvertMethod(ILExecThread *thread,
ILMethod *method,
newName[nameLength + 1] = '\0';
/* Look up the method within the module
*/
- fnInfo.func =
ILDynLibraryGetSymbol(moduleHandle, newName);
+ fnInfo.un.func =
ILDynLibraryGetSymbol(moduleHandle, newName);
}
- if(!fnInfo.func)
+ if(!fnInfo.un.func)
{
/* Look up the method within the module
*/
- fnInfo.func =
ILDynLibraryGetSymbol(moduleHandle, name);
+ fnInfo.un.func =
ILDynLibraryGetSymbol(moduleHandle, name);
}
#else /* !IL_WIN32_PLATFORM */
/* Look up the method within the module */
- fnInfo.func =
ILDynLibraryGetSymbol(moduleHandle, name);
+ fnInfo.un.func =
ILDynLibraryGetSymbol(moduleHandle, name);
#endif /* !IL_WIN32_PLATFORM */
#else /* !IL_CONFIG_PINVOKE */
METADATA_UNLOCK(_ILExecThreadProcess(thread));
@@ -380,7 +423,7 @@ static unsigned char *ConvertMethod(ILExecThread *thread,
ILMethod *method,
}
/* Bail out if we did not find the underlying native method */
- if(!(fnInfo.func) && !(ctorfnInfo.func))
+ if(!(fnInfo.un.func) && !(ctorfnInfo.un.func))
{
METADATA_UNLOCK(_ILExecThreadProcess(thread));
if(pinv)
@@ -390,30 +433,20 @@ static unsigned char *ConvertMethod(ILExecThread *thread,
ILMethod *method,
return 0;
}
- #if defined(HAVE_LIBFFI)
- /* Generate a "cif" structure to handle the native call details
*/
- if(fnInfo.func)
+ if(fnInfo.un.gen && fnInfo.flags == _IL_INTERNAL_GENCODE)
{
- /* Make the "cif" structure for the normal method entry
*/
- cif = _ILMakeCifForMethod(_ILExecThreadProcess(thread),
-
method, (pinv == 0));
- if(!cif)
+ if((start = GenMethod(coder, method, fnInfo.un.gen,
+ errorCode,
errorInfo)) == 0)
{
METADATA_UNLOCK(_ILExecThreadProcess(thread));
*errorCode = IL_CONVERT_OUT_OF_MEMORY;
return 0;
}
}
- else
- {
- cif = 0;
- }
- if(ctorfnInfo.func)
+ else if(ctorfnInfo.un.gen && (ctorfnInfo.flags ==
_IL_INTERNAL_GENCODE))
{
- /* Make the "cif" structure for the allocating
constructor */
- ctorcif =
_ILMakeCifForConstructor(_ILExecThreadProcess(thread),
-
method, (pinv == 0));
- if(!ctorcif)
+ if((start = GenMethod(coder, method, ctorfnInfo.un.gen,
+ errorCode,
errorInfo)) == 0)
{
METADATA_UNLOCK(_ILExecThreadProcess(thread));
*errorCode = IL_CONVERT_OUT_OF_MEMORY;
@@ -422,73 +455,106 @@ static unsigned char *ConvertMethod(ILExecThread
*thread, ILMethod *method,
}
else
{
- ctorcif = 0;
- }
- #else
- /* Use the marshalling function pointer as the cif if no libffi
*/
- cif = fnInfo.marshal;
- ctorcif = ctorfnInfo.marshal;
- #endif
-
- /* Generate the coder stub for marshalling the call */
- if(!isConstructor)
- {
- /* We only need the method entry point */
- if(!ILCoderSetupExtern(coder, &start, method,
- fnInfo.func,
cif, (pinv == 0)))
- {
- METADATA_UNLOCK(_ILExecThreadProcess(thread));
- *errorCode = IL_CONVERT_OUT_OF_MEMORY;
- return 0;
- }
- while((result = ILCoderFinish(coder)) !=
IL_CODER_END_OK)
+ #if defined(HAVE_LIBFFI)
+ /* Generate a "cif" structure to handle the native call
details */
+ if(fnInfo.un.func)
{
- /* Do we need a coder restart due to cache
overflow? */
- if(result != IL_CODER_END_RESTART)
+ /* Make the "cif" structure for the normal
method entry */
+ cif =
_ILMakeCifForMethod(_ILExecThreadProcess(thread),
+
method, (pinv == 0));
+ if(!cif)
{
METADATA_UNLOCK(_ILExecThreadProcess(thread));
*errorCode = IL_CONVERT_OUT_OF_MEMORY;
return 0;
}
- if(!ILCoderSetupExtern(coder, &start, method,
-
fnInfo.func, cif, (pinv == 0)))
+ }
+ else
+ {
+ cif = 0;
+ }
+ if(ctorfnInfo.un.func)
+ {
+ /* Make the "cif" structure for the allocating
constructor */
+ ctorcif =
_ILMakeCifForConstructor(_ILExecThreadProcess(thread),
+
method, (pinv == 0));
+ if(!ctorcif)
{
METADATA_UNLOCK(_ILExecThreadProcess(thread));
*errorCode = IL_CONVERT_OUT_OF_MEMORY;
return 0;
}
}
- }
- else
- {
- /* We need both the method and constructor entry points
*/
- if(!ILCoderSetupExternCtor(coder, &start, method,
-
fnInfo.func, cif,
-
ctorfnInfo.func, ctorcif,
-
(pinv == 0)))
+ else
{
- METADATA_UNLOCK(_ILExecThreadProcess(thread));
- *errorCode = IL_CONVERT_OUT_OF_MEMORY;
- return 0;
+ ctorcif = 0;
}
- while((result = ILCoderFinish(coder)) !=
IL_CODER_END_OK)
+ #else
+ /* Use the marshalling function pointer as the cif if
no libffi */
+ cif = fnInfo.marshal;
+ ctorcif = ctorfnInfo.marshal;
+ #endif
+
+ /* Generate the coder stub for marshalling the call */
+ if(!isConstructor)
{
- /* Do we need a coder restart due to cache
overflow? */
- if(result != IL_CODER_END_RESTART)
+ /* We only need the method entry point */
+ if(!ILCoderSetupExtern(coder, &start, method,
+
fnInfo.un.func, cif, (pinv == 0)))
{
METADATA_UNLOCK(_ILExecThreadProcess(thread));
*errorCode = IL_CONVERT_OUT_OF_MEMORY;
return 0;
}
+ while((result = ILCoderFinish(coder)) !=
IL_CODER_END_OK)
+ {
+ /* Do we need a coder restart due to
cache overflow? */
+ if(result != IL_CODER_END_RESTART)
+ {
+
METADATA_UNLOCK(_ILExecThreadProcess(thread));
+ *errorCode =
IL_CONVERT_OUT_OF_MEMORY;
+ return 0;
+ }
+ if(!ILCoderSetupExtern(coder, &start,
method,
+
fnInfo.un.func, cif, (pinv == 0)))
+ {
+
METADATA_UNLOCK(_ILExecThreadProcess(thread));
+ *errorCode =
IL_CONVERT_OUT_OF_MEMORY;
+ return 0;
+ }
+ }
+ }
+ else
+ {
+ /* We need both the method and constructor
entry points */
if(!ILCoderSetupExternCtor(coder, &start,
method,
-
fnInfo.func, cif,
-
ctorfnInfo.func, ctorcif,
+
fnInfo.un.func, cif,
+
ctorfnInfo.un.func, ctorcif,
(pinv == 0)))
{
METADATA_UNLOCK(_ILExecThreadProcess(thread));
*errorCode = IL_CONVERT_OUT_OF_MEMORY;
return 0;
}
+ while((result = ILCoderFinish(coder)) !=
IL_CODER_END_OK)
+ {
+ /* Do we need a coder restart due to
cache overflow? */
+ if(result != IL_CODER_END_RESTART)
+ {
+
METADATA_UNLOCK(_ILExecThreadProcess(thread));
+ *errorCode =
IL_CONVERT_OUT_OF_MEMORY;
+ return 0;
+ }
+ if(!ILCoderSetupExternCtor(coder,
&start, method,
+
fnInfo.un.func, cif,
+
ctorfnInfo.un.func, ctorcif,
+
(pinv == 0)))
+ {
+
METADATA_UNLOCK(_ILExecThreadProcess(thread));
+ *errorCode =
IL_CONVERT_OUT_OF_MEMORY;
+ return 0;
+ }
+ }
}
}
}
diff --git a/engine/engine.h b/engine/engine.h
index f4b1399..5a56c73 100644
--- a/engine/engine.h
+++ b/engine/engine.h
@@ -209,6 +209,37 @@ struct _tagILExecContext
/* class private data */
typedef struct _tagILClassPrivate ILClassPrivate;
+/*
+ * Values for the ILInternalInfo's flags member.
+ */
+#define _IL_INTERNAL_NATIVE 0
+#define _IL_INTERNAL_GENCODE 1
+
+/*
+ * Prototype fpr the code generator stored in the ILInternalInfo's func member
+ * if flags == _IL_INTERNAL_GENCODE.
+ */
+typedef int (*ILGenCodeFunc)(ILCoder *coder, ILMethod *method,
+ unsigned char **start,
+ ILCoderExceptions
*coderExceptions);
+
+/*
+ * Information that is returned for an internalcall method.
+ * The "marshal" value is ignored for libffi-capable systems.
+ */
+typedef struct
+{
+ union
+ {
+ void *func;
+ ILGenCodeFunc gen;
+ } un;
+#if defined(IL_USE_CVM) && !defined(HAVE_LIBFFI)
+ void *marshal;
+#endif
+ ILInt32 flags;
+} ILInternalInfo;
+
#ifdef IL_USE_JIT
#include "jitc.h"
#endif
@@ -858,17 +889,6 @@ ILObject *_ILEngineAllocAtomic(ILExecThread *thread,
ILClass *classInfo,
ILObject *_ILEngineAllocObject(ILExecThread *thread, ILClass *classInfo);
/*
- * Information that is returned for an internalcall method.
- * The "marshal" value is ignored for libffi-capable systems.
- */
-typedef struct
-{
- void *func;
- void *marshal;
-
-} ILInternalInfo;
-
-/*
* Find the function for an "internalcall" method.
* Returns zero if there is no function information.
*/
@@ -1264,6 +1284,11 @@ ILUInt32 _ILPackCVMStackArgs(ILExecThread *thread,
CVMWord *stacktop,
*/
ILUInt32 _ILStackWordsForType(ILExecThread *thread, ILType *type);
+/*
+ * Get the engine type for a given type.
+ */
+ILEngineType _ILTypeToEngineType(ILType *type);
+
#ifdef __cplusplus
};
#endif
diff --git a/engine/internal.c b/engine/internal.c
index 352417e..93f6c2f 100644
--- a/engine/internal.c
+++ b/engine/internal.c
@@ -151,19 +151,15 @@ int _ILFindInternalCall(ILExecProcess *process,ILMethod
*method,
if(ctorAlloc &&
entry[1].methodName &&
!(entry[1].signature))
{
- info->func =
entry[1].func;
- #if defined(HAVE_LIBFFI)
- info->marshal = 0;
- #else
+ info->un.func =
entry[1].func;
+ #if defined(IL_USE_CVM) &&
!defined(HAVE_LIBFFI)
info->marshal =
entry[1].marshal;
#endif
}
else
{
- info->func =
entry->func;
- #if defined(HAVE_LIBFFI)
- info->marshal = 0;
- #else
+ info->un.func =
entry->func;
+ #if defined(IL_USE_CVM) &&
!defined(HAVE_LIBFFI)
info->marshal =
entry->marshal;
#endif
}
@@ -212,19 +208,15 @@ int _ILFindInternalCall(ILExecProcess *process,ILMethod
*method,
if(ctorAlloc &&
entry[1].methodName &&
!(entry[1].signature))
{
- info->func =
entry[1].func;
- #if defined(HAVE_LIBFFI)
- info->marshal =
0;
- #else
+ info->un.func =
entry[1].func;
+ #if defined(IL_USE_CVM)
&& !defined(HAVE_LIBFFI)
info->marshal =
entry[1].marshal;
#endif
}
else
{
- info->func =
entry->func;
- #if defined(HAVE_LIBFFI)
- info->marshal =
0;
- #else
+ info->un.func =
entry->func;
+ #if defined(IL_USE_CVM)
&& !defined(HAVE_LIBFFI)
info->marshal =
entry->marshal;
#endif
}
diff --git a/engine/jitc.c b/engine/jitc.c
index c523c89..7b5ddd5 100755
--- a/engine/jitc.c
+++ b/engine/jitc.c
@@ -372,11 +372,6 @@ static ILJitType _ILJitSignature_ILJitTraceInOut = 0;
*/
static void *JITCoder_HandleLockedMethod(ILCoder *coder, ILMethod *method);
-/*
- * Forward declaration of the JIT coder's instance block.
- */
-typedef struct _tagILJITCoder ILJITCoder;
-
#define IL_JITC_DECLARATIONS
#include "jitc_locals.c"
#include "jitc_stack.c"
@@ -392,38 +387,6 @@ typedef struct _tagILJITCoder ILJITCoder;
#include "jitc_profile.c"
#undef IL_JITC_DECLARATIONS
-/*
- * Prototype for inlining functioncalls.
- *
- * On entry of the function the args are allready popped off the evaluation
- * stack. The args pointer points to the first arg (the one at the lowest
- * stack position).
- * The function is responsible to push the result value on the stack if the
- * return type is not void.
- *
- * The function has to return 0 on failure. Any other value will be treated as
- * success.
- *
- * int func(ILJITCoder *, ILMethod *, ILCoderMethodInfo *, ILJitStackItem *,
ILInt32)
- */
-typedef int (*ILJitInlineFunc)(ILJITCoder *jitCoder,
-
ILMethod *method,
-
ILCoderMethodInfo *methodInfo,
-
ILJitStackItem *args,
-
ILInt32 numArgs);
-
-/*
- * Private method information for the jit coder.
- */
-typedef struct _tagILJitMethodInfo ILJitMethodInfo;
-struct _tagILJitMethodInfo
-{
- ILJitFunction jitFunction; /* Implementation of the
method. */
- ILUInt32 implementationType; /* Flag how the method is implemented.
*/
- ILInternalInfo fnInfo; /* Information for internal
calls or pinvokes. */
- ILJitInlineFunc inlineFunc; /* Function for inlining. */
-};
-
#define _IL_JIT_IMPL_DEFAULT 0x000
#define _IL_JIT_IMPL_INTERNAL 0x001
#define _IL_JIT_IMPL_INTERNALALLOC 0x002
@@ -434,17 +397,21 @@ struct _tagILJitMethodInfo
#define _IL_JIT_IMPL_INLINE 0x200
#define _IL_JIT_IMPL_INLINE_MASK 0x300
-/* Error codes stored in fnInfo.func in case a library or method was not */
-/* found */
+/*
+ * Error codes stored in fnInfo.func in case a library or method was not
+ * found
+ */
#define _IL_JIT_PINVOKE_DLLNOTFOUND ((void *)0x01)
#define _IL_JIT_PINVOKE_ENTRYPOINTNOTFOUND ((void *)0x02)
#define _IL_JIT_PINVOKE_ERRORMASK ((void *)0x03)
#ifdef IL_NATIVE_INT64
-#define _ILJitPinvokeError(fnInfo) ((((ILInt64)(fnInfo).func) &
~((ILInt64)_IL_JIT_PINVOKE_ERRORMASK)) == 0)
+#define _ILJitPinvokeError(fnInfo) \
+ ((((ILInt64)(fnInfo).un.func) & ~((ILInt64)_IL_JIT_PINVOKE_ERRORMASK))
== 0)
#endif
#ifdef IL_NATIVE_INT32
-#define _ILJitPinvokeError(fnInfo) ((((ILInt32)(fnInfo).func) &
~((ILInt32)_IL_JIT_PINVOKE_ERRORMASK)) == 0)
+#define _ILJitPinvokeError(fnInfo) \
+ ((((ILInt32)(fnInfo).un.func) & ~((ILInt32)_IL_JIT_PINVOKE_ERRORMASK))
== 0)
#endif
/*
@@ -3162,7 +3129,7 @@ static int _ILJitFunctionIsInternal(ILJITCoder *coder,
ILMethod *method,
{
if((jitMethodInfo->implementationType) &
_IL_JIT_IMPL_INTERNALMASK)
{
- fnInfo->func = jitMethodInfo->fnInfo.func;
+ *fnInfo = jitMethodInfo->fnInfo;
return (jitMethodInfo->implementationType) &
_IL_JIT_IMPL_INTERNALMASK;
}
}
@@ -3395,7 +3362,8 @@ static int _ILJitCompileInternal(ILJitFunction func)
jitParams[current - 1] = paramValue;
}
returnValue = _ILJitCallInternal(jitCoder, thread, method,
-
jitMethodInfo->fnInfo.func, methodName,
+
jitMethodInfo->fnInfo.un.func,
+
methodName,
jitParams, numParams - 1);
#else
for(current = 0; current < numParams; ++current)
@@ -3407,7 +3375,8 @@ static int _ILJitCompileInternal(ILJitFunction func)
jitParams[current] = paramValue;
}
returnValue = _ILJitCallInternal(jitCoder, thread, method,
-
jitMethodInfo->fnInfo.func, methodName,
+
jitMethodInfo->fnInfo.un.func,
+
methodName,
jitParams, numParams);
#endif
jit_insn_return(jitCoder->jitFunction, returnValue);
@@ -3700,7 +3669,7 @@ static int _ILJitSetMethodInfo(ILJITCoder *jitCoder,
ILMethod *method,
/* Get the method's owner class. */
info = ILMethod_Owner(method);
classPrivate = (ILClassPrivate *)(info->userData);
- fnInfo.func = 0;
+ ILMemZero(&fnInfo, sizeof(ILInternalInfo));
if(classPrivate->jitTypes.jitTypeKind != 0)
{
@@ -3723,39 +3692,6 @@ static int _ILJitSetMethodInfo(ILJITCoder *jitCoder,
ILMethod *method,
}
break;
- case IL_JIT_TYPEKIND_DELEGATE:
- case IL_JIT_TYPEKIND_MULTICASTDELEGATE:
- {
- ILType *type = ILClassToType(info);
-
- /* Handle the special cases. */
- if(method == ILTypeGetDelegateMethod(type))
- {
- /* Flag method implemented in IL.. */
- implementationType =
_IL_JIT_IMPL_DEFAULT;
-
- /* now set the on demand compiler
function */
- onDemandCompiler =
_ILJitCompileMultiCastDelegateInvoke;
- }
- else if (method == (ILMethod
*)ILTypeGetDelegateBeginInvokeMethod(type))
- {
- /* Flag method implemented in IL.. */
- implementationType =
_IL_JIT_IMPL_DEFAULT;
-
- /* now set the on demand compiler
function */
- onDemandCompiler =
_ILJitCompileDelegateBeginInvoke;
- }
- else if (method == (ILMethod
*)ILTypeGetDelegateEndInvokeMethod(type))
- {
- /* Flag method implemented in IL.. */
- implementationType =
_IL_JIT_IMPL_DEFAULT;
-
- /* now set the on demand compiler
function */
- onDemandCompiler =
_ILJitCompileDelegateEndInvoke;
- }
- }
- break;
-
case IL_JIT_TYPEKIND_SYSTEM_MATH:
{
ILType *signature = ILMethod_Signature(method);
@@ -4000,33 +3936,33 @@ static int _ILJitSetMethodInfo(ILJITCoder *jitCoder,
ILMethod *method,
newName[nameLength + 1]
= '\0';
/* Look up the method
within the module */
- fnInfo.func =
ILDynLibraryGetSymbol(moduleHandle, newName);
+ fnInfo.un.func =
ILDynLibraryGetSymbol(moduleHandle, newName);
}
- if(!fnInfo.func)
+ if(!fnInfo.un.func)
{
/* Look up the method
within the module */
- fnInfo.func =
ILDynLibraryGetSymbol(moduleHandle, name);
+ fnInfo.un.func =
ILDynLibraryGetSymbol(moduleHandle, name);
}
- if(!(fnInfo.func))
+ if(!(fnInfo.un.func))
{
- fnInfo.func =
_IL_JIT_PINVOKE_ENTRYPOINTNOTFOUND;
+ fnInfo.un.func =
_IL_JIT_PINVOKE_ENTRYPOINTNOTFOUND;
}
#else /* !IL_WIN32_PLATFORM */
/* Look up the method within
the module */
- fnInfo.func =
ILDynLibraryGetSymbol(moduleHandle, name);
+ fnInfo.un.func =
ILDynLibraryGetSymbol(moduleHandle, name);
- if(!(fnInfo.func))
+ if(!(fnInfo.un.func))
{
- fnInfo.func =
_IL_JIT_PINVOKE_ENTRYPOINTNOTFOUND;
+ fnInfo.un.func =
_IL_JIT_PINVOKE_ENTRYPOINTNOTFOUND;
}
#endif /* !IL_WIN32_PLATFORM */
}
else
{
- fnInfo.func =
_IL_JIT_PINVOKE_DLLNOTFOUND;
+ fnInfo.un.func =
_IL_JIT_PINVOKE_DLLNOTFOUND;
}
/* Flag the method pinvoke. */
@@ -4058,7 +3994,7 @@ static int _ILJitSetMethodInfo(ILJITCoder *jitCoder,
ILMethod *method,
{
_ILFindInternalCall(_ILExecThreadProcess(thread),
method, 0, &fnInfo);
- if(fnInfo.func)
+ if(fnInfo.un.func)
{
/* Flag the
method internal. */
implementationType = _IL_JIT_IMPL_INTERNAL;
@@ -4074,7 +4010,11 @@ static int _ILJitSetMethodInfo(ILJITCoder *jitCoder,
ILMethod *method,
{
implementationType = _IL_JIT_IMPL_DEFAULT;
}
- if(fnInfo.func)
+ if(fnInfo.flags
== _IL_INTERNAL_GENCODE)
+ {
+
implementationType = _IL_JIT_IMPL_DEFAULT;
+ }
+ else
if(fnInfo.un.func)
{
/* Flag
the method an allocating constructor. */
implementationType = _IL_JIT_IMPL_INTERNALALLOC;
@@ -4082,7 +4022,11 @@ static int _ILJitSetMethodInfo(ILJITCoder *jitCoder,
ILMethod *method,
}
else
{
- if(fnInfo.func)
+ if(fnInfo.flags
== _IL_INTERNAL_GENCODE)
+ {
+
implementationType = _IL_JIT_IMPL_DEFAULT;
+ }
+ else
if(fnInfo.un.func)
{
/* Flag
the method internal. */
implementationType = _IL_JIT_IMPL_INTERNAL;
@@ -4094,7 +4038,11 @@ static int _ILJitSetMethodInfo(ILJITCoder *jitCoder,
ILMethod *method,
{
implementationType = _IL_JIT_IMPL_DEFAULT;
}
-
if(fnInfo.func)
+
if(fnInfo.flags == _IL_INTERNAL_GENCODE)
+ {
+
implementationType = _IL_JIT_IMPL_DEFAULT;
+ }
+ else
if(fnInfo.un.func)
{
/* Flag the method an allocating constructor. */
implementationType = _IL_JIT_IMPL_INTERNALALLOC;
@@ -4112,7 +4060,11 @@ static int _ILJitSetMethodInfo(ILJITCoder *jitCoder,
ILMethod *method,
}
else
{
- if(fnInfo.func)
+ if(fnInfo.flags ==
_IL_INTERNAL_GENCODE)
+ {
+
implementationType = _IL_JIT_IMPL_DEFAULT;
+ }
+ else if(fnInfo.un.func)
{
/* Flag the
method internal. */
implementationType = _IL_JIT_IMPL_INTERNAL;
@@ -4121,13 +4073,20 @@ static int _ILJitSetMethodInfo(ILJITCoder *jitCoder,
ILMethod *method,
}
/* Bail out if the native method could
not be found. */
- if(!(fnInfo.func))
+ if(fnInfo.flags == _IL_INTERNAL_NATIVE
&& !(fnInfo.un.func))
{
return 0;
}
/* now set the on demand compiler. */
- onDemandCompiler =
_ILJitCompileInternal;
+ if(fnInfo.flags == _IL_INTERNAL_GENCODE)
+ {
+ onDemandCompiler =
_ILJitCompile;
+ }
+ else
+ {
+ onDemandCompiler =
_ILJitCompileInternal;
+ }
}
break;
@@ -4195,7 +4154,7 @@ static int _ILJitSetMethodInfo(ILJITCoder *jitCoder,
ILMethod *method,
/* Copy the infos to the MethodInfo structure. */
jitMethodInfo->jitFunction = jitFunction;
jitMethodInfo->implementationType = implementationType;
- jitMethodInfo->fnInfo.func = fnInfo.func;
+ jitMethodInfo->fnInfo = fnInfo;
jitMethodInfo->inlineFunc = inlineFunc;
/* and link the new jitFunction to the method. */
diff --git a/engine/jitc.h b/engine/jitc.h
index 65a6053..0c2f214 100644
--- a/engine/jitc.h
+++ b/engine/jitc.h
@@ -136,6 +136,45 @@ struct _tagILJitTypes
}
/*
+ * Forward declaration of the JIT coder's instance block.
+ */
+typedef struct _tagILJITCoder ILJITCoder;
+
+typedef struct _tagILJitStackItem ILJitStackItem;
+
+/*
+ * Prototype for inlining functioncalls.
+ *
+ * On entry of the function the args are allready popped off the evaluation
+ * stack. The args pointer points to the first arg (the one at the lowest
+ * stack position).
+ * The function is responsible to push the result value on the stack if the
+ * return type is not void.
+ *
+ * The function has to return 0 on failure. Any other value will be treated as
+ * success.
+ *
+ * int func(ILJITCoder *, ILMethod *, ILCoderMethodInfo *, ILJitStackItem *,
ILInt32)
+ */
+typedef int (*ILJitInlineFunc)(ILJITCoder *jitCoder,
+
ILMethod *method,
+
ILCoderMethodInfo *methodInfo,
+
ILJitStackItem *args,
+
ILInt32 numArgs);
+
+/*
+ * Private method information for the jit coder.
+ */
+typedef struct _tagILJitMethodInfo ILJitMethodInfo;
+struct _tagILJitMethodInfo
+{
+ ILJitFunction jitFunction; /* Implementation of the
method. */
+ ILUInt32 implementationType; /* Flag how the method is implemented.
*/
+ ILInternalInfo fnInfo; /* Information for internal
calls or pinvokes. */
+ ILJitInlineFunc inlineFunc; /* Function for inlining. */
+};
+
+/*
* Initialize the libjit coder.
* Returns 1 on success and 0 on failure.
*/
diff --git a/engine/jitc_call.c b/engine/jitc_call.c
index c3426ea..35c13ce 100644
--- a/engine/jitc_call.c
+++ b/engine/jitc_call.c
@@ -532,7 +532,7 @@ static void JITCoder_CallMethod(ILCoder *coder,
ILCoderMethodInfo *info,
#endif
returnValue = _ILJitCallInternal(jitCoder, thread,
methodInfo,
-
fnInfo.func, methodName,
+
fnInfo.un.func, methodName,
jitParams,
argCount);
if(returnItem && returnItem->engineType != ILEngineType_Invalid)
@@ -585,7 +585,7 @@ static void JITCoder_CallMethod(ILCoder *coder,
ILCoderMethodInfo *info,
{
#if !defined(IL_CONFIG_REDUCE_CODE) && !defined(_IL_JIT_ENABLE_DEBUG)
ILPInvoke *pinv = ILPInvokeFind(methodInfo);
- if(pinv &&
((ILJitMethodInfo*)(methodInfo->userData))->fnInfo.func)
+ if(pinv &&
((ILJitMethodInfo*)(methodInfo->userData))->fnInfo.un.func)
{
returnValue = _ILJitInlinePinvoke(jitCoder, methodInfo,
jitParams);
}
@@ -845,7 +845,7 @@ static void JITCoder_CallCtor(ILCoder *coder,
ILCoderMethodInfo *info,
#endif
returnValue = _ILJitCallInternal(jitCoder, thread,
methodInfo,
-
fnInfo.func, methodName,
+
fnInfo.un.func, methodName,
jitParams,
argCount);
_ILJitStackPushNotNullValue(jitCoder, returnValue);
@@ -863,7 +863,7 @@ static void JITCoder_CallCtor(ILCoder *coder,
ILCoderMethodInfo *info,
returnValue = _ILJitCallInternal(jitCoder, thread,
methodInfo,
-
fnInfo.func, methodName,
+
fnInfo.un.func, methodName,
jitParams, argCount + 1);
_ILJitStackPushNotNullValue(jitCoder, jitParams[0]);
}
diff --git a/engine/jitc_pinvoke.c b/engine/jitc_pinvoke.c
index 1dfe5a1..519b887 100644
--- a/engine/jitc_pinvoke.c
+++ b/engine/jitc_pinvoke.c
@@ -126,11 +126,11 @@ static int _ILJitCompilePinvoke(jit_function_t func)
/* Check if the method to invoke was found on this system. */
if(_ILJitPinvokeError(jitMethodInfo->fnInfo))
{
- if(jitMethodInfo->fnInfo.func == _IL_JIT_PINVOKE_DLLNOTFOUND)
+ if(jitMethodInfo->fnInfo.un.func == _IL_JIT_PINVOKE_DLLNOTFOUND)
{
_ILJitThrowSystem(jitCoder->jitFunction,
_IL_JIT_DLL_NOT_FOUND);
}
- else if(jitMethodInfo->fnInfo.func ==
_IL_JIT_PINVOKE_ENTRYPOINTNOTFOUND)
+ else if(jitMethodInfo->fnInfo.un.func ==
_IL_JIT_PINVOKE_ENTRYPOINTNOTFOUND)
{
_ILJitThrowSystem(jitCoder->jitFunction,
_IL_JIT_ENTRYPOINT_NOT_FOUND);
}
@@ -273,7 +273,7 @@ static int _ILJitCompilePinvoke(jit_function_t func)
#endif
if(returnType==jit_type_void)
{
- jit_insn_call_native(func, 0, jitMethodInfo->fnInfo.func,
+ jit_insn_call_native(func, 0, jitMethodInfo->fnInfo.un.func,
callSignature,
#ifdef IL_JIT_THREAD_IN_SIGNATURE
jitParams,
numParams - 1, 0);
@@ -284,7 +284,7 @@ static int _ILJitCompilePinvoke(jit_function_t func)
else
{
type = ILTypeGetEnumType(ILTypeGetReturn(ilSignature));
- returnValue = jit_insn_call_native(func, 0,
jitMethodInfo->fnInfo.func,
+ returnValue = jit_insn_call_native(func, 0,
jitMethodInfo->fnInfo.un.func,
callSignature,
#ifdef IL_JIT_THREAD_IN_SIGNATURE
jitParams,
numParams - 1, 0);
@@ -430,11 +430,11 @@ static ILJitValue _ILJitInlinePinvoke(ILJITCoder
*jitCoder, ILMethod *method, IL
/* Check if the method to invoke was found on this system. */
if(_ILJitPinvokeError(jitMethodInfo->fnInfo))
{
- if(jitMethodInfo->fnInfo.func == _IL_JIT_PINVOKE_DLLNOTFOUND)
+ if(jitMethodInfo->fnInfo.un.func == _IL_JIT_PINVOKE_DLLNOTFOUND)
{
_ILJitThrowSystem(jitCoder->jitFunction,
_IL_JIT_DLL_NOT_FOUND);
}
- else if(jitMethodInfo->fnInfo.func ==
_IL_JIT_PINVOKE_ENTRYPOINTNOTFOUND)
+ else if(jitMethodInfo->fnInfo.un.func ==
_IL_JIT_PINVOKE_ENTRYPOINTNOTFOUND)
{
_ILJitThrowSystem(jitCoder->jitFunction,
_IL_JIT_ENTRYPOINT_NOT_FOUND);
}
@@ -587,7 +587,7 @@ static ILJitValue _ILJitInlinePinvoke(ILJITCoder *jitCoder,
ILMethod *method, IL
#endif
if(returnType==jit_type_void)
{
- jit_insn_call_native(func, 0, jitMethodInfo->fnInfo.func,
+ jit_insn_call_native(func, 0, jitMethodInfo->fnInfo.un.func,
callSignature,
#ifdef IL_JIT_THREAD_IN_SIGNATURE
jitParams,
numParams - 1, 0);
@@ -598,7 +598,7 @@ static ILJitValue _ILJitInlinePinvoke(ILJITCoder *jitCoder,
ILMethod *method, IL
else
{
type = ILTypeGetEnumType(ILTypeGetReturn(ilSignature));
- returnValue = jit_insn_call_native(func, 0,
jitMethodInfo->fnInfo.func,
+ returnValue = jit_insn_call_native(func, 0,
jitMethodInfo->fnInfo.un.func,
callSignature,
#ifdef IL_JIT_THREAD_IN_SIGNATURE
jitParams,
numParams - 1, 0);
diff --git a/engine/jitc_setup.c b/engine/jitc_setup.c
index 761715f..8288c96 100644
--- a/engine/jitc_setup.c
+++ b/engine/jitc_setup.c
@@ -121,6 +121,8 @@ static int JITCoder_Setup(ILCoder *_coder, unsigned char
**start,
/* Setup exception handling */
SetupExceptions(coder, coderExceptions, hasRethrow);
+ *start = (unsigned char *)1;
+
return 1;
}
diff --git a/engine/jitc_stack.c b/engine/jitc_stack.c
index 0dd5b58..ff64a7f 100644
--- a/engine/jitc_stack.c
+++ b/engine/jitc_stack.c
@@ -22,7 +22,6 @@
#ifdef _IL_JIT_OPTIMIZE_LOCALS
-typedef struct _tagILJitStackItem ILJitStackItem;
struct _tagILJitStackItem
{
ILInt32 flags;
diff --git a/engine/lib_array.c b/engine/lib_array.c
index 5ea5b00..53be44b 100644
--- a/engine/lib_array.c
+++ b/engine/lib_array.c
@@ -1996,8 +1996,10 @@ int _ILGetInternalArray(ILMethod *method, int *isCtor,
ILInternalInfo *info)
if(!strcmp(name, ".ctor"))
{
*isCtor = 1;
- info->func = (void *)System_SArray_ctor;
+ info->un.func = (void *)System_SArray_ctor;
+#if defined(IL_USE_CVM) && !defined(HAVE_LIBFFI)
info->marshal = (void *)System_SArray_ctor_marshal;
+#endif /* defined(IL_USE_CVM) && !defined(HAVE_LIBFFI) */
return 1;
}
else
@@ -2017,15 +2019,19 @@ int _ILGetInternalArray(ILMethod *method, int *isCtor,
ILInternalInfo *info)
== (ILMember *)method)
{
/* This is the first constructor */
- info->func = (void *)System_MArray_ctor_1;
+ info->un.func = (void *)System_MArray_ctor_1;
+#if defined(IL_USE_CVM) && !defined(HAVE_LIBFFI)
info->marshal = (void *)System_MArray_ctor_1_marshal;
+#endif /* defined(IL_USE_CVM) && !defined(HAVE_LIBFFI) */
return 1;
}
else
{
/* This is the second constructor */
- info->func = (void *)System_MArray_ctor_2;
+ info->un.func = (void *)System_MArray_ctor_2;
+#if defined(IL_USE_CVM) && !defined(HAVE_LIBFFI)
info->marshal = (void *)System_MArray_ctor_2_marshal;
+#endif /* defined(IL_USE_CVM) && !defined(HAVE_LIBFFI) */
return 1;
}
}
@@ -2043,15 +2049,19 @@ int _ILGetInternalArray(ILMethod *method, int *isCtor,
ILInternalInfo *info)
{
if(rank == 2)
{
- info->func = (void
*)System_MArray_Get2_sbyte;
+ info->un.func = (void
*)System_MArray_Get2_sbyte;
+#if defined(IL_USE_CVM) && !defined(HAVE_LIBFFI)
info->marshal =
(void
*)System_MArray_Get2_sbyte_marshal;
+#endif /* defined(IL_USE_CVM) && !defined(HAVE_LIBFFI) */
}
else
{
- info->func = (void
*)System_MArray_Get_sbyte;
+ info->un.func = (void
*)System_MArray_Get_sbyte;
+#if defined(IL_USE_CVM) && !defined(HAVE_LIBFFI)
info->marshal =
(void
*)System_MArray_Get_sbyte_marshal;
+#endif /* defined(IL_USE_CVM) && !defined(HAVE_LIBFFI) */
}
return 1;
}
@@ -2061,15 +2071,19 @@ int _ILGetInternalArray(ILMethod *method, int *isCtor,
ILInternalInfo *info)
{
if(rank == 2)
{
- info->func = (void
*)System_MArray_Get2_byte;
+ info->un.func = (void
*)System_MArray_Get2_byte;
+#if defined(IL_USE_CVM) && !defined(HAVE_LIBFFI)
info->marshal =
(void
*)System_MArray_Get2_byte_marshal;
+#endif /* defined(IL_USE_CVM) && !defined(HAVE_LIBFFI) */
}
else
{
- info->func = (void
*)System_MArray_Get_byte;
+ info->un.func = (void
*)System_MArray_Get_byte;
+#if defined(IL_USE_CVM) && !defined(HAVE_LIBFFI)
info->marshal =
(void
*)System_MArray_Get_byte_marshal;
+#endif /* defined(IL_USE_CVM) && !defined(HAVE_LIBFFI) */
}
return 1;
}
@@ -2079,15 +2093,19 @@ int _ILGetInternalArray(ILMethod *method, int *isCtor,
ILInternalInfo *info)
{
if(rank == 2)
{
- info->func = (void
*)System_MArray_Get2_short;
+ info->un.func = (void
*)System_MArray_Get2_short;
+#if defined(IL_USE_CVM) && !defined(HAVE_LIBFFI)
info->marshal =
(void
*)System_MArray_Get2_short_marshal;
+#endif /* defined(IL_USE_CVM) && !defined(HAVE_LIBFFI) */
}
else
{
- info->func = (void
*)System_MArray_Get_short;
+ info->un.func = (void
*)System_MArray_Get_short;
+#if defined(IL_USE_CVM) && !defined(HAVE_LIBFFI)
info->marshal =
(void
*)System_MArray_Get_short_marshal;
+#endif /* defined(IL_USE_CVM) && !defined(HAVE_LIBFFI) */
}
return 1;
}
@@ -2098,15 +2116,19 @@ int _ILGetInternalArray(ILMethod *method, int *isCtor,
ILInternalInfo *info)
{
if(rank == 2)
{
- info->func = (void
*)System_MArray_Get2_ushort;
+ info->un.func = (void
*)System_MArray_Get2_ushort;
+#if defined(IL_USE_CVM) && !defined(HAVE_LIBFFI)
info->marshal =
(void
*)System_MArray_Get2_ushort_marshal;
+#endif /* defined(IL_USE_CVM) && !defined(HAVE_LIBFFI) */
}
else
{
- info->func = (void
*)System_MArray_Get_ushort;
+ info->un.func = (void
*)System_MArray_Get_ushort;
+#if defined(IL_USE_CVM) && !defined(HAVE_LIBFFI)
info->marshal =
(void
*)System_MArray_Get_ushort_marshal;
+#endif /* defined(IL_USE_CVM) && !defined(HAVE_LIBFFI) */
}
return 1;
}
@@ -2116,15 +2138,19 @@ int _ILGetInternalArray(ILMethod *method, int *isCtor,
ILInternalInfo *info)
{
if(rank == 2)
{
- info->func = (void
*)System_MArray_Get2_int;
+ info->un.func = (void
*)System_MArray_Get2_int;
+#if defined(IL_USE_CVM) && !defined(HAVE_LIBFFI)
info->marshal =
(void
*)System_MArray_Get2_int_marshal;
+#endif /* defined(IL_USE_CVM) && !defined(HAVE_LIBFFI) */
}
else
{
- info->func = (void
*)System_MArray_Get_int;
+ info->un.func = (void
*)System_MArray_Get_int;
+#if defined(IL_USE_CVM) && !defined(HAVE_LIBFFI)
info->marshal =
(void
*)System_MArray_Get_int_marshal;
+#endif /* defined(IL_USE_CVM) && !defined(HAVE_LIBFFI) */
}
return 1;
}
@@ -2134,15 +2160,19 @@ int _ILGetInternalArray(ILMethod *method, int *isCtor,
ILInternalInfo *info)
{
if(rank == 2)
{
- info->func = (void
*)System_MArray_Get2_uint;
+ info->un.func = (void
*)System_MArray_Get2_uint;
+#if defined(IL_USE_CVM) && !defined(HAVE_LIBFFI)
info->marshal =
(void
*)System_MArray_Get2_uint_marshal;
+#endif /* defined(IL_USE_CVM) && !defined(HAVE_LIBFFI) */
}
else
{
- info->func = (void
*)System_MArray_Get_uint;
+ info->un.func = (void
*)System_MArray_Get_uint;
+#if defined(IL_USE_CVM) && !defined(HAVE_LIBFFI)
info->marshal =
(void
*)System_MArray_Get_uint_marshal;
+#endif /* defined(IL_USE_CVM) && !defined(HAVE_LIBFFI) */
}
return 1;
}
@@ -2152,15 +2182,19 @@ int _ILGetInternalArray(ILMethod *method, int *isCtor,
ILInternalInfo *info)
{
if(rank == 2)
{
- info->func = (void
*)System_MArray_Get2_nativeInt;
+ info->un.func = (void
*)System_MArray_Get2_nativeInt;
+#if defined(IL_USE_CVM) && !defined(HAVE_LIBFFI)
info->marshal =
(void
*)System_MArray_Get2_nativeInt_marshal;
+#endif /* defined(IL_USE_CVM) && !defined(HAVE_LIBFFI) */
}
else
{
- info->func = (void
*)System_MArray_Get_nativeInt;
+ info->un.func = (void
*)System_MArray_Get_nativeInt;
+#if defined(IL_USE_CVM) && !defined(HAVE_LIBFFI)
info->marshal =
(void
*)System_MArray_Get_nativeInt_marshal;
+#endif /* defined(IL_USE_CVM) && !defined(HAVE_LIBFFI) */
}
return 1;
}
@@ -2170,15 +2204,19 @@ int _ILGetInternalArray(ILMethod *method, int *isCtor,
ILInternalInfo *info)
{
if(rank == 2)
{
- info->func = (void
*)System_MArray_Get2_nativeUInt;
+ info->un.func = (void
*)System_MArray_Get2_nativeUInt;
+#if defined(IL_USE_CVM) && !defined(HAVE_LIBFFI)
info->marshal =
(void
*)System_MArray_Get2_nativeUInt_marshal;
+#endif /* defined(IL_USE_CVM) && !defined(HAVE_LIBFFI) */
}
else
{
- info->func = (void
*)System_MArray_Get_nativeUInt;
+ info->un.func = (void
*)System_MArray_Get_nativeUInt;
+#if defined(IL_USE_CVM) && !defined(HAVE_LIBFFI)
info->marshal =
(void
*)System_MArray_Get_nativeUInt_marshal;
+#endif /* defined(IL_USE_CVM) && !defined(HAVE_LIBFFI) */
}
return 1;
}
@@ -2188,15 +2226,19 @@ int _ILGetInternalArray(ILMethod *method, int *isCtor,
ILInternalInfo *info)
{
if(rank == 2)
{
- info->func = (void
*)System_MArray_Get2_long;
+ info->un.func = (void
*)System_MArray_Get2_long;
+#if defined(IL_USE_CVM) && !defined(HAVE_LIBFFI)
info->marshal =
(void
*)System_MArray_Get2_long_marshal;
+#endif /* defined(IL_USE_CVM) && !defined(HAVE_LIBFFI) */
}
else
{
- info->func = (void
*)System_MArray_Get_long;
+ info->un.func = (void
*)System_MArray_Get_long;
+#if defined(IL_USE_CVM) && !defined(HAVE_LIBFFI)
info->marshal =
(void
*)System_MArray_Get_long_marshal;
+#endif /* defined(IL_USE_CVM) && !defined(HAVE_LIBFFI) */
}
return 1;
}
@@ -2206,15 +2248,19 @@ int _ILGetInternalArray(ILMethod *method, int *isCtor,
ILInternalInfo *info)
{
if(rank == 2)
{
- info->func = (void
*)System_MArray_Get2_ulong;
+ info->un.func = (void
*)System_MArray_Get2_ulong;
+#if defined(IL_USE_CVM) && !defined(HAVE_LIBFFI)
info->marshal =
(void
*)System_MArray_Get2_ulong_marshal;
+#endif /* defined(IL_USE_CVM) && !defined(HAVE_LIBFFI) */
}
else
{
- info->func = (void
*)System_MArray_Get_ulong;
+ info->un.func = (void
*)System_MArray_Get_ulong;
+#if defined(IL_USE_CVM) && !defined(HAVE_LIBFFI)
info->marshal =
(void
*)System_MArray_Get_ulong_marshal;
+#endif /* defined(IL_USE_CVM) && !defined(HAVE_LIBFFI) */
}
return 1;
}
@@ -2224,15 +2270,19 @@ int _ILGetInternalArray(ILMethod *method, int *isCtor,
ILInternalInfo *info)
{
if(rank == 2)
{
- info->func = (void
*)System_MArray_Get2_float;
+ info->un.func = (void
*)System_MArray_Get2_float;
+#if defined(IL_USE_CVM) && !defined(HAVE_LIBFFI)
info->marshal =
(void
*)System_MArray_Get2_float_marshal;
+#endif /* defined(IL_USE_CVM) && !defined(HAVE_LIBFFI) */
}
else
{
- info->func = (void
*)System_MArray_Get_float;
+ info->un.func = (void
*)System_MArray_Get_float;
+#if defined(IL_USE_CVM) && !defined(HAVE_LIBFFI)
info->marshal =
(void
*)System_MArray_Get_float_marshal;
+#endif /* defined(IL_USE_CVM) && !defined(HAVE_LIBFFI) */
}
return 1;
}
@@ -2242,15 +2292,19 @@ int _ILGetInternalArray(ILMethod *method, int *isCtor,
ILInternalInfo *info)
{
if(rank == 2)
{
- info->func = (void
*)System_MArray_Get2_double;
+ info->un.func = (void
*)System_MArray_Get2_double;
+#if defined(IL_USE_CVM) && !defined(HAVE_LIBFFI)
info->marshal =
(void
*)System_MArray_Get2_double_marshal;
+#endif /* defined(IL_USE_CVM) && !defined(HAVE_LIBFFI) */
}
else
{
- info->func = (void
*)System_MArray_Get_double;
+ info->un.func = (void
*)System_MArray_Get_double;
+#if defined(IL_USE_CVM) && !defined(HAVE_LIBFFI)
info->marshal =
(void
*)System_MArray_Get_double_marshal;
+#endif /* defined(IL_USE_CVM) && !defined(HAVE_LIBFFI) */
}
return 1;
}
@@ -2260,15 +2314,19 @@ int _ILGetInternalArray(ILMethod *method, int *isCtor,
ILInternalInfo *info)
{
if(rank == 2)
{
- info->func = (void
*)System_MArray_Get2_nativeFloat;
+ info->un.func = (void
*)System_MArray_Get2_nativeFloat;
+#if defined(IL_USE_CVM) && !defined(HAVE_LIBFFI)
info->marshal =
(void
*)System_MArray_Get2_nativeFloat_marshal;
+#endif /* defined(IL_USE_CVM) && !defined(HAVE_LIBFFI) */
}
else
{
- info->func = (void
*)System_MArray_Get_nativeFloat;
+ info->un.func = (void
*)System_MArray_Get_nativeFloat;
+#if defined(IL_USE_CVM) && !defined(HAVE_LIBFFI)
info->marshal =
(void
*)System_MArray_Get_nativeFloat_marshal;
+#endif /* defined(IL_USE_CVM) && !defined(HAVE_LIBFFI) */
}
return 1;
}
@@ -2276,33 +2334,43 @@ int _ILGetInternalArray(ILMethod *method, int *isCtor,
ILInternalInfo *info)
case IL_META_ELEMTYPE_TYPEDBYREF:
{
- info->func = (void
*)System_MArray_Get_managedValue;
+ info->un.func = (void
*)System_MArray_Get_managedValue;
+#if defined(IL_USE_CVM) && !defined(HAVE_LIBFFI)
info->marshal =
(void
*)System_MArray_Get_managedValue_marshal;
+#endif /* defined(IL_USE_CVM) && !defined(HAVE_LIBFFI) */
return 1;
}
/* Not reached */
}
- info->func = (void *)System_MArray_Get_int;
+ info->un.func = (void *)System_MArray_Get_int;
+#if defined(IL_USE_CVM) && !defined(HAVE_LIBFFI)
info->marshal = (void *)System_MArray_Get_int_marshal;
+#endif /* defined(IL_USE_CVM) && !defined(HAVE_LIBFFI) */
return 1;
}
else if(ILType_IsValueType(type))
{
- info->func = (void *)System_MArray_Get_managedValue;
+ info->un.func = (void *)System_MArray_Get_managedValue;
+#if defined(IL_USE_CVM) && !defined(HAVE_LIBFFI)
info->marshal = (void
*)System_MArray_Get_managedValue_marshal;
+#endif /* defined(IL_USE_CVM) && !defined(HAVE_LIBFFI) */
return 1;
}
else if(rank == 2)
{
- info->func = (void *)System_MArray_Get2_ref;
+ info->un.func = (void *)System_MArray_Get2_ref;
+#if defined(IL_USE_CVM) && !defined(HAVE_LIBFFI)
info->marshal = (void *)System_MArray_Get2_ref_marshal;
+#endif /* defined(IL_USE_CVM) && !defined(HAVE_LIBFFI) */
return 1;
}
else
{
- info->func = (void *)System_MArray_Get_ref;
+ info->un.func = (void *)System_MArray_Get_ref;
+#if defined(IL_USE_CVM) && !defined(HAVE_LIBFFI)
info->marshal = (void *)System_MArray_Get_ref_marshal;
+#endif /* defined(IL_USE_CVM) && !defined(HAVE_LIBFFI) */
return 1;
}
}
@@ -2320,15 +2388,19 @@ int _ILGetInternalArray(ILMethod *method, int *isCtor,
ILInternalInfo *info)
{
if(rank == 2)
{
- info->func = (void
*)System_MArray_Set2_byte;
+ info->un.func = (void
*)System_MArray_Set2_byte;
+#if defined(IL_USE_CVM) && !defined(HAVE_LIBFFI)
info->marshal =
(void
*)System_MArray_Set2_byte_marshal;
+#endif /* defined(IL_USE_CVM) && !defined(HAVE_LIBFFI) */
}
else
{
- info->func = (void
*)System_MArray_Set_byte;
+ info->un.func = (void
*)System_MArray_Set_byte;
+#if defined(IL_USE_CVM) && !defined(HAVE_LIBFFI)
info->marshal =
(void
*)System_MArray_Set_byte_marshal;
+#endif /* defined(IL_USE_CVM) && !defined(HAVE_LIBFFI) */
}
return 1;
}
@@ -2340,15 +2412,19 @@ int _ILGetInternalArray(ILMethod *method, int *isCtor,
ILInternalInfo *info)
{
if(rank == 2)
{
- info->func = (void
*)System_MArray_Set2_short;
+ info->un.func = (void
*)System_MArray_Set2_short;
+#if defined(IL_USE_CVM) && !defined(HAVE_LIBFFI)
info->marshal =
(void
*)System_MArray_Set2_short_marshal;
+#endif /* defined(IL_USE_CVM) && !defined(HAVE_LIBFFI) */
}
else
{
- info->func = (void
*)System_MArray_Set_short;
+ info->un.func = (void
*)System_MArray_Set_short;
+#if defined(IL_USE_CVM) && !defined(HAVE_LIBFFI)
info->marshal =
(void
*)System_MArray_Set_short_marshal;
+#endif /* defined(IL_USE_CVM) && !defined(HAVE_LIBFFI) */
}
return 1;
}
@@ -2359,15 +2435,19 @@ int _ILGetInternalArray(ILMethod *method, int *isCtor,
ILInternalInfo *info)
{
if(rank == 2)
{
- info->func = (void
*)System_MArray_Set2_int;
+ info->un.func = (void
*)System_MArray_Set2_int;
+#if defined(IL_USE_CVM) && !defined(HAVE_LIBFFI)
info->marshal =
(void
*)System_MArray_Set2_int_marshal;
+#endif /* defined(IL_USE_CVM) && !defined(HAVE_LIBFFI) */
}
else
{
- info->func = (void
*)System_MArray_Set_int;
+ info->un.func = (void
*)System_MArray_Set_int;
+#if defined(IL_USE_CVM) && !defined(HAVE_LIBFFI)
info->marshal =
(void
*)System_MArray_Set_int_marshal;
+#endif /* defined(IL_USE_CVM) && !defined(HAVE_LIBFFI) */
}
return 1;
}
@@ -2378,15 +2458,19 @@ int _ILGetInternalArray(ILMethod *method, int *isCtor,
ILInternalInfo *info)
{
if(rank == 2)
{
- info->func = (void
*)System_MArray_Set2_nativeInt;
+ info->un.func = (void
*)System_MArray_Set2_nativeInt;
+#if defined(IL_USE_CVM) && !defined(HAVE_LIBFFI)
info->marshal =
(void
*)System_MArray_Set2_nativeInt_marshal;
+#endif /* defined(IL_USE_CVM) && !defined(HAVE_LIBFFI) */
}
else
{
- info->func = (void
*)System_MArray_Set_nativeInt;
+ info->un.func = (void
*)System_MArray_Set_nativeInt;
+#if defined(IL_USE_CVM) && !defined(HAVE_LIBFFI)
info->marshal =
(void
*)System_MArray_Set_nativeInt_marshal;
+#endif /* defined(IL_USE_CVM) && !defined(HAVE_LIBFFI) */
}
return 1;
}
@@ -2397,15 +2481,19 @@ int _ILGetInternalArray(ILMethod *method, int *isCtor,
ILInternalInfo *info)
{
if(rank == 2)
{
- info->func = (void
*)System_MArray_Set2_long;
+ info->un.func = (void
*)System_MArray_Set2_long;
+#if defined(IL_USE_CVM) && !defined(HAVE_LIBFFI)
info->marshal =
(void
*)System_MArray_Set2_long_marshal;
+#endif /* defined(IL_USE_CVM) && !defined(HAVE_LIBFFI) */
}
else
{
- info->func = (void
*)System_MArray_Set_long;
+ info->un.func = (void
*)System_MArray_Set_long;
+#if defined(IL_USE_CVM) && !defined(HAVE_LIBFFI)
info->marshal =
(void
*)System_MArray_Set_long_marshal;
+#endif /* defined(IL_USE_CVM) && !defined(HAVE_LIBFFI) */
}
return 1;
}
@@ -2415,15 +2503,19 @@ int _ILGetInternalArray(ILMethod *method, int *isCtor,
ILInternalInfo *info)
{
if(rank == 2)
{
- info->func = (void
*)System_MArray_Set2_float;
+ info->un.func = (void
*)System_MArray_Set2_float;
+#if defined(IL_USE_CVM) && !defined(HAVE_LIBFFI)
info->marshal =
(void
*)System_MArray_Set2_float_marshal;
+#endif /* defined(IL_USE_CVM) && !defined(HAVE_LIBFFI) */
}
else
{
- info->func = (void
*)System_MArray_Set_float;
+ info->un.func = (void
*)System_MArray_Set_float;
+#if defined(IL_USE_CVM) && !defined(HAVE_LIBFFI)
info->marshal =
(void
*)System_MArray_Set_float_marshal;
+#endif /* defined(IL_USE_CVM) && !defined(HAVE_LIBFFI) */
}
return 1;
}
@@ -2433,15 +2525,19 @@ int _ILGetInternalArray(ILMethod *method, int *isCtor,
ILInternalInfo *info)
{
if(rank == 2)
{
- info->func = (void
*)System_MArray_Set2_double;
+ info->un.func = (void
*)System_MArray_Set2_double;
+#if defined(IL_USE_CVM) && !defined(HAVE_LIBFFI)
info->marshal =
(void
*)System_MArray_Set2_double_marshal;
+#endif /* defined(IL_USE_CVM) && !defined(HAVE_LIBFFI) */
}
else
{
- info->func = (void
*)System_MArray_Set_double;
+ info->un.func = (void
*)System_MArray_Set_double;
+#if defined(IL_USE_CVM) && !defined(HAVE_LIBFFI)
info->marshal =
(void
*)System_MArray_Set_double_marshal;
+#endif /* defined(IL_USE_CVM) && !defined(HAVE_LIBFFI) */
}
return 1;
}
@@ -2451,15 +2547,19 @@ int _ILGetInternalArray(ILMethod *method, int *isCtor,
ILInternalInfo *info)
{
if(rank == 2)
{
- info->func = (void
*)System_MArray_Set2_nativeFloat;
+ info->un.func = (void
*)System_MArray_Set2_nativeFloat;
+#if defined(IL_USE_CVM) && !defined(HAVE_LIBFFI)
info->marshal =
(void
*)System_MArray_Set2_nativeFloat_marshal;
+#endif /* defined(IL_USE_CVM) && !defined(HAVE_LIBFFI) */
}
else
{
- info->func = (void
*)System_MArray_Set_nativeFloat;
+ info->un.func = (void
*)System_MArray_Set_nativeFloat;
+#if defined(IL_USE_CVM) && !defined(HAVE_LIBFFI)
info->marshal =
(void
*)System_MArray_Set_nativeFloat_marshal;
+#endif /* defined(IL_USE_CVM) && !defined(HAVE_LIBFFI) */
}
return 1;
}
@@ -2467,40 +2567,52 @@ int _ILGetInternalArray(ILMethod *method, int *isCtor,
ILInternalInfo *info)
case IL_META_ELEMTYPE_TYPEDBYREF:
{
- info->func = (void
*)System_MArray_Set_managedValue;
+ info->un.func = (void
*)System_MArray_Set_managedValue;
+#if defined(IL_USE_CVM) && !defined(HAVE_LIBFFI)
info->marshal =
(void
*)System_MArray_Set_managedValue_marshal;
+#endif /* defined(IL_USE_CVM) && !defined(HAVE_LIBFFI) */
return 1;
}
/* Not reached */
}
- info->func = (void *)System_MArray_Set_int;
+ info->un.func = (void *)System_MArray_Set_int;
+#if defined(IL_USE_CVM) && !defined(HAVE_LIBFFI)
info->marshal = (void *)System_MArray_Set_int_marshal;
+#endif /* defined(IL_USE_CVM) && !defined(HAVE_LIBFFI) */
return 1;
}
else if(ILType_IsValueType(type))
{
- info->func = (void *)System_MArray_Set_managedValue;
+ info->un.func = (void *)System_MArray_Set_managedValue;
+#if defined(IL_USE_CVM) && !defined(HAVE_LIBFFI)
info->marshal = (void
*)System_MArray_Set_managedValue_marshal;
+#endif /* defined(IL_USE_CVM) && !defined(HAVE_LIBFFI) */
return 1;
}
else if(rank == 2)
{
- info->func = (void *)System_MArray_Set2_ref;
+ info->un.func = (void *)System_MArray_Set2_ref;
+#if defined(IL_USE_CVM) && !defined(HAVE_LIBFFI)
info->marshal = (void *)System_MArray_Set2_ref_marshal;
+#endif /* defined(IL_USE_CVM) && !defined(HAVE_LIBFFI) */
return 1;
}
else
{
- info->func = (void *)System_MArray_Set_ref;
+ info->un.func = (void *)System_MArray_Set_ref;
+#if defined(IL_USE_CVM) && !defined(HAVE_LIBFFI)
info->marshal = (void *)System_MArray_Set_ref_marshal;
+#endif /* defined(IL_USE_CVM) && !defined(HAVE_LIBFFI) */
return 1;
}
}
else if(!strcmp(name, "Address"))
{
- info->func = (void *)System_MArray_Address;
+ info->un.func = (void *)System_MArray_Address;
+#if defined(IL_USE_CVM) && !defined(HAVE_LIBFFI)
info->marshal = (void *)System_MArray_Address_marshal;
+#endif /* defined(IL_USE_CVM) && !defined(HAVE_LIBFFI) */
return 1;
}
else
diff --git a/engine/lib_delegate.c b/engine/lib_delegate.c
index 7060586..10a444a 100644
--- a/engine/lib_delegate.c
+++ b/engine/lib_delegate.c
@@ -20,8 +20,10 @@
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
-#include "engine.h"
+#include "engine_private.h"
+#include "coder.h"
#include "lib_defs.h"
+#include "il_opcodes.h"
#ifdef __cplusplus
extern "C" {
@@ -117,6 +119,15 @@ void _IL_AsyncResult_SetOutParams(ILExecThread *_thread,
ILObject *del,
paramcount = ILTypeNumParams(invokeSignature);
+ if(paramcount == 0 || outParams == 0)
+ {
+ /*
+ * The called method has no arguments so there is nothing to do.
+ * Or the outParams Array is null. This might be a programming
error.
+ */
+ return;
+ }
+
if (ArrayLength(args) < paramcount || ArrayLength(outParams) <
paramcount)
{
return;
@@ -144,954 +155,1324 @@ void _IL_AsyncResult_SetOutParams(ILExecThread
*_thread, ILObject *del,
outArray[j++] = argsArray[i - 1];
}
}
-
}
-/*
- * public Delegate(Object target, IntPtr method);
- */
-static ILObject *Delegate_ctor(ILExecThread *thread,
- ILObject *target,
- ILNativeInt method)
+static ILMethod *_GetMethod(ILClass *classInfo, const char *name,
+ ILType *signature)
{
- ILClass *classInfo;
- ILObject *_this;
+ return (ILMethod *)ILClassNextMemberMatch(classInfo, 0,
+
IL_META_MEMBERKIND_METHOD,
+
name, signature);
+}
- /* Allocate space for the delegate object */
- classInfo = ILMethod_Owner(thread->method);
- _this = _ILEngineAllocObject(thread, classInfo);
+static ILField *_GetField(ILClass *classInfo, const char *name)
+{
+ ILField *field;
- if(!_this)
+ field = 0;
+ while((field = (ILField *)ILClassNextMemberByKind(classInfo, (ILMember
*)field,
+
IL_META_MEMBERKIND_FIELD)) != 0)
{
- return 0;
+ if(!strcmp(ILField_Name(field), name))
+ {
+ return field;
+ }
}
-
- /* Set the delegate's fields */
- ((System_Delegate *)_this)->target = target;
- ((System_Delegate *)_this)->methodInfo = (ILMethod *)method;
- ((System_Delegate *)_this)->closure = 0;
-
- /* Done */
- return _this;
+ return 0;
}
-#ifdef IL_USE_CVM
-/*
- * Parameter information for delegate invocation.
- */
-typedef struct
+static void _ILCoderLoadInt32Constant(ILCoder *coder, ILUInt32 value)
{
- CVMWord *words;
- ILUInt32 numWords;
+ if(value < 9)
+ {
+ ILCoderConstant(coder, IL_OP_LDC_I4_0 + value, 0);
+ }
+ else
+ {
+ unsigned char int32Constant[4];
-} DelegateInvokeParams;
+ IL_WRITE_UINT32(int32Constant, value);
+ ILCoderConstant(coder, IL_OP_LDC_I4, int32Constant);
+ }
+}
-/*
- * Read a double value from a stack position.
- */
-static IL_INLINE ILDouble DelegateReadDouble(CVMWord *stack)
+static int _ILCoderCreateSimpleArrayType(ILMethod *method,
+
ILType *elemType,
+
ILType **arrayType,
+
ILClass **arrayClass)
{
-#ifdef CVM_DOUBLES_ALIGNED_WORD
- return *((ILDouble *)stack);
-#else
- ILDouble temp;
- ILMemCpy(&temp, stack, sizeof(ILDouble));
- return temp;
-#endif
+ ILType *typeInfo;
+ ILClass *classInfo;
+ ILImage *image;
+ ILContext *context;
+
+ image = ILProgramItem_Image(method);
+ context = ILImageToContext(image);
+ typeInfo = ILTypeFindOrCreateArray(context, 1, elemType);
+ if(!typeInfo)
+ {
+ return 0;
+ }
+ classInfo = ILClassFromType(image, 0, typeInfo, 0);
+ if(!classInfo)
+ {
+ return 0;
+ }
+ classInfo = ILClassResolve(classInfo);
+ *arrayType = typeInfo;
+ *arrayClass = classInfo;
+ return 1;
}
-/*
- * Pack the parameters for a delegate invocation.
- */
-static int PackDelegateInvokeParams(ILExecThread *thread, ILMethod *method,
- int isCtor, void
*_this, void *userData)
+static int _ILCoderUnboxValue(ILCoder *coder, ILImage *image, ILType *type,
+ ILCoderPrefixInfo
*prefixInfo)
{
- DelegateInvokeParams *params = (DelegateInvokeParams *)userData;
- ILType *signature = ILMethod_Signature(method);
- CVMWord *stacktop = thread->stackTop;
- ILType *type;
- unsigned long numParams;
- unsigned long paramNum;
- ILNativeFloat nativeFloat;
- CVMWord *words;
- ILUInt32 size;
-
- /* Push the "this" pointer if necessary */
- if(ILType_HasThis(signature))
+ ILClass *classInfo;
+
+ type = ILTypeGetEnumType(type);
+ classInfo = ILClassFromType(image, 0, type, 0);
+ if(!classInfo)
{
- if(stacktop >= thread->stackLimit)
+ return 0;
+ }
+
+ if(ILType_IsPrimitive(type))
+ {
+ /*
+ * Unbox the object to produce a managed pointer
+ */
+ ILCoderUnbox(coder, classInfo, prefixInfo);
+ switch(ILType_ToElement(type))
{
- _ILExecThreadSetException(thread, _ILSystemException
- (thread, "System.StackOverflowException"));
- return 1;
+ case IL_META_ELEMTYPE_I1:
+ {
+ ILCoderPtrAccess(coder, IL_OP_LDIND_I1,
prefixInfo);
+ }
+ break;
+
+ case IL_META_ELEMTYPE_BOOLEAN:
+ case IL_META_ELEMTYPE_U1:
+ {
+ ILCoderPtrAccess(coder, IL_OP_LDIND_U1,
prefixInfo);
+ }
+ break;
+
+ case IL_META_ELEMTYPE_I2:
+ {
+ ILCoderPtrAccess(coder, IL_OP_LDIND_I2,
prefixInfo);
+ }
+ break;
+
+ case IL_META_ELEMTYPE_CHAR:
+ case IL_META_ELEMTYPE_U2:
+ {
+ ILCoderPtrAccess(coder, IL_OP_LDIND_U2,
prefixInfo);
+ }
+ break;
+
+ case IL_META_ELEMTYPE_I4:
+ {
+ ILCoderPtrAccess(coder, IL_OP_LDIND_I4,
prefixInfo);
+ }
+ break;
+
+ case IL_META_ELEMTYPE_U4:
+ {
+ ILCoderPtrAccess(coder, IL_OP_LDIND_U4,
prefixInfo);
+ }
+ break;
+
+ case IL_META_ELEMTYPE_I8:
+ case IL_META_ELEMTYPE_U8:
+ {
+ ILCoderPtrAccess(coder, IL_OP_LDIND_I8,
prefixInfo);
+ }
+ break;
+
+ case IL_META_ELEMTYPE_I:
+ case IL_META_ELEMTYPE_U:
+ {
+ ILCoderPtrAccess(coder, IL_OP_LDIND_I,
prefixInfo);
+ }
+ break;
+
+ case IL_META_ELEMTYPE_R4:
+ {
+ ILCoderPtrAccess(coder, IL_OP_LDIND_R4,
prefixInfo);
+ }
+ break;
+
+ case IL_META_ELEMTYPE_R8:
+ {
+ ILCoderPtrAccess(coder, IL_OP_LDIND_R8,
prefixInfo);
+ }
+ break;
+
+ default:
+ {
+ /*
+ * Copy the value type on the stack.
+ */
+ ILCoderPtrAccessManaged(coder, IL_OP_LDOBJ,
classInfo, prefixInfo);
+ }
}
- stacktop->ptrValue = _this;
- ++stacktop;
}
-
- /* Push the parameter words */
- if((stacktop + params->numWords) >= thread->stackLimit)
+ else if(ILType_IsValueType(type))
{
- _ILExecThreadSetException(thread, _ILSystemException
- (thread, "System.StackOverflowException"));
- return 1;
+ /*
+ * Unbox the object to produce a managed pointer
+ */
+ ILCoderUnbox(coder, classInfo, prefixInfo);
+ /*
+ * And copy the value type.
+ */
+ ILCoderPtrAccessManaged(coder, IL_OP_LDOBJ,
classInfo, prefixInfo);
}
- /* Expand "float" and "double" parameters, because the frame variables
- are in "fixed up" form, rather than native float form */
- numParams = ILTypeNumParams(signature);
- words = params->words;
- for(paramNum = 1; paramNum <= numParams; ++paramNum)
+ else
{
- void *ptr;
-
- type = ILTypeGetParam(signature, paramNum);
- if(type == ILType_Float32)
- {
- nativeFloat = (ILNativeFloat)(*((ILFloat *)words));
- ptr = (void *)&nativeFloat;
- size = CVM_WORDS_PER_NATIVE_FLOAT;
- }
- else if(type == ILType_Float64)
- {
- nativeFloat = (ILNativeFloat)DelegateReadDouble(words);
- ptr = (void *)&nativeFloat;
- size = CVM_WORDS_PER_NATIVE_FLOAT;
- }
- else
- {
- ptr = (void *)words;
- size = ((ILSizeOfType(thread, type) + sizeof(CVMWord) -
1)
- / sizeof(CVMWord));
- }
- ILMemCpy(stacktop, ptr, size * sizeof(CVMWord));
- words += size;
- stacktop += size;
+ /*
+ * Everything else is an object reference.
+ *
+ * So there is nothing to do.
+ */
}
-
- /* Update the stack top */
- thread->stackTop = stacktop;
- return 0;
+ return 1;
}
-/*
- * public Type Invoke(...);
- */
-static void Delegate_Invoke(ILExecThread *thread,
- void *result,
- ILObject *_this)
+static ILType *CreateDelegateSignature(ILType *invokeSignature, ILImage *image)
{
- ILObject *target;
- ILMethod *method;
- DelegateInvokeParams params;
-
- /* If this is a multicast delegate, then execute "prev" first */
- if(((System_Delegate *)_this)->prev)
+ ILType *signature;
+ ILType *returnType;
+ ILClass *objectClass;
+ ILUInt32 numParams;
+ ILUInt32 param;
+ ILContext *context;
+
+ context = ILImageToContext(image);
+ returnType = ILTypeGetReturn(invokeSignature);
+ /*
+ objectClass = ILClassResolveSystem(image, 0, "Object", "System");
+ if(!objectClass)
{
- Delegate_Invoke(thread, result, ((System_Delegate
*)_this)->prev);
- if(_ILExecThreadHasException(thread))
- {
- return;
- }
+ return 0;
}
-
- /* Extract the fields from the delegate and validate them */
- target = ((System_Delegate *)_this)->target;
- method = ((System_Delegate *)_this)->methodInfo;
- if(!method)
+ */
+ signature = ILTypeCreateMethod(context, returnType);
+ if(!signature)
{
- ILExecThreadThrowSystem(thread, "System.MissingMethodException",
- (const char
*)0);
- return;
+ return 0;
}
-
- /* Locate the start and end of the parameters to "Invoke",
- excluding the "this" value that represents the delegate */
- params.words = thread->frame + 1;
- params.numWords = _ILGetMethodParamCount(thread, method, 1);
-
- /* Call the method */
- _ILCallMethod(thread, method,
- _ILCallUnpackDirectResult, result,
- 0, target,
- PackDelegateInvokeParams, ¶ms);
-}
-
-static ILObject *Delegate_BeginInvoke(ILExecThread *thread, ILObject *_this)
-{
- void *array;
- ILClass *classInfo;
- ILObject *obj;
- ILObject *result = 0;
- ILType *beginInvokeMethodSignature;
- ILMethod *beginInvokeMethodInfo, *async_ctor;
- CVMWord *stackTop = thread->stackTop;
- int paramWords, paramCount;
-
- /* Get the AsyncResult classs */
- classInfo = ILExecThreadLookupClass
- (
- thread,
- "System.Runtime.Remoting.Messaging.AsyncResult"
- );
-
- if (classInfo == 0)
+ /*
+ if(!ILTypeAddParam(context, signature, ILType_FromClass(objectClass)))
{
- ILExecThreadThrowSystem(thread,
"System.MissingMethodException", (const char *)0);
-
return 0;
}
+ */
+ numParams = ILTypeNumParams(invokeSignature);
+ param = 1;
+ while(param <= numParams)
+ {
+ ILType *paramType;
- /* Get the constructor for AsyncResult */
- async_ctor = ILExecThreadLookupMethod
- (
- thread,
- "System.Runtime.Remoting.Messaging.AsyncResult",
- ".ctor",
-
"(ToSystem.Delegate;[oSystem.Object;oSystem.AsyncCallback;oSystem.Object;)V"
- );
+ paramType = ILTypeGetParam(invokeSignature, param);
+ if(!ILTypeAddParam(context, signature, paramType))
+ {
+ return 0;
+ }
+ ++param;
+ }
+ return signature;
+}
- if (async_ctor == 0)
+static ILStandAloneSig* _ILCoderCreateLocalSignature(ILCoder *coder,
+
ILImage *image,
+
ILType **locals,
+
ILUInt32 numLocals)
+{
+ ILImage *syntheticImage;
+ ILContext *context;
+ ILType *localSig;
+ ILUInt32 local;
+
+ context = ILImageToContext(image);
+ syntheticImage = ILContextGetSynthetic(context);
+ if(!syntheticImage)
{
- ILExecThreadThrowSystem(thread,
"System.MissingMethodException", (const char *)0);
-
return 0;
}
-
- /* Get the BeginInvoke method for the delegate */
- beginInvokeMethodInfo = (ILMethod *)ILTypeGetDelegateBeginInvokeMethod
- (
-
ILType_FromClass(GetObjectClassPrivate(_this)->classInfo)
- );
-
- if(!beginInvokeMethodInfo)
+ localSig = ILTypeCreateLocalList(context);
+ if(!localSig)
{
- ILExecThreadThrowSystem(thread, "System.MissingMethodException",
- (const char *)0);
-
return 0;
}
-
- /* Get the signature for the BeginInvoke method */
- beginInvokeMethodSignature = ILMethod_Signature(beginInvokeMethodInfo);
-
- /* The number of paramters for the BeginInvoke method */
- paramCount = ILTypeNumParams(beginInvokeMethodSignature);
-
- /* Get the number of CVM words the delegate method requires */
- paramWords = _ILGetMethodParamCount
- (
- thread,
- beginInvokeMethodInfo,
- 0
- );
-
- /* Pack the parameters into a managed object array */
- _ILPackCVMStackArgs
- (
- thread,
- /* stackTop is the part "just below" the IAsyncResult
parameter */
- thread->frame + paramWords - 2,
- /* 0 is return param */
- 1,
- /* Number of parameters in BeginInvoke not including
the AsyncResult & state */
- paramCount - 2,
- /* Can use BeginInvoke signature because the first
parameters are the same */
- beginInvokeMethodSignature,
- &array
- );
-
- obj = _ILEngineAllocObject(thread, classInfo);
-
- /* Call AsyncResult constructor */
- ILExecThreadCall
- (
- thread,
- async_ctor,
- &result,
- obj,
- (System_Delegate *)_this,
- array /* Delegate method arguments */,
- (thread->frame + paramWords - 2)->ptrValue /*
AsyncCallback */,
- (thread->frame + paramWords - 1)->ptrValue /*
AsyncState */
- );
-
- thread->stackTop = stackTop;
-
- return obj;
+ local = 0;
+ while(local < numLocals)
+ {
+ if(!ILTypeAddLocal(context, localSig, locals[local]))
+ {
+ return 0;
+ }
+ ++local;
+ }
+ return ILStandAloneSigCreate(syntheticImage, 0, localSig);
}
-static void Delegate_EndInvoke(ILExecThread *thread,
- void *result,
- ILObject *_this)
-{
- ILObject *retValue;
- ILObject *array;
- ILObject **arrayBuffer;
+static int _ILCoderGenDelegateCtor(ILCoder *coder, ILMethod *method,
+ unsigned
char **start,
+
ILCoderExceptions *coderExceptions)
+{
ILClass *classInfo;
- ILType *retType;
- ILMethod *endInvokeMethodInfo;
- ILType *endInvokeMethodSignature;
- ILMethod *asyncEndInvokeMethodInfo;
- CVMWord *stackTop = thread->stackTop;
- int i, paramWords, paramCount;
- CVMWord *frame;
-
- classInfo = GetObjectClass(_this);
-
- /* Get the "EndInvoke" method */
- endInvokeMethodInfo = (ILMethod *)ILTypeGetDelegateEndInvokeMethod
- (
-
ILType_FromClass(GetObjectClassPrivate(_this)->classInfo)
- );
-
- if (endInvokeMethodInfo == 0)
- {
- ILExecThreadThrowSystem(thread,
"System.MissingMethodException", (const char *)0);
+ ILClass *delegateClassInfo;
+ ILField *targetField;
+ ILField *methodField;
+ ILType *signature;
+ ILCoderPrefixInfo prefixInfo;
+ ILMethodCode code;
+ ILEngineStackItem stack[2];
- return;
+ classInfo = ILMethod_Owner(method);
+ delegateClassInfo = ILClassResolveSystem(ILProgramItem_Image(method),
+
0, "Delegate", "System");
+ if(!delegateClassInfo)
+ {
+ /* Ran out of memory trying to create "System.Delegate" */
+ return IL_CODER_END_TOO_BIG;
}
-
- /* Get the return type of the delegate */
- retType = ILTypeGetReturn(ILMethod_Signature(endInvokeMethodInfo));
-
- endInvokeMethodSignature = ILMethod_Signature(endInvokeMethodInfo);
-
- /* Number of parameters for the EndInvoke method */
- paramCount = ILTypeNumParams(endInvokeMethodSignature);
-
- /* Get the number of CVM words the parameters take up */
- paramWords = _ILGetMethodParamCount
- (
- thread,
- endInvokeMethodInfo,
- 0
- );
-
- /* Get the AsyncResult.EndInvoke method */
- asyncEndInvokeMethodInfo = ILExecThreadLookupMethod
- (
- thread,
- "System.Runtime.Remoting.Messaging.AsyncResult",
- "EndInvoke",
- "(T[oSystem.Object;)oSystem.Object;"
- );
-
- if (asyncEndInvokeMethodInfo == 0)
+ targetField = _GetField(delegateClassInfo, "target");
+ if(!targetField)
{
- ILExecThreadThrowSystem(thread,
"System.MissingMethodException", (const char *)0);
-
- return;
+ /* Field "target" is missing in the System.Delegate class */
+ return IL_CODER_END_TOO_BIG;
+ }
+ methodField = _GetField(delegateClassInfo, "method");
+ if(!methodField)
+ {
+ /* Field "target" is missing in the System.Delegate class */
+ return IL_CODER_END_TOO_BIG;
}
- /* Create an array to store the out params */
- array = ILExecThreadNew(thread, "[oSystem.Object;", "(Ti)V",
- (ILVaUInt)paramCount - 1 /* Number of out-params is (number of
params) - (1 for AsyncResult) */);
-
- arrayBuffer = ((ILObject **)ArrayToBuffer(array));
+ signature = ILMethod_Signature(method);
- if (array == 0)
+ /* Initialize the prefix information */
+ ILMemZero(&prefixInfo, sizeof(ILCoderPrefixInfo));
+ ILMemZero(&code, sizeof(ILMethodCode));
+ code.maxStack = 2;
+
+ if(!ILCoderSetup(coder, start, method, &code, coderExceptions, 0))
{
- ILExecThreadThrowOutOfMemory(thread);
-
- return;
+ return IL_CODER_END_TOO_BIG;
}
- /* Call AsyncResult.EndInvoke. */
- ILExecThreadCall
- (
- thread,
- asyncEndInvokeMethodInfo,
- &retValue,
- /* IAsyncResult */
- (thread->frame + paramWords - 1)->ptrValue,
- /* Array for out-params */
- array
- );
+ /* Load the this pointer on the stack */
+ stack[0].engineType = ILEngineType_O;
+ stack[0].typeInfo = ILType_FromClass(delegateClassInfo);
+ ILCoderLoadArg(coder, 0, stack[0].typeInfo);
- /*
- * Pack "out" values back onto the stack.
- */
+ /* Load the target argument on the stack */
+ _ILCoderLoadArgs(coder, &(stack[1]), method, signature, 1, 1);
+
+ ILCoderStoreField(coder, ILEngineType_O, stack[0].typeInfo,
+ targetField,
ILField_Type(targetField),
+ stack[1].engineType, &prefixInfo);
+
+ /* Load the this pointer on the stack */
+ stack[0].engineType = ILEngineType_O;
+ stack[0].typeInfo = ILType_FromClass(delegateClassInfo);
+ ILCoderLoadArg(coder, 0, stack[0].typeInfo);
- /* Skip the "this" pointer */
- frame = thread->frame + 1;
+ /* Load the method pointer argument on the stack */
+ _ILCoderLoadArgs(coder, &(stack[1]), method, signature, 2, 2);
+
+ ILCoderStoreField(coder, ILEngineType_O, stack[0].typeInfo,
+ methodField, stack[1].typeInfo,
+ stack[1].engineType, &prefixInfo);
+
+ /* And return from this method */
+ ILCoderReturnInsn(coder, ILEngineType_Invalid, ILType_Void);
- for (i = 1; i <= paramCount - 1 /* -1 to skip IAsyncResult */; i++)
- {
- ILUInt32 paramSize;
- ILType *paramType;
+ /* Mark the end of the method */
+ ILCoderMarkEnd(coder);
- paramType = ILTypeGetParam(endInvokeMethodSignature, i);
- paramSize = _ILStackWordsForType(thread, paramType);
- paramType = ILType_Ref(paramType);
+ return ILCoderFinish(coder);
+}
- if (ILType_IsPrimitive(paramType) ||
ILType_IsValueType(paramType))
- {
- /* If the param is a value type then unbox directly
into the argument */
- ILExecThreadUnbox(thread, paramType, arrayBuffer[i -
1], frame->ptrValue);
- }
- else if (ILType_IsClass(paramType))
- {
- /* If the param is a class reference then set the new
class reference */
- *(ILObject **)frame->ptrValue = arrayBuffer[i - 1];
- }
- else
- {
- /* Don't know how to return this type of out param */
- }
+static int GenDelegateInvoke(ILCoder *coder, ILMethod *method,
+ ILType *signature,
ILUInt32 numParams,
+ ILEngineStackItem
*stack,
+ ILField *targetField,
ILField *methodField)
+{
+ ILCoderPrefixInfo prefixInfo;
+ ILCoderMethodInfo coderMethodInfo;
+ ILType *returnType;
+ ILType *thisType;
+
+ /* Initialize the prefix information */
+ ILMemZero(&prefixInfo, sizeof(ILCoderPrefixInfo));
+ returnType = ILTypeGetReturn(signature);
+ thisType = ILType_FromClass(ILMethod_Owner(method));
+
+ ILCoderLoadThisField(coder, targetField,
+ ILField_Type(targetField),
&prefixInfo);
+ stack[0].typeInfo = ILField_Type(targetField);
+ stack[0].engineType = _ILTypeToEngineType(stack[0].typeInfo);
+ ILCoderBranch(coder, IL_OP_BRTRUE, 1, ILEngineType_O, ILEngineType_O);
+ /* The stack is empty now */
+ _ILCoderLoadArgs(coder, stack, method, signature, 1, numParams - 1);
+ ILCoderLoadThisField(coder, methodField, ILType_Int, &prefixInfo);
+
+ coderMethodInfo.args = stack;
+ coderMethodInfo.numBaseArgs = numParams - 1;
+ coderMethodInfo.numVarArgs = 0;
+ coderMethodInfo.hasParamArray = 0;
+ coderMethodInfo.tailCall = 0;
+ coderMethodInfo.signature = CreateDelegateSignature(signature,
+
ILProgramItem_Image(method));
+ if(!coderMethodInfo.signature)
+ {
+ return 0;
+ }
- frame += paramSize;
+ _ILCoderSetReturnType(&(stack[numParams - 1]), returnType);
+ ILCoderCallIndirect(coder, &coderMethodInfo,
+ &(stack[numParams - 1]));
+ if(returnType != ILType_Void)
+ {
+ ILCoderReturnInsn(coder, _ILTypeToEngineType(returnType),
+ returnType);
}
+ else
+ {
+ ILCoderReturnInsn(coder, ILEngineType_Invalid, ILType_Void);
+ }
+ ILCoderLabel(coder, 1);
+ ILCoderLoadThisField(coder, targetField,
+ ILField_Type(targetField),
&prefixInfo);
+ stack[0].typeInfo = ILField_Type(targetField);
+ stack[0].engineType = _ILTypeToEngineType(stack[0].typeInfo);
+ _ILCoderLoadArgs(coder, &(stack[1]), method, signature, 1, numParams -
1);
+ ILCoderLoadThisField(coder, methodField, ILType_Int, &prefixInfo);
+
+ coderMethodInfo.args = stack;
+ coderMethodInfo.numBaseArgs = numParams;
+ coderMethodInfo.numVarArgs = 0;
+ coderMethodInfo.hasParamArray = 0;
+#ifdef IL_USE_CVM
+ coderMethodInfo.tailCall = 1;
+#else /* IL_USE_JIT */
+ /*
+ * TODO: Make this a tail call if tail calls are fixed in libjit.
+ */
+ coderMethodInfo.tailCall = 0;
+#endif /* !IL_USE_JIT */
+ coderMethodInfo.signature = signature;
- /* Set the return value */
- if (ILTypeIsValue(retType))
+ _ILCoderSetReturnType(&(stack[numParams]), returnType);
+ ILCoderCallIndirect(coder, &coderMethodInfo, &(stack[numParams]));
+ if(returnType != ILType_Void)
{
- ILExecThreadUnbox(thread, retType, retValue, result);
+ ILCoderReturnInsn(coder, _ILTypeToEngineType(returnType),
+ returnType);
}
else
{
- *((ILObject **)result) = retValue;
- }
-
- thread->stackTop = stackTop;
+ ILCoderReturnInsn(coder, ILEngineType_Invalid, ILType_Void);
+ }
+ return 1;
}
-#endif /* IL_USE_CVM */
+static int _ILCoderGenDelegateInvoke(ILCoder *coder, ILMethod *method,
+
unsigned char **start,
+
ILCoderExceptions *coderExceptions)
+{
+ ILType *signature;
-#ifdef IL_USE_JIT
+ signature = ILMethod_Signature(method);
+ if(signature)
+ {
+ ILUInt32 numParams;
-/*
- * public Type Invoke(...);
- */
-static void Delegate_Invoke(ILExecThread *thread,
- void *result,
- ILObject *_this)
-{
- /* This is a dummy because the real function is generated by the */
- /* jit coder. */
-}
+ numParams = ILTypeNumParams(signature);
+ if(ILType_HasThis(signature))
+ {
+ /* Add the hidden this parameter */
+ ++numParams;
+ }
+ {
+ ILClass *delegateClassInfo;
+ ILField *targetField;
+ ILField *methodField;
+ ILMethodCode code;
+ ILEngineStackItem stack[numParams + 3];
+
+ delegateClassInfo =
ILClassResolveSystem(ILProgramItem_Image(method),
+
0, "Delegate", "System");
+ if(!delegateClassInfo)
+ {
+ /* Ran out of memory trying to create
"System.Delegate" */
+ return IL_CODER_END_TOO_BIG;
+ }
+ targetField = _GetField(delegateClassInfo, "target");
+ if(!targetField)
+ {
+ /* Field "target" is missing in the
System.Delegate class */
+ return IL_CODER_END_TOO_BIG;
+ }
+ methodField = _GetField(delegateClassInfo, "method");
+ if(!methodField)
+ {
+ /* Field "target" is missing in the
System.Delegate class */
+ return IL_CODER_END_TOO_BIG;
+ }
+ ILMemZero(&code, sizeof(ILMethodCode));
+ code.maxStack = numParams + 3;
+
+ if(!ILCoderSetup(coder, start, method, &code,
coderExceptions, 0))
+ {
+ /* The coder setup failed */
+ return IL_CODER_END_TOO_BIG;
+ }
+ if(!GenDelegateInvoke(coder, method, signature,
numParams,
+ stack, targetField,
methodField))
+ {
+ return IL_CODER_END_TOO_BIG;
+ }
-static ILObject *Delegate_BeginInvoke(ILExecThread *thread, ILObject *_this)
-{
- /* This is a dummy because the real function is generated by the */
- /* jit coder. */
- return 0;
+ /* Mark the end of the method */
+ ILCoderMarkEnd(coder);
+
+ return ILCoderFinish(coder);
+ }
+ }
+ return IL_CODER_END_TOO_BIG;
}
-static void Delegate_EndInvoke(ILExecThread *thread,
- void *result,
- ILObject *_this)
+static int _ILCoderGenMulticastDelegateInvoke(ILCoder *coder, ILMethod *method,
+
unsigned char **start,
+
ILCoderExceptions *coderExceptions)
{
- /* This is a dummy because the real function is generated by the */
- /* jit coder. */
-}
+ ILType *signature;
-#endif /* IL_USE_JIT */
+ signature = ILMethod_Signature(method);
+ if(signature)
+ {
+ ILUInt32 numParams;
-#if !defined(HAVE_LIBFFI)
+ numParams = ILTypeNumParams(signature);
+ if(ILType_HasThis(signature))
+ {
+ /* Add the hidden this parameter */
+ ++numParams;
+ }
+ {
+ ILCoderPrefixInfo prefixInfo;
+ ILCoderMethodInfo coderMethodInfo;
+ ILType *returnType;
+ ILType *thisType;
+ ILClass *multicastDelegateClassInfo;
+ ILClass *delegateClassInfo;
+ ILField *prevField;
+ ILField *targetField;
+ ILField *methodField;
+ ILMethodCode code;
+ ILEngineStackItem stack[numParams + 3];
+
+ multicastDelegateClassInfo =
ILClassResolveSystem(ILProgramItem_Image(method),
+
0, "MulticastDelegate",
+
"System");
+ if(!multicastDelegateClassInfo)
+ {
+ /* Ran out of memory trying to create
"System.MulticastDelegate" */
+ return IL_CODER_END_TOO_BIG;
+ }
+ prevField = _GetField(multicastDelegateClassInfo,
"prev");
+ if(!prevField)
+ {
+ /* Field "prev" is missing in the
System.MulticastDelegate class */
+ return IL_CODER_END_TOO_BIG;
+ }
-/*
- * Marshal a delegate constructor.
- */
-static void Delegate_ctor_marshal
- (void (*fn)(), void *rvalue, void **avalue)
-{
- *((ILObject **)rvalue) =
- Delegate_ctor(*((ILExecThread **)(avalue[0])),
- *((ILObject **)(avalue[1])),
- *((ILNativeInt *)(avalue[2])));
-}
+ delegateClassInfo =
ILClassResolveSystem(ILProgramItem_Image(method),
+
0, "Delegate", "System");
+ if(!delegateClassInfo)
+ {
+ /* Ran out of memory trying to create
"System.Delegate" */
+ return IL_CODER_END_TOO_BIG;
+ }
+ targetField = _GetField(delegateClassInfo, "target");
+ if(!targetField)
+ {
+ /* Field "target" is missing in the
System.Delegate class */
+ return IL_CODER_END_TOO_BIG;
+ }
+ methodField = _GetField(delegateClassInfo, "method");
+ if(!methodField)
+ {
+ /* Field "target" is missing in the
System.Delegate class */
+ return IL_CODER_END_TOO_BIG;
+ }
+ returnType = ILTypeGetReturn(signature);
+ thisType = ILType_FromClass(ILMethod_Owner(method));
+ ILMemZero(&code, sizeof(ILMethodCode));
+ code.maxStack = numParams + 3;
+
+ if(!ILCoderSetup(coder, start, method, &code,
coderExceptions, 0))
+ {
+ /* The coder setup failed */
+ return IL_CODER_END_TOO_BIG;
+ }
-/*
- * Marshal a delegate "Invoke" method for the various return types.
- */
-static void Delegate_Invoke_marshal
- (void (*fn)(), void *rvalue, void **avalue)
-{
- Delegate_Invoke(*((ILExecThread **)(avalue[0])), rvalue,
- *((ILObject **)(avalue[1])));
-}
-static void Delegate_Invoke_sbyte_marshal
- (void (*fn)(), void *rvalue, void **avalue)
-{
- ILInt8 result;
- Delegate_Invoke(*((ILExecThread **)(avalue[0])), &result,
- *((ILObject **)(avalue[1])));
- *((ILNativeInt *)rvalue) = (ILNativeInt)result;
-}
-static void Delegate_Invoke_byte_marshal
- (void (*fn)(), void *rvalue, void **avalue)
-{
- ILUInt8 result;
- Delegate_Invoke(*((ILExecThread **)(avalue[0])), &result,
- *((ILObject **)(avalue[1])));
- *((ILNativeInt *)rvalue) = (ILNativeInt)result;
-}
-static void Delegate_Invoke_short_marshal
- (void (*fn)(), void *rvalue, void **avalue)
-{
- ILInt16 result;
- Delegate_Invoke(*((ILExecThread **)(avalue[0])), &result,
- *((ILObject **)(avalue[1])));
- *((ILNativeInt *)rvalue) = (ILNativeInt)result;
-}
-static void Delegate_Invoke_ushort_marshal
- (void (*fn)(), void *rvalue, void **avalue)
-{
- ILUInt16 result;
- Delegate_Invoke(*((ILExecThread **)(avalue[0])), &result,
- *((ILObject **)(avalue[1])));
- *((ILNativeInt *)rvalue) = (ILNativeInt)result;
-}
-static void Delegate_Invoke_int_marshal
- (void (*fn)(), void *rvalue, void **avalue)
-{
- ILInt32 result;
- Delegate_Invoke(*((ILExecThread **)(avalue[0])), &result,
- *((ILObject **)(avalue[1])));
- *((ILNativeInt *)rvalue) = (ILNativeInt)result;
-}
-static void Delegate_Invoke_uint_marshal
- (void (*fn)(), void *rvalue, void **avalue)
-{
- ILUInt32 result;
- Delegate_Invoke(*((ILExecThread **)(avalue[0])), &result,
- *((ILObject **)(avalue[1])));
- *((ILNativeUInt *)rvalue) = (ILNativeUInt)result;
-}
+ ILCoderLoadThisField(coder, prevField,
+
ILField_Type(prevField), &prefixInfo);
+ ILCoderBranch(coder, IL_OP_BRFALSE, 2, ILEngineType_O,
+ ILEngineType_O);
+ ILCoderLoadThisField(coder, prevField,
+
ILField_Type(prevField), &prefixInfo);
+ stack[0].typeInfo = thisType;
+ stack[0].engineType = ILEngineType_O;
+ _ILCoderLoadArgs(coder, &(stack[1]), method, signature,
1, numParams - 1);
+
+ coderMethodInfo.args = stack;
+ coderMethodInfo.numBaseArgs = numParams;
+ coderMethodInfo.numVarArgs = 0;
+ coderMethodInfo.hasParamArray = 0;
+ coderMethodInfo.tailCall = 0;
+ coderMethodInfo.signature = signature;
+
+ _ILCoderSetReturnType(&(stack[numParams]), returnType);
+ ILCoderCallMethod(coder, &coderMethodInfo,
&(stack[numParams]),
+ method);
+ /*
+ * If the delegate returns a valoe pop the value from
the stack.
+ */
+ if(returnType != ILType_Void)
+ {
+ ILCoderPop(coder, stack[numParams].engineType,
returnType);
+ }
-#define Delegate_Invoke_void_marshal
Delegate_Invoke_marshal
-#define Delegate_Invoke_long_marshal
Delegate_Invoke_marshal
-#define Delegate_Invoke_ulong_marshal
Delegate_Invoke_marshal
-#define Delegate_Invoke_float_marshal
Delegate_Invoke_marshal
-#define Delegate_Invoke_double_marshal
Delegate_Invoke_marshal
-#define Delegate_Invoke_nativeFloat_marshal
Delegate_Invoke_marshal
-#define Delegate_Invoke_typedref_marshal
Delegate_Invoke_marshal
-#define Delegate_Invoke_ref_marshal
Delegate_Invoke_marshal
-#define Delegate_Invoke_managedValue_marshal Delegate_Invoke_marshal
+ ILCoderLabel(coder, 2);
+ /*
+ * Now generate the Delegate.Invoke code.
+ */
+ if(!GenDelegateInvoke(coder, method, signature,
numParams,
+ stack, targetField,
methodField))
+ {
+ return IL_CODER_END_TOO_BIG;
+ }
-/*
-* Marshal a delegate "EndInvoke" method for the various return types.
-*/
-static void Delegate_EndInvoke_marshal
-(void (*fn)(), void *rvalue, void **avalue)
-{
- Delegate_EndInvoke(*((ILExecThread **)(avalue[0])), rvalue,
- *((ILObject **)(avalue[1])));
-}
-static void Delegate_EndInvoke_sbyte_marshal
-(void (*fn)(), void *rvalue, void **avalue)
-{
- ILInt8 result;
- Delegate_EndInvoke(*((ILExecThread **)(avalue[0])), &result,
- *((ILObject **)(avalue[1])));
- *((ILNativeInt *)rvalue) = (ILNativeInt)result;
-}
-static void Delegate_EndInvoke_byte_marshal
-(void (*fn)(), void *rvalue, void **avalue)
-{
- ILUInt8 result;
- Delegate_EndInvoke(*((ILExecThread **)(avalue[0])), &result,
- *((ILObject **)(avalue[1])));
- *((ILNativeInt *)rvalue) = (ILNativeInt)result;
-}
-static void Delegate_EndInvoke_short_marshal
-(void (*fn)(), void *rvalue, void **avalue)
-{
- ILInt16 result;
- Delegate_EndInvoke(*((ILExecThread **)(avalue[0])), &result,
- *((ILObject **)(avalue[1])));
- *((ILNativeInt *)rvalue) = (ILNativeInt)result;
-}
-static void Delegate_EndInvoke_ushort_marshal
-(void (*fn)(), void *rvalue, void **avalue)
-{
- ILUInt16 result;
- Delegate_EndInvoke(*((ILExecThread **)(avalue[0])), &result,
- *((ILObject **)(avalue[1])));
- *((ILNativeInt *)rvalue) = (ILNativeInt)result;
-}
-static void Delegate_EndInvoke_int_marshal
-(void (*fn)(), void *rvalue, void **avalue)
-{
- ILInt32 result;
- Delegate_EndInvoke(*((ILExecThread **)(avalue[0])), &result,
- *((ILObject **)(avalue[1])));
- *((ILNativeInt *)rvalue) = (ILNativeInt)result;
-}
-static void Delegate_EndInvoke_uint_marshal
-(void (*fn)(), void *rvalue, void **avalue)
-{
- ILUInt32 result;
- Delegate_EndInvoke(*((ILExecThread **)(avalue[0])), &result,
- *((ILObject **)(avalue[1])));
- *((ILNativeUInt *)rvalue) = (ILNativeUInt)result;
+ /* Mark the end of the method */
+ ILCoderMarkEnd(coder);
+
+ return ILCoderFinish(coder);
+ }
+ }
+ return IL_CODER_END_TOO_BIG;
}
-#define Delegate_EndInvoke_void_marshal
Delegate_EndInvoke_marshal
-#define Delegate_EndInvoke_long_marshal
Delegate_EndInvoke_marshal
-#define Delegate_EndInvoke_ulong_marshal
Delegate_EndInvoke_marshal
-#define Delegate_EndInvoke_float_marshal
Delegate_EndInvoke_marshal
-#define Delegate_EndInvoke_double_marshal
Delegate_EndInvoke_marshal
-#define Delegate_EndInvoke_nativeFloat_marshal
Delegate_EndInvoke_marshal
-#define Delegate_EndInvoke_typedref_marshal
Delegate_EndInvoke_marshal
-#define Delegate_EndInvoke_ref_marshal
Delegate_EndInvoke_marshal
-#define Delegate_EndInvoke_managedValue_marshal
Delegate_EndInvoke_marshal
-
-/*
- * Point all invoke types at the common function (we'll be
- * calling it through the marshalling stub so it doesn't
- * matter what this value is).
- */
-#define Delegate_Invoke_void
Delegate_Invoke
-#define Delegate_Invoke_sbyte
Delegate_Invoke
-#define Delegate_Invoke_byte
Delegate_Invoke
-#define Delegate_Invoke_short
Delegate_Invoke
-#define Delegate_Invoke_ushort
Delegate_Invoke
-#define Delegate_Invoke_int
Delegate_Invoke
-#define Delegate_Invoke_uint
Delegate_Invoke
-#define Delegate_Invoke_long
Delegate_Invoke
-#define Delegate_Invoke_ulong
Delegate_Invoke
-#define Delegate_Invoke_float
Delegate_Invoke
-#define Delegate_Invoke_double
Delegate_Invoke
-#define Delegate_Invoke_nativeFloat
Delegate_Invoke
-#define Delegate_Invoke_typedref
Delegate_Invoke
-#define Delegate_Invoke_ref
Delegate_Invoke
-#define Delegate_Invoke_managedValue Delegate_Invoke
-
-
-#define Delegate_EndInvoke_void
Delegate_EndInvoke
-#define Delegate_EndInvoke_sbyte
Delegate_EndInvoke
-#define Delegate_EndInvoke_byte
Delegate_EndInvoke
-#define Delegate_EndInvoke_short
Delegate_EndInvoke
-#define Delegate_EndInvoke_ushort
Delegate_EndInvoke
-#define Delegate_EndInvoke_int
Delegate_EndInvoke
-#define Delegate_EndInvoke_uint
Delegate_EndInvoke
-#define Delegate_EndInvoke_long
Delegate_EndInvoke
-#define Delegate_EndInvoke_ulong
Delegate_EndInvoke
-#define Delegate_EndInvoke_float
Delegate_EndInvoke
-#define Delegate_EndInvoke_double
Delegate_EndInvoke
-#define Delegate_EndInvoke_nativeFloat
Delegate_EndInvoke
-#define Delegate_EndInvoke_typedref
Delegate_EndInvoke
-#define Delegate_EndInvoke_ref
Delegate_EndInvoke
-#define Delegate_EndInvoke_managedValue
Delegate_EndInvoke
-
-#else /* HAVE_LIBFFI */
-
-/*
- * Wrap "Delegate_Invoke" for the various return types.
- */
-static void Delegate_Invoke_void(ILExecThread *thread,
- ILObject
*_this)
+static int _ILCoderGenDelegateBeginInvoke(ILCoder *coder, ILMethod *method,
+
unsigned char **start,
+
ILCoderExceptions *coderExceptions)
{
- Delegate_Invoke(thread, (void *)0, _this);
-}
-#define Delegate_X_type(x, iltype,type) \
-static type Delegate_##x##_##iltype(ILExecThread *thread, \
-
ILObject *_this) \
-{ \
- type result; \
- Delegate_##x(thread, &result, _this); \
- return result; \
-}
-Delegate_X_type(Invoke, byte, ILUInt8)
-Delegate_X_type(Invoke, sbyte, ILInt8)
-Delegate_X_type(Invoke, short, ILInt16)
-Delegate_X_type(Invoke, ushort, ILUInt16)
-Delegate_X_type(Invoke, int, ILInt32)
-Delegate_X_type(Invoke, uint, ILUInt32)
-Delegate_X_type(Invoke, long, ILInt64)
-Delegate_X_type(Invoke, ulong, ILUInt64)
-Delegate_X_type(Invoke, float, ILFloat)
-Delegate_X_type(Invoke, double, ILDouble)
-Delegate_X_type(Invoke, nativeFloat, ILNativeFloat)
-Delegate_X_type(Invoke, typedref, ILTypedRef)
-Delegate_X_type(Invoke, ref, void *)
-#define Delegate_Invoke_managedValue Delegate_Invoke
+ ILType *signature;
-/*
-* Marshalling stubs for libffi (not required).
-*/
-#define Delegate_ctor_marshal 0
-#define Delegate_Invoke_void_marshal 0
-#define Delegate_Invoke_sbyte_marshal 0
-#define Delegate_Invoke_byte_marshal 0
-#define Delegate_Invoke_short_marshal 0
-#define Delegate_Invoke_ushort_marshal 0
-#define Delegate_Invoke_int_marshal 0
-#define Delegate_Invoke_uint_marshal 0
-#define Delegate_Invoke_long_marshal 0
-#define Delegate_Invoke_ulong_marshal 0
-#define Delegate_Invoke_float_marshal 0
-#define Delegate_Invoke_double_marshal 0
-#define Delegate_Invoke_nativeFloat_marshal 0
-#define Delegate_Invoke_typedref_marshal 0
-#define Delegate_Invoke_ref_marshal 0
-#define Delegate_Invoke_managedValue_marshal 0
+ signature = ILMethod_Signature(method);
+ if(signature)
+ {
+ ILImage *image;
+ ILType *returnType;
+ ILClass *delegateClass;
+ ILClass *objectClassInfo;
+ ILType *arrayType;
+ ILClass *arrayClass;
+ ILClass *asyncResultClass;
+ ILMethod *asyncResultCtorInfo;
+ ILUInt32 numParams;
+ ILMethodCode code;
+ ILCoderPrefixInfo prefixInfo;
+ ILCoderMethodInfo coderMethodInfo;
+ ILType *locals[2];
+ ILEngineStackItem stack[4];
+
+ image = ILProgramItem_Image(method);
+ delegateClass = ILMethod_Owner(method);
+ returnType = ILTypeGetReturn(signature);
+ numParams = ILTypeNumParams(signature);
+
+ objectClassInfo = ILClassResolveSystem(image, 0, "Object",
"System");
+ if(!objectClassInfo)
+ {
+ /* Ran out of memory trying to create "System.Delegate"
*/
+ return IL_CODER_END_TOO_BIG;
+ }
-/*
- * "Delegate_EndInvoke" for various return types.
- */
-static void Delegate_EndInvoke_void(ILExecThread *thread,
- ILObject *_this)
-{
- Delegate_EndInvoke(thread, (void *)0, _this);
-}
-Delegate_X_type(EndInvoke, byte, ILUInt8)
-Delegate_X_type(EndInvoke, sbyte, ILInt8)
-Delegate_X_type(EndInvoke, short, ILInt16)
-Delegate_X_type(EndInvoke, ushort, ILUInt16)
-Delegate_X_type(EndInvoke, int, ILInt32)
-Delegate_X_type(EndInvoke, uint, ILUInt32)
-Delegate_X_type(EndInvoke, long, ILInt64)
-Delegate_X_type(EndInvoke, ulong, ILUInt64)
-Delegate_X_type(EndInvoke, float, ILFloat)
-Delegate_X_type(EndInvoke, double, ILDouble)
-Delegate_X_type(EndInvoke, nativeFloat, ILNativeFloat)
-Delegate_X_type(EndInvoke, typedref, ILTypedRef)
-Delegate_X_type(EndInvoke, ref, void *)
-#define Delegate_EndInvoke_managedValue
Delegate_EndInvoke
+ asyncResultClass = ILClassResolveSystem(image, 0, "AsyncResult",
+
"System.Runtime.Remoting.Messaging");
+ if(!asyncResultClass)
+ {
+ /* Ran out of memory trying to create "System.Delegate"
*/
+ return IL_CODER_END_TOO_BIG;
+ }
-/*
- * Marshalling stubs for "Delegate_EndInvoke" for libffi (not required).
- */
-#define Delegate_ctor_marshal 0
-#define Delegate_EndInvoke_void_marshal 0
-#define Delegate_EndInvoke_sbyte_marshal 0
-#define Delegate_EndInvoke_byte_marshal 0
-#define Delegate_EndInvoke_short_marshal 0
-#define Delegate_EndInvoke_ushort_marshal 0
-#define Delegate_EndInvoke_int_marshal 0
-#define Delegate_EndInvoke_uint_marshal 0
-#define Delegate_EndInvoke_long_marshal 0
-#define Delegate_EndInvoke_ulong_marshal 0
-#define Delegate_EndInvoke_float_marshal 0
-#define Delegate_EndInvoke_double_marshal 0
-#define Delegate_EndInvoke_nativeFloat_marshal 0
-#define Delegate_EndInvoke_typedref_marshal 0
-#define Delegate_EndInvoke_ref_marshal 0
-#define Delegate_EndInvoke_managedValue_marshal 0
-
-#endif /* HAVE_LIBFFI */
-
- /*
- * Table of functions pointers for each possible return type.
- */
-typedef struct _tagInternalFuncs
-{
- void *void_func;
- void *sbyte_func;
- void *byte_func;
- void *short_func;
- void *ushort_func;
- void *int_func;
- void *uint_func;
- void *long_func;
- void *ulong_func;
- void *float_func;
- void *double_func;
- void *nativeFloat_func;
- void *typedref_Func;
- void *ref_func;
- void *managedValue_func;
-}
-InternalFuncs;
-
-#define DEFINE_FUNCS_TABLE(prefix) \
- static InternalFuncs FuncsFor_Delegate_##prefix =\
- {
\
- Delegate_##prefix##_void,
\
- Delegate_##prefix##_sbyte,
\
- Delegate_##prefix##_byte,
\
- Delegate_##prefix##_short,
\
- Delegate_##prefix##_ushort,
\
- Delegate_##prefix##_int,
\
- Delegate_##prefix##_uint,
\
- Delegate_##prefix##_long,
\
- Delegate_##prefix##_ulong,
\
- Delegate_##prefix##_float,
\
- Delegate_##prefix##_double,
\
- Delegate_##prefix##_nativeFloat,
\
- Delegate_##prefix##_typedref, \
- Delegate_##prefix##_ref,
\
- Delegate_##prefix##_managedValue
\
- };
-
-#define DEFINE_MARSHAL_FUNCS_TABLE(prefix) \
- static InternalFuncs MarshalFuncsFor_Delegate_##prefix =\
- {
\
- Delegate_##prefix##_void_marshal, \
- Delegate_##prefix##_sbyte_marshal, \
- Delegate_##prefix##_byte_marshal, \
- Delegate_##prefix##_short_marshal, \
- Delegate_##prefix##_ushort_marshal, \
- Delegate_##prefix##_int_marshal,
\
- Delegate_##prefix##_uint_marshal, \
- Delegate_##prefix##_long_marshal, \
- Delegate_##prefix##_ulong_marshal, \
- Delegate_##prefix##_float_marshal, \
- Delegate_##prefix##_double_marshal, \
- Delegate_##prefix##_nativeFloat_marshal, \
- Delegate_##prefix##_typedref_marshal, \
- Delegate_##prefix##_ref_marshal,
\
- Delegate_##prefix##_managedValue_marshal \
- };
+ /* Get the AsyncResult.BeginInvoke method */
+ asyncResultCtorInfo = _GetMethod(asyncResultClass, ".ctor", 0);
+ if(asyncResultCtorInfo == 0)
+ {
+ return IL_CODER_END_TOO_BIG;
+ }
-/*
- * Define function table for each return type for Delegate.Invoke.
- */
-DEFINE_FUNCS_TABLE(Invoke)
+ if(!_ILCoderCreateSimpleArrayType(method,
+
ILType_FromClass(objectClassInfo),
+
&arrayType, &arrayClass))
+ {
+ /* Ran out of memory trying to create "System.Delegate"
*/
+ return IL_CODER_END_TOO_BIG;
+ }
-/*
- * Define marshalling function table for each return type for Delegate.Invoke.
- */
-DEFINE_MARSHAL_FUNCS_TABLE(Invoke)
+ ILMemZero(&code, sizeof(ILMethodCode));
+ if(numParams > 2)
+ {
+ /*
+ * The delegate has arguments so we'll need an array
for the
+ * boxed arguments.
+ */
+ locals[0] = arrayType;
+ code.localVarSig = _ILCoderCreateLocalSignature(coder,
image, locals, 1);
+ if(!code.localVarSig)
+ {
+ /* Ran out of memory trying to create te locals
signature */
+ return IL_CODER_END_TOO_BIG;
+ }
+ }
+ code.maxStack = 4;
-/*
- * Define function table for each return type for Delegate.EndInvoke.
- */
-DEFINE_FUNCS_TABLE(EndInvoke)
+ ILMemZero(&prefixInfo, sizeof(ILCoderPrefixInfo));
+ if(!ILCoderSetup(coder, start, method, &code, coderExceptions,
0))
+ {
+ /* The coder setup failed */
+ return IL_CODER_END_TOO_BIG;
+ }
-/*
- * Define marshalling function table for each return type for
Delegate.EndInvoke.
- */
-DEFINE_MARSHAL_FUNCS_TABLE(EndInvoke)
+ if(numParams > 2)
+ {
+ ILUInt32 currentParam;
+ ILUInt32 currentLabel;
+ ILExecThread *thread;
+
+ thread = ILExecThreadCurrent();
+ /*
+ * Setup the labels used to handle byref arguments.
+ */
+ currentLabel = 0;
+
+ /*
+ * We have arguments so create an array to hold the
+ * boxed values.
+ * Load the number of elements for the array to be
created on the stack.
+ */
+ _ILCoderLoadInt32Constant(coder, numParams - 2);
+ /*
+ * Create the array for the params.
+ */
+ ILCoderNewArray(coder, arrayType, arrayClass,
ILEngineType_I4);
+ /*
+ * Save the array in the local slot 0
+ */
+ ILCoderStoreLocal(coder, 0, ILEngineType_O, locals[0]);
+ currentParam = 1;
+ while(currentParam <= (numParams - 2))
+ {
+ ILType *paramType;
+
+ paramType = ILTypeGetParam(signature,
currentParam);
+ if(ILType_IsRef(paramType))
+ {
+ ILType *refType;
+ ILClass *refClassInfo;
+ int refTypeIsValue;
+
+ refType = ILType_Ref(paramType);
+ refClassInfo = ILClassFromType(image,
0, refType, 0);
+ if(!refClassInfo)
+ {
+ return IL_CODER_END_TOO_BIG;
+ }
+ refTypeIsValue = ILTypeIsValue(refType);
+ /*
+ * Load the argument on the stack.
+ */
+ _ILCoderLoadArgs(coder, stack, method,
signature,
+
currentParam, currentParam);
+ ILCoderBranch(coder, IL_OP_BRFALSE,
currentLabel + 1,
+
ILEngineType_O, ILEngineType_O);
+ /*
+ * Load the array and the index on the
stack for the
+ * store to the array.
+ */
+ ILCoderLoadLocal(coder, 0, locals[0]);
+ _ILCoderLoadInt32Constant(coder,
currentParam - 1);
+ if(refTypeIsValue)
+ {
+ /*
+ * Load the managed pointer on
the stack.
+ */
+ _ILCoderLoadArgs(coder,
&stack[2], method, signature,
+
currentParam, currentParam);
+ /*
+ * And box the value the
pointer references.
+ */
+
if(!_ILCoderBoxPtr(_ILExecThreadProcess(thread),
+
refType, refClassInfo, 0))
+ {
+ return
IL_CODER_END_TOO_BIG;
+ }
+ }
+ else
+ {
+ /*
+ * Load the object reference
from the pointer.
+ */
+ _ILCoderLoadArgs(coder,
&stack[2], method, signature,
+
currentParam, currentParam);
+ /*
+ * And get the referenced
object.
+ */
+ ILCoderPtrAccess(coder,
IL_OP_LDIND_REF, &prefixInfo);
+ }
+ /*
+ * Store the pointer on the stack in
the array.
+ */
+ ILCoderArrayAccess(coder,
IL_OP_STELEM_REF,
+
ILEngineType_I4,
+
ILType_FromClass(objectClassInfo),
+
&prefixInfo);
+ ILCoderBranch(coder, IL_OP_BR,
currentLabel + 2,
+
ILEngineType_O, ILEngineType_O);
+ ILCoderLabel(coder, currentLabel + 1);
+ /*
+ * Handle the case where the ref
pointer is null.
+ */
+ /*
+ * Load the array and the index on the
stack for the
+ * store to the array.
+ */
+ ILCoderLoadLocal(coder, 0, locals[0]);
+ _ILCoderLoadInt32Constant(coder,
currentParam - 1);
+ if(refTypeIsValue)
+ {
+ /*
+ * TODO: Create a 0 boxed value
+ */
+ ILCoderConstant(coder,
IL_OP_LDNULL, 0);
+ }
+ else
+ {
+ /*
+ * Load a null reference and
store it in the array.
+ */
+ ILCoderConstant(coder,
IL_OP_LDNULL, 0);
+ }
+ ILCoderArrayAccess(coder,
IL_OP_STELEM_REF,
+
ILEngineType_I4,
+
ILType_FromClass(objectClassInfo),
+
&prefixInfo);
+ ILCoderLabel(coder, currentLabel + 2);
+ currentLabel += 2;
+ }
+ else
+ {
+ /*
+ * Load the array and the index on the
stack for the
+ * store to the array.
+ */
+ ILCoderLoadLocal(coder, 0, locals[0]);
+ _ILCoderLoadInt32Constant(coder,
currentParam - 1);
+ if(ILTypeIsValue(paramType))
+ {
+ ILClass *paramClassInfo;
+ ILExecThread *thread;
+
+ thread = ILExecThreadCurrent();
+ paramClassInfo =
ILClassFromType(image, 0, paramType, 0);
+ if(!paramClassInfo)
+ {
+ return
IL_CODER_END_TOO_BIG;
+ }
+ /*
+ * Get the address of the
argument.
+ */
+ ILCoderAddrOfArg(coder,
currentParam);
+
+ /*
+ * And box the value the
pointer references.
+ */
+
if(!_ILCoderBoxPtr(_ILExecThreadProcess(thread),
+
paramType, paramClassInfo, 0))
+ {
+ return
IL_CODER_END_TOO_BIG;
+ }
+ }
+ else
+ {
+ /*
+ * Load the argument on the
stack.
+ */
+ _ILCoderLoadArgs(coder,
&stack[2], method, signature,
+
currentParam, currentParam);
+ }
+ ILCoderArrayAccess(coder,
IL_OP_STELEM_REF, ILEngineType_I4,
+
ILType_FromClass(objectClassInfo),
+
&prefixInfo);
+ }
+ ++currentParam;
+ }
+ }
-static int _ILGetInternalDelegateFunc(ILInternalInfo *info, ILType *returnType,
- InternalFuncs *internalFuncs, InternalFuncs *internalMarshalFuncs)
-{
- ILType *type;
+ /*
+ * Create the AsyncResult object.
+ */
+ /*
+ * The current delegate object.
+ */
+ _ILCoderLoadArgs(coder, stack, method, signature, 0, 0);
+ /*
+ * The array with the arguments
+ */
+ if(numParams > 2)
+ {
+ ILCoderLoadLocal(coder, 0, locals[0]);
+ }
+ else
+ {
+ /*
+ * No arguments so the array to hold the values is not
needed.
+ */
+ ILCoderConstant(coder, IL_OP_LDNULL, 0);
+ }
+ stack[1].typeInfo = arrayType;
+ stack[1].engineType = ILEngineType_O;
+ /*
+ * The callback and the state object.
+ */
+ _ILCoderLoadArgs(coder, &stack[2], method, signature, numParams
- 1, numParams);
+
+ coderMethodInfo.args = stack;
+ coderMethodInfo.numBaseArgs = 4;
+ coderMethodInfo.numVarArgs = 0;
+ coderMethodInfo.hasParamArray = 0;
+ coderMethodInfo.tailCall = 0;
+ coderMethodInfo.signature =
ILMethod_Signature(asyncResultCtorInfo);
+
+ ILCoderCallCtor(coder, &coderMethodInfo, asyncResultCtorInfo);
+ /*
+ * Return the AsyncResult to the caller.
+ */
+ ILCoderReturnInsn(coder, _ILTypeToEngineType(returnType),
+ returnType);
+ /* Mark the end of the method */
+ ILCoderMarkEnd(coder);
+
+ return ILCoderFinish(coder);
+ }
+ return IL_CODER_END_TOO_BIG;
+}
- type = ILTypeGetEnumType(returnType);
+static int _ILCoderGenDelegateEndInvoke(ILCoder *coder, ILMethod *method,
+
unsigned char **start,
+
ILCoderExceptions *coderExceptions)
+{
+ ILType *signature;
- if(ILType_IsPrimitive(type))
+ signature = ILMethod_Signature(method);
+ if(signature)
{
- /* The delegate returns a primitive type */
- switch(ILType_ToElement(type))
+ ILImage *image;
+ ILClass *delegateClass;
+ ILType *arrayType;
+ ILClass *arrayClass;
+ ILClass *objectClassInfo;
+ ILType *returnType;
+ ILClass *returnClass;
+ ILClass *asyncResultClass;
+ ILMethod *asyncEndInvokeMethodInfo;
+ ILMethod *invokeMethodInfo;
+ ILType *invokeSignature;
+ ILUInt32 numParams;
+ ILMethodCode code;
+ ILType *locals[2];
+
+ image = ILProgramItem_Image(method);
+ numParams = ILTypeNumParams(signature);
+ returnType = ILTypeGetReturn(signature);
+ delegateClass = ILMethod_Owner(method);
+ ILMemZero(&code, sizeof(ILMethodCode));
+ objectClassInfo = ILClassResolveSystem(image, 0, "Object",
"System");
+ if(!objectClassInfo)
{
- case IL_META_ELEMTYPE_VOID:
- {
- info->func = internalFuncs->void_func;
- info->marshal = internalMarshalFuncs->void_func;
- }
- break;
+ /* Ran out of memory trying to create "System.Delegate"
*/
+ return IL_CODER_END_TOO_BIG;
+ }
- case IL_META_ELEMTYPE_BOOLEAN:
- case IL_META_ELEMTYPE_I1:
- {
- info->func = internalFuncs->sbyte_func;
- info->marshal =
internalMarshalFuncs->sbyte_func;
- }
- break;
+ asyncResultClass = ILClassResolveSystem(image, 0, "AsyncResult",
+
"System.Runtime.Remoting.Messaging");
+ if(!asyncResultClass)
+ {
+ /* Ran out of memory trying to create "System.Delegate"
*/
+ return IL_CODER_END_TOO_BIG;
+ }
+ /* Get the AsyncResult.EndInvoke method */
+ asyncEndInvokeMethodInfo = _GetMethod(asyncResultClass,
"EndInvoke", 0);
+ if(asyncEndInvokeMethodInfo == 0)
+ {
+ return IL_CODER_END_TOO_BIG;
+ }
- case IL_META_ELEMTYPE_U1:
- {
- info->func = internalFuncs->byte_func;
- info->marshal = internalMarshalFuncs->byte_func;
- }
- break;
+ returnClass = ILClassFromType(image, 0, returnType, 0);
+ if(!returnClass)
+ {
+ return IL_CODER_END_TOO_BIG;
+ }
- case IL_META_ELEMTYPE_I2:
- {
- info->func = internalFuncs->short_func;
- info->marshal =
internalMarshalFuncs->short_func;
- }
- break;
+ invokeMethodInfo = _GetMethod(delegateClass, "Invoke", 0);
+ if(!invokeMethodInfo)
+ {
+ return IL_CODER_END_TOO_BIG;
+ }
+ invokeSignature = ILMethod_Signature(invokeMethodInfo);
- case IL_META_ELEMTYPE_U2:
- case IL_META_ELEMTYPE_CHAR:
- {
- info->func = internalFuncs->ushort_func;
- info->marshal =
internalMarshalFuncs->ushort_func;
- }
- break;
+ if(!_ILCoderCreateSimpleArrayType(method,
+
ILType_FromClass(objectClassInfo),
+
&arrayType, &arrayClass))
+ {
+ /* Ran out of memory trying to create "System.Delegate"
*/
+ return IL_CODER_END_TOO_BIG;
+ }
- case IL_META_ELEMTYPE_I4:
- #ifdef IL_NATIVE_INT32
- case IL_META_ELEMTYPE_I:
- #endif
- {
- info->func = internalFuncs->int_func;
- info->marshal = internalMarshalFuncs->int_func;
- }
- break;
+ locals[0] = arrayType;
+ if(numParams > 1 && returnType != ILType_Void)
+ {
+ locals[1] = ILType_FromClass(objectClassInfo);
+ code.localVarSig = _ILCoderCreateLocalSignature(coder,
image, locals, 2);
+ }
+ else
+ {
+ code.localVarSig = _ILCoderCreateLocalSignature(coder,
image, locals, 1);
+ }
+ if(!code.localVarSig)
+ {
+ /* Ran out of memory trying to create te locals
signature */
+ return IL_CODER_END_TOO_BIG;
+ }
- case IL_META_ELEMTYPE_U4:
- #ifdef IL_NATIVE_INT32
- case IL_META_ELEMTYPE_U:
- #endif
+ {
+ ILCoderPrefixInfo prefixInfo;
+ ILCoderMethodInfo coderMethodInfo;
+ ILEngineStackItem stack[3];
+
+ ILMemZero(&prefixInfo, sizeof(ILCoderPrefixInfo));
+ code.maxStack = 3;
+ if(!ILCoderSetup(coder, start, method, &code,
coderExceptions, 0))
{
- info->func = internalFuncs->uint_func;
- info->marshal = internalMarshalFuncs->uint_func;
+ /* The coder setup failed */
+ return IL_CODER_END_TOO_BIG;
}
- break;
-
- case IL_META_ELEMTYPE_I8:
- #ifdef IL_NATIVE_INT64
- case IL_META_ELEMTYPE_I:
- #endif
+
+ if(numParams > 1)
{
- info->func = internalFuncs->long_func;
- info->marshal = internalMarshalFuncs->long_func;
+ /*
+ * We have byref arguments so create an array
to hold the
+ * boxed byref values.
+ * Load the number of elements for the array to
be created on the stack.
+ */
+ _ILCoderLoadInt32Constant(coder, numParams - 1);
+ /*
+ * Create the array for the out params.
+ */
+ ILCoderNewArray(coder, arrayType, arrayClass,
ILEngineType_I4);
}
- break;
-
- case IL_META_ELEMTYPE_U8:
- #ifdef IL_NATIVE_INT64
- case IL_META_ELEMTYPE_U:
- #endif
+ else
{
- info->func = internalFuncs->ulong_func;
- info->marshal =
internalMarshalFuncs->ulong_func;
+ /*
+ * No ref arguments so the array to hold the
values is not needed.
+ */
+ ILCoderConstant(coder, IL_OP_LDNULL, 0);
}
- break;
-
- case IL_META_ELEMTYPE_R4:
+ /*
+ * Save the array in the local slot 0
+ */
+ ILCoderStoreLocal(coder, 0, ILEngineType_O, locals[0]);
+
+ /*
+ * Call the IAsyncResult.EndInvoke method.
+ */
+ _ILCoderLoadArgs(coder, stack, method, signature,
+ numParams, numParams);
+ ILCoderLoadLocal(coder, 0, locals[0]);
+ stack[1].typeInfo = arrayType;
+ stack[1].engineType = ILEngineType_O;
+ _ILCoderSetReturnType(&stack[2], returnType);
+
+ coderMethodInfo.args = stack;
+ coderMethodInfo.numBaseArgs = 2;
+ coderMethodInfo.numVarArgs = 0;
+ coderMethodInfo.hasParamArray = 0;
+ coderMethodInfo.tailCall = 0;
+ coderMethodInfo.signature =
ILMethod_Signature(asyncEndInvokeMethodInfo);
+
+ ILCoderCallMethod(coder, &coderMethodInfo, &(stack[2]),
+
asyncEndInvokeMethodInfo);
+
+ if(returnType == ILType_Void)
{
- info->func = internalFuncs->float_func;
- info->marshal =
internalMarshalFuncs->float_func;
+ /*
+ * Pop the object returned from the stack.
+ */
+ ILCoderPop(coder, ILEngineType_O,
ILType_Invalid);
}
- break;
-
- case IL_META_ELEMTYPE_R8:
+ if(numParams > 1)
{
- info->func = internalFuncs->double_func;
- info->marshal =
internalMarshalFuncs->double_func;
+ ILUInt32 paramCount;
+ ILUInt32 paramNum;
+ ILUInt32 currentParam;
+
+ if(returnType != ILType_Void)
+ {
+ /*
+ * Save the object with the return
value in the local slot 1
+ */
+ ILCoderStoreLocal(coder, 1,
ILEngineType_O, locals[1]);
+ }
+ /*
+ * Copy the ref values.
+ */
+ paramCount = ILTypeNumParams(invokeSignature);
+ paramNum = 1;
+ currentParam = 0;
+ while(paramNum <= paramCount)
+ {
+ ILType *paramType;
+
+ paramType =
ILTypeGetParam(invokeSignature, paramNum);
+ if(ILType_IsRef(paramType))
+ {
+ ILType *refType;
+ ILClass *refClass;
+
+ refType = ILType_Ref(paramType);
+ refType =
ILTypeGetEnumType(refType);
+ refClass =
ILClassFromType(image, 0, refType, 0);
+ if(!refClass)
+ {
+ return
IL_CODER_END_TOO_BIG;
+ }
+
+ /*
+ * Load the ref address for
this argument on the stack
+ * for the store to this
addtess.
+ */
+ _ILCoderLoadArgs(coder, stack,
method, signature,
+
currentParam + 1, currentParam + 1);
+ /*
+ * Load the array on the stack.
+ */
+ ILCoderLoadLocal(coder, 0,
locals[0]);
+ /*
+ * Load the index on the stack.
+ */
+
_ILCoderLoadInt32Constant(coder, currentParam);
+ /*
+ * And get the object from the
array.
+ */
+ ILCoderArrayAccess(coder,
IL_OP_LDELEM_REF,
+
ILEngineType_I4,
+
ILType_FromClass(objectClassInfo),
+
&prefixInfo);
+ /*
+ * Cast the class to the
expected class and throw an
+ * exception if that's not
possible.
+ */
+ ILCoderCastClass(coder,
refClass, 1, &prefixInfo);
+ if(ILType_IsPrimitive(refType))
+ {
+ /*
+ * Unbox the object to
produce a managed pointer
+ */
+ ILCoderUnbox(coder,
refClass, &prefixInfo);
+
switch(ILType_ToElement(refType))
+ {
+ case
IL_META_ELEMTYPE_I1:
+ {
+
ILCoderPtrAccess(coder, IL_OP_LDIND_I1,
+
&prefixInfo);
+
ILCoderPtrAccess(coder, IL_OP_STIND_I1,
+
&prefixInfo);
+ }
+ break;
+
+ case
IL_META_ELEMTYPE_BOOLEAN:
+ case
IL_META_ELEMTYPE_U1:
+ {
+
ILCoderPtrAccess(coder, IL_OP_LDIND_U1,
+
&prefixInfo);
+
ILCoderPtrAccess(coder, IL_OP_STIND_I1,
+
&prefixInfo);
+ }
+ break;
+
+ case
IL_META_ELEMTYPE_I2:
+ {
+
ILCoderPtrAccess(coder, IL_OP_LDIND_I2,
+
&prefixInfo);
+
ILCoderPtrAccess(coder, IL_OP_STIND_I2,
+
&prefixInfo);
+ }
+ break;
+
+ case
IL_META_ELEMTYPE_CHAR:
+ case
IL_META_ELEMTYPE_U2:
+ {
+
ILCoderPtrAccess(coder, IL_OP_LDIND_U2,
+
&prefixInfo);
+
ILCoderPtrAccess(coder, IL_OP_STIND_I2,
+
&prefixInfo);
+ }
+ break;
+
+ case
IL_META_ELEMTYPE_I4:
+ {
+
ILCoderPtrAccess(coder, IL_OP_LDIND_I4,
+
&prefixInfo);
+
ILCoderPtrAccess(coder, IL_OP_STIND_I4,
+
&prefixInfo);
+ }
+ break;
+
+ case
IL_META_ELEMTYPE_U4:
+ {
+
ILCoderPtrAccess(coder, IL_OP_LDIND_U4,
+
&prefixInfo);
+
ILCoderPtrAccess(coder, IL_OP_STIND_I4,
+
&prefixInfo);
+ }
+ break;
+
+ case
IL_META_ELEMTYPE_I8:
+ case
IL_META_ELEMTYPE_U8:
+ {
+
ILCoderPtrAccess(coder, IL_OP_LDIND_I8,
+
&prefixInfo);
+
ILCoderPtrAccess(coder, IL_OP_STIND_I8,
+
&prefixInfo);
+ }
+ break;
+
+ case
IL_META_ELEMTYPE_I:
+ case
IL_META_ELEMTYPE_U:
+ {
+
ILCoderPtrAccess(coder, IL_OP_LDIND_I,
+
&prefixInfo);
+
ILCoderPtrAccess(coder, IL_OP_STIND_I,
+
&prefixInfo);
+ }
+ break;
+
+ case
IL_META_ELEMTYPE_R4:
+ {
+
ILCoderPtrAccess(coder, IL_OP_LDIND_R4,
+
&prefixInfo);
+
ILCoderPtrAccess(coder, IL_OP_STIND_R4,
+
&prefixInfo);
+ }
+ break;
+
+ case
IL_META_ELEMTYPE_R8:
+ {
+
ILCoderPtrAccess(coder, IL_OP_LDIND_R8,
+
&prefixInfo);
+
ILCoderPtrAccess(coder, IL_OP_STIND_R8,
+
&prefixInfo);
+ }
+ break;
+
+ default:
+ {
+ /*
+ * Copy
the value type.
+ */
+
ILCoderCopyObject(coder, ILEngineType_M,
+
ILEngineType_M, refClass);
+ }
+ }
+ }
+ else
if(ILType_IsValueType(refType))
+ {
+ /*
+ * Unbox the object to
produce a managed pointer
+ */
+ ILCoderUnbox(coder,
refClass, &prefixInfo);
+ /*
+ * And copy the value
type.
+ */
+
ILCoderCopyObject(coder, ILEngineType_M,
+
ILEngineType_M, refClass);
+ }
+ else
+ {
+ /*
+ * Everything else is
an object reference.
+ */
+ ILCoderPtrAccess(coder,
IL_OP_STIND_REF,
+
&prefixInfo);
+ }
+ ++ currentParam;
+ }
+ ++paramNum;
+ }
+ if(returnType != ILType_Void)
+ {
+ /*
+ * Reload the return value on the stack.
+ */
+ ILCoderLoadLocal(coder, 1, locals[1]);
+ }
}
- break;
-
- case IL_META_ELEMTYPE_R:
+ if(returnType != ILType_Void)
{
- info->func = internalFuncs->nativeFloat_func;
- info->marshal =
internalMarshalFuncs->nativeFloat_func;
+ /*
+ * Get the return value.
+ * If the value returned is a value type we
have to unbox the
+ * value prior to returning it.
+ */
+ ILCoderCastClass(coder, returnClass, 1,
&prefixInfo);
+ if(!_ILCoderUnboxValue(coder, image,
returnType, &prefixInfo))
+ {
+ return IL_CODER_END_TOO_BIG;
+ }
+ ILCoderReturnInsn(coder,
_ILTypeToEngineType(returnType),
+ returnType);
}
- break;
-
- case IL_META_ELEMTYPE_TYPEDBYREF:
+ else
{
- info->func = internalFuncs->typedref_Func;
- info->marshal =
internalMarshalFuncs->typedref_Func;
+ ILCoderReturnInsn(coder, ILEngineType_Invalid,
ILType_Void);
}
- break;
-
- default: return 0;
+ /* Mark the end of the method */
+ ILCoderMarkEnd(coder);
+
+ return ILCoderFinish(coder);
}
}
- else if(ILType_IsValueType(type))
- {
- /* The delegate returns a managed value */
- info->func = internalFuncs->managedValue_func;
- info->marshal = internalMarshalFuncs->managedValue_func;
- }
- else
- {
- /* Everything else is assumed to be a pointer */
- info->func = internalFuncs->ref_func;
- info->marshal = internalMarshalFuncs->ref_func;;
- }
+ return IL_CODER_END_TOO_BIG;
+}
- return 1;
+#ifdef IL_USE_JIT
+
+static ILObject *Delegate_BeginInvoke(ILExecThread *thread, ILObject *_this)
+{
+ /* This is a dummy because the real function is generated by the */
+ /* jit coder. */
+ return 0;
}
+#endif /* IL_USE_JIT */
+
int _ILGetInternalDelegate(ILMethod *method, int *isCtor,
ILInternalInfo *info)
{
@@ -1119,31 +1500,38 @@ int _ILGetInternalDelegate(ILMethod *method, int
*isCtor,
if(_ILLookupTypeMatch(type, "(ToSystem.Object;j)V"))
{
*isCtor = 1;
- info->func = (void *)Delegate_ctor;
- info->marshal = (void *)Delegate_ctor_marshal;
+ info->un.gen = _ILCoderGenDelegateCtor;
+ info->flags = _IL_INTERNAL_GENCODE;
return 1;
}
}
else if(!strcmp(name, "Invoke") && ILType_HasThis(type))
{
/* This is the delegate invocation method */
+ ILClass *parent;
*isCtor = 0;
- return _ILGetInternalDelegateFunc
- (
- info,
- ILTypeGetReturn(type),
- &FuncsFor_Delegate_Invoke,
- &MarshalFuncsFor_Delegate_Invoke
- );
+ parent = ILClass_ParentClass(classInfo);
+ name = ILClass_Name(parent);
+ if(!strcmp(name, "MulticastDelegate"))
+ {
+ info->un.gen = _ILCoderGenMulticastDelegateInvoke;
+ info->flags = _IL_INTERNAL_GENCODE;
+ return 1;
+ }
+ if(!strcmp(name, "Delegate"))
+ {
+ info->un.gen = _ILCoderGenDelegateInvoke;
+ info->flags = _IL_INTERNAL_GENCODE;
+ return 1;
+ }
}
else if(!strcmp(name, "BeginInvoke"))
{
*isCtor = 0;
- info->func = (void *)Delegate_BeginInvoke;
- info->marshal = (void *)0;
-
+ info->un.gen = (void *)_ILCoderGenDelegateBeginInvoke;
+ info->flags = _IL_INTERNAL_GENCODE;
return 1;
}
else if(!strcmp(name, "EndInvoke"))
@@ -1151,13 +1539,9 @@ int _ILGetInternalDelegate(ILMethod *method, int *isCtor,
/* This is the delegate invocation method */
*isCtor = 0;
- return _ILGetInternalDelegateFunc
- (
- info,
- ILTypeGetReturn(type),
- &FuncsFor_Delegate_EndInvoke,
- &MarshalFuncsFor_Delegate_EndInvoke
- );
+ info->un.gen = (void *)_ILCoderGenDelegateEndInvoke;
+ info->flags = _IL_INTERNAL_GENCODE;
+ return 1;
}
return 0;
diff --git a/engine/verify.c b/engine/verify.c
index b7a8572..5a978c3 100644
--- a/engine/verify.c
+++ b/engine/verify.c
@@ -19,6 +19,7 @@
*/
#include "engine.h"
+#include "coder.h"
#include "lib_defs.h"
#include "il_coder.h"
#include "il_opcodes.h"
diff --git a/engine/verify_call.c b/engine/verify_call.c
index 9bd1a70..02a8f5b 100644
--- a/engine/verify_call.c
+++ b/engine/verify_call.c
@@ -1577,22 +1577,6 @@ static int GetArrayClearHandler(ILExecProcess *process,
return -1;
}
-/*
- * Set return type information within a stack item.
- */
-static void SetReturnType(ILEngineStackItem *item, ILType *returnType)
-{
- item->engineType = TypeToEngineType(returnType);
- if(item->engineType != ILEngineType_M)
- {
- item->typeInfo = returnType;
- }
- else
- {
- item->typeInfo = ILType_Ref(ILTypeStripPrefixes(returnType));
- }
-}
-
#elif defined(IL_VERIFY_LOCALS)
ILType *methodSignature;
@@ -1681,14 +1665,7 @@ case IL_OP_CALL:
if(numParams >= 0)
{
returnType = ILTypeGetReturn(methodSignature);
- if(returnType != ILType_Void)
- {
- SetReturnType(&(stack[stackSize]),
returnType);
- }
- else
- {
- stack[stackSize].engineType =
ILEngineType_Invalid;
- }
+ _ILCoderSetReturnType(&(stack[stackSize]),
returnType);
callNonvirtualFromVirtual:
@@ -2271,14 +2248,7 @@ case IL_OP_CALLI:
if(numParams >= 0)
{
returnType = ILTypeGetReturn(methodSignature);
- if(returnType != ILType_Void)
- {
- SetReturnType(&(stack[stackSize]), returnType);
- }
- else
- {
- stack[stackSize].engineType =
ILEngineType_Invalid;
- }
+ _ILCoderSetReturnType(&(stack[stackSize]), returnType);
ILCoderCallIndirect(coder, &callInfo,
&(stack[stackSize]));
stackSize -= (ILUInt32)numParams;
if(returnType != ILType_Void)
@@ -2452,8 +2422,9 @@ case IL_OP_CALLVIRT:
}
else
{
-
if(BoxPtr(_ILExecThreadProcess(thread),
-
constrainedType, thisClass, numParams))
+
if(_ILCoderBoxPtr(_ILExecThreadProcess(thread),
+
constrainedType, thisClass,
+
numParams))
{
item->engineType = ILEngineType_O;
item->typeInfo
= ILType_FromClass(thisClass);
@@ -2477,14 +2448,7 @@ case IL_OP_CALLVIRT:
if(numParams >= 0)
{
returnType = ILTypeGetReturn(methodSignature);
- if(returnType != ILType_Void)
- {
- SetReturnType(&(stack[stackSize]),
returnType);
- }
- else
- {
- stack[stackSize].engineType =
ILEngineType_Invalid;
- }
+ _ILCoderSetReturnType(&(stack[stackSize]),
returnType);
if(!ILMethod_IsVirtual(methodInfo) ||
callNonVirtual)
{
goto callNonvirtualFromVirtual;
diff --git a/engine/verify_obj.c b/engine/verify_obj.c
index ea30c7c..f521afe 100644
--- a/engine/verify_obj.c
+++ b/engine/verify_obj.c
@@ -76,144 +76,6 @@ static ILField *GetFieldToken(ILExecProcess *process,
ILMethod *method, unsigned
}
/*
- * Process a "box" operation on a value. Returns zero if
- * invalid parameters.
- */
-static int BoxValue(ILExecProcess *process, ILEngineType valueType,
- ILType *typeInfo, ILClass *boxClass)
-{
- ILUInt32 size;
- ILType *rawType;
-
- /* Determine the raw version of the boxing type */
- rawType = ILTypeGetEnumType(ILClassToType(boxClass));
-
- /* Get the size of the value type */
- size = _ILSizeOfTypeLocked(process, rawType);
-
- /* Determine how to box the value */
- if(ILType_IsPrimitive(rawType))
- {
- if(valueType == ILEngineType_I4)
- {
- /* Determine if we are boxing a byte, short, or int
- based on the raw type */
- switch(ILType_ToElement(rawType))
- {
- case IL_META_ELEMTYPE_BOOLEAN:
- case IL_META_ELEMTYPE_I1:
- case IL_META_ELEMTYPE_U1:
- {
- ILCoderBoxSmaller(process->coder,
boxClass, valueType, ILType_Int8);
- return 1;
- }
- /* Not reached */
-
- case IL_META_ELEMTYPE_I2:
- case IL_META_ELEMTYPE_U2:
- case IL_META_ELEMTYPE_CHAR:
- {
- ILCoderBoxSmaller(process->coder,
boxClass, valueType, ILType_Int16);
- return 1;
- }
- /* Not reached */
-
- case IL_META_ELEMTYPE_I4:
- case IL_META_ELEMTYPE_U4:
- #ifdef IL_NATIVE_INT32
- case IL_META_ELEMTYPE_I:
- case IL_META_ELEMTYPE_U:
- #endif
- {
- ILCoderBox(process->coder, boxClass,
valueType, size);
- return 1;
- }
- /* Not reached */
- }
- }
- else if(valueType == ILEngineType_I)
- {
- /* Box a native integer */
- switch(ILType_ToElement(rawType))
- {
- case IL_META_ELEMTYPE_I:
- case IL_META_ELEMTYPE_U:
- {
- ILCoderBox(process->coder, boxClass,
valueType, size);
- return 1;
- }
- /* Not reached */
- }
- }
- else if(valueType == ILEngineType_I8)
- {
- /* Box a 64-bit integer */
- switch(ILType_ToElement(rawType))
- {
- case IL_META_ELEMTYPE_I8:
- case IL_META_ELEMTYPE_U8:
- {
- ILCoderBox(process->coder, boxClass,
valueType, size);
- return 1;
- }
- /* Not reached */
- }
- }
- else if(valueType == ILEngineType_F)
- {
- /* Determine if we are boxing a float or double
- based on the size of the value type */
- if(rawType == ILType_Float32)
- {
- ILCoderBoxSmaller(process->coder, boxClass,
valueType, ILType_Float32);
- return 1;
- }
- else if(rawType == ILType_Float64 ||
- rawType == ILType_Float)
- {
- ILCoderBoxSmaller(process->coder, boxClass,
valueType, ILType_Float64);
- return 1;
- }
- }
- }
- else if(valueType == ILEngineType_MV ||
- valueType == ILEngineType_TypedRef)
- {
- if(ILTypeIdentical(typeInfo, ILClassToType(boxClass)))
- {
- ILCoderBox(process->coder, boxClass, valueType, size);
- return 1;
- }
- }
- return 0;
-}
-
-/*
- * Process a "box" operation on a value. Returns zero if
- * invalid parameters.
- */
-static int BoxPtr(ILExecProcess *process, ILType *typeInfo,
- ILClass *boxClass, ILUInt32 pos)
-{
- ILUInt32 size;
- ILType *rawType;
-
- /* Determine the raw version of the boxing type */
- rawType = ILTypeGetEnumType(ILClassToType(boxClass));
-
- /* Get the size of the value type */
- size = _ILSizeOfTypeLocked(process, rawType);
-
- if(ILTypeIdentical(typeInfo, ILClassToType(boxClass)))
- {
- ILCoderBoxPtr(process->coder, boxClass, size, pos);
- return 1;
- }
-
- return 0;
-}
-
-/*
* Get a particular system value type.
*/
static ILType *GetSystemValueType(ILMethod *method, const char *name)
@@ -326,8 +188,9 @@ case IL_OP_BOX:
classInfo = GetClassToken(method, pc);
if(classInfo && ILClassIsValueType(classInfo))
{
- if(BoxValue(_ILExecThreadProcess(thread), stack[stackSize -
1].engineType,
- stack[stackSize - 1].typeInfo,
classInfo))
+ if(_ILCoderBoxValue(_ILExecThreadProcess(thread),
+ stack[stackSize -
1].engineType,
+ stack[stackSize -
1].typeInfo, classInfo))
{
stack[stackSize - 1].engineType = ILEngineType_O;
stack[stackSize - 1].typeInfo =
ILType_FromClass(classInfo);
diff --git a/engine/verify_var.c b/engine/verify_var.c
index 6b6bc19..a2cb2b4 100644
--- a/engine/verify_var.c
+++ b/engine/verify_var.c
@@ -20,48 +20,8 @@
#if defined(IL_VERIFY_GLOBALS)
-/*
- * Get the type of a parameter to the current method.
- */
-static ILType *GetParamType(ILType *signature, ILMethod *method, ILUInt32 num)
-{
- ILClass *owner;
- ILType *synthetic;
- if(ILType_HasThis(signature))
- {
- /* This method has a "this" parameter */
- if(!num)
- {
- owner = ILMethod_Owner(method);
- if(ILClassIsValueType(owner))
- {
- /* The "this" parameter is a value type, which
is
- being passed as a managed pointer. Return
- ILType_Invalid to tell the caller that
special
- handling is required */
- return ILType_Invalid;
- }
- synthetic = ILClassGetSynType(owner);
- if(synthetic)
- {
- return synthetic;
- }
- else
- {
- return ILType_FromClass(owner);
- }
- }
- else
- {
- return ILTypeGetParam(signature, num);
- }
- }
- else
- {
- return ILTypeGetParam(signature, num + 1);
- }
-}
-
+ /* Nothing to do here */
+
#elif defined(IL_VERIFY_LOCALS)
ILUInt32 argNum;
@@ -77,7 +37,7 @@ case IL_OP_LDARG_0:
{
VERIFY_INSN_ERROR();
}
- stack[stackSize].typeInfo = GetParamType(signature, method, argNum);
+ stack[stackSize].typeInfo = _ILCoderGetParamType(signature, method,
argNum);
if(ILType_IsClass(stack[stackSize].typeInfo))
{
if(len >= 6 && pc[1] == IL_OP_LDFLD &&
@@ -144,7 +104,7 @@ checkLDArg:
{
VERIFY_INSN_ERROR();
}
- stack[stackSize].typeInfo = GetParamType(signature, method, argNum);
+ stack[stackSize].typeInfo = _ILCoderGetParamType(signature, method,
argNum);
checkLDArg2:
if(stack[stackSize].typeInfo == ILType_Invalid)
{
@@ -193,7 +153,7 @@ checkSTArg:
{
VERIFY_INSN_ERROR();
}
- type = GetParamType(signature, method, argNum);
+ type = _ILCoderGetParamType(signature, method, argNum);
if(type == ILType_Invalid)
{
/* Storing into the "this" argument of a value type method.
@@ -317,7 +277,7 @@ checkLDArgA:
{
VERIFY_INSN_ERROR();
}
- stack[stackSize].typeInfo = GetParamType(signature, method, argNum);
+ stack[stackSize].typeInfo = _ILCoderGetParamType(signature, method,
argNum);
if(stack[stackSize].typeInfo == ILType_Invalid)
{
/* Cannot take the address of the "this" parameter in
-----------------------------------------------------------------------
Summary of changes:
ChangeLog | 66 ++
engine/Makefile.am | 2 +
engine/coder.c | 264 +++++++
engine/coder.h | 68 ++
engine/convert.c | 204 ++++--
engine/engine.h | 47 +-
engine/internal.c | 24 +-
engine/jitc.c | 149 ++---
engine/jitc.h | 39 +
engine/jitc_call.c | 8 +-
engine/jitc_pinvoke.c | 16 +-
engine/jitc_setup.c | 2 +
engine/jitc_stack.c | 1 -
engine/lib_array.c | 224 ++++--
engine/lib_delegate.c | 2080 +++++++++++++++++++++++++++++--------------------
engine/verify.c | 1 +
engine/verify_call.c | 48 +-
engine/verify_obj.c | 143 +----
engine/verify_var.c | 52 +--
19 files changed, 2102 insertions(+), 1336 deletions(-)
create mode 100644 engine/coder.c
create mode 100644 engine/coder.h
hooks/post-receive
--
DotGNU Portable.NET engine, compilers and tools (pnet)
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [dotgnu-pnet-commits] [SCM] DotGNU Portable.NET engine, compilers and tools (pnet) branch, master, updated. 38f20fb9b1211606a5a15b16c64f28accc344951,
Klaus Treichel <=