public static TypeSpecGenericParamTag Read(CatalogReader rpa, BinaryReader reader) { TypeSpecGenericParamTypeTag paramType = TypeSpecGenericParamTypeTag.Read(reader); uint index = reader.ReadUInt32(); return new TypeSpecGenericParamTag(paramType, index); }
public static HighProtectedRegion Read(TagRepository rpa, CatalogReader catalog, HighMethodBodyParseContext methodBody, CodeLocationTag baseLocation, bool haveDebugInfo, BinaryReader reader) { HighProtectedRegion region; RegionTypeEnum regionType = (RegionTypeEnum)reader.ReadByte(); HighRegion tryRegion = HighRegion.Read(rpa, catalog, methodBody, baseLocation, haveDebugInfo, reader); switch (regionType) { case RegionTypeEnum.TryCatch: region = new HighTryCatchRegion(tryRegion); break; case RegionTypeEnum.TryFault: region = new HighTryFaultRegion(tryRegion); break; case RegionTypeEnum.TryFinally: region = new HighTryFinallyRegion(tryRegion); break; default: throw new Exception("Invalid protected region type"); } region.ReadHandlers(rpa, catalog, methodBody, baseLocation, haveDebugInfo, reader); return region; }
public static TypeSpecTag ReadVariant(CatalogReader rpa, BinaryReader reader) { TypeSpecTag tag = null; SubTypeCode typeCode = (SubTypeCode)reader.ReadByte(); switch (typeCode) { case SubTypeCode.Array: tag = TypeSpecArrayTag.Read(rpa, reader); break; case SubTypeCode.Class: tag = TypeSpecClassTag.Read(rpa, reader); break; case SubTypeCode.GenericParameter: tag = TypeSpecGenericParamTag.Read(rpa, reader); break; case SubTypeCode.Void: tag = TypeSpecVoidTag.Read(rpa, reader); break; default: throw new Exception("Malformed type tag"); } return tag; }
public static HighEnumLiteral Read(CatalogReader catalog, BinaryReader reader, uint literalSize, bool isSigned) { string name = catalog.GetString(reader.ReadUInt32()); long value; switch (literalSize) { case 8: value = reader.ReadInt64(); break; case 4: if (isSigned) value = reader.ReadInt32(); else value = reader.ReadUInt32(); break; case 2: if (isSigned) value = reader.ReadInt16(); else value = reader.ReadUInt16(); break; case 1: if (isSigned) value = reader.ReadSByte(); else value = reader.ReadByte(); break; default: throw new ArgumentException(); } return new HighEnumLiteral(name, value); }
public static HighEscapePathTerminator Read(TagRepository rpa, CatalogReader catalog, HighMethodBodyParseContext methodBody, HighCfgNodeHandle[] cfgNodes, BinaryReader reader) { uint escapePath = reader.ReadUInt32(); HighCfgNodeHandle cfgNode = cfgNodes[reader.ReadUInt32()]; return new HighEscapePathTerminator(escapePath, cfgNode); }
public static HighRegion Read(TagRepository rpa, CatalogReader catalog, HighMethodBodyParseContext methodBody, CodeLocationTag baseLocation, bool haveDebugInfo, BinaryReader reader) { uint numCfgNodes = reader.ReadUInt32(); if (numCfgNodes == 0) throw new Exception("Region has no CFG nodes"); HighCfgNodeHandle[] cfgNodes = new HighCfgNodeHandle[numCfgNodes]; for (uint i = 0; i < numCfgNodes; i++) cfgNodes[i] = new HighCfgNodeHandle(); for (uint i = 0; i < numCfgNodes; i++) cfgNodes[i].Value = HighCfgNode.Read(rpa, catalog, methodBody, cfgNodes, baseLocation, haveDebugInfo, reader); RegionPhiResolver phiResolver = new RegionPhiResolver(cfgNodes); for (uint i = 0; i < numCfgNodes; i++) { foreach (HighPhi phi in cfgNodes[i].Value.Phis) phi.Resolve(phiResolver); } HighCfgNodeHandle entryNode = cfgNodes[0]; if (entryNode.Value.Phis.Length != 0) throw new RpaLoadException("Region entry node has phis"); return new HighRegion(entryNode); }
public static HighPhi Read(TagRepository rpa, CatalogReader catalog, HighMethodBodyParseContext methodBody, HighCfgNodeHandle[] cfgNodes, uint[] predecessors, BinaryReader reader) { HighSsaRegister dest = HighSsaRegister.ReadDestinationDef(rpa, catalog, reader); if (dest == null) throw new Rpa.RpaLoadException("Phi has no destination"); HighUnresolvedPhiCollection unresolvedCollection = HighUnresolvedPhiCollection.Read(rpa, catalog, cfgNodes, predecessors, reader); return new HighPhi(dest, unresolvedCollection); }
protected override void ReadHandlers(TagRepository rpa, CatalogReader catalog, HighMethodBodyParseContext methodBody, CodeLocationTag baseLocation, bool haveDebugInfo, BinaryReader reader) { uint numCatchHandlers = reader.ReadUInt32(); m_catchHandlers = new HighCatchHandler[numCatchHandlers]; for (uint i = 0; i < numCatchHandlers; i++) { HighCatchHandler hdl = new HighCatchHandler(); hdl.Read(rpa, catalog, methodBody, baseLocation, haveDebugInfo, reader); m_catchHandlers[i] = hdl; } }
public static TypeSpecClassTag Read(CatalogReader rpa, BinaryReader reader) { TypeNameTag typeNameTag = rpa.GetTypeName(reader.ReadUInt32()); uint numArgTypes = typeNameTag.NumGenericParameters; TypeSpecTag[] argTypes = new TypeSpecTag[numArgTypes]; for (uint i = 0; i < numArgTypes; i++) argTypes[i] = rpa.GetTypeSpec(reader.ReadUInt32()); return new TypeSpecClassTag(typeNameTag, argTypes); }
public static HighUnresolvedPhiCollection Read(TagRepository rpa, CatalogReader catalog, HighCfgNodeHandle[] cfgNodes, uint[] predecessors, BinaryReader reader) { int numLinks = predecessors.Length; List<UnresolvedLink> links = new List<UnresolvedLink>(); foreach (uint pred in predecessors) { UnresolvedLink link = UnresolvedLink.Read(rpa, catalog, pred, reader); links.Add(link); } return new HighUnresolvedPhiCollection(links.ToArray()); }
public static HighEHCluster Read(TagRepository rpa, CatalogReader catalog, HighMethodBodyParseContext methodBody, HighCfgNodeHandle[] cfgNodes, CodeLocationTag baseLocation, bool haveDebugInfo, BinaryReader reader) { uint numTerminators = reader.ReadUInt32(); HighEscapePathTerminator[] escapePathTerminators = new HighEscapePathTerminator[numTerminators]; for (uint i = 0; i < numTerminators; i++) { HighEscapePathTerminator terminator = HighEscapePathTerminator.Read(rpa, catalog, methodBody, cfgNodes, reader); escapePathTerminators[i] = terminator; } HighProtectedRegion protRegion = HighProtectedRegion.Read(rpa, catalog, methodBody, baseLocation, haveDebugInfo, reader); return new HighEHCluster(protRegion, escapePathTerminators); }
public static HighCfgNode Read(TagRepository rpa, CatalogReader catalog, HighMethodBodyParseContext methodBody, HighCfgNodeHandle[] cfgNodes, CodeLocationTag baseLocation, bool haveDebugInfo, BinaryReader reader) { uint numPredecessors = reader.ReadUInt32(); uint numPhis = reader.ReadUInt32(); uint numInstructions = reader.ReadUInt32(); uint numConstants = reader.ReadUInt32(); List<HighPhi> phis = new List<HighPhi>(); List<HighInstruction> instructions = new List<HighInstruction>(); List<HighSsaRegister> ssaRegisters = new List<HighSsaRegister>(); List<uint> predecessors = new List<uint>(); List<HighCfgNodeHandle> realPreds = new List<HighCfgNodeHandle>(); // WARNING: SSA indexes from phis and constants must match CollectRegsFromNode for (uint i = 0; i < numPredecessors; i++) { uint predIndex = reader.ReadUInt32(); predecessors.Add(predIndex); realPreds.Add(cfgNodes[predIndex]); } uint[] predecessorsArray = predecessors.ToArray(); for (uint i = 0; i < numPhis; i++) { HighPhi phi = HighPhi.Read(rpa, catalog, methodBody, cfgNodes, predecessorsArray, reader); phis.Add(phi); ssaRegisters.Add(phi.Dest); } for (uint i = 0; i < numConstants; i++) { HighSsaRegister constant = HighSsaRegister.ReadConstant(rpa, catalog, reader); ssaRegisters.Add(constant); } if (numInstructions == 0) throw new RpaLoadException("Empty CFG node"); for (uint i = 0; i < numInstructions; i++) { HighInstruction instr = HighInstruction.Read(rpa, catalog, methodBody, cfgNodes, ssaRegisters, baseLocation, haveDebugInfo, reader); instructions.Add(instr); } return new HighCfgNode(realPreds.ToArray(), phis.ToArray(), instructions.ToArray()); }
// Export exists in CppBuilder.ExportClassDefinitions public static HighMethod Read(TagRepository rpa, CatalogReader catalog, BinaryReader reader, TypeNameTag declaringClass) { bool isStatic = reader.ReadBoolean(); MethodSignatureTag methodSignature = catalog.GetMethodSignature(reader.ReadUInt32()); string name = catalog.GetString(reader.ReadUInt32()); MethodDeclTag methodDeclTag = new MethodDeclTag(name, methodSignature, declaringClass); methodDeclTag = rpa.InternMethodDeclTag(methodDeclTag); bool isInternal = reader.ReadBoolean(); HighMethodBody methodBody; if (isInternal) methodBody = null; else methodBody = HighMethodBody.Read(rpa, catalog, methodDeclTag, reader); return new HighMethod(isStatic, methodSignature, methodBody, methodDeclTag, isInternal); }
public static HighMethodBody Read(TagRepository rpa, CatalogReader catalog, MethodDeclTag methodDecl, BinaryReader reader) { bool haveInstanceLocal = reader.ReadBoolean(); uint numArgs = reader.ReadUInt32(); uint numLocals = reader.ReadUInt32(); bool haveDebugInfo = reader.ReadBoolean(); HighLocal instanceLocal; if (haveInstanceLocal) { instanceLocal = new HighLocal(); instanceLocal.Read(rpa, catalog, reader); } else instanceLocal = null; HighLocal[] args = new HighLocal[numArgs]; HighLocal[] locals = new HighLocal[numLocals]; for (uint i = 0; i < numArgs; i++) { HighLocal arg = new HighLocal(); arg.Read(rpa, catalog, reader); args[i] = arg; } for (uint i = 0; i < numLocals; i++) { HighLocal local = new HighLocal(); local.Read(rpa, catalog, reader); locals[i] = local; } HighMethodBodyParseContext parseContext = new HighMethodBodyParseContext(instanceLocal, args, locals); CodeLocationTag baseLocation = new CodeLocationTag(methodDecl, 0); HighRegion region = HighRegion.Read(rpa, catalog, parseContext, baseLocation, haveDebugInfo, reader); return new HighMethodBody(region, instanceLocal, args, locals, haveDebugInfo); }
private void ReadEnum(TagRepository rpa, CatalogReader catalog, BinaryReader reader) { byte underlyingTypeSymbol = reader.ReadByte(); bool isSigned; uint literalSize; switch ((EnumUnderlyingType)underlyingTypeSymbol) { case EnumUnderlyingType.Int8: case EnumUnderlyingType.Int16: case EnumUnderlyingType.Int32: case EnumUnderlyingType.Int64: isSigned = true; break; case EnumUnderlyingType.UInt8: case EnumUnderlyingType.UInt16: case EnumUnderlyingType.UInt32: case EnumUnderlyingType.UInt64: isSigned = false; break; default: throw new Exception("Unrecognized enum underlying type"); } switch ((EnumUnderlyingType)underlyingTypeSymbol) { case EnumUnderlyingType.Int8: case EnumUnderlyingType.UInt8: literalSize = 1; break; case EnumUnderlyingType.Int16: case EnumUnderlyingType.UInt16: literalSize = 2; break; case EnumUnderlyingType.Int32: case EnumUnderlyingType.UInt32: literalSize = 4; break; case EnumUnderlyingType.Int64: case EnumUnderlyingType.UInt64: literalSize = 8; break; default: throw new Exception(); } uint numLiterals = reader.ReadUInt32(); HighEnumLiteral[] literals = new HighEnumLiteral[numLiterals]; for (uint i = 0; i < numLiterals; i++) literals[i] = HighEnumLiteral.Read(catalog, reader, literalSize, isSigned); m_enumLiterals = literals; m_underlyingType = (EnumUnderlyingType)underlyingTypeSymbol; }
public static UnresolvedLink Read(TagRepository rpa, CatalogReader catalog, uint predecessorIndex, BinaryReader reader) { bool isConstant = reader.ReadBoolean(); HighSsaRegister constantReg; uint linkIndex; if (isConstant) { constantReg = HighSsaRegister.ReadConstant(rpa, catalog, reader); linkIndex = 0; } else { constantReg = null; linkIndex = reader.ReadUInt32(); } return new UnresolvedLink(isConstant, constantReg, predecessorIndex, linkIndex); }
private void ReadVtableThunks(TagRepository rpa, CatalogReader catalog, BinaryReader reader) { bool isInterface = (m_semantics == TypeSemantics.Interface); if (!isInterface) { if (m_semantics != TypeSemantics.Class && m_semantics != TypeSemantics.Struct) throw new ArgumentException(); } if (!isInterface) { uint numReplacedSlots = reader.ReadUInt32(); m_replacedSlots = new HighClassVtableSlot[numReplacedSlots]; for (uint i = 0; i < numReplacedSlots; i++) { HighClassVtableSlot mapping = HighClassVtableSlot.Read(rpa, catalog, reader, isInterface); m_replacedSlots[i] = mapping; } } uint numNewSlots = reader.ReadUInt32(); m_newSlots = new HighClassVtableSlot[numNewSlots]; for (uint i = 0; i < numNewSlots; i++) { HighClassVtableSlot mapping = HighClassVtableSlot.Read(rpa, catalog, reader, isInterface); m_newSlots[i] = mapping; } }
private void ReadDelegate(TagRepository rpa, CatalogReader catalog, BinaryReader reader) { m_isMulticastDelegate = reader.ReadBoolean(); ReadGenericParameterVariance(reader); m_delegateSignature = catalog.GetMethodSignature(reader.ReadUInt32()); if (m_delegateSignature.NumGenericParameters > 0) throw new Exception("Delegate has generic parameters"); }
public void Read(TagRepository rpa, CatalogReader catalog, HighMethodBodyParseContext methodBody, CodeLocationTag baseLocation, bool haveDebugInfo, BinaryReader reader) { m_catchType = catalog.GetTypeSpec(reader.ReadUInt32()); m_region = HighRegion.Read(rpa, catalog, methodBody, baseLocation, haveDebugInfo, reader); }
public static HighSsaRegister ReadConstant(TagRepository rpa, CatalogReader catalog, BinaryReader reader) { HighValueType vt = (HighValueType)reader.ReadByte(); TypeSpecTag type = catalog.GetTypeSpec(reader.ReadUInt32()); TypeNameTag typeName = null; if (vt != HighValueType.Null) { TypeSpecClassTag classTag = type as TypeSpecClassTag; if (classTag == null) throw new Exception("Constant is not a class tag"); typeName = classTag.TypeName; if (classTag.ArgTypes.Length != 0 || typeName.ContainerType != null || typeName.AssemblyName != "mscorlib" || typeName.TypeNamespace != "System") throw new Exception("Constant type unrecognized"); } switch (vt) { case HighValueType.Null: return new HighSsaRegister(HighValueType.Null, type, null); case HighValueType.ConstantString: { if (typeName.TypeName != "String") throw new Exception("Constant type mismatch"); string str = catalog.GetString(reader.ReadUInt32()); return new HighSsaRegister(HighValueType.ConstantString, type, str); } case HighValueType.ConstantValue: { string classNameStr = typeName.TypeName; object constValue; if (classNameStr == "SByte") constValue = reader.ReadSByte(); else if (classNameStr == "Byte") constValue = reader.ReadByte(); else if (classNameStr == "Int16") constValue = reader.ReadInt16(); else if (classNameStr == "UInt16") constValue = reader.ReadUInt16(); else if (classNameStr == "Int32") constValue = reader.ReadInt32(); else if (classNameStr == "UInt32") constValue = reader.ReadUInt32(); else if (classNameStr == "Int64") constValue = reader.ReadInt64(); else if (classNameStr == "UInt64") constValue = reader.ReadUInt64(); else if (classNameStr == "IntPtr") constValue = reader.ReadInt64(); else if (classNameStr == "UIntPtr") constValue = reader.ReadUInt64(); else if (classNameStr == "Single") constValue = reader.ReadSingle(); else if (classNameStr == "Double") constValue = reader.ReadDouble(); else throw new Exception("Invalid constant"); return new HighSsaRegister(HighValueType.ConstantValue, type, constValue); } default: throw new Exception("Invalid constant"); } }
private void ReadClassDefinitions(TagRepository rpa, CatalogReader catalog, BinaryReader reader) { m_parentClass = null; if (m_semantics == TypeSemantics.Class) { m_isSealed = reader.ReadBoolean(); m_isAbstract = reader.ReadBoolean(); uint parentClassIndex = reader.ReadUInt32(); if (parentClassIndex == 0) { if (m_typeName.AssemblyName != "mscorlib" || m_typeName.TypeNamespace != "System" || m_typeName.TypeName != "Object") throw new Exception("Parentless class is not System.Object"); } else { TypeSpecTag parentClass = catalog.GetTypeSpec(parentClassIndex - 1); TypeSpecClassTag clsTag = parentClass as TypeSpecClassTag; if (clsTag == null) throw new Exception("Parent class spec wasn't a class"); m_parentClass = clsTag; } } if (m_semantics == TypeSemantics.Struct || m_semantics == TypeSemantics.Enum) { m_isSealed = true; m_isAbstract = false; } if (m_semantics == TypeSemantics.Interface) { m_isSealed = false; m_isAbstract = true; ReadGenericParameterVariance(reader); } uint numInterfaces = reader.ReadUInt32(); TypeSpecClassTag[] interfaces = new TypeSpecClassTag[numInterfaces]; for (uint i = 0; i < numInterfaces; i++) { TypeSpecTag typeSpec = catalog.GetTypeSpec(reader.ReadUInt32()); TypeSpecClassTag classTag = typeSpec as TypeSpecClassTag; if (classTag == null) throw new RpaLoadException("Interface implementation is not a class tag"); interfaces[i] = classTag; } m_parentInterfaces = interfaces; this.ReadVtableThunks(rpa, catalog, reader); if (m_semantics == TypeSemantics.Class || m_semantics == TypeSemantics.Struct) { uint numMethods = reader.ReadUInt32(); m_methods = new HighMethod[numMethods]; for (uint i = 0; i < numMethods; i++) { HighMethod method = HighMethod.Read(rpa, catalog, reader, m_typeName); m_methods[i] = method; } uint numInstanceFields = reader.ReadUInt32(); m_instanceFields = new HighField[numInstanceFields]; for (uint i = 0; i < numInstanceFields; i++) { HighField field = HighField.Read(rpa, catalog, reader); m_instanceFields[i] = field; } this.ReadInterfaceImplementations(rpa, catalog, reader); } }
public override void ReadHeader(TagRepository rpa, CatalogReader catalog, HighMethodBodyParseContext methodBody, HighCfgNodeHandle[] cfgNodes, List<HighSsaRegister> ssaRegisters, CodeLocationTag baseLocation, bool haveDebugInfo, BinaryReader reader) { m_conversionType = (NumConversionType)reader.ReadByte(); m_destPrecision = reader.ReadUInt32(); m_sourcePrecision = reader.ReadUInt32(); }
public static HighSsaRegister ReadDestinationDef(TagRepository rpa, CatalogReader catalog, BinaryReader reader) { HighValueType vt = (HighValueType)reader.ReadByte(); TypeSpecTag type = catalog.GetTypeSpec(reader.ReadUInt32()); switch (vt) { case HighValueType.ManagedPtr: case HighValueType.ValueValue: case HighValueType.ReferenceValue: break; default: throw new RpaLoadException("Invalid SSA destination type"); } return new HighSsaRegister(vt, type, null); }
private void ReadInterfaceImplementations(TagRepository rpa, CatalogReader catalog, BinaryReader reader) { if (m_semantics != TypeSemantics.Class && m_semantics != TypeSemantics.Struct) return; uint numInterfaces = reader.ReadUInt32(); m_interfaceImpls = new HighInterfaceImplementation[numInterfaces]; for (uint i = 0; i < numInterfaces; i++) { HighInterfaceImplementation impl = new HighInterfaceImplementation(); impl.Read(rpa, catalog, reader); m_interfaceImpls[i] = impl; } }
public void Read(TagRepository rpa, CatalogReader catalog, BinaryReader reader) { m_semantics = (TypeSemantics)reader.ReadByte(); switch (m_semantics) { case TypeSemantics.Class: case TypeSemantics.Interface: case TypeSemantics.Struct: case TypeSemantics.Enum: case TypeSemantics.Delegate: break; default: throw new RpaLoadException("Invalid type semantics"); } m_typeName = catalog.GetTypeName(reader.ReadUInt32()); if (m_typeName.AssemblyName != catalog.AssemblyName) throw new Exception("Type definition outside of assembly"); m_numGenericParameters = m_typeName.NumGenericParameters; m_underlyingType = EnumUnderlyingType.NotEnum; if (m_semantics == TypeSemantics.Delegate) { this.ReadDelegate(rpa, catalog, reader); } else if (m_semantics == TypeSemantics.Enum) { this.ReadEnum(rpa, catalog, reader); } else { this.ReadClassDefinitions(rpa, catalog, reader); if (m_semantics == Clarity.Rpa.TypeSemantics.Class || m_semantics == Clarity.Rpa.TypeSemantics.Struct) this.ReadClassStatics(rpa, catalog, reader); } }
public override void ReadHeader(TagRepository rpa, CatalogReader catalog, HighMethodBodyParseContext methodBody, HighCfgNodeHandle[] cfgNodes, List<HighSsaRegister> ssaRegisters, CodeLocationTag baseLocation, bool haveDebugInfo, BinaryReader reader) { }
private void ReadClassStatics(TagRepository rpa, CatalogReader catalog, BinaryReader reader) { uint numStaticFields = reader.ReadUInt32(); m_staticFields = new HighField[numStaticFields]; for (uint i = 0; i < numStaticFields; i++) { HighField fld = HighField.Read(rpa, catalog, reader); m_staticFields[i] = fld; } }
public override void ReadHeader(TagRepository rpa, CatalogReader catalog, HighMethodBodyParseContext methodBody, HighCfgNodeHandle[] cfgNodes, List<HighSsaRegister> ssaRegisters, CodeLocationTag baseLocation, bool haveDebugInfo, BinaryReader reader) { m_fieldIndex = reader.ReadUInt32(); m_isStatic = reader.ReadBoolean(); }
public static TypeSpecTag Read(CatalogReader rpa, BinaryReader reader) { return new TypeSpecVoidTag(); }
protected override void ReadHandlers(TagRepository rpa, CatalogReader catalog, HighMethodBodyParseContext methodBody, CodeLocationTag baseLocation, bool haveDebugInfo, BinaryReader reader) { m_finallyRegion = HighRegion.Read(rpa, catalog, methodBody, baseLocation, haveDebugInfo, reader); }