private static void InitObj(MethodVariables variables, Stack <Expression> stack, Instruction instruction, SyntaxGraphNode node) { var addr = Pop(stack); var value = new InitObjExpression((TypeReference)instruction.Operand, instruction); node.AddStatement(new StoreIndirectStatement(addr, value, MetadataType.Object, instruction)); }
private static void Dup(MethodVariables variables, Stack <Expression> stack, Instruction instruction, SyntaxGraphNode node) { // Store the current value in a temporary, then load it into the stack twice var value = Pop(stack); var temp = variables.CreateTemporary(); node.AddStatement(new StoreTemporaryStatement(temp, value, instruction)); stack.Push(new TemporaryExpression(temp, instruction)); stack.Push(new TemporaryExpression(temp, instruction)); }
public static SyntaxGraph Create(ControlFlowGraph controlFlowGraph, MethodVariables variables) { var syntaxNodes = new SortedDictionary <int, SyntaxGraphNode>(); // Populate the nodes list foreach (var controlFlowNode in controlFlowGraph.Nodes) { syntaxNodes.Add(controlFlowNode.Offset, new SyntaxGraphNode(controlFlowNode.Offset)); } // Now fill them foreach (var controlFlowNode in controlFlowGraph.Nodes) { var stack = new Stack <Expression>(); var syntaxNode = syntaxNodes[controlFlowNode.Offset]; foreach (var instruction in controlFlowNode.Instructions) { if (!_opCodeHandlers.TryGetValue(instruction.OpCode, out var handler)) { throw new NotSupportedException($"Unsupported opcode: {instruction.OpCode}"); } handler?.Invoke(variables, stack, instruction, syntaxNode); } // Copy the edges if (controlFlowNode.OutboundLinks.Any()) { var unconditional = controlFlowNode.OutboundLinks.Single(l => l.Condition == Condition.Unconditional); var conditional = controlFlowNode.OutboundLinks.SingleOrDefault(l => l.Condition == Condition.Conditional); syntaxNode.AddLink(null, syntaxNodes[unconditional.Target.Offset]); if (conditional != null) { syntaxNode.AddLink(Pop(stack), syntaxNodes[conditional.Target.Offset]); } } if (stack.Count > 0) { throw new NotImplementedException("Not yet implemented: forwarding stacks"); } } return(new SyntaxGraph(syntaxNodes, variables)); }
private static void StArg(MethodVariables variables, Stack <Expression> stack, Instruction instruction, SyntaxGraphNode node) { var value = Pop(stack); node.AddStatement(new StoreParameterStatement((ParameterReference)instruction.Operand, value, instruction)); }
private static void Return(MethodVariables variables, Stack <Expression> stack, Instruction instruction, SyntaxGraphNode node) { var value = PopOrDefault(stack); node.AddStatement(new ReturnStatement(value, instruction)); }
private static void CastClass(MethodVariables variables, Stack <Expression> stack, Instruction instruction, SyntaxGraphNode node) { var value = Pop(stack); stack.Push(new CastExpression(value, (TypeReference)instruction.Operand, instruction)); }
private static void LdToken(MethodVariables variables, Stack <Expression> stack, Instruction instruction, SyntaxGraphNode node) { stack.Push(new TokenExpression((MemberReference)instruction.Operand, instruction)); }
public static SyntaxGraph Create(MethodVariables variables, params SyntaxGraphNode[] nodes) => Create(variables, (IEnumerable <SyntaxGraphNode>)nodes);
private static void LdNull(MethodVariables variables, Stack <Expression> stack, Instruction instruction, SyntaxGraphNode node) { stack.Push(new ConstantExpression(null, MetadataType.Object, instruction)); }
private static void LocAlloc(MethodVariables variables, Stack <Expression> stack, Instruction instruction, SyntaxGraphNode node) { var size = Pop(stack); stack.Push(new LocallocExpression(size, instruction)); }
private static void ArgList(MethodVariables variables, Stack <Expression> stack, Instruction instruction, SyntaxGraphNode node) { stack.Push(new ArglistExpression(instruction)); }
private static void Pop(MethodVariables variables, Stack <Expression> stack, Instruction instruction, SyntaxGraphNode node) { node.AddStatement(new DiscardStatement(Pop(stack), instruction)); }
public static SyntaxGraph Create(MethodVariables variables, IEnumerable <SyntaxGraphNode> nodes) { return(new SyntaxGraph( new SortedDictionary <int, SyntaxGraphNode>(nodes.ToDictionary(n => n.Offset)), variables)); }
private static void IsInst(MethodVariables variables, Stack <Expression> stack, Instruction instruction, SyntaxGraphNode node) { var obj = Pop(stack); stack.Push(new IsTypeExpression(obj, (TypeReference)instruction.Operand, instruction)); }
private static void LdObj(MethodVariables variables, Stack <Expression> stack, Instruction instruction, SyntaxGraphNode node) { var addr = Pop(stack); stack.Push(new DereferenceExpression(addr, (TypeReference)instruction.Operand, instruction)); }
private static void LdLen(MethodVariables variables, Stack <Expression> stack, Instruction instruction, SyntaxGraphNode node) { var array = Pop(stack); stack.Push(new ArrayLengthExpression(array, instruction)); }
public SyntaxGraph(SortedDictionary <int, SyntaxGraphNode> nodes, MethodVariables variables) { _nodes = nodes; _variables = variables; }