public override void VisitVariableDefinitionCollection(VariableDefinitionCollection variables) { MethodBody body = variables.Container as MethodBody; if (body == null || body.LocalVarToken == 0) { return; } StandAloneSigTable sasTable = m_reflectReader.TableReader.GetStandAloneSigTable(); StandAloneSigRow sasRow = sasTable [(int)GetRid(body.LocalVarToken) - 1]; LocalVarSig sig = m_reflectReader.SigReader.GetLocalVarSig(sasRow.Signature); for (int i = 0; i < sig.Count; i++) { LocalVarSig.LocalVariable lv = sig.LocalVariables [i]; TypeReference varType = m_reflectReader.GetTypeRefFromSig( lv.Type, new GenericContext(body.Method)); if (lv.ByRef) { varType = new ReferenceType(varType); } if ((lv.Constraint & Constraint.Pinned) != 0) { varType = new PinnedType(varType); } varType = m_reflectReader.GetModifierType(lv.CustomMods, varType); body.Variables.Add(new VariableDefinition( string.Concat("V_", i), i, body.Method, varType)); } }
MetadataToken GetCallSiteToken(CallSite cs) { uint sig; int sentinel = cs.GetSentinel(); if (sentinel > 0) { sig = m_reflectWriter.SignatureWriter.AddMethodDefSig( m_reflectWriter.GetMethodDefSig(cs)); } else { sig = m_reflectWriter.SignatureWriter.AddMethodRefSig( m_reflectWriter.GetMethodRefSig(cs)); } if (m_standaloneSigCache.Contains(sig)) { return((MetadataToken)m_standaloneSigCache [sig]); } StandAloneSigTable sasTable = m_reflectWriter.MetadataTableWriter.GetStandAloneSigTable(); StandAloneSigRow sasRow = m_reflectWriter.MetadataRowWriter.CreateStandAloneSigRow(sig); sasTable.Rows.Add(sasRow); MetadataToken token = new MetadataToken(TokenType.Signature, (uint)sasTable.Rows.Count); m_standaloneSigCache [sig] = token; return(token); }
public override void VisitVariableDefinitionCollection(VariableDefinitionCollection variables) { MethodBody body = variables.Container as MethodBody; if (body == null || stripped) { return; } uint sig = m_reflectWriter.SignatureWriter.AddLocalVarSig( GetLocalVarSig(variables)); if (m_localSigCache.Contains(sig)) { body.LocalVarToken = (int)m_localSigCache [sig]; return; } StandAloneSigTable sasTable = m_reflectWriter.MetadataTableWriter.GetStandAloneSigTable(); StandAloneSigRow sasRow = m_reflectWriter.MetadataRowWriter.CreateStandAloneSigRow( sig); sasTable.Rows.Add(sasRow); body.LocalVarToken = sasTable.Rows.Count; m_localSigCache [sig] = body.LocalVarToken; }
private FunctionPointerType /*?*/ GetStandAloneMethodSignature( uint standAloneMethodToken ) { StandAloneSigRow sigRow = this.PEFileToObjectModel.PEFileReader.StandAloneSigTable[standAloneMethodToken & TokenTypeIds.RIDMask]; uint signatureBlobOffset = sigRow.Signature; // TODO: error checking offset in range MemoryBlock signatureMemoryBlock = this.PEFileToObjectModel.PEFileReader.BlobStream.GetMemoryBlockAt(signatureBlobOffset); // TODO: Error checking enough space in signature memoryBlock. MemoryReader memoryReader = new MemoryReader(signatureMemoryBlock); // TODO: Check if this is really field signature there. StandAloneMethodSignatureConverter standAloneSigConv = new StandAloneMethodSignatureConverter(this.PEFileToObjectModel, this.MethodDefinition, memoryReader); if (standAloneSigConv.ReturnTypeReference == null) { return(null); } return (new FunctionPointerType( this.PEFileToObjectModel, 0xFFFFFFFF, (CallingConvention)standAloneSigConv.FirstByte, standAloneSigConv.ReturnCustomModifiers, standAloneSigConv.IsReturnByReference, standAloneSigConv.ReturnTypeReference, standAloneSigConv.RequiredParameters, standAloneSigConv.VarArgParameters )); }
public override void FromRawData(byte [] buff, int offs, int numRows) { for (int i = numRows; --i >= 0;) { Row row = new StandAloneSigRow(this); row.FromRawData(buff, offs); Add(row); offs += StandAloneSigRow.LogicalSize; } }
/// <summary> /// Reads the specified token. /// </summary> /// <param name="token">The token.</param> /// <param name="result">The result.</param> public void Read(TokenTypes token, out StandAloneSigRow result) { if ((token & TokenTypes.TableMask) != TokenTypes.StandAloneSig) { throw new ArgumentException("Invalid token type for StandAloneSigRow.", "token"); } using (BinaryReader reader = CreateReaderForToken(token)) { result = new StandAloneSigRow(ReadIndexValue(reader, IndexType.BlobHeap)); } }
private bool LoadLocalSignature() { EnumerableArrayWrapper <LocalVariableDefinition, ILocalDefinition> localVariables = ILReader.EmptyLocalVariables; uint locVarRID = _methodIL.LocalSignatureToken & TokenTypeIds.RIDMask; if (locVarRID != 0x00000000) { StandAloneSigRow sigRow = this.PEFileToObjectModel.PEFileReader.StandAloneSigTable[locVarRID]; // TODO: error checking offset in range MemoryBlock signatureMemoryBlock = this.PEFileToObjectModel.PEFileReader.BlobStream.GetMemoryBlockAt(sigRow.Signature); // TODO: Error checking enough space in signature memoryBlock. MemoryReader memoryReader = new MemoryReader(signatureMemoryBlock); // TODO: Check if this is really local var signature there. LocalVariableSignatureConverter locVarSigConv = new LocalVariableSignatureConverter(this.PEFileToObjectModel, this.MethodBody, memoryReader); localVariables = locVarSigConv.LocalVariables; } this.MethodBody.SetLocalVariables(localVariables); return(true); }
/// <summary> /// Performs stage specific processing on the compiler context. /// </summary> public void Run() { using (Stream code = methodCompiler.GetInstructionStream()) { // Initialize the instruction methodCompiler.InstructionSet = new InstructionSet(256); // update the base class InstructionSet = methodCompiler.InstructionSet; using (codeReader = new BinaryReader(code)) { // The size of the code in bytes MethodHeader header = new MethodHeader(); ReadMethodHeader(codeReader, ref header); if (header.localsSignature.RID != 0) { StandAloneSigRow row = methodCompiler.Method.Module.MetadataModule.Metadata.ReadStandAloneSigRow(header.localsSignature); LocalVariableSignature localsSignature; if (methodCompiler.Method.DeclaringType is CilGenericType) { localsSignature = new LocalVariableSignature(methodCompiler.Method.Module.MetadataModule.Metadata, row.SignatureBlobIdx, (methodCompiler.Method.DeclaringType as CilGenericType).GenericArguments); } else { localsSignature = new LocalVariableSignature(methodCompiler.Method.Module.MetadataModule.Metadata, row.SignatureBlobIdx); } methodCompiler.SetLocalVariableSignature(localsSignature); } /* Decode the instructions */ Decode(methodCompiler, ref header); // When we leave, the operand stack must only contain the locals... //Debug.Assert(_operandStack.Count == _method.Locals.Count); } } }
public virtual void VisitStandAloneSigRow(StandAloneSigRow row) { }
void IMetadataProvider.Read(TokenTypes token, out StandAloneSigRow result) { TableHeap theap = (TableHeap)_streams[(int)HeapType.Tables]; theap.Read(token, out result); }