public override void Write(ModuleWriter writer) { // Count the block size. int blockSize = 0; foreach (BasicBlock bb in basicBlocks) { blockSize += bb.GetRawBlockSize(); } // Count the argument size. int argSize = 0; for (int i = 0; i < arguments.Length; ++i) { argSize += arguments[i].GetSize(); } // Count the exceptions. int numexceptions = CountExceptionContexts(); int exceptionSize = 0; if (numexceptions > 0) { exceptionSize = exceptionContext.GetFullSize(); } // Create the member header. MemberHeader mheader = new MemberHeader(); mheader.memberType = (byte)MemberHeaderType.Function; mheader.memberFlags = (uint)GetFlags(); mheader.memberName = GetModule().RegisterString(GetName()); mheader.memberSize = (uint)(FunctionHeader.HeaderSize + blockSize + argSize + nextLocalId * LocalVariable.LocalDataSize + exceptionSize + genericPrototype.GetSize()); mheader.memberAttributes = GetAttributeCount(); // Write the member header. mheader.Write(writer); // Write the attributes. WriteAttributes(writer); // Create the header. FunctionHeader header = new FunctionHeader(); header.functionType = GetModule().RegisterType(GetFunctionType()); header.numargs = (ushort)arguments.Length; header.numlocals = (ushort)nextLocalId; header.numblocks = (ushort)basicBlocks.Count; header.numexceptions = (byte)numexceptions; if (IsMethod() && !IsStatic()) { Method method = (Method)this; if (method.IsAbstract() || method.IsContract() || method.IsOverride() || method.IsVirtual()) { header.vslot = (short)method.GetVSlot(); } } // Write the header. header.Write(writer); // Write the generic signature. genericPrototype.Write(writer, GetModule()); // Write the argument names. ChelaModule module = GetModule(); for (int i = 0; i < arguments.Length; ++i) { arguments[i].Write(writer, module); } // Write the locals. foreach (LocalVariable local in locals) { if (!local.IsPseudoLocal) { local.Write(writer); } } // Write the basic blocks. foreach (BasicBlock bb in basicBlocks) { bb.Write(GetModule(), writer); } // Write the exception contexts. if (exceptionContext != null) { exceptionContext.Write(writer); } }