void WriteExceptionHandlerCollection(ExceptionHandlerCollection seh) { m_codeWriter.QuadAlign(); if (seh.Count < 0x15 && !IsFat(seh)) { m_codeWriter.Write((byte)MethodDataSection.EHTable); m_codeWriter.Write((byte)(seh.Count * 12 + 4)); m_codeWriter.Write(new byte [2]); foreach (ExceptionHandler eh in seh) { m_codeWriter.Write((ushort)eh.Type); m_codeWriter.Write((ushort)eh.TryStart.Offset); m_codeWriter.Write((byte)(eh.TryEnd.Offset - eh.TryStart.Offset)); m_codeWriter.Write((ushort)eh.HandlerStart.Offset); m_codeWriter.Write((byte)GetLength(eh.HandlerStart, eh.HandlerEnd, seh.Container.Instructions)); WriteHandlerSpecific(eh); } } else { m_codeWriter.Write((byte)(MethodDataSection.FatFormat | MethodDataSection.EHTable)); WriteFatBlockSize(seh); foreach (ExceptionHandler eh in seh) { m_codeWriter.Write((uint)eh.Type); m_codeWriter.Write((uint)eh.TryStart.Offset); m_codeWriter.Write((uint)(eh.TryEnd.Offset - eh.TryStart.Offset)); m_codeWriter.Write((uint)eh.HandlerStart.Offset); m_codeWriter.Write((uint)GetLength(eh.HandlerStart, eh.HandlerEnd, seh.Container.Instructions)); WriteHandlerSpecific(eh); } } }
bool IsFat(ExceptionHandlerCollection seh, Instruction last) { for (int i = 0; i < seh.Count; i++) { ExceptionHandler eh = seh [i]; if (IsRangeFat(eh.TryStart, eh.TryEnd, last)) { return(true); } switch (eh.Type) { case ExceptionHandlerType.Catch: case ExceptionHandlerType.Fault: case ExceptionHandlerType.Finally: if (IsRangeFat(eh.HandlerStart, eh.HandlerEnd, last)) { return(true); } break; case ExceptionHandlerType.Filter: if (IsRangeFat(eh.FilterStart, eh.FilterEnd, last)) { return(true); } break; } } return(false); }
static bool IsFat(ExceptionHandlerCollection seh) { for (int i = 0; i < seh.Count; i++) { ExceptionHandler eh = seh [i]; if (IsRangeFat(eh.TryStart, eh.TryEnd, seh.Container.Instructions)) { return(true); } if (IsRangeFat(eh.HandlerStart, eh.HandlerEnd, seh.Container.Instructions)) { return(true); } switch (eh.Type) { case ExceptionHandlerType.Filter: if (IsRangeFat(eh.FilterStart, eh.FilterEnd, seh.Container.Instructions)) { return(true); } break; } } return(false); }
public MethodBody(MethodDefinition meth) { m_method = meth; m_instructions = new InstructionCollection (this); m_exceptions = new ExceptionHandlerCollection (this); m_variables = new VariableDefinitionCollection (this); }
public void AddRange(ExceptionHandlerCollection value) { foreach (ExceptionHandler handler in value) { Add(handler); } }
public MethodBody(MethodDefinition meth) { m_method = meth; m_instructions = new InstructionCollection(this); m_exceptions = new ExceptionHandlerCollection(this); m_variables = new VariableDefinitionCollection(this); }
void WriteFatBlockSize(ExceptionHandlerCollection seh) { int size = seh.Count * 24 + 4; m_codeWriter.Write((byte)(size & 0xff)); m_codeWriter.Write((byte)((size >> 8) & 0xff)); m_codeWriter.Write((byte)((size >> 16) & 0xff)); }
void MarkBlockStarts (ExceptionHandlerCollection handlers) { for (int i = 0; i < handlers.Count; i++) { var handler = handlers [i]; MarkBlockStart (handler.TryStart); MarkBlockStart (handler.HandlerStart); if (handler.Type == ExceptionHandlerType.Filter) { MarkExceptionObjectPosition (handler.FilterStart); MarkBlockStart (handler.FilterStart); } else if (handler.Type == ExceptionHandlerType.Catch) MarkExceptionObjectPosition (handler.HandlerStart); } }
private void MarkExceptionHandlers(ExceptionHandlerCollection exceptionHandlers) { foreach (ExceptionHandler exceptionHandler in exceptionHandlers) { AddActionAfter(exceptionHandler.TryStart, delegate { generator.BeginExceptionBlock(); }); if (exceptionHandler.Type == ExceptionHandlerType.Filter) { AddActionAfter(exceptionHandler.FilterStart, delegate { generator.BeginExceptFilterBlock(); }); } AddActionAfter(exceptionHandler.HandlerStart, delegate { switch (exceptionHandler.Type) { case ExceptionHandlerType.Catch: generator.BeginCatchBlock(outer.ResolveType(exceptionHandler.CatchType)); break; case ExceptionHandlerType.Fault: generator.BeginFaultBlock(); break; case ExceptionHandlerType.Finally: generator.BeginFinallyBlock(); break; } }); AddActionBefore(exceptionHandler.HandlerEnd, delegate { generator.EndExceptionBlock(); }); } }
bool IsFat (ExceptionHandlerCollection seh, Instruction last) { for (int i = 0; i < seh.Count; i++) { ExceptionHandler eh = seh [i]; if (IsRangeFat (eh.TryStart, eh.TryEnd, last)) return true; switch (eh.Type) { case ExceptionHandlerType.Catch : case ExceptionHandlerType.Fault : case ExceptionHandlerType.Finally : if (IsRangeFat (eh.HandlerStart, eh.HandlerEnd, last)) return true; break; case ExceptionHandlerType.Filter : if (IsRangeFat (eh.FilterStart, eh.FilterEnd, last)) return true; break; } } return false; }
public void VisitExceptionHandlerCollection (ExceptionHandlerCollection seh) { foreach (ExceptionHandler eh in seh) eh.Accept (this); }
// TODO, do we need to implement like in java... by sunlw //private Variable arg(int varIndex, Type type) //{ // Variable resultVariable; // if (!slots.Find(varIndex, out resultVariable) || resultVariable == null) // { // LocalVariableInfo localVar = new LocalVariableInfo("local_" + varIndex, type); // //slots.put(varIndex, localVar); // slots[varIndex] = localVar; // localVariables.Add(localVar); // resultVariable = localVar; // } // Type varType = resultVariable.Type; // if (!varType.Equals(type) && (type.IsPrimitive() || varType.IsPrimitive())) // { // // Apparently the compiler reuses local variables and it is possible // // that the types change. So if types change we have to drop // // the arg and try again. // //slots.put(varIndex, null); // slots[varIndex] = null; // return arg(varIndex, type); // } // return resultVariable; //} public void VisitExceptionHandlerCollection(ExceptionHandlerCollection seh) { foreach (ExceptionHandler handler in seh) { VisitExceptionHandler(handler); } }
static bool IsFat(ExceptionHandlerCollection seh) { for (int i = 0; i < seh.Count; i++) { ExceptionHandler eh = seh [i]; if (IsRangeFat (eh.TryStart, eh.TryEnd, seh.Container.Instructions)) return true; if (IsRangeFat (eh.HandlerStart, eh.HandlerEnd, seh.Container.Instructions)) return true; switch (eh.Type) { case ExceptionHandlerType.Filter : if (IsRangeFat (eh.FilterStart, eh.FilterEnd, seh.Container.Instructions)) return true; break; } } return false; }
public override void VisitExceptionHandlerCollection(ExceptionHandlerCollection seh) { for (int i = 0; i < seh.Count; i++) VisitExceptionHandler(seh[i]); }
void WriteExceptionHandlerCollection (ExceptionHandlerCollection seh) { m_codeWriter.QuadAlign (); Instruction last = seh.Container.Instructions [seh.Container.Instructions.Count - 1]; if (!IsFat (seh, last)) { m_codeWriter.Write ((byte) MethodDataSection.EHTable); m_codeWriter.Write ((byte) (seh.Count * 12 + 4)); m_codeWriter.Write (new byte [2]); foreach (ExceptionHandler eh in seh) { m_codeWriter.Write ((ushort) eh.Type); m_codeWriter.Write ((ushort) eh.TryStart.Offset); m_codeWriter.Write ((byte) (eh.TryEnd.Offset - eh.TryStart.Offset)); m_codeWriter.Write ((ushort) eh.HandlerStart.Offset); m_codeWriter.Write ((byte) GetLength (eh.HandlerStart, eh.HandlerEnd, last)); WriteHandlerSpecific (eh); } } else { m_codeWriter.Write ((byte) (MethodDataSection.FatFormat | MethodDataSection.EHTable)); WriteFatBlockSize (seh); foreach (ExceptionHandler eh in seh) { m_codeWriter.Write ((uint) eh.Type); m_codeWriter.Write ((uint) eh.TryStart.Offset); m_codeWriter.Write ((uint) (eh.TryEnd.Offset - eh.TryStart.Offset)); m_codeWriter.Write ((uint) eh.HandlerStart.Offset); m_codeWriter.Write ((uint) GetLength (eh.HandlerStart, eh.HandlerEnd, last)); WriteHandlerSpecific (eh); } } }
public override void VisitExceptionHandlerCollection(ExceptionHandlerCollection seh) { }
void WriteFatBlockSize (ExceptionHandlerCollection seh) { int size = seh.Count * 24 + 4; m_codeWriter.Write ((byte) (size & 0xff)); m_codeWriter.Write ((byte) ((size >> 8) & 0xff)); m_codeWriter.Write ((byte) ((size >> 16) & 0xff)); }
public void AddRange(ExceptionHandlerCollection value) { foreach (ExceptionHandler handler in value) Add(handler); }