public override LocalVariableDefinition[] GetLocals() { LocalVariableDefinition[] locals = _methodIL.GetLocals(); LocalVariableDefinition[] clone = null; for (int i = 0; i < locals.Length; i++) { TypeDesc uninst = locals[i].Type; TypeDesc inst = uninst.InstantiateSignature(_typeInstantiation, _methodInstantiation); if (uninst != inst) { if (clone == null) { clone = new LocalVariableDefinition[locals.Length]; for (int j = 0; j < clone.Length; j++) { clone[j] = locals[j]; } } clone[i] = new LocalVariableDefinition(inst, locals[i].IsPinned); } } return((clone == null) ? locals : clone); }
public LocalVariableDefinition[] ParseLocalsSignature() { if (_reader.ReadSignatureHeader().Kind != SignatureKind.LocalVariables) { throw new BadImageFormatException(); } int count = _reader.ReadCompressedInteger(); LocalVariableDefinition[] locals; if (count > 0) { locals = new LocalVariableDefinition[count]; for (int i = 0; i < count; i++) { bool isPinned = false; SignatureTypeCode typeCode = ParseTypeCode(); if (typeCode == SignatureTypeCode.Pinned) { isPinned = true; typeCode = ParseTypeCode(); } locals[i] = new LocalVariableDefinition(ParseType(typeCode), isPinned); } } else { locals = Array.Empty <LocalVariableDefinition>(); } return(locals); }
public LocalVariableDefinition[] ParseLocalsSignature() { if ((_reader.ReadByte() & 0xF) != 7) // IMAGE_CEE_CS_CALLCONV_LOCAL_SIG - add it to SignatureCallingConvention? { throw new BadImageFormatException(); } int count = _reader.ReadCompressedInteger(); LocalVariableDefinition[] locals; if (count > 0) { locals = new LocalVariableDefinition[count]; for (int i = 0; i < count; i++) { bool isPinned = false; SignatureTypeCode typeCode = ParseTypeCode(); if (typeCode == SignatureTypeCode.Pinned) { isPinned = true; typeCode = ParseTypeCode(); } locals[i] = new LocalVariableDefinition(ParseType(typeCode), isPinned); } } else { locals = Array.Empty <LocalVariableDefinition>(); } return(locals); }
private void GetLocalSizeAndOffsetAtIndex(int index, out int size, out int offset) { LocalVariableDefinition local = _locals[index]; size = local.Type.GetElementSize().AsInt; offset = 0; for (int i = 0; i < index; i++) { offset += _locals[i].Type.GetElementSize().AsInt; } }
public void EmitVariableDeclaration(VariableDeclarationSyntax node) { // lookup variable kind var local = new LocalVariableDefinition(); local.Name = (string)node.Identifier.Value; local.Index = CurrentFunction.Definition.Body.Locals.Count; CurrentFunction.Definition.Body.Locals.Add(local); if (node.Initializer != null) { EmitExpression(node.Initializer); Generator.Emit(OpCodes.Stloc, local.Index); } }
public ILImporter(LLVMBuilderRef builder, WebAssemblyCodegenCompilation compilation, LLVMModuleRef module, LLVMValueRef helperFunc, MethodDesc delegateCtor) { this._builder = builder; this._compilation = compilation; this.Module = module; this._currentFunclet = helperFunc; _locals = new LocalVariableDefinition[0]; if (delegateCtor == null) { _signature = new MethodSignature(MethodSignatureFlags.None, 0, GetWellKnownType(WellKnownType.Void), new TypeDesc[0]); } else { _signature = delegateCtor.Signature; _argSlots = new LLVMValueRef[_signature.Length]; int signatureIndex = 2; // past hidden param int thisOffset = 0; if (!_signature.IsStatic) { thisOffset = 1; } for (int i = 0; i < _signature.Length; i++) { if (CanStoreTypeOnStack(_signature[i])) { LLVMValueRef storageAddr; LLVMValueRef argValue = helperFunc.GetParam((uint)signatureIndex); // The caller will always pass the argument on the stack. If this function doesn't have // EH, we can put it in an alloca for efficiency and better debugging. Otherwise, // copy it to the shadow stack so funclets can find it int argOffset = i + thisOffset; string argName = $"arg{argOffset}_"; storageAddr = _builder.BuildAlloca(GetLLVMTypeForTypeDesc(_signature[i]), argName); _argSlots[i] = storageAddr; _builder.BuildStore(argValue, storageAddr); signatureIndex++; } } } _thisType = GetWellKnownType(WellKnownType.Void); _pointerSize = compilation.NodeFactory.Target.PointerSize; _exceptionRegions = new ExceptionRegion[0]; }