/// <summary> /// Sets the instruction. /// </summary> /// <param name="instruction">The instruction.</param> /// <param name="operandCount">The operand count.</param> /// <param name="resultCount">The result count.</param> public InstructionNode(BaseInstruction instruction, int operandCount, byte resultCount) { Instruction = instruction; OperandCount = operandCount; ResultCount = resultCount; Size = InstructionSize.None; }
public void Save(BaseInstruction instruction) { var client = new RedisClient(); var key = new InstructionKeys ().GetKey (instruction.Id); var json = instruction.ToJson (); client.Set(key, json); var idManager = new InstructionIdManager (); idManager.Add (instruction); }
public void Add(BaseInstruction instruction) { var key = new InstructionKeys ().GetIdsKey (instruction.TargetType, instruction.TargetId); var client = new RedisClient (); var stringToAppend = instruction.Id.ToString(); if (client.Exists (key)) stringToAppend = "." + stringToAppend; client.Append (key, stringToAppend); }
protected void TransformLoadInstruction(Context context, BaseInstruction loadUp, BaseInstruction loadUpImm, BaseInstruction loadDownImm, Operand result, Operand operand1, Operand operand2) { BaseInstruction instruction; operand1 = MoveConstantToRegister(context, operand1); if (operand2.IsResolvedConstant) { if (operand2.ConstantUnsignedLongInteger >= 0 && operand2.ConstantSignedInteger <= (1 << 13)) { instruction = loadUpImm; } else if (operand2.ConstantUnsignedLongInteger < 0 && -operand2.ConstantSignedInteger <= (1 << 13)) { instruction = loadDownImm; operand2 = CreateConstant((uint)-operand2.ConstantSignedInteger); } else { instruction = loadDownImm; operand2 = MoveConstantToRegister(context, operand2); } } else if (operand2.IsUnresolvedConstant) { instruction = loadUp; operand2 = MoveConstantToRegister(context, operand2); } else { instruction = loadUpImm; } context.SetInstruction(instruction, ConditionCode.Always, result, operand1, operand2); }
public Node(BaseInstruction instruction, ConditionCode condition) { NodeType = NodeType.Instruction; Instruction = instruction; ConditionCode = condition; }
/// <summary> /// Sets the instruction. /// </summary> /// <param name="instruction">The instruction.</param> public InstructionNode(BaseInstruction instruction) : this(instruction, instruction.DefaultOperandCount, instruction.DefaultResultCount) { }
/// <summary> /// Sets the instruction. /// </summary> /// <param name="instruction">The instruction.</param> /// <param name="condition">The condition.</param> /// <param name="block">The block.</param> public void SetInstruction(BaseInstruction instruction, ConditionCode condition, BasicBlock block) { SetInstruction(instruction); ConditionCode = condition; AddBranchTarget(block); }
/// <summary> /// Sets the instruction. /// </summary> /// <param name="instruction">The instruction.</param> /// <param name="condition">The condition.</param> /// <param name="block">The block.</param> public InstructionNode(BaseInstruction instruction, ConditionCode condition, BasicBlock block) : this(instruction, condition) { AddBranchTarget(block); }
private bool IsCommutative(BaseInstruction instruction) { return(instruction == X86.Addsd || instruction == X86.Addss || instruction == X86.Mulsd || instruction == X86.Mulss); }
public String DecompileInstruction_C(BaseInstruction BI) { return(DecompileInstruction(BI.GetCUsage(), BI.CStringify, BI.C)); }
/// <summary> /// Sets the instruction. /// </summary> /// <param name="instruction">The instruction.</param> /// <param name="result">The result.</param> /// <param name="result2">The result2.</param> /// <param name="operand1">The operand1.</param> public void SetInstruction2(BaseInstruction instruction, Operand result, Operand result2, Operand operand1) { SetInstruction(instruction, 1, 2); Result = result; Result2 = result2; Operand1 = operand1; }
public String DecompileInstruction_A(BaseInstruction BI) { return(DecompileInstruction(BI.GetAUsage(), BI.AStringify, BI.A)); }
public String DecompileInstruction_B(BaseInstruction BI) { return(DecompileInstruction(BI.GetBUsage(), BI.BStringify, BI.B)); }
public String StringifyInstruction_C(BaseInstruction BI) { return(StringifyInstruction(BI.GetCUsage(), BI.CStringify, BI.C)); }
public String StringifyInstruction_B(BaseInstruction BI) { return(StringifyInstruction(BI.GetBUsage(), BI.BStringify, BI.B)); }
public String StringifyInstruction_A(BaseInstruction BI) { return(StringifyInstruction(BI.GetAUsage(), BI.AStringify, BI.A)); }
/// <summary> /// Sets the instruction. /// </summary> /// <param name="instruction">The instruction.</param> /// <param name="condition">The condition.</param> /// <param name="updateStatus">if set to <c>true</c> [update status].</param> /// <param name="result">The result.</param> /// <param name="operand1">The operand1.</param> /// <param name="operand2">The operand2.</param> public void SetInstruction(BaseInstruction instruction, ConditionCode condition, bool updateStatus, Operand result, Operand operand1, Operand operand2) { SetInstruction(instruction, 2, (byte)((result == null) ? 0 : 1)); Result = result; Operand1 = operand1; Operand2 = operand2; ConditionCode = condition; UpdateStatus = updateStatus; }
protected static InstructionNode GetPreviousNodeUntil(Context context, BaseInstruction untilInstruction, int window, Operand operand1 = null, Operand operand2 = null) { return(GetPreviousNodeUntil(context, untilInstruction, window, out _, operand1, operand2)); }
/// <summary> /// Sets the instruction. /// </summary> /// <param name="instruction">The instruction.</param> /// <param name="size">The size.</param> /// <param name="result">The result.</param> /// <param name="operand1">The operand1.</param> /// <param name="operand2">The operand2.</param> /// <param name="operand3">The operand3.</param> public void SetInstruction(BaseInstruction instruction, InstructionSize size, Operand result, Operand operand1, Operand operand2, Operand operand3) { SetInstruction(instruction, result, operand1, operand2, operand3); Size = size; }
protected static InstructionNode GetNextNodeUntil(Context context, BaseInstruction untilInstruction, int window, Operand operand = null) { return(GetNextNodeUntil(context, untilInstruction, window, out _, operand)); }
/// <summary> /// Sets the instruction. /// </summary> /// <param name="instruction">The instruction.</param> /// <param name="result">The result.</param> /// <param name="result2">The result2.</param> /// <param name="operand1">The operand1.</param> /// <param name="operand2">The operand2.</param> /// <param name="operand3">The operand3.</param> public void SetInstruction2(BaseInstruction instruction, Operand result, Operand result2, Operand operand1, Operand operand2, Operand operand3) { SetInstruction(instruction, 3, 2); Result = result; Result2 = result2; Operand1 = operand1; Operand2 = operand2; Operand3 = operand3; }
protected void TransformInstruction(Context context, BaseInstruction virtualInstruction, BaseInstruction immediateInstruction, Operand result, StatusRegister statusRegister, Operand operand1) { if (operand1.IsConstant) { operand1 = CreateRotatedImmediateOperand(context, operand1); } if (operand1.IsVirtualRegister || operand1.IsCPURegister) { context.SetInstruction(virtualInstruction, result, operand1); } else if (operand1.IsResolvedConstant) { context.SetInstruction(immediateInstruction, result, operand1); } else { throw new CompilerException("Error at {context} in {Method}"); } }
/// <summary> /// Sets the instruction. /// </summary> /// <param name="instruction">The instruction.</param> /// <param name="updateStatus">if set to <c>true</c> [update status].</param> /// <param name="result">The result.</param> public InstructionNode(BaseInstruction instruction, bool updateStatus, Operand result) : this(instruction, result) { UpdateStatus = updateStatus; }
protected void TransformInstruction(Context context, BaseInstruction virtualInstruction, BaseInstruction immediateInstruction, Operand result, StatusRegister statusRegister, Operand operand1, Operand operand2) { if (operand1.IsConstant) { if (virtualInstruction.IsCommutative && !operand2.IsConstant) { var temp = operand1; operand1 = operand2; operand2 = temp; } else { operand1 = MoveConstantToRegister(context, operand1); } } if (operand2.IsConstant) { operand2 = CreateRotatedImmediateOperand(context, operand2); } Debug.Assert(operand1.IsVirtualRegister || operand1.IsCPURegister); if (operand2.IsVirtualRegister || operand2.IsCPURegister) { context.SetInstruction(virtualInstruction, statusRegister, result, operand1, operand2); } else if (operand2.IsResolvedConstant) { context.SetInstruction(immediateInstruction, statusRegister, result, operand1, operand2); } else { throw new CompilerException("Error at {context} in {Method}"); } }
/// <summary> /// Sets the instruction. /// </summary> /// <param name="instruction">The instruction.</param> /// <param name="operandCount">The operand count.</param> /// <param name="resultCount">The result count.</param> public void SetInstruction(BaseInstruction instruction, int operandCount, byte resultCount) { Debug.Assert(!IsBlockStartInstruction); Debug.Assert(!IsBlockEndInstruction); int label = Label; var block = Block; Clear(); Instruction = instruction; OperandCount = operandCount; ResultCount = resultCount; Label = label; Size = InstructionSize.None; Block = block; //Block.DebugCheck(); }
protected void TransformInstructionXXX(Context context, BaseInstruction virtualInstruction, BaseInstruction immediateInstruction, Operand result, StatusRegister statusRegister, Operand operand1, Operand operand2) { // TODO!!!!! // AddFloatR4 result, operand1, operand2 // TODO: (across all float instructions) // if operand1 is constant // if resolved & specific constant, then AdfImm // else if resolved & non-specific constant, then LoadConstant, adf // else if unresolved, throw not implemented if (operand1.IsConstant) { if (virtualInstruction.IsCommutative && !operand2.IsConstant) { var temp = operand1; operand1 = operand2; operand2 = temp; } else { operand1 = MoveConstantToRegister(context, operand1); } } if (operand2.IsConstant) { operand2 = CreateRotatedImmediateOperand(context, operand2); } Debug.Assert(operand1.IsVirtualRegister || operand1.IsCPURegister); if (operand2.IsVirtualRegister || operand2.IsCPURegister) { context.SetInstruction(virtualInstruction, statusRegister, result, operand1, operand2); } else if (operand2.IsResolvedConstant) { context.SetInstruction(immediateInstruction, statusRegister, result, operand1, operand2); } else { throw new CompilerException("Error at {context} in {Method}"); } }
/// <summary> /// Sets the instruction. /// </summary> /// <param name="instruction">The instruction.</param> /// <param name="block1">The block1.</param> /// <param name="block2">The block2.</param> public void SetInstruction(BaseInstruction instruction, BasicBlock block1, BasicBlock block2) { SetInstruction(instruction); AddBranchTarget(block1); AddBranchTarget(block2); }
/// <summary> /// Sets the instruction. /// </summary> /// <param name="instruction">The instruction.</param> /// <param name="target">The target.</param> public InstructionNode(BaseInstruction instruction, MosaMethod target) : this(instruction) { InvokeMethod = target; }
private static void Replace(Context context, BaseInstruction floatingPointInstruction, BaseInstruction signedInstruction, BaseInstruction unsignedInstruction) { if (context.Result.IsR) { context.ReplaceInstructionOnly(floatingPointInstruction); } else if (context.Result.IsUnsigned) { context.ReplaceInstructionOnly(unsignedInstruction); } else { context.ReplaceInstructionOnly(signedInstruction); } }
/// <summary> /// Sets the instruction. /// </summary> /// <param name="instruction">The instruction.</param> /// <param name="condition">The condition.</param> /// <param name="result">The result.</param> public void SetInstruction(BaseInstruction instruction, ConditionCode condition, Operand result) { SetInstruction(instruction, 0, (byte)((result == null) ? 0 : 1)); Result = result; ConditionCode = condition; }
protected void TransformExtend(Context context, BaseInstruction instruction, Operand result, Operand operand1) { operand1 = MoveConstantToRegister(context, operand1); context.SetInstruction(instruction, ConditionCode.Always, result, operand1); }
public Node(BaseInstruction instruction) { NodeType = NodeType.Instruction; Instruction = instruction; }
/// <summary> /// Sets the instruction. /// </summary> /// <param name="instruction">The instruction.</param> /// <param name="result">The result.</param> /// <param name="operand1">The operand1.</param> public void SetInstruction(BaseInstruction instruction, bool updateStatus, Operand result, Operand operand1) { SetInstruction(instruction, 1, (byte)((result == null) ? 0 : 1)); Result = result; Operand1 = operand1; UpdateStatus = updateStatus; }
protected void TransformStoreInstruction(Context context, BaseInstruction storeUp, BaseInstruction storeUpImm, BaseInstruction loadDownImm, Operand operand1, Operand operand2, Operand operand3) { BaseInstruction instruction; operand1 = MoveConstantToRegister(context, operand1); if (operand2.IsResolvedConstant) { if (operand2.ConstantUnsigned64 >= 0 && operand2.ConstantSigned32 <= (1 << 13)) { instruction = storeUpImm; } else if (operand2.ConstantUnsigned64 < 0 && -operand2.ConstantSigned32 <= (1 << 13)) { instruction = loadDownImm; operand2 = CreateConstant((uint)-operand2.ConstantSigned32); } else { instruction = loadDownImm; operand2 = MoveConstantToRegister(context, operand2); } } else if (operand2.IsUnresolvedConstant) { instruction = storeUp; operand2 = MoveConstantToRegister(context, operand2); } else { instruction = storeUpImm; } context.SetInstruction(instruction, ConditionCode.Always, null, operand1, operand2, operand3); }
/// <summary> /// Sets the instruction. /// </summary> /// <param name="instruction">The instruction.</param> /// <param name="condition">The condition.</param> /// <param name="result">The result.</param> /// <param name="operand1">The operand1.</param> /// <param name="operand2">The operand2.</param> /// <param name="block">The block.</param> public void SetInstruction(BaseInstruction instruction, ConditionCode condition, Operand result, Operand operand1, Operand operand2, BasicBlock block) { SetInstruction(instruction, 2, (byte)((result == null) ? 0 : 1)); Result = result; Operand1 = operand1; Operand2 = operand2; ConditionCode = condition; AddBranchTarget(block); }
protected void Inline(InstructionNode callSiteNode, BasicBlocks blocks) { var mapBlocks = new Dictionary <BasicBlock, BasicBlock>(blocks.Count); var map = new Dictionary <Operand, Operand>(); var nextBlock = Split(callSiteNode); // create basic blocks foreach (var block in blocks) { var newBlock = CreateNewBlock(); mapBlocks.Add(block, newBlock); } // copy instructions foreach (var block in blocks) { var newBlock = mapBlocks[block]; for (var node = block.AfterFirst; !node.IsBlockEndInstruction; node = node.Next) { if (node.IsEmpty) { continue; } if (node.Instruction == IRInstruction.Prologue) { continue; } if (node.Instruction == IRInstruction.Epilogue) { newBlock.BeforeLast.Insert(new InstructionNode(IRInstruction.Jmp, nextBlock)); continue; } if (node.Instruction == IRInstruction.SetReturn32 || node.Instruction == IRInstruction.SetReturn64 || node.Instruction == IRInstruction.SetReturnR4 || node.Instruction == IRInstruction.SetReturnR8 || node.Instruction == IRInstruction.SetReturnCompound) { if (callSiteNode.Result != null) { var newOperand = Map(node.Operand1, map, callSiteNode); BaseInstruction moveInstruction = null; if (node.Instruction == IRInstruction.SetReturn32) { moveInstruction = IRInstruction.MoveInt32; } else if (node.Instruction == IRInstruction.SetReturn64) { moveInstruction = IRInstruction.MoveInt64; } else if (node.Instruction == IRInstruction.SetReturnR4) { moveInstruction = IRInstruction.MoveFloatR4; } else if (node.Instruction == IRInstruction.SetReturnR8) { moveInstruction = IRInstruction.MoveFloatR8; } else if (node.Instruction == IRInstruction.SetReturnCompound) { moveInstruction = IRInstruction.MoveCompound; } Debug.Assert(moveInstruction != null); var moveNode = new InstructionNode(moveInstruction, callSiteNode.Result, newOperand); newBlock.BeforeLast.Insert(moveNode); } continue; } var newNode = new InstructionNode(node.Instruction, node.OperandCount, node.ResultCount) { ConditionCode = node.ConditionCode, Label = callSiteNode.Label }; if (node.BranchTargets != null) { // copy targets foreach (var target in node.BranchTargets) { newNode.AddBranchTarget(mapBlocks[target]); } } // copy results for (int i = 0; i < node.ResultCount; i++) { var op = node.GetResult(i); var newOp = Map(op, map, callSiteNode); newNode.SetResult(i, newOp); } // copy operands for (int i = 0; i < node.OperandCount; i++) { var op = node.GetOperand(i); var newOp = Map(op, map, callSiteNode); newNode.SetOperand(i, newOp); } // copy other if (node.MosaType != null) { newNode.MosaType = node.MosaType; } if (node.MosaField != null) { newNode.MosaField = node.MosaField; } UpdateParameterInstructions(newNode); newBlock.BeforeLast.Insert(newNode); } } var prologue = mapBlocks[blocks.PrologueBlock]; var callSiteOperands = callSiteNode.GetOperands(); if (callSiteOperands.Count > 1) { var context = new Context(prologue); for (int i = 1; i < callSiteOperands.Count; i++) { var operand = callSiteOperands[i]; if (!operand.IsVirtualRegister || operand.Low == null) { continue; } context.AppendInstruction(IRInstruction.GetLow64, operand.Low, operand); context.AppendInstruction(IRInstruction.GetHigh64, operand.High, operand); } } callSiteNode.SetInstruction(IRInstruction.Jmp, prologue); }
/// <summary> /// Sets the instruction. /// </summary> /// <param name="instruction">The instruction.</param> /// <param name="result">The result.</param> /// <param name="operand1">The operand1.</param> /// <param name="operand2">The operand2.</param> /// <param name="operand3">The operand3.</param> public void SetInstruction(BaseInstruction instruction, Operand result, Operand operand1, Operand operand2, Operand operand3) { SetInstruction(instruction, 3, (byte)((result == null) ? 0 : 1)); Result = result; Operand1 = operand1; Operand2 = operand2; Operand3 = operand3; }
protected override bool IsThreeTwoAddressRequired(BaseInstruction instruction) { return((instruction as X86Instruction)?.ThreeTwoAddressConversion == true); }
/// <summary> /// Sets the instruction. /// </summary> /// <param name="instruction">The instruction.</param> /// <param name="result">The result.</param> /// <param name="result2">The result2.</param> public void SetInstruction2(BaseInstruction instruction, Operand result, Operand result2) { SetInstruction(instruction, 1, 2); Result = result; Result2 = result2; }
protected override bool IsMov(BaseInstruction instruction) { return(instruction == X64.Mov32 || instruction == X64.Mov64 || instruction == X64.Movsd || instruction == X64.Movss); }
/// <summary> /// Sets the instruction. /// </summary> /// <param name="instruction">The instruction.</param> /// <param name="block1">The block1.</param> /// <param name="block2">The block2.</param> public InstructionNode(BaseInstruction instruction, BasicBlock block1, BasicBlock block2) : this(instruction) { AddBranchTarget(block1); AddBranchTarget(block2); }
public void Add(BaseInstruction instruction) { _expressions.Add(instruction); }
/// <summary> /// Sets the instruction. /// </summary> /// <param name="instruction">The instruction.</param> /// <param name="condition">The condition.</param> public InstructionNode(BaseInstruction instruction, ConditionCode condition) : this(instruction) { ConditionCode = condition; }
/// <summary> /// Determines whether [is instruction move] [the specified instruction]. /// </summary> /// <param name="instruction">The instruction.</param> /// <returns></returns> public override bool IsInstructionMove(BaseInstruction instruction) { return(instruction == X86.Mov32 || instruction == X86.Movsd || instruction == X86.Movss); }
/// <summary> /// Sets the instruction. /// </summary> /// <param name="instruction">The instruction.</param> /// <param name="result">The result.</param> public InstructionNode(BaseInstruction instruction, Operand result) : this(instruction, 0, 1) { Result = result; }
/// <summary> /// Determines whether [is instruction move] [the specified instruction]. /// </summary> /// <param name="instruction">The instruction.</param> /// <returns></returns> public override bool IsInstructionMove(BaseInstruction instruction) { // TODO return(false); }
/// <summary> /// Sets the instruction. /// </summary> /// <param name="instruction">The instruction.</param> /// <param name="result">The result.</param> /// <param name="operand1">The operand1.</param> public InstructionNode(BaseInstruction instruction, Operand result, Operand operand1) : this(instruction, 1, 1) { Result = result; Operand1 = operand1; }
protected override void Setup() { loadInstruction = Select(IRInstruction.LoadInt32, IRInstruction.LoadInt64); moveInstruction = Select(IRInstruction.MoveInt32, IRInstruction.MoveInt64); }
/// <summary> /// Replaces the instruction only. /// </summary> /// <param name="instruction">The instruction.</param> public void ReplaceInstructionOnly(BaseInstruction instruction) { Instruction = instruction; }
private bool IntegerOperation(BaseInstruction instruction, ulong operand1, ulong operand2, ConditionCode conditionCode, out ulong result) { if (instruction == IRInstruction.AddSigned || instruction == IRInstruction.AddUnsigned) { result = operand1 + operand2; return(true); } else if (instruction == IRInstruction.SubSigned || instruction == IRInstruction.SubUnsigned) { result = operand1 - operand2; return(true); } else if (instruction == IRInstruction.MulUnsigned || instruction == IRInstruction.MulSigned) { result = operand1 * operand2; return(true); } else if (instruction == IRInstruction.DivUnsigned && operand2 != 0) { result = operand1 / operand2; return(true); } else if (instruction == IRInstruction.DivSigned && operand2 != 0) { result = (ulong)((long)operand1 / (long)operand2); return(true); } else if (instruction == IRInstruction.RemUnsigned && operand2 != 0) { result = operand1 % operand2; return(true); } else if (instruction == IRInstruction.RemSigned && operand2 != 0) { result = (ulong)((long)operand1 % (long)operand2); return(true); } else if (instruction == IRInstruction.ArithmeticShiftRight) { result = (ulong)(((long)operand1) >> (int)operand2); return(true); } else if (instruction == IRInstruction.ShiftRight) { result = operand1 >> (int)operand2; return(true); } else if (instruction == IRInstruction.ShiftLeft) { result = operand1 << (int)operand2; return(true); } else if (instruction == IRInstruction.CompareInteger) { bool?compare = Compare(operand1, operand2, conditionCode); if (compare.HasValue) { result = compare.Value ? 1u : 0u; return(true); } } result = 0; return(false); }
/// <summary> /// Sets the instruction. /// </summary> /// <param name="instruction">The instruction.</param> public void SetInstruction(BaseInstruction instruction) { if (instruction != null) SetInstruction(instruction, instruction.DefaultOperandCount, instruction.DefaultResultCount); else SetInstruction(null, 0, 0); //Block.DebugCheck(); }
public BaseTransformation(BaseInstruction instruction) : this() { Instruction = instruction; }
/// <summary> /// Sets the instruction. /// </summary> /// <param name="instruction">The instruction.</param> /// <param name="target">The target.</param> public void SetInstruction(BaseInstruction instruction, MosaMethod target) { SetInstruction(instruction); InvokeMethod = target; }
public BaseTransformation(BaseInstruction instruction, bool log = false) : this() { Instruction = instruction; Log = log; }
/// <summary> /// Sets the instruction. /// </summary> /// <param name="instruction">The instruction.</param> /// <param name="condition">The condition.</param> public void SetInstruction(BaseInstruction instruction, ConditionCode condition) { SetInstruction(instruction); ConditionCode = condition; }
/// <summary> /// Determines whether [is instruction move] [the specified instruction]. /// </summary> /// <param name="instruction">The instruction.</param> /// <returns></returns> public override bool IsInstructionMove(BaseInstruction instruction) { return(instruction == ARMv6.Mov); }
/// <summary> /// Sets the instruction. /// </summary> /// <param name="instruction">The instruction.</param> /// <param name="result">The result.</param> public void SetInstruction(BaseInstruction instruction, Operand result) { SetInstruction(instruction, 0, 1); Result = result; }
protected abstract bool IsNop(BaseInstruction instruction);
/// <summary> /// Determines whether the specified instruction is commutative. /// </summary> /// <param name="instruction">The instruction.</param> /// <returns> /// <c>true</c> if the specified instruction is commutative; otherwise, <c>false</c>. /// </returns> private static bool IsCommutative(BaseInstruction instruction) { return (instruction is CIL.AddInstruction) || (instruction is CIL.MulInstruction) || (instruction is IR.LogicalAnd) || (instruction is IR.LogicalOr) || (instruction is IR.LogicalXor); }
protected abstract bool IsMov(BaseInstruction instruction);