Пример #1
0
        public void Write(HighFileBuilder fileBuilder, HighMethodBuilder methodBuilder, HighRegionBuilder regionBuilder, bool haveDebugInfo, BinaryWriter writer)
        {
            writer.Write((uint)m_escapePathTerminators.Length);

            foreach (HighEscapePathTerminator terminator in m_escapePathTerminators)
                terminator.Write(fileBuilder, regionBuilder, writer);

            m_protRegion.Write(fileBuilder, methodBuilder, haveDebugInfo, writer);
        }
Пример #2
0
 public void Write(HighFileBuilder fileBuilder, HighRegionBuilder regionBuilder, BinaryWriter writer)
 {
     if (m_reg.IsConstant)
     {
         writer.Write(true);
         m_reg.WriteConstant(fileBuilder, regionBuilder, writer);
     }
     else
     {
         writer.Write(false);
         writer.Write(regionBuilder.FindPredecessorSsaIndex(m_predecessor.Value, m_reg));
     }
 }
Пример #3
0
        public void Write(HighFileBuilder fileBuilder, HighRegionBuilder regionBuilder, HighCfgNodeHandle[] predecessors, BinaryWriter writer)
        {
            m_dest.WriteDestinationDef(fileBuilder, regionBuilder, writer);

            int numPreds = predecessors.Length;
            if (m_links.Length != numPreds)
                throw new ArgumentException("Phi and node have different number of predecessors");

            for (int i = 0; i < numPreds; i++)
            {
                HighPhiLink link = m_links[i];
                if (link.Predecessor.Value != predecessors[i].Value)
                    throw new ArgumentException("Phi has a mismatched predecessor");
                link.Write(fileBuilder, regionBuilder, writer);
            }
        }
Пример #4
0
        public void Write(HighFileBuilder fileBuilder, HighMethodBuilder methodBuilder, bool haveDebugInfo, BinaryWriter writer)
        {
            HighRegionBuilder regionBuilder = new HighRegionBuilder();
            regionBuilder.IndexCfgNode(m_entryNode.Value);

            MemoryStream regionNodesStream = new MemoryStream();
            BinaryWriter regionNodesWriter = new BinaryWriter(regionNodesStream);

            HighCfgNode cfgNode = regionBuilder.DequeueUnemittedNode();
            while (cfgNode != null)
            {
                cfgNode.Write(fileBuilder, methodBuilder, regionBuilder, haveDebugInfo, regionNodesWriter);

                cfgNode = regionBuilder.DequeueUnemittedNode();
            }

            regionNodesWriter.Flush();

            regionBuilder.WriteHeader(writer);
            writer.Flush();
            regionNodesStream.WriteTo(writer.BaseStream);
        }
Пример #5
0
 protected override void WriteHandlers(HighFileBuilder fileBuilder, HighMethodBuilder methodBuilder, bool haveDebugInfo, BinaryWriter writer)
 {
     m_finallyRegion.Write(fileBuilder, methodBuilder, haveDebugInfo, writer);
 }
Пример #6
0
 protected abstract void WriteHandlers(HighFileBuilder fileBuilder, HighMethodBuilder methodBuilder, bool haveDebugInfo, BinaryWriter writer);
Пример #7
0
        public void Write(HighFileBuilder fileBuilder, HighMethodBuilder methodBuilder, HighRegionBuilder regionBuilder, bool haveDebugInfo, BinaryWriter writer)
        {
            HighCfgNodeBuilder cfgNodeBuilder = new HighCfgNodeBuilder();

            HashSet<HighSsaRegister> gatheredConstants = new HashSet<HighSsaRegister>();
            List<HighSsaRegister> constants = new List<HighSsaRegister>();

            HighInstruction.VisitSsaDelegate constVisitor = delegate (ref HighSsaRegister use)
            {
                if (use.IsConstant && !gatheredConstants.Contains(use))
                {
                    gatheredConstants.Add(use);
                    constants.Add(use);
                }
            };

            foreach (HighInstruction instr in m_instructions)
                instr.VisitSsaUses(constVisitor);

            writer.Write((uint)m_predecessors.Length);
            writer.Write((uint)m_phis.Length);
            writer.Write((uint)m_instructions.Length);
            writer.Write((uint)constants.Count);

            foreach (HighCfgNodeHandle pred in m_predecessors)
                writer.Write(regionBuilder.IndexCfgNode(pred.Value));

            foreach (HighPhi phi in m_phis)
            {
                cfgNodeBuilder.AddSsa(phi.Dest);
                phi.Write(fileBuilder, regionBuilder, m_predecessors, writer);
            }

            foreach (HighSsaRegister constant in constants)
            {
                cfgNodeBuilder.AddSsa(constant);
                constant.WriteConstant(fileBuilder, regionBuilder, writer);
            }

            foreach (HighInstruction instr in m_instructions)
                instr.Write(fileBuilder, methodBuilder, regionBuilder, cfgNodeBuilder, haveDebugInfo, writer);
        }
Пример #8
0
 protected override void WriteHandlers(HighFileBuilder fileBuilder, HighMethodBuilder methodBuilder, bool haveDebugInfo, BinaryWriter writer)
 {
     writer.Write((uint)m_catchHandlers.Length);
     foreach (HighCatchHandler catchHandler in m_catchHandlers)
         catchHandler.Write(fileBuilder, methodBuilder, haveDebugInfo, writer);
 }
Пример #9
0
 public void Write(HighFileBuilder fileBuilder, HighRegionBuilder regionBuilder, BinaryWriter writer)
 {
     writer.Write((uint)m_escapePath);
     writer.Write(regionBuilder.IndexCfgNode(m_cfgNode.Value));
 }
Пример #10
0
 public override void WriteHeader(HighFileBuilder fileBuilder, HighMethodBuilder methodBuilder, HighRegionBuilder regionBuilder, HighCfgNodeBuilder cfgNodeBuilder, bool haveDebugInfo, BinaryWriter writer)
 {
     writer.Write((byte)m_conversionType);
     writer.Write(m_destPrecision);
     writer.Write(m_sourcePrecision);
 }
Пример #11
0
        public void Write(HighFileBuilder fileBuilder, BinaryWriter writer)
        {
            writer.Write(m_instanceLocal != null);
            writer.Write((uint)m_args.Length);
            writer.Write((uint)m_locals.Length);
            writer.Write(m_haveDebugInfo);

            List<HighLocal> allLocals = new List<HighLocal>();
            if (m_instanceLocal != null)
                allLocals.Add(m_instanceLocal);
            allLocals.AddRange(m_args);
            allLocals.AddRange(m_locals);

            foreach (HighLocal local in allLocals)
                local.Write(fileBuilder, writer);

            HighMethodBuilder methodBuilder = new HighMethodBuilder(allLocals.ToArray());

            m_region.Write(fileBuilder, methodBuilder, m_haveDebugInfo, writer);
        }
Пример #12
0
        private bool WriteSignatureMatchedBinding(HighFileBuilder fileBuilder, BinaryWriter writer, CppClass cls, CppVtableSlot ifcSlot, CLRTypeSpec ifcTypeSpec)
        {
            bool haveMatch = false;
            foreach (CppVtableSlot vtSlot in cls.NewImplementationVisibleVtableSlots)
            {
                if (ifcSlot.Name == vtSlot.Name && ifcSlot.Signature.Equals(vtSlot.Signature))
                {
                    if (haveMatch)
                    {
                        Console.WriteLine("WARNING: Class " + cls.FullName + " has multiple matches for the same interface implementation");
                        break;
                    }
                    haveMatch = true;

                    writer.Write(true);    // HACK - FIXME
                    WriteInterfaceBinding(fileBuilder, writer, ifcSlot, vtSlot);
                }
            }

            if (haveMatch == true)
                return true;

            CLRTypeSpec parentSpec = cls.ParentTypeSpec;
            if (parentSpec == null)
                return false;

            CppClass parentClass = GetCachedClass(parentSpec);

            // Look for prior implementations of this interface, if any are found, STOP and return no-match.
            // See TestInheritedImplementationDeprioritization.  Matches are only recorded if they're new.
            foreach (CLRTypeSpec ifc in parentClass.NewlyImplementedInterfaces)
                if (ifc.Equals(ifcTypeSpec))
                    return false;
            foreach (CLRTypeSpec ifc in parentClass.ReimplementedInterfaces)
                if (ifc.Equals(ifcTypeSpec))
                    return false;
            return WriteSignatureMatchedBinding(fileBuilder, writer, parentClass, ifcSlot, ifcTypeSpec);
        }
Пример #13
0
        public CppBuilder(string exportDir, string stubDir, CLRAssemblyCollection assemblies, IDictionary<CLRAssembly, string> pdbPaths)
        {
            m_assemblies = assemblies;
            m_exportPath = exportDir;
            m_stubDir = stubDir;
            m_typeSpecClasses = new Dictionary<CLRTypeSpec, CppClass>();
            m_fullNameClasses = new Dictionary<string, CppClass>();
            m_pdbs = new Dictionary<CLRAssembly, PdbDebugInfo>();

            foreach (KeyValuePair<CLRAssembly, string> pdbPath in pdbPaths)
            {
                using (System.IO.FileStream fs = new FileStream(pdbPath.Value, FileMode.Open, FileAccess.Read))
                {
                    PdbDebugInfo pdbDebugInfo = new PdbDebugInfo(fs);
                    m_pdbs.Add(pdbPath.Key, pdbDebugInfo);
                }
            }

            // Generate type def cache
            foreach (CLRAssembly assm in assemblies)
            {
                CLRMetaDataTables tables = assm.MetaData.MetaDataTables;
                ICLRTable typeDefs = tables.GetTable(CLRMetaDataTables.TableIndex.TypeDef);

                for (uint i = 0; i < typeDefs.NumRows; i++)
                {
                    CLRTypeDefRow typeDef = (CLRTypeDefRow)typeDefs.GetRow(i);
                    CacheTypeDef(typeDef);
                }
            }

            // Export everything
            foreach (CLRAssembly assm in assemblies)
            {
                CLRMetaDataTables tables = assm.MetaData.MetaDataTables;
                ICLRTable typeDefs = tables.GetTable(CLRMetaDataTables.TableIndex.TypeDef);

                ICLRTable assemblyTable = tables.GetTable(CLRMetaDataTables.TableIndex.Assembly);
                CLRAssemblyRow assemblyRow = (CLRAssemblyRow)assemblyTable.GetRow(0);

                Clarity.Rpa.HighFileBuilder fileBuilder = new Clarity.Rpa.HighFileBuilder();

                using (FileStream fs = new FileStream(exportDir + assemblyRow.Name + ".rpa", FileMode.Create))
                {
                    using (BinaryWriter writer = new BinaryWriter(fs))
                    {
                        using (MemoryStream objDataStream = new MemoryStream())
                        {
                            using (BinaryWriter objDataWriter = new BinaryWriter(objDataStream))
                            {
                                uint numUsableTypes = 0;

                                for (uint i = 0; i < typeDefs.NumRows; i++)
                                {
                                    CLRTypeDefRow typeDef = (CLRTypeDefRow)typeDefs.GetRow(i);
                                    if (typeDef.Extends == null)
                                    {
                                        if (typeDef.TypeNamespace == "" && typeDef.TypeName == "<Module>")
                                            continue;

                                        if (typeDef.Semantics != CLRTypeDefRow.TypeSemantics.Interface && (typeDef.TypeNamespace != "System" || typeDef.TypeName != "Object"))
                                            throw new Exception("Unexpected parentless type");
                                    }
                                    numUsableTypes++;
                                }

                                objDataWriter.Write(numUsableTypes);

                                for (uint i = 0; i < typeDefs.NumRows; i++)
                                {
                                    CLRTypeDefRow typeDef = (CLRTypeDefRow)typeDefs.GetRow(i);

                                    if (typeDef.Extends == null && typeDef.TypeNamespace == "" && typeDef.TypeName == "<Module>")
                                        continue;

                                    ExportTypeDef(fileBuilder, objDataWriter, typeDef);
                                }

                                uint assemblyNameIndex = fileBuilder.IndexString(assemblyRow.Name);

                                writer.Write(0x41503252);   // R2PA
                                fileBuilder.FlushAndWriteCatalogs(writer);
                                writer.Write(assemblyNameIndex);
                                writer.Flush();

                                objDataWriter.Flush();
                                objDataStream.WriteTo(fs);
                            }
                        }
                    }
                }
            }
        }
Пример #14
0
        public void WriteConstant(HighFileBuilder fileBuilder, HighRegionBuilder regionBuilder, BinaryWriter writer)
        {
            if (!this.IsConstant)
                throw new Exception("Can't use non-constant as a constant");
            writer.Write((byte)m_valueType);
            writer.Write(fileBuilder.IndexTypeSpecTag(m_type));

            if (m_valueType == HighValueType.Null)
            {
            }
            else if (m_valueType == HighValueType.ConstantString)
                writer.Write(fileBuilder.IndexString((string)m_constValue));
            else if (m_valueType == HighValueType.ConstantValue)
            {
                TypeSpecClassTag classTag = (TypeSpecClassTag)m_type;
                TypeNameTag className = classTag.TypeName;
                string classNameStr = className.TypeName;

                if (classNameStr == "SByte")
                    writer.Write((sbyte)m_constValue);
                else if (classNameStr == "Byte")
                    writer.Write((byte)m_constValue);
                else if (classNameStr == "Int16")
                    writer.Write((short)m_constValue);
                else if (classNameStr == "UInt16")
                    writer.Write((ushort)m_constValue);
                else if (classNameStr == "Int32")
                    writer.Write((int)m_constValue);
                else if (classNameStr == "UInt32")
                    writer.Write((uint)m_constValue);
                else if (classNameStr == "Int64")
                    writer.Write((long)m_constValue);
                else if (classNameStr == "UInt64")
                    writer.Write((ulong)m_constValue);
                else if (classNameStr == "IntPtr")
                    writer.Write((long)m_constValue);
                else if (classNameStr == "UIntPtr")
                    writer.Write((ulong)m_constValue);
                else if (classNameStr == "Single")
                    writer.Write((float)m_constValue);
                else if (classNameStr == "Double")
                    writer.Write((double)m_constValue);
                else
                    throw new ArgumentException();
            }
            else
                throw new Exception();
        }
Пример #15
0
 public override void WriteHeader(HighFileBuilder fileBuilder, HighMethodBuilder methodBuilder, HighRegionBuilder regionBuilder, HighCfgNodeBuilder cfgNodeBuilder, bool haveDebugInfo, BinaryWriter writer)
 {
     writer.Write(m_fieldIndex);
     writer.Write(m_isStatic);
 }
Пример #16
0
        public void WriteDestinationDef(HighFileBuilder fileBuilder, HighRegionBuilder regionBuilder, BinaryWriter writer)
        {
            if (this.IsConstant)
                throw new Exception("Can't use constant as a destination");

            writer.Write((byte)m_valueType);
            writer.Write(fileBuilder.IndexTypeSpecTag(m_type));
        }
 public override void Write(HighFileBuilder highFileBuilder, BinaryWriter catalogWriter)
 {
     throw new NotImplementedException();
 }
Пример #18
0
 public void Write(HighFileBuilder fileBuilder, HighMethodBuilder methodBuilder, bool haveDebugInfo, BinaryWriter writer)
 {
     writer.Write(fileBuilder.IndexTypeSpecTag(m_catchType));
     m_region.Write(fileBuilder, methodBuilder, haveDebugInfo, writer);
 }
Пример #19
0
 public abstract void Write(HighFileBuilder highFileBuilder, BinaryWriter catalogWriter);
Пример #20
0
        public override void Write(HighFileBuilder highFileBuilder, BinaryWriter catalogWriter)
        {
            uint typeName = highFileBuilder.IndexTypeNameTag(m_typeNameTag);
            List<uint> argTypes = new List<uint>();

            foreach (TypeSpecTag typeTag in m_argTypes)
                argTypes.Add(highFileBuilder.IndexTypeSpecTag(typeTag));

            catalogWriter.Write((byte)SubTypeCode.Class);
            catalogWriter.Write(typeName);

            foreach (uint argType in argTypes)
                catalogWriter.Write(argType);
        }
Пример #21
0
 public override void Write(HighFileBuilder highFileBuilder, BinaryWriter catalogWriter)
 {
     catalogWriter.Write((byte)SubTypeCode.Void);
 }
Пример #22
0
 public override void WriteHeader(HighFileBuilder fileBuilder, HighMethodBuilder methodBuilder, HighRegionBuilder regionBuilder, HighCfgNodeBuilder cfgNodeBuilder, bool haveDebugInfo, BinaryWriter writer)
 {
 }
 public override void WriteHeader(HighFileBuilder fileBuilder, HighMethodBuilder methodBuilder, HighRegionBuilder regionBuilder, HighCfgNodeBuilder cfgNodeBuilder, bool haveDebugInfo, BinaryWriter writer)
 {
     throw new NotImplementedException();
 }
Пример #24
0
 public override void Write(HighFileBuilder highFileBuilder, BinaryWriter catalogWriter)
 {
     catalogWriter.Write((byte)SubTypeCode.GenericParameter);
     m_genericParamType.Write(catalogWriter);
     catalogWriter.Write(m_index);
 }
Пример #25
0
 public void Write(HighFileBuilder fileBuilder, HighMethodBuilder methodBuilder, bool haveDebugInfo, BinaryWriter writer)
 {
     writer.Write((byte)this.RegionType);
     m_tryRegion.Write(fileBuilder, methodBuilder, haveDebugInfo, writer);
     WriteHandlers(fileBuilder, methodBuilder, haveDebugInfo, writer);
 }