Write3Bytes() private method

private Write3Bytes ( uint val ) : void
val uint
return void
Exemplo n.º 1
0
        internal void Write(PEWriter output)
        {
            if (Diag.DiagOn) Console.WriteLine("Writing header flags = " + Hex.Short(headerFlags));
            if (tinyFormat) {
                if (Diag.DiagOn) Console.WriteLine("Writing tiny code");
                output.Write((byte)headerFlags);
            } else {
                if (Diag.DiagOn) Console.WriteLine("Writing fat code");
                output.Write(headerFlags);
                output.Write((ushort)maxStack);
                output.Write(offset);
                output.Write(localSigIx);
            }
            if (Diag.DiagOn) {
                Console.WriteLine(Hex.Int(tide) + " CIL instructions");
                Console.WriteLine("starting instructions at " + output.Seek(0,SeekOrigin.Current));
            }

            // Added to enable PDB generation
            if (output.pdbWriter != null) {

                // Open the method
                output.pdbWriter.OpenMethod((int)thisMeth.Token());

                // Check if this is the entry point method
                if (thisMeth.HasEntryPoint()) output.pdbWriter.SetEntryPoint((int)thisMeth.Token());
            }

            // Write out each memember of the buffer
            for (int i=0; i < tide; i++) {
                buffer[i].Write(output);
            }

            // Added to enable PDB generation
            if (output.pdbWriter != null && tide > 0) {
                output.pdbWriter.CloseMethod();
            }
            if (Diag.DiagOn) Console.WriteLine("ending instructions at " + output.Seek(0,SeekOrigin.Current));
            for (int i=0; i < paddingNeeded; i++) { output.Write((byte)0); }
            if (exceptions != null) {
                // Console.WriteLine("Writing exceptions");
                // Console.WriteLine("header = " + Hex.Short(exceptHeader) + " exceptSize = " + Hex.Int(exceptSize));
                output.Write(exceptHeader);
                output.Write3Bytes((uint)exceptSize);
                for (int i=0; i < exceptions.Count; i++) {
                    TryBlock tryBlock = (TryBlock)exceptions[i];
                    tryBlock.Write(output,fatExceptionFormat);
                }
            }
        }