public static x86DataLocation GetMember(x86DataLocation Position, Identifier Type, int Index) { if (Type.RealId is NonrefArrayType) { var ArrType = Type.RealId as NonrefArrayType; return(Position.GetPart(ArrType.ElementSize * Index, ArrType.TypeOfValues.Size)); } else if (Type.RealId is StructType) { var ValueType = Type.RealId as StructType; var Members = ValueType.StructuredScope.IdentifierList; var Var = Members[Index] as MemberVariable; if (Var == null) { throw new ApplicationException("Not movable"); } var MemberType = Var.TypeOfSelf.RealId as Type; return(Position.GetPart(Var.Offset, MemberType.Size)); } else { throw new InvalidOperationException(); } }
public static bool SamePosition(x86Architecture Arch, ExpressionNode Self, x86DataLocation N, x86OverlappingMode Mode = x86OverlappingMode.Whole) { var S = x86Expressions.GetLocation(Arch, Self); return(S == null ? false : S.Compare(N, Mode)); }
public bool IsFree(x86DataLocation Pos) { if (Pos is x86GRegLocation) { return(GRegisters.IsFree(Pos as x86GRegLocation)); } else if (Pos is x86SSERegLocation) { return(!SSERegisters[(Pos as x86SSERegLocation).Index]); } else if (Pos is x86StackLocation) { return(StackOffset <= (Pos as x86StackLocation).Offset); } else if (Pos is x86MultiLocation) { var MPos = Pos as x86MultiLocation; for (var i = 0; i < MPos.Locations.Length; i++) { if (!IsFree(MPos.Locations[i])) { return(false); } } return(true); } else { throw new ApplicationException(); } }
public void SetUsed(x86DataLocation Pos) { if (Pos is x86GRegLocation) { SetUsed(Pos as x86GRegLocation); } else if (Pos is x86StackLocation) { SetUsed(Pos as x86StackLocation); } else if (Pos is x86SSERegLocation) { SetUsed(Pos as x86SSERegLocation); } else if (Pos is x86MultiLocation) { var MPos = Pos as x86MultiLocation; for (var i = 0; i < MPos.Locations.Length; i++) { SetUsed(MPos.Locations[i]); } } else { throw new ApplicationException(); } }
public bool IsFree(x86DataLocation Pos) { if (Pos is x86GRegLocation) { var RegPos = Pos as x86GRegLocation; return(IsFree(RegPos)); } else if (Pos is x86MultiLocation) { var MultiPos = Pos as x86MultiLocation; foreach (var e in MultiPos.Locations) { var RegPos = e as x86GRegLocation; if (RegPos == null) { throw new ApplicationException(); } return(IsFree(RegPos)); } return(true); } else { throw new ApplicationException(); } }
public bool CheckLocation(x86DataLocation Location) { if (Location is x86SSERegLocation) { return(true); } return(CheckLocation(Location.Size)); }
private x86DataLocation AllocMultiPos(int Size, int Align, x86DataLocationType DataCalcPos, x86DataList CantBe, int PartSize) { var Count = Size / PartSize; var Positions = new x86DataLocation[Count]; for (var i = 0; i < Count; i++) { Positions[i] = Allocate(Arch.RegSize, Align, DataCalcPos, CantBe); if (Positions[i] == null) { return(null); } } return(new x86MultiLocation(Arch, Size, Positions)); }
public void Reset() { FPUItemsOnStack = 0; UsedFPUStack = 0; SameAllocationAsType = x86SameAllocationAsType.None; Flags &= x86NodeFlags.LeftByReset; DataCalcPos = x86DataLocationType.None; PreferredOutput = null; UsedData = null; UsedDataBySelf = null; TempCantBe = null; PreAllocate = null; Properties = new x86DataProperties(); NeededTempByPlugin = new x86NeededTempData(); Output = null; ParameterBytes = 0; OriginalShiftSize = 0; }
private static x86MemoryLocation GetIndexerPosition(x86Architecture Arch, x86DataLocation Address, x86GRegLocation AddressTempGReg, x86DataLocation Offset, x86GRegLocation OffsetTempGReg, int Size, int Displacement = 0, byte Scale = 1) { if (Offset != null && Address.Size != Offset.Size) { throw new ApplicationException(); } var Ret = new x86IndexLocation(Arch, 0, Size, null); if (!Ret.Add(Address, AddressTempGReg)) { return(null); } if (Offset != null && !Ret.Add(Offset, OffsetTempGReg, Scale)) { return(null); } Ret.Offset += Displacement; return(Ret); }
public void SetUsed(x86DataLocation Pos) { if (Pos is x86GRegLocation) { SetUsed(Pos as x86GRegLocation); } else if (Pos is x86MultiLocation) { var MultiPos = Pos as x86MultiLocation; for (var i = 0; i < MultiPos.Locations.Length; i++) { var RegPos = MultiPos.Locations[i] as x86GRegLocation; if (RegPos == null) { throw new ApplicationException(); } SetUsed(RegPos); } } else { throw new ApplicationException(); } }
public static void GetDefaultStoredDataType(ref x86StoredDataType StoredDataTypePart, x86DataLocation Location) { GetDefaultStoredDataType(ref StoredDataTypePart, Location.Size); }
public x86LinkedNodeData(x86DataLocation Specified = null, x86LinkedNodeFlags Flags = x86LinkedNodeFlags.None) { this.Specified = Specified; this.Location = null; this.Flags = Flags; }
public x86StoredDataType SelfOrDefault(x86DataLocation Location) { return(SelfOrDefault(Location.Size)); }
public static x86DataLocation GetLocation(x86Architecture Arch, ExpressionNode Node) { var Data = Node.Data.Get <x86NodeData>(); var Type = Node.Type.RealId as Type; var Size = Type.Size; if (Data != null && Data.Output != null) { if (Data.Output is x86PostCalcedLocation) { return(Data.ExtractedOutput); } return(Data.Output); } else if (Node is OpExpressionNode) { var OpNode = Node as OpExpressionNode; var Op = OpNode.Operator; var Ch = OpNode.Children; if (Op == Operator.Assignment) { return(GetLocation(Arch, Ch[0])); } else if (Op == Operator.Index) { var Address = GetLocation(Arch, Ch[0]); var Offset = GetLocation(Arch, Ch[1]); if (Address == null || Offset == null) { return(null); } var Ch0Type = Ch[0].Type.RealId; var AddressTempGReg = Data.TempData.GetGRegister(x86TempGRegPurposeType.Index, 0); var OffsetTempGReg = Data.TempData.GetGRegister(x86TempGRegPurposeType.Index, 1); if (Ch0Type is PointerType) { return(GetIndexerPosition(Arch, Address, AddressTempGReg, Offset, OffsetTempGReg, Size, Data.Displacement, Data.Scale)); } else { throw new ApplicationException(); } } else if (Op == Operator.Member) { var IdCh1 = Ch[1] as IdExpressionNode; if (IdCh1 == null) { throw new ApplicationException(); } if (IdCh1.Identifier is Function && !IsVirtualMember(Node)) { return(GetDefaultIdLocation(Arch, IdCh1.Identifier)); } var SrcPos = GetLocation(Arch, Ch[0]); if (SrcPos == null) { return(null); } var Ch0Type = Ch[0].Type.RealId as Type; var AddressTempGReg = Data.TempData.GetGRegister(x86TempGRegPurposeType.Index, 0); if ((Ch0Type.TypeFlags & TypeFlags.ReferenceValue) != 0) { SrcPos = GetIndexerPosition(Arch, SrcPos, AddressTempGReg, null, null, Ch0Type.InstanceSize); } if (SrcPos == null) { return(null); } #warning WARNING, temp solution to allow ZinniaCore compilation SrcPos = SrcPos.GetPart(0); SrcPos.Size = int.MaxValue; var Splitable = SrcPos as x86SplittableLocation; if (Splitable == null) { throw new ApplicationException(); } if (IdCh1.Identifier is MemberVariable) { var MemVar = IdCh1.Identifier as MemberVariable; return(Splitable.GetPart(MemVar.Offset, Size)); } else if (IdCh1.Identifier is MemberFunction) { var MemFunc = IdCh1.Identifier as MemberFunction; var Ptrs = Splitable.GetPart(0, Size); var RegSize = Arch.RegSize; var Global = MemFunc.Container.GlobalContainer; var OffsetValue = new IntegerValue(MemFunc.VirtualIndex * RegSize); var OffsetType = Global.CommonIds.GetIdentifier(typeof(SignedType), RegSize); var Offset = new x86ConstLocation(Arch, OffsetValue, OffsetType, 0, RegSize); return(GetIndexerPosition(Arch, Ptrs, AddressTempGReg, Offset, null, RegSize)); } throw new ApplicationException(); } else if (Op == Operator.Unknown) { if (Data.Operator == x86Operator.Swap) { var Locations = new x86DataLocation[2]; Locations[0] = GetLocation(Arch, Ch[0]); Locations[1] = GetLocation(Arch, Ch[1]); if (Locations[0] == null || Locations[1] == null) { return(null); } return(new x86MultiLocation(Arch, Size, Locations)); } } } else if (Node is ConstExpressionNode) { var ConstNode = Node as ConstExpressionNode; return(new x86ConstLocation(Arch, ConstNode, 0, Size)); } else if (Node is IdExpressionNode) { var IdNode = Node as IdExpressionNode; var Id = IdNode.Identifier; if (!(Id is LocalVariable)) { return(GetDefaultIdLocation(Arch, Id)); } var IdData = Id.Data.Get <x86IdentifierData>(); var IdPos = IdData.Location; if (IdPos == null) { return(null); } if ((Data.Flags & x86NodeFlags.IdentifierByRef) != 0) { Type = Id.Container.GlobalContainer.CommonIds.GetIdentifier(typeof(SignedType), Arch.RegSize); var Offset = new x86ConstLocation(Arch, new IntegerValue(0), Type, 0, Arch.RegSize); var AddressTempGReg = Data.TempData.GetGRegister(x86TempGRegPurposeType.Index, -1); return(GetIndexerPosition(Arch, IdPos, AddressTempGReg, Offset, null, Size)); } return(IdPos); } else if (Node is DataPointerNode) { var IdDescNode = Node as DataPointerNode; if (IdDescNode.DescPointerType == DataPointerType.Assembly) { return(new x86NamedLabelPosition(Arch, IdDescNode.Assembly.DescLabel)); } else if (IdDescNode.DescPointerType == DataPointerType.Identifier) { return(GetDescLocation(Arch, IdDescNode.Id)); } else if (IdDescNode.DescPointerType == DataPointerType.IncBin) { return(new x86NamedLabelPosition(Arch, IdDescNode.IncBin.Label)); } else { throw new NotImplementedException(); } } else if (Node is LabelExpressionNode) { var LabelNode = Node as LabelExpressionNode; return(new x86NamedLabelPosition(Arch, LabelNode.Label)); } return(null); }