Inheritance: System.IO.BinaryWriter
Exemplo n.º 1
0
        internal void WriteData(MyBinaryWriter bw)
        {
            DataOffset = (int)bw.BaseStream.Position;
            bw.Write(file_name);

            if (guid == null)
            {
                guid = new byte[16];
            }

            if (hash == null)
            {
                try {
                    using (FileStream fs = new FileStream(file_name, FileMode.Open, FileAccess.Read)) {
                        MD5 md5 = MD5.Create();
                        hash = md5.ComputeHash(fs);
                    }
                } catch {
                    hash = new byte [16];
                }
            }

            bw.Write(guid);
            bw.Write(hash);
            bw.Write((byte)(auto_generated ? 1 : 0));
        }
Exemplo n.º 2
0
        internal void WriteData(MyBinaryWriter bw)
        {
            DataOffset = (int)bw.BaseStream.Position;
            bw.Write(file_name);

            if (guid == null)
            {
                guid = new byte[16];
            }

            if (hash == null)
            {
                try {
                    using (var fs = PclFileAccess.OpenFileStream(file_name)) {
                        var md5 = Microsoft.CodeAnalysis.CryptographicHashProvider.TryGetAlgorithm(System.Reflection.AssemblyHashAlgorithm.MD5);
                        hash = md5.ComputeHash(fs);
                    }
                } catch {
                    hash = new byte [16];
                }
            }

            bw.Write(guid);
            bw.Write(hash);
            bw.Write((byte)(auto_generated ? 1 : 0));
        }
Exemplo n.º 3
0
 internal void Write(MyBinaryWriter bw)
 {
     bw.WriteLeb128((int)BlockType);
     bw.WriteLeb128(Parent);
     bw.WriteLeb128(StartOffset);
     bw.WriteLeb128(EndOffset);
 }
Exemplo n.º 4
0
        internal void WriteData(MonoSymbolFile file, MyBinaryWriter bw)
        {
            if (index <= 0)
            {
                throw new InvalidOperationException();
            }

            LocalVariableTableOffset = (int)bw.BaseStream.Position;
            int num_locals = locals != null ? locals.Length : 0;

            bw.WriteLeb128(num_locals);
            for (int i = 0; i < num_locals; i++)
            {
                locals [i].Write(file, bw);
            }
            file.LocalCount += num_locals;

            CodeBlockTableOffset = (int)bw.BaseStream.Position;
            int num_code_blocks = code_blocks != null ? code_blocks.Length : 0;

            bw.WriteLeb128(num_code_blocks);
            for (int i = 0; i < num_code_blocks; i++)
            {
                code_blocks [i].Write(bw);
            }

            ScopeVariableTableOffset = (int)bw.BaseStream.Position;
            int num_scope_vars = scope_vars != null ? scope_vars.Length : 0;

            bw.WriteLeb128(num_scope_vars);
            for (int i = 0; i < num_scope_vars; i++)
            {
                scope_vars [i].Write(bw);
            }

            if (real_name != null)
            {
                RealNameOffset = (int)bw.BaseStream.Position;
                bw.Write(real_name);
            }

            LineNumberTableOffset = (int)bw.BaseStream.Position;
            lnt.Write(file, bw);

            DataOffset = (int)bw.BaseStream.Position;

            bw.WriteLeb128(CompileUnitIndex);
            bw.WriteLeb128(LocalVariableTableOffset);
            bw.WriteLeb128(NamespaceID);

            bw.WriteLeb128(CodeBlockTableOffset);
            bw.WriteLeb128(ScopeVariableTableOffset);

            bw.WriteLeb128(RealNameOffset);
            bw.WriteLeb128((int)flags);
        }
Exemplo n.º 5
0
        internal void Write(MyBinaryWriter bw)
        {
            if ((index <= 0) || (DataOffset == 0))
            {
                throw new InvalidOperationException();
            }

            bw.Write(Token);
            bw.Write(DataOffset);
            bw.Write(LineNumberTableOffset);
        }
Exemplo n.º 6
0
 internal void Write(MonoSymbolFile file, MyBinaryWriter bw)
 {
     bw.Write(Name);
     bw.WriteLeb128(Index);
     bw.WriteLeb128(Parent);
     bw.WriteLeb128(UsingClauses.Length);
     foreach (string uc in UsingClauses)
     {
         bw.Write(uc);
     }
 }
Exemplo n.º 7
0
        internal void Write(MyBinaryWriter bw)
        {
            bw.WriteLeb128(ID);

            bw.WriteLeb128(captured_vars.Count);
            foreach (CapturedVariable cv in captured_vars)
            {
                cv.Write(bw);
            }

            bw.WriteLeb128(captured_scopes.Count);
            foreach (CapturedScope cs in captured_scopes)
            {
                cs.Write(bw);
            }
        }
Exemplo n.º 8
0
        internal void WriteData(MyBinaryWriter bw)
        {
            DataOffset = (int)bw.BaseStream.Position;
            bw.Write(file_name);

            if (guid == null)
            {
                guid = new byte[16];
            }

            if (hash == null)
            {
                hash = ComputeHash();
            }

            bw.Write(guid);
            bw.Write(hash);
            bw.Write((byte)(auto_generated ? 1 : 0));
        }
Exemplo n.º 9
0
        internal void WriteData(MyBinaryWriter bw)
        {
            DataOffset = (int)bw.BaseStream.Position;
            bw.WriteLeb128(source.Index);

            int count_includes = include_files != null ? include_files.Count : 0;

            bw.WriteLeb128(count_includes);
            if (include_files != null)
            {
                foreach (SourceFileEntry entry in include_files)
                {
                    bw.WriteLeb128(entry.Index);
                }
            }

            bw.WriteLeb128(namespaces.Count);
            foreach (NamespaceEntry ns in namespaces)
            {
                ns.Write(file, bw);
            }
        }
		internal void Write (MyBinaryWriter bw)
		{
			bw.WriteLeb128 (ID);

			bw.WriteLeb128 (captured_vars.Count);
			foreach (CapturedVariable cv in captured_vars)
				cv.Write (bw);

			bw.WriteLeb128 (captured_scopes.Count);
			foreach (CapturedScope cs in captured_scopes)
				cs.Write (bw);
		}
		internal void WriteData (MonoSymbolFile file, MyBinaryWriter bw)
		{
			if (index <= 0)
				throw new InvalidOperationException ();

			LocalVariableTableOffset = (int) bw.BaseStream.Position;
			int num_locals = locals != null ? locals.Length : 0;
			bw.WriteLeb128 (num_locals);
			for (int i = 0; i < num_locals; i++)
				locals [i].Write (file, bw);
			file.LocalCount += num_locals;

			CodeBlockTableOffset = (int) bw.BaseStream.Position;
			int num_code_blocks = code_blocks != null ? code_blocks.Length : 0;
			bw.WriteLeb128 (num_code_blocks);
			for (int i = 0; i < num_code_blocks; i++)
				code_blocks [i].Write (bw);

			ScopeVariableTableOffset = (int) bw.BaseStream.Position;
			int num_scope_vars = scope_vars != null ? scope_vars.Length : 0;
			bw.WriteLeb128 (num_scope_vars);
			for (int i = 0; i < num_scope_vars; i++)
				scope_vars [i].Write (bw);

			if (real_name != null) {
				RealNameOffset = (int) bw.BaseStream.Position;
				bw.Write (real_name);
			}

			LineNumberTableOffset = (int) bw.BaseStream.Position;
			lnt.Write (file, bw);

			DataOffset = (int) bw.BaseStream.Position;

			bw.WriteLeb128 (CompileUnitIndex);
			bw.WriteLeb128 (LocalVariableTableOffset);
			bw.WriteLeb128 (NamespaceID);

			bw.WriteLeb128 (CodeBlockTableOffset);
			bw.WriteLeb128 (ScopeVariableTableOffset);

			bw.WriteLeb128 (RealNameOffset);
			bw.WriteLeb128 ((int) flags);
		}
		internal void Write (MyBinaryWriter bw)
		{
			if ((index <= 0) || (DataOffset == 0))
				throw new InvalidOperationException ();

			bw.Write (Token);
			bw.Write (DataOffset);
			bw.Write (LineNumberTableOffset);
		}
		internal void Write (MonoSymbolFile file, MyBinaryWriter bw)
		{
			bw.Write (Name);
			bw.WriteLeb128 (Index);
			bw.WriteLeb128 (Parent);
			bw.WriteLeb128 (UsingClauses.Length);
			foreach (string uc in UsingClauses)
				bw.Write (uc);
		}
        void Write(MyBinaryWriter bw, Guid guid)
        {
            // Magic number and file version.
            bw.Write(OffsetTable.Magic);
            bw.Write(MajorVersion);
            bw.Write(MinorVersion);

            bw.Write(guid.ToByteArray());

            //
            // Offsets of file sections; we must write this after we're done
            // writing the whole file, so we just reserve the space for it here.
            //
            long offset_table_offset = bw.BaseStream.Position;

            ot.Write(bw, MajorVersion, MinorVersion);

            //
            // Sort the methods according to their tokens and update their index.
            //
            methods.Sort();
            for (int i = 0; i < methods.Count; i++)
            {
                ((MethodEntry)methods [i]).Index = i + 1;
            }

            //
            // Write data sections.
            //
            ot.DataSectionOffset = (int)bw.BaseStream.Position;
            foreach (SourceFileEntry source in sources)
            {
                source.WriteData(bw);
            }
            foreach (CompileUnitEntry comp_unit in comp_units)
            {
                comp_unit.WriteData(bw);
            }
            foreach (MethodEntry method in methods)
            {
                method.WriteData(this, bw);
            }
            ot.DataSectionSize = (int)bw.BaseStream.Position - ot.DataSectionOffset;

            //
            // Write the method index table.
            //
            ot.MethodTableOffset = (int)bw.BaseStream.Position;
            for (int i = 0; i < methods.Count; i++)
            {
                MethodEntry entry = (MethodEntry)methods [i];
                entry.Write(bw);
            }
            ot.MethodTableSize = (int)bw.BaseStream.Position - ot.MethodTableOffset;

            //
            // Write source table.
            //
            ot.SourceTableOffset = (int)bw.BaseStream.Position;
            for (int i = 0; i < sources.Count; i++)
            {
                SourceFileEntry source = (SourceFileEntry)sources [i];
                source.Write(bw);
            }
            ot.SourceTableSize = (int)bw.BaseStream.Position - ot.SourceTableOffset;

            //
            // Write compilation unit table.
            //
            ot.CompileUnitTableOffset = (int)bw.BaseStream.Position;
            for (int i = 0; i < comp_units.Count; i++)
            {
                CompileUnitEntry unit = (CompileUnitEntry)comp_units [i];
                unit.Write(bw);
            }
            ot.CompileUnitTableSize = (int)bw.BaseStream.Position - ot.CompileUnitTableOffset;

            //
            // Write anonymous scope table.
            //
            ot.AnonymousScopeCount       = anonymous_scopes != null ? anonymous_scopes.Count : 0;
            ot.AnonymousScopeTableOffset = (int)bw.BaseStream.Position;
            if (anonymous_scopes != null)
            {
                foreach (AnonymousScopeEntry scope in anonymous_scopes.Values)
                {
                    scope.Write(bw);
                }
            }
            ot.AnonymousScopeTableSize = (int)bw.BaseStream.Position - ot.AnonymousScopeTableOffset;

            //
            // Fixup offset table.
            //
            ot.TypeCount        = last_type_index;
            ot.MethodCount      = methods.Count;
            ot.SourceCount      = sources.Count;
            ot.CompileUnitCount = comp_units.Count;

            //
            // Write offset table.
            //
            ot.TotalFileSize = (int)bw.BaseStream.Position;
            bw.Seek((int)offset_table_offset, SeekOrigin.Begin);
            ot.Write(bw, MajorVersion, MinorVersion);
            bw.Seek(0, SeekOrigin.End);

#if false
            Console.WriteLine("TOTAL: {0} line numbes, {1} bytes, extended {2} bytes, " +
                              "{3} methods.", NumLineNumbers, LineNumberSize,
                              ExtendedLineNumberSize, methods.Count);
#endif
        }
		internal void Write (MyBinaryWriter bw)
		{
			bw.WriteLeb128 ((int) BlockType);
			bw.WriteLeb128 (Parent);
			bw.WriteLeb128 (StartOffset);
			bw.WriteLeb128 (EndOffset);
		}
Exemplo n.º 16
0
        internal void Write(MonoSymbolFile file, MyBinaryWriter bw)
        {
            int start = (int)bw.BaseStream.Position;

            bool last_is_hidden = false;
            int  last_line = 1, last_offset = 0, last_file = 1;

            for (int i = 0; i < LineNumbers.Length; i++)
            {
                int line_inc   = LineNumbers [i].Row - last_line;
                int offset_inc = LineNumbers [i].Offset - last_offset;

                if (SuppressDuplicates && (i + 1 < LineNumbers.Length))
                {
                    if (LineNumbers [i + 1].Equals(LineNumbers [i]))
                    {
                        continue;
                    }
                }

                if (LineNumbers [i].File != last_file)
                {
                    bw.Write(DW_LNS_set_file);
                    bw.WriteLeb128(LineNumbers [i].File);
                    last_file = LineNumbers [i].File;
                }

                if (LineNumbers [i].IsHidden != last_is_hidden)
                {
                    bw.Write((byte)0);
                    bw.Write((byte)1);
                    bw.Write(DW_LNE_MONO_negate_is_hidden);
                    last_is_hidden = LineNumbers [i].IsHidden;
                }

                if (offset_inc >= MaxAddressIncrement)
                {
                    if (offset_inc < 2 * MaxAddressIncrement)
                    {
                        bw.Write(DW_LNS_const_add_pc);
                        offset_inc -= MaxAddressIncrement;
                    }
                    else
                    {
                        bw.Write(DW_LNS_advance_pc);
                        bw.WriteLeb128(offset_inc);
                        offset_inc = 0;
                    }
                }

                if ((line_inc < LineBase) || (line_inc >= LineBase + LineRange))
                {
                    bw.Write(DW_LNS_advance_line);
                    bw.WriteLeb128(line_inc);
                    if (offset_inc != 0)
                    {
                        bw.Write(DW_LNS_advance_pc);
                        bw.WriteLeb128(offset_inc);
                    }
                    bw.Write(DW_LNS_copy);
                }
                else
                {
                    byte opcode;
                    opcode = (byte)(line_inc - LineBase + (LineRange * offset_inc) +
                                    OpcodeBase);
                    bw.Write(opcode);
                }

                last_line   = LineNumbers [i].Row;
                last_offset = LineNumbers [i].Offset;
            }

            bw.Write((byte)0);
            bw.Write((byte)1);
            bw.Write(DW_LNE_end_sequence);

            file.ExtendedLineNumberSize += (int)bw.BaseStream.Position - start;
        }
		internal void Write (MonoSymbolFile file, MyBinaryWriter bw)
		{
			bw.WriteLeb128 (Index);
			bw.Write (Name);
			bw.WriteLeb128 (BlockIndex);
		}
Exemplo n.º 18
0
        internal void Write(MonoSymbolFile file, MyBinaryWriter bw)
        {
            int start = (int) bw.BaseStream.Position;

            bool last_is_hidden = false;
            int last_line = 1, last_offset = 0, last_file = 1;
            for (int i = 0; i < LineNumbers.Length; i++) {
                int line_inc = LineNumbers [i].Row - last_line;
                int offset_inc = LineNumbers [i].Offset - last_offset;

                if (SuppressDuplicates && (i+1 < LineNumbers.Length)) {
                    if (LineNumbers [i+1].Equals (LineNumbers [i]))
                        continue;
                }

                if (LineNumbers [i].File != last_file) {
                    bw.Write (DW_LNS_set_file);
                    bw.WriteLeb128 (LineNumbers [i].File);
                    last_file = LineNumbers [i].File;
                }

                if (LineNumbers [i].IsHidden != last_is_hidden) {
                    bw.Write ((byte) 0);
                    bw.Write ((byte) 1);
                    bw.Write (DW_LNE_MONO_negate_is_hidden);
                    last_is_hidden = LineNumbers [i].IsHidden;
                }

            #if DEBUGGER_SOURCE
                if (LineNumbers [i].SourceRange != null) {
                    bw.Write ((byte) 0);
                    long tmp_offset = bw.BaseStream.Position;
                    bw.Write ((byte) 0);
                    bw.Write (DW_LNE_MONO_set_source_range);

                    /*
                     * Use a private extended opcode to encode source ranges.
                     *
                     * Instead of only having one integer "line number", we now have a struct
                     * containing 'StartLine', 'EndLine', 'StartColumn' and 'EndColumn'.
                     */

                    SourceRangeEntry range = (SourceRangeEntry) LineNumbers [i].SourceRange;
                    /*
                     * We use some optimization here: since the start and end lines are usually
                     * close together, we use relative values, so we can encode it as a single-byte
                     * even for large source files.
                     */
                    bw.WriteLeb128 (range.StartLine - last_line);
                    bw.WriteLeb128 (range.EndLine - range.StartLine);
                    bw.WriteLeb128 (range.StartColumn);
                    bw.WriteLeb128 (range.EndColumn);

                    long tmp_size = bw.BaseStream.Position - tmp_offset - 1;
                    long tmp_end = bw.BaseStream.Position;
                    bw.BaseStream.Position = tmp_offset;
                    bw.Write ((byte) tmp_size);
                    bw.BaseStream.Position = tmp_end;
                }
            #endif

                if (offset_inc >= MaxAddressIncrement) {
                    if (offset_inc < 2 * MaxAddressIncrement) {
                        bw.Write (DW_LNS_const_add_pc);
                        offset_inc -= MaxAddressIncrement;
                    } else {
                        bw.Write (DW_LNS_advance_pc);
                        bw.WriteLeb128 (offset_inc);
                        offset_inc = 0;
                    }
                }

                if ((line_inc < LineBase) || (line_inc >= LineBase + LineRange)) {
                    bw.Write (DW_LNS_advance_line);
                    bw.WriteLeb128 (line_inc);
                    if (offset_inc != 0) {
                        bw.Write (DW_LNS_advance_pc);
                        bw.WriteLeb128 (offset_inc);
                    }
                    bw.Write (DW_LNS_copy);
                } else {
                    byte opcode;
                    opcode = (byte) (line_inc - LineBase + (LineRange * offset_inc) +
                             OpcodeBase);
                    bw.Write (opcode);
                }

                last_line = LineNumbers [i].Row;
                last_offset = LineNumbers [i].Offset;
            }

            bw.Write ((byte) 0);
            bw.Write ((byte) 1);
            bw.Write (DW_LNE_end_sequence);

            file.ExtendedLineNumberSize += (int) bw.BaseStream.Position - start;
        }
		internal void Write (MyBinaryWriter bw)
		{
			bw.Write (Name);
			bw.Write (CapturedName);
			bw.Write ((byte) Kind);
		}
Exemplo n.º 20
0
 internal void Write(MyBinaryWriter bw)
 {
     bw.WriteLeb128(Scope);
     bw.Write(CapturedName);
 }
Exemplo n.º 21
0
 internal void Write(MonoSymbolFile file, MyBinaryWriter bw)
 {
     bw.WriteLeb128(Index);
     bw.Write(Name);
     bw.WriteLeb128(BlockIndex);
 }
		internal void Write (MyBinaryWriter bw)
		{
			bw.WriteLeb128 (Scope);
			bw.WriteLeb128 (Index);
		}
		internal void Write (MyBinaryWriter bw)
		{
			bw.WriteLeb128 (Scope);
			bw.Write (CapturedName);
		}
Exemplo n.º 24
0
 internal void Write(MyBinaryWriter bw)
 {
     bw.Write(Name);
     bw.Write(CapturedName);
     bw.Write((byte)Kind);
 }
		internal void WriteData (MyBinaryWriter bw)
		{
			DataOffset = (int) bw.BaseStream.Position;
			bw.WriteLeb128 (source.Index);

			int count_includes = include_files != null ? include_files.Count : 0;
			bw.WriteLeb128 (count_includes);
			if (include_files != null) {
				foreach (SourceFileEntry entry in include_files)
					bw.WriteLeb128 (entry.Index);
			}

			bw.WriteLeb128 (namespaces.Count);
			foreach (NamespaceEntry ns in namespaces)
				ns.Write (file, bw);
		}
Exemplo n.º 26
0
 internal void Write(MyBinaryWriter bw)
 {
     bw.WriteLeb128(Scope);
     bw.WriteLeb128(Index);
 }
		internal void WriteData (MyBinaryWriter bw)
		{
			DataOffset = (int) bw.BaseStream.Position;
			bw.Write (file_name);

			if (guid == null) {
				guid = Guid.NewGuid ().ToByteArray ();
				try {
					using (FileStream fs = new FileStream (file_name, FileMode.Open, FileAccess.Read)) {
						MD5 md5 = MD5.Create ();
						hash = md5.ComputeHash (fs);
					}
				} catch {
					hash = new byte [16];
				}
			}

			bw.Write (guid);
			bw.Write (hash);
			bw.Write ((byte) (auto_generated ? 1 : 0));
		}
		internal void Write (MonoSymbolFile file, MyBinaryWriter bw)
		{
			int start = (int) bw.BaseStream.Position;

			bool last_is_hidden = false;
			int last_line = 1, last_offset = 0, last_file = 1;
			for (int i = 0; i < LineNumbers.Length; i++) {
				int line_inc = LineNumbers [i].Row - last_line;
				int offset_inc = LineNumbers [i].Offset - last_offset;

				if (SuppressDuplicates && (i+1 < LineNumbers.Length)) {
					if (LineNumbers [i+1].Equals (LineNumbers [i]))
						continue;
				}

				if (LineNumbers [i].File != last_file) {
					bw.Write (DW_LNS_set_file);
					bw.WriteLeb128 (LineNumbers [i].File);
					last_file = LineNumbers [i].File;
				}

				if (LineNumbers [i].IsHidden != last_is_hidden) {
					bw.Write ((byte) 0);
					bw.Write ((byte) 1);
					bw.Write (DW_LNE_MONO_negate_is_hidden);
					last_is_hidden = LineNumbers [i].IsHidden;
				}

				if (offset_inc >= MaxAddressIncrement) {
					if (offset_inc < 2 * MaxAddressIncrement) {
						bw.Write (DW_LNS_const_add_pc);
						offset_inc -= MaxAddressIncrement;
					} else {
						bw.Write (DW_LNS_advance_pc);
						bw.WriteLeb128 (offset_inc);
						offset_inc = 0;
					}
				}

				if ((line_inc < LineBase) || (line_inc >= LineBase + LineRange)) {
					bw.Write (DW_LNS_advance_line);
					bw.WriteLeb128 (line_inc);
					if (offset_inc != 0) {
						bw.Write (DW_LNS_advance_pc);
						bw.WriteLeb128 (offset_inc);
					}
					bw.Write (DW_LNS_copy);
				} else {
					byte opcode;
					opcode = (byte) (line_inc - LineBase + (LineRange * offset_inc) +
							 OpcodeBase);
					bw.Write (opcode);
				}

				last_line = LineNumbers [i].Row;
				last_offset = LineNumbers [i].Offset;
			}

			bw.Write ((byte) 0);
			bw.Write ((byte) 1);
			bw.Write (DW_LNE_end_sequence);

			file.ExtendedLineNumberSize += (int) bw.BaseStream.Position - start;
		}
Exemplo n.º 29
0
		void Write (MyBinaryWriter bw, Guid guid)
		{
			// Magic number and file version.
			bw.Write (OffsetTable.Magic);
			bw.Write (MajorVersion);
			bw.Write (MinorVersion);

			bw.Write (guid.ToByteArray ());

			//
			// Offsets of file sections; we must write this after we're done
			// writing the whole file, so we just reserve the space for it here.
			//
			long offset_table_offset = bw.BaseStream.Position;
			ot.Write (bw, MajorVersion, MinorVersion);

			//
			// Sort the methods according to their tokens and update their index.
			//
			methods.Sort ();
			for (int i = 0; i < methods.Count; i++)
				((MethodEntry) methods [i]).Index = i + 1;

			//
			// Write data sections.
			//
			ot.DataSectionOffset = (int) bw.BaseStream.Position;
			foreach (SourceFileEntry source in sources)
				source.WriteData (bw);
			foreach (CompileUnitEntry comp_unit in comp_units)
				comp_unit.WriteData (bw);
			foreach (MethodEntry method in methods)
				method.WriteData (this, bw);
			ot.DataSectionSize = (int) bw.BaseStream.Position - ot.DataSectionOffset;

			//
			// Write the method index table.
			//
			ot.MethodTableOffset = (int) bw.BaseStream.Position;
			for (int i = 0; i < methods.Count; i++) {
				MethodEntry entry = (MethodEntry) methods [i];
				entry.Write (bw);
			}
			ot.MethodTableSize = (int) bw.BaseStream.Position - ot.MethodTableOffset;

			//
			// Write source table.
			//
			ot.SourceTableOffset = (int) bw.BaseStream.Position;
			for (int i = 0; i < sources.Count; i++) {
				SourceFileEntry source = (SourceFileEntry) sources [i];
				source.Write (bw);
			}
			ot.SourceTableSize = (int) bw.BaseStream.Position - ot.SourceTableOffset;

			//
			// Write compilation unit table.
			//
			ot.CompileUnitTableOffset = (int) bw.BaseStream.Position;
			for (int i = 0; i < comp_units.Count; i++) {
				CompileUnitEntry unit = (CompileUnitEntry) comp_units [i];
				unit.Write (bw);
			}
			ot.CompileUnitTableSize = (int) bw.BaseStream.Position - ot.CompileUnitTableOffset;

			//
			// Write anonymous scope table.
			//
			ot.AnonymousScopeCount = anonymous_scopes != null ? anonymous_scopes.Count : 0;
			ot.AnonymousScopeTableOffset = (int) bw.BaseStream.Position;
			if (anonymous_scopes != null) {
				foreach (AnonymousScopeEntry scope in anonymous_scopes.Values)
					scope.Write (bw);
			}
			ot.AnonymousScopeTableSize = (int) bw.BaseStream.Position - ot.AnonymousScopeTableOffset;

			//
			// Fixup offset table.
			//
			ot.TypeCount = last_type_index;
			ot.MethodCount = methods.Count;
			ot.SourceCount = sources.Count;
			ot.CompileUnitCount = comp_units.Count;

			//
			// Write offset table.
			//
			ot.TotalFileSize = (int) bw.BaseStream.Position;
			bw.Seek ((int) offset_table_offset, SeekOrigin.Begin);
			ot.Write (bw, MajorVersion, MinorVersion);
			bw.Seek (0, SeekOrigin.End);

#if false
			Console.WriteLine ("TOTAL: {0} line numbes, {1} bytes, extended {2} bytes, " +
					   "{3} methods.", NumLineNumbers, LineNumberSize,
					   ExtendedLineNumberSize, methods.Count);
#endif
		}
Exemplo n.º 30
0
        internal void Write(MonoSymbolFile file, MyBinaryWriter bw, bool hasColumnsInfo, bool hasEndInfo)
        {
            int start = (int)bw.BaseStream.Position;

            bool last_is_hidden = false;
            int  last_line = 1, last_offset = 0, last_file = 1;

            for (int i = 0; i < LineNumbers.Length; i++)
            {
                int line_inc   = LineNumbers [i].Row - last_line;
                int offset_inc = LineNumbers [i].Offset - last_offset;

                if (LineNumbers [i].File != last_file)
                {
                    bw.Write(DW_LNS_set_file);
                    bw.WriteLeb128(LineNumbers [i].File);
                    last_file = LineNumbers [i].File;
                }

                if (LineNumbers [i].IsHidden != last_is_hidden)
                {
                    bw.Write((byte)0);
                    bw.Write((byte)1);
                    bw.Write(DW_LNE_MONO_negate_is_hidden);
                    last_is_hidden = LineNumbers [i].IsHidden;
                }

                if (offset_inc >= MaxAddressIncrement)
                {
                    if (offset_inc < 2 * MaxAddressIncrement)
                    {
                        bw.Write(DW_LNS_const_add_pc);
                        offset_inc -= MaxAddressIncrement;
                    }
                    else
                    {
                        bw.Write(DW_LNS_advance_pc);
                        bw.WriteLeb128(offset_inc);
                        offset_inc = 0;
                    }
                }

                if ((line_inc < LineBase) || (line_inc >= LineBase + LineRange))
                {
                    bw.Write(DW_LNS_advance_line);
                    bw.WriteLeb128(line_inc);
                    if (offset_inc != 0)
                    {
                        bw.Write(DW_LNS_advance_pc);
                        bw.WriteLeb128(offset_inc);
                    }
                    bw.Write(DW_LNS_copy);
                }
                else
                {
                    byte opcode;
                    opcode = (byte)(line_inc - LineBase + (LineRange * offset_inc) +
                                    OpcodeBase);
                    bw.Write(opcode);
                }

                last_line   = LineNumbers [i].Row;
                last_offset = LineNumbers [i].Offset;
            }

            bw.Write((byte)0);
            bw.Write((byte)1);
            bw.Write(DW_LNE_end_sequence);

            if (hasColumnsInfo)
            {
                for (int i = 0; i < LineNumbers.Length; i++)
                {
                    var ln = LineNumbers [i];
                    if (ln.Row >= 0)
                    {
                        bw.WriteLeb128(ln.Column);
                    }
                }
            }

            if (hasEndInfo)
            {
                for (int i = 0; i < LineNumbers.Length; i++)
                {
                    var ln = LineNumbers [i];
                    if (ln.EndRow == -1 || ln.EndColumn == -1 || ln.Row > ln.EndRow)
                    {
                        bw.WriteLeb128(0xffffff);
                    }
                    else
                    {
                        bw.WriteLeb128(ln.EndRow - ln.Row);
                        bw.WriteLeb128(ln.EndColumn);
                    }
                }
            }

            file.ExtendedLineNumberSize += (int)bw.BaseStream.Position - start;
        }
Exemplo n.º 31
0
        internal void WriteData(MyBinaryWriter bw)
        {
            DataOffset = (int) bw.BaseStream.Position;
            bw.Write (file_name);

            if (guid == null) {
                guid = Guid.NewGuid ().ToByteArray ();
                hash = compute_hash (file_name);
            }

            bw.Write (guid);
            bw.Write (hash);
            bw.Write ((byte) (auto_generated ? 1 : 0));
        }