Exemplo n.º 1
0
 internal void WriteBinary(BinDumpWriter writer)
 {
     writer.WriteVarUInt32((uint)FromChar);
     writer.WriteVarInt32(ToChar - FromChar);
     writer.WriteVarUInt32((uint)FromLine);
     writer.WriteVarInt32(ToLine - FromLine);
     writer.WriteBoolean(IsStepStop);
 }
Exemplo n.º 2
0
 internal void WriteBinaryEnv(BinDumpWriter bw, Dictionary <SymbolRef, int> symbolMap)
 {
     if (this.i_Env != null)
     {
         bw.WriteVarUInt32((uint)(symbolMap[i_Env] + 1));
     }
     else
     {
         bw.WriteVarUInt32(0);
     }
 }
Exemplo n.º 3
0
        public void BinDump_VarUInt()
        {
            using (var stream = new MemoryStream())
            {
                var writer = new BinDumpWriter(stream);
                var reader = new BinDumpReader(stream);

                writer.WriteVarUInt32(12);
                stream.Seek(0, SeekOrigin.Begin);
                Assert.AreEqual(reader.ReadVarUInt32(), 12);
                stream.Seek(0, SeekOrigin.Begin);

                writer.WriteVarUInt32(200);
                stream.Seek(0, SeekOrigin.Begin);
                Assert.AreEqual(reader.ReadVarUInt32(), 200);
                stream.Seek(0, SeekOrigin.Begin);

                writer.WriteVarUInt32(17000);
                stream.Seek(0, SeekOrigin.Begin);
                Assert.AreEqual(reader.ReadVarUInt32(), 17000);
                stream.Seek(0, SeekOrigin.Begin);

                writer.WriteVarUInt32(2100000);
                stream.Seek(0, SeekOrigin.Begin);
                Assert.AreEqual(reader.ReadVarUInt32(), 2100000);
                stream.Seek(0, SeekOrigin.Begin);

                writer.WriteVarUInt32(200000118);
                stream.Seek(0, SeekOrigin.Begin);
                Assert.AreEqual(reader.ReadVarUInt32(), 200000118);
                stream.Seek(0, SeekOrigin.Begin);

                writer.WriteVarUInt32(uint.MaxValue - 1);
                stream.Seek(0, SeekOrigin.Begin);
                Assert.AreEqual(reader.ReadVarUInt32(), uint.MaxValue - 1);
                stream.Seek(0, SeekOrigin.Begin);
            }
        }
Exemplo n.º 4
0
        internal int Dump(Stream stream, int baseAddress, bool hasUpvalues, bool writeSourceRefs)
        {
            var bw = new BinDumpWriter(stream);

            Dictionary <SymbolRef, int> symbolMap = new Dictionary <SymbolRef, int>();

            Instruction?meta = FindMeta(ref baseAddress);

            if (meta == null)
            {
                throw new ArgumentException("baseAddress");
            }

            bw.WriteUInt64(DUMP_CHUNK_MAGIC);
            bw.WriteByte(DUMP_CHUNK_VERSION);
            bw.WriteBoolean(hasUpvalues);
            bw.WriteVarUInt32((uint)meta.Value.NumVal);

            for (int i = 0; i <= meta.Value.NumVal; i++)
            {
                SymbolRef[] symbolList;
                SymbolRef   symbol;

                m_RootChunk.Code[baseAddress + i].GetSymbolReferences(out symbolList, out symbol);

                if (symbol != null)
                {
                    AddSymbolToMap(symbolMap, symbol);
                }

                if (symbolList != null)
                {
                    foreach (var s in symbolList)
                    {
                        AddSymbolToMap(symbolMap, s);
                    }
                }
            }

            foreach (SymbolRef sr in symbolMap.Keys.ToArray())
            {
                if (sr.i_Env != null)
                {
                    AddSymbolToMap(symbolMap, sr.i_Env);
                }
            }

            SymbolRef[] allSymbols = new SymbolRef[symbolMap.Count];

            foreach (KeyValuePair <SymbolRef, int> pair in symbolMap)
            {
                allSymbols[pair.Value] = pair.Key;
            }

            bw.WriteVarUInt32((uint)symbolMap.Count);

            foreach (SymbolRef sym in allSymbols)
            {
                sym.WriteBinary(bw);
            }

            foreach (SymbolRef sym in allSymbols)
            {
                sym.WriteBinaryEnv(bw, symbolMap);
            }

            for (int i = 0; i <= meta.Value.NumVal; i++)
            {
                m_RootChunk.Code[baseAddress + i].WriteBinary(bw, baseAddress, symbolMap);
            }
            for (int i = 0; i <= meta.Value.NumVal; i++)
            {
                if (m_RootChunk.SourceRefs[baseAddress + i] == null || !writeSourceRefs)
                {
                    bw.WriteByte(0);
                }
                else if (i != 0 && m_RootChunk.SourceRefs[baseAddress + i] == m_RootChunk.SourceRefs[baseAddress + i - 1])
                {
                    bw.WriteByte(1);
                }
                else
                {
                    bw.WriteByte(2);
                    m_RootChunk.SourceRefs[baseAddress + i].WriteBinary(bw);
                }
            }


            return(meta.Value.NumVal + baseAddress + 1);
        }