Ejemplo n.º 1
0
/*
 * Convert an image into an assembly object.
 */
static ILObject *ImageToAssembly(ILExecThread *thread, ILImage *image)
{
	void *item;
	item = ILImageTokenInfo(image, (IL_META_TOKEN_ASSEMBLY | 1));
	if(item)
	{
		return _ILClrToObject(thread, item, "System.Reflection.Assembly");
	}
	/* TODO: if the image does not have an assembly manifest,
	   then look for the parent assembly */
	return 0;
}
Ejemplo n.º 2
0
/*
 * Output a table of exception matching directives.
 * Each table entry specifies a region of code for the
 * directive.  Whenever an exception occurs in this
 * region, the method will jump to the instructions
 * contained in the table entry.  These instructions
 * will typically call "finally" handlers, and then
 * attempt to match the exception against the rules.
 */
static void OutputExceptionTable(ILCoder *coder, ILMethod *method,
								 ILException *exceptions, int hasRethrow)
{
	ILUInt32 offset;
	ILUInt32 end;
	int isStatic;
	ILException *exception;
	ILClass *classInfo;
	
	/* Process all regions in the method */
	offset = 0;
	for(;;)
	{
		/* Find the end of the region that starts at "offset" */
		end = IL_MAX_UINT32;
		exception = exceptions;
		while(exception != 0)
		{
			if(offset < exception->tryOffset)
			{
				/* We are in the code before this exception region */
				if(end > exception->tryOffset)
				{
					end = exception->tryOffset;
				}
			}
			else if(offset >= exception->tryOffset &&
			        offset < (exception->tryOffset + exception->tryLength))
			{
				/* We are in code in the middle of this exception region */
				if(end > (exception->tryOffset + exception->tryLength))
				{
					end = exception->tryOffset + exception->tryLength;
				}
			}
			exception = exception->next;
		}
		if(end == IL_MAX_UINT32)
		{
			break;
		}

		/* Output the region information to the table */
		ILCoderTryHandlerStart(coder, offset, end);

		/* Output exception matching code for this region */
		exception = exceptions;
		while(exception != 0)
		{
			if(offset >= exception->tryOffset &&
			   offset < (exception->tryOffset + exception->tryLength))
			{
				if((exception->flags & (IL_META_EXCEPTION_FINALLY |
										IL_META_EXCEPTION_FAULT)) != 0)
				{
					/* Call a "finally" or "fault" clause */
					ILCoderFinally(coder, exception, exception->handlerOffset);					
				}
				else if((exception->flags & IL_META_EXCEPTION_FILTER) == 0)
				{
					/* Match against a "catch" clause */
					classInfo = ILProgramItemToClass
						((ILProgramItem *)ILImageTokenInfo
							(ILProgramItem_Image(method), exception->extraArg));

					ILCoderCatch(coder, exception, classInfo, hasRethrow);
				}
				else
				{
					/* TODO: handle a "filter" clause */
				}
			}
			exception = exception->next;
		}

		/* If execution falls off the end of the matching code,
		   then throw the exception to the calling method */
		ILCoderThrow(coder, 0);

		/* Mark the end of the handler */
		ILCoderTryHandlerEnd(coder);

		/* Advance to the next region within the code */
		offset = end;
	}

	/* If execution gets here, then there were no applicable catch blocks,
	   so we always throw the exception to the calling method */
	ILCoderTryHandlerStart(coder, 0, IL_MAX_UINT32);
	
	if (ILMethod_IsSynchronized(method))
	{
		/* Exit the sync lock before throwing to the calling method */
		isStatic = ILMethod_IsStatic(method);
		PUSH_SYNC_OBJECT();
		ILCoderCallInlineable(coder, IL_INLINEMETHOD_MONITOR_EXIT, 0);
	}

	ILCoderThrow(coder, 0);
	ILCoderTryHandlerEnd(coder);
}