public OperationsList() { First = new OperationNode(); Last = First; First.Next = Last; Current = Last; }
public void MoveNext() { if (Current.Next != null) { Current = Current.Next; } }
public static Instruction CreateBinaryInstruction( string mnemonic, OperationNode op, int exUnit, ValueNode vres, RegisterSet vresRegs, ValueNode v1, RegisterSet v1Regs, ValueNode v2, RegisterSet v2Regs) { InstructionPattern ip = new InstructionPattern(); ip.AddNode(op); ip.AddNode(vres); ip.AddNode(v1); ip.AddNode(v2); ip.AddEdge(op, vres); ip.AddEdge(v1, op); ip.AddEdge(v2, op); ip.OperandValues.Add(v1); ip.OperandValues.Add(v2); ip.ResultValue = vres; Instruction i = new Instruction(mnemonic, ip); i.ExecutionUnit = exUnit; i.ResultRegisters = vresRegs; i.OperandsRegisters[0] = v1Regs; i.OperandsRegisters[1] = v2Regs; return i; }
public Redo(OperationNode lastOperation) { OperationId = ID; if (lastOperation.Next != null) _lastCanceledOperation = lastOperation.Next.Value; }
private Node Execute(string exp, char op) // Overloaded Execute function { int counter = 0; int i = exp.Length - 1; // start from end of string while (i >= 0) { if (exp[i] == '(') { counter++; } else if (exp[i] == ')') { counter--; } if (counter == 0 && exp[i] == op) // if hit correct operator { // Form the subtree with the OperationNode being the root OperationNode opNode = new OperationNode(op); opNode.Left = Execute(exp.Substring(0, i)); opNode.Right = Execute(exp.Substring(i + 1)); return(opNode); } i--; } return(null); }
private void AddChildren(OperationNode <int> node, string query) { try { bool symbolFound = false; foreach (var operation in _operations) { var position = query.IndexOf(operation.Symbol); if (position != -1) { node.Param = int.Parse(query.Substring(0, position)); node.Operation = operation; node.Next = new OperationNode <int>(); var subquery = query.Substring(position + 1); AddChildren(node.Next, subquery); symbolFound = true; } } if (!symbolFound) { node.Param = int.Parse(query); } } catch (Exception) { throw new Exception("Unknown operation!"); } }
public void MovePrevious() { if (Current.Previous != null) { Current = Current.Previous; } }
public Undo(OperationNode lastOperation) { OperationId = ID; if (lastOperation != null) { _lastOperation = lastOperation.Value; } }
public OperationNode <int> Parse(string query) { var tree = new OperationNode <int>(); AddChildren(tree, query); return(tree); }
public void Add(Operation operation) { Current.Next = new OperationNode() { Value = operation, Previous = Current }; Last = Current.Next; Current = Last; }
public Redo(OperationNode lastOperation) { OperationId = ID; if (lastOperation.Next != null) { _lastCanceledOperation = lastOperation.Next.Value; } }
public string Visit(OperationNode node) { switch (node.OperationType) { // prefix stuff case OperationType.Positive: case OperationType.Negative: case OperationType.Not: case OperationType.PrefixIncrement: case OperationType.PrefixDecrement: return(ASTHelper.PrintToken(node.Token) + Print(node.Operands[0])); // postfix stuff case OperationType.PostfixIncrement: case OperationType.PostfixDecrement: return(Print(node.Operands[0]) + ASTHelper.PrintToken(node.Token)); // normal infix stuff case OperationType.Addition: case OperationType.Substraction: case OperationType.Multiplication: case OperationType.Division: case OperationType.Power: case OperationType.Modulo: case OperationType.Or: case OperationType.And: case OperationType.Xor: case OperationType.Equal: case OperationType.NotEqual: case OperationType.Less: case OperationType.LessOrEqual: case OperationType.Greater: case OperationType.GreaterOrEqual: case OperationType.Access: case OperationType.Assign: return(Print(node.Operands[0]) + ASTHelper.PrintToken(node.Token) + Print(node.Operands[1])); case OperationType.ArrayAccess: return(Print(node.Operands[0]) // name of the array + ASTHelper.PrintToken(node.Token) // '[' + Utilities.Join(",", Print, node.Operands.Skip(1)) // indices + ASTHelper.PrintToken(node.AdditionalTokens[0])); // ']' case OperationType.Conditional: return(Print(node.Operands[0]) + ASTHelper.PrintToken(node.Token) + Print(node.Operands[1]) + ASTHelper.PrintToken(node.AdditionalTokens[0]) + Print(node.Operands[2])); default: throw new Exception("Oho, someone forgot to implement a printer for an operation type..."); } }
private string Enclose(OperationNode subNode, Operation op) { string res = Visit((dynamic)subNode); if (subNode.Op < op) // Here we do the check { res = "(" + res + ")"; } return(res); }
internal Node ResolveQuery(BinaryExpression binaryExpression) { var @operator = binaryExpression.NodeType; dynamic binaryExpressionLeft = binaryExpression.Left; dynamic binaryExpressionRight = binaryExpression.Right; dynamic queryLeft = ResolveQuery(binaryExpressionLeft); dynamic queryRight = ResolveQuery(binaryExpressionRight); var operationNode = new OperationNode(@operator, queryLeft, queryRight); return(operationNode); }
/// <summary> /// Applies the simplification rule to the given node, assuming the rule is applicable /// </summary> /// <param name="orig">The original node</param> /// <returns>The simplified node</returns> public virtual Node <C> TryApply(OperationNode <C> orig) { var assignments = new Dictionary <Variable <ValueType>, Node <ValueType> >(); if (!CanApply((Node <ValueType>)orig, (Node <ValueType>)before, assignments)) { return(orig); } return((Node <C>)Assign((Node <ValueType>)after, assignments)); }
private int CalculateTotal(OperationNode <int> note) { //TODO need to implement correct tree handling if (note.Next == null) { return(0); } var total = note.Operation.Calculate(note.Param, note.Next.Param); return(total); }
protected void CreateSingleLoop( ProgramGraph g, ValueNode ap, ValueNode bp, ValueNode s, ValueNode ap1, ValueNode bp1, ValueNode s1) { OperationNode[] o = new OperationNode[8]; o[0] = new AddOperationNode(); o[1] = new MulOperationNode(); o[2] = new LoadOperationNode(); o[3] = new AddOperationNode(); o[4] = new LoadOperationNode(); o[5] = new AddOperationNode(); o[6] = new ConstOperationNode(); o[7] = new ConstOperationNode(); foreach (OperationNode op in o) g.AddNode(op); ValueNode[] v = new ValueNode[7]; v[0] = new FloatRegisterNode(); v[1] = new FloatRegisterNode(); v[2] = new FloatRegisterNode(); v[3] = new IntRegisterNode(); v[4] = new IntRegisterNode(); v[5] = new IntConstantNode(4); v[6] = new IntConstantNode(4); foreach (ValueNode val in v) g.AddNode(val); g.AddEdge(v[0], o[0]); g.AddEdge(s, o[0]); g.AddEdge(o[0], s1); g.AddEdge(v[1], o[1]); g.AddEdge(v[2], o[1]); g.AddEdge(o[1], v[0]); g.AddEdge(ap, o[2]); g.AddEdge(o[2], v[1]); g.AddEdge(ap, o[3]); g.AddEdge(v[3], o[3]); g.AddEdge(o[3], ap1); g.AddEdge(bp, o[4]); g.AddEdge(o[4], v[2]); g.AddEdge(bp, o[5]); g.AddEdge(v[4], o[5]); g.AddEdge(o[5], bp1); g.AddEdge(v[5], o[6]); g.AddEdge(o[6], v[3]); g.AddEdge(v[6], o[7]); g.AddEdge(o[7], v[4]); }
public Operation Create(int id, OperationNode lastOperationNode) { switch (id) { case Undo.ID: return new Undo(lastOperationNode); case Redo.ID: return new Redo(lastOperationNode); default: return CreateOperation(id); } }
private void Enclose(OperationNode subNode, Operation op) { if (subNode.Op < op) { Text = Text + "("; Visit((dynamic)subNode); Text = Text + ")"; } else { Visit((dynamic)subNode); } }
public Operation Create(int id, OperationNode lastOperationNode) { switch (id) { case Undo.ID: return(new Undo(lastOperationNode)); case Redo.ID: return(new Redo(lastOperationNode)); default: return(CreateOperation(id)); } }
private void BuildTree() { shuntingYardAlgorithm(); var newStack = new Stack <Node>(); while (oStack.Count() != 0) { if (precedenceDictionary.ContainsKey(oStack.Peek())) { var newOp = new OperationNode(oStack.Pop()); try { newOp.mRight = newStack.Pop(); } catch { newOp.mRight = null; } try { newOp.mLeft = newStack.Pop(); } catch { newOp.mLeft = null; } newStack.Push(newOp); } else { if (Double.TryParse(oStack.Peek(), out var value)) { var tempNum = new NumberNode(value); newStack.Push(tempNum); oStack.Pop(); } else { var tempVar = new VariableNode(oStack.Pop()); varNameList.Add(tempVar.mVar); newStack.Push(tempVar); } } } mRoot = newStack.Pop(); }
private IOperationNode CreateExpressionTree(List <object> list) { var operationIndex = -1; foreach (var operations in OperationsPriority.Reverse()) { operationIndex = list.FindLastIndex(x => x is string && operations.Any(y => y == (string)x)); if (operationIndex >= 0) { break; } } if (operationIndex == -1) { return((IOperationNode)list.First()); } var operationSymbol = (string)list[operationIndex]; // root var operationNode = new OperationNode(operationSymbol); // left node if (operationIndex > 0) { var leftNode = CreateExpressionTree(list.GetRange(0, operationIndex)); operationNode.Operations[0] = leftNode; } // right node if (operationIndex < list.Count - 1) { var rightNode = CreateExpressionTree(list.GetRange(operationIndex + 1, list.Count - operationIndex - 1)); operationNode.Operations[1] = rightNode; } // case unary unary expression if (OperationsType[operationSymbol] == 1 && operationNode.Operations[0] != null) { var leftOperationNode = operationNode.Operations[0] as OperationNode; leftOperationNode.Operations[0] = operationNode; operationNode.Operations[0] = null; operationNode = leftOperationNode; } return(operationNode); }
//the remade make tree algorithem so a rpn string can be evaluated, //uses a stack of nodes and trees to hold items private Node makeTree(string expression) { expression = shuntingYardAlgo(expression); int expLength = expression.Length; Stack <Node> expStack = new Stack <Node>(); expStack.Push(null); OperationNode tempTree = null; Node tempNodeR = null, tempNodeL = null; string tSubString = ""; int iter = 1, prevSpace = 0; for (; iter < expLength; iter++) { if (expression[iter] == ' ') { tSubString = expression.Substring(prevSpace + 1, (iter - prevSpace - 1)); prevSpace = iter; if (tSubString.Length != 0) { switch (tSubString) { case "+": case "-": case "*": case "/": tempNodeR = expStack.Pop(); tempNodeL = expStack.Pop(); tempTree = new OperationNode(Convert.ToChar(tSubString), tempNodeL, tempNodeR); expStack.Push(tempTree); break; case "_": //unary negation is handled differently, a node with a negative is made tempNodeR = expStack.Pop(); tempTree = new OperationNode(Convert.ToChar("-"), MakeNodes("0"), tempNodeR); //the left node is 0 and the right node is the value expStack.Push(tempTree); break; default: expStack.Push(MakeNodes(tSubString)); break; } } } } return(expStack.Pop()); }
/// <summary> /// performs an in order tree walk, going through all operations and returning lastOp as the last one /// </summary> /// <param name="lastOp"></param> /// <returns></returns> public IEnumerable <OperationNode> OperationData(OperationNode lastOp) { if (mRoot == null || mRoot == NIL) { yield return(lastOp); yield break; } if (mTreeWalkStack == null) { mTreeWalkStack = new Stack <Node>(); } Node current = mRoot; bool hasNodes = true; while (hasNodes) { if (current != NIL) { ApplyModifier(current); // all modifier must be appied so that the indices are valid mTreeWalkStack.Push(current); current = current.Left; } else { if (mTreeWalkStack.Count > 0) { current = mTreeWalkStack.Pop(); var op = current.OperationA; if (op != null) { yield return(new OperationNode(current.Key, op.Value, op.Operation, op.Count)); } op = current.OperationB; if (op != null) { yield return(new OperationNode(current.Key, op.Value, op.Operation, op.Count)); } current = current.Right; } else { hasNodes = false; } } } yield return(lastOp); }
public bool Visit(OperationNode node) { switch (node.OperationType) { case OperationType.PrefixIncrement: case OperationType.PostfixIncrement: case OperationType.PrefixDecrement: case OperationType.PostfixDecrement: case OperationType.Access: case OperationType.Assign: return(false); default: return(node.Operands.All(IsContant)); } }
public void ResolveHaving <T, TKey>(SqlFunctionType type, Expression <Func <T, TKey> > expression, ExpressionType expType, object value) { builder.FunctionType = type; builder.PartType = SqlPartType.Having; var member = ExpressionHelper.GetMemberExpression(expression.Body); if (member != null) { OperationNode node = new OperationNode(); node.Left = new MemberNode(member); node.Right = new ValueNode(value); node.Operator = expType; builder.BuildWhere(node); } }
public static QueryPlan Build(IPreparedOperation operation) { if (operation is null) { throw new ArgumentNullException(nameof(operation)); } var context = new QueryPlanContext(operation); OperationNode operationNode = Prepare(context); QueryPlan[] deferredPlans = operationNode.Deferred.Count > 0 ? new QueryPlan[operationNode.Deferred.Count] : Array.Empty <QueryPlan>(); Dictionary <int, QueryPlan>?streamPlans = context.Streams.Count > 0 ? new Dictionary <int, QueryPlan>() : null; if (operationNode.Deferred.Count > 0) { for (var i = 0; i < operationNode.Deferred.Count; i++) { deferredPlans[i] = new QueryPlan( operationNode.Deferred[i].CreateStep(), deferredPlans, streamPlans); } } if (context.Streams.Count > 0) { foreach (StreamPlanNode streamPlanNode in context.Streams.Values) { var streamPlan = new QueryPlan( streamPlanNode.Root.CreateStep(), deferredPlans, streamPlans); streamPlans !.Add(streamPlanNode.Id, streamPlan); } } return(new QueryPlan(operationNode.CreateStep(), deferredPlans, streamPlans)); }
/* * An assignation is in the form of : * - x = 5; * - x = y * 1 / z; */ public AbstractStatementNode AssignationExpression() { AbstractExpressionNode left; if (IsOperator(OperatorType.Dereference)) { left = ArithmeticPrimitive(); } else { var ident = GetTokenValueOrThrow <string>(TokenType.Identifier, $"assignation identifier not found"); var symbol = Symbols.Search <AbstractSymbol>(ident); if (symbol is AbstractAddressableSymbol) { var addressableSymbol = (AbstractAddressableSymbol)symbol; var identNode = new AddressableIdentifierNode(addressableSymbol); if (IsOperatorUnconsumed(OperatorType.BracketOpen)) { var indexExpression = BracketEnclosed(ArithmeticExpression); left = new OperationNode(OperatorType.Add, identNode, indexExpression); // recursive ident[a][b][c]... while (IsOperatorUnconsumed(OperatorType.BracketOpen)) { indexExpression = BracketEnclosed(ArithmeticExpression); left = new OperationNode(OperatorType.Add, new DereferenceNode(left), indexExpression); } } else { return(new AssignationNode(identNode, AbstractAssign(identNode))); } } else if (symbol is FunctionSymbol) { return(new BlockNode ( CallExpression((FunctionSymbol)symbol), new DropNode() )); } else { throw new InvalidOperationException("assignation or call expression expected"); } } return(new PointerAssignationNode(left, AbstractAssign(left))); }
public Operation Create(string name, OperationNode lastOperationNode) { switch (name.ToLower()) { case "undo": return Create(Undo.ID, lastOperationNode); case "redo": return Create(Redo.ID, lastOperationNode); default: int id; if (int.TryParse(name, out id)) { return Create(id, lastOperationNode); } return CreateOperation(name); } }
public static OperationNode Build(QueryPlanContext context) { var root = new SequenceNode { CancelOnError = true }; context.Root = root; context.NodePath.Push(root); foreach (ISelection mutation in context.Operation.GetRootSelectionSet().Selections) { context.SelectionPath.Push(mutation); var mutationStep = new ResolverNode( mutation, context.SelectionPath.PeekOrDefault(), GetStrategyFromSelection(mutation)); root.AddNode(mutationStep); QueryStrategy.VisitChildren(mutation, context); } context.NodePath.Pop(); QueryPlanNode optimized = QueryStrategy.Optimize(context.Root); var operationNode = new OperationNode(optimized); if (context.Deferred.Count > 0) { foreach (QueryPlanNode?deferred in QueryStrategy.BuildDeferred(context)) { operationNode.Deferred.Add(deferred); } } if (context.Streams.Count > 0) { operationNode.Streams.AddRange(context.Streams.Values); } return(operationNode); }
public static GraphNode ToGraphNode(OperationNode node) { var root = new GraphNode(node.GetHashCode(), "\"" + node.Representation + "\""); root.AddProperty("color", "dodgerblue"); root.AddProperty("tooltip", nameof(OperationNode)); if (node.Representation == "++" || node.Representation == "--") { root = new GraphNode(node.GetHashCode(), ((node as OperationNode).OperationType.EndsWith("post") ? "\"(postfix)" : "\"(prefix)") + node.Representation + "\""); } foreach (var child in (node as OperationNode).Operands) { root.AddNode(ToGraphNode((dynamic)child)); } return(root); }
public bool Visit(OperationNode node) { if (node.OperationType == OperationType.Access) { if (node.Operands.Count != 2) { return(false); } // we only need to check the left-hand operand, because we know the right-hand operand // is an IdentNode, because an access operation is defined as : // access-operation : // value '.' identifier // hence, the left-hand side return(node.Operands[0].Accept(this)); } return(false); }
public Operation Create(string name, OperationNode lastOperationNode) { switch (name.ToLower()) { case "undo": return(Create(Undo.ID, lastOperationNode)); case "redo": return(Create(Redo.ID, lastOperationNode)); default: int id; if (int.TryParse(name, out id)) { return(Create(id, lastOperationNode)); } return(CreateOperation(name)); } }
private double EvalNode(Node node) // Evaluate each node in expression tree recursively { ConstantValueNode constantNode = node as ConstantValueNode; if (constantNode != null) { return(constantNode.Value); } VariableNode variableNode = node as VariableNode; if (variableNode != null) { return(_variables[variableNode.VariableName]); } OperationNode operationNode = node as OperationNode; if (operationNode != null) { switch (operationNode.Operator) { case '+': return(EvalNode(operationNode.Left) + EvalNode(operationNode.Right)); case '-': return(EvalNode(operationNode.Left) - EvalNode(operationNode.Right)); case '*': return(EvalNode(operationNode.Left) * EvalNode(operationNode.Right)); case '/': return(EvalNode(operationNode.Left) / EvalNode(operationNode.Right)); default: Console.WriteLine("Not a valid operator: " + operationNode.Operator); return(0); } } Console.WriteLine("Not a valid node."); // error return(0); }
public static Instruction CreateLeftTernaryInstruction( string mnemonic, OperationNode op1, OperationNode op2, int exUnit, ValueNode vres, RegisterSet vresRegs, ValueNode v1, RegisterSet v1Regs, ValueNode v2, RegisterSet v2Regs, ValueNode v3, RegisterSet v3Regs) { InstructionPattern ip = new InstructionPattern(); ip.AddNode(op1); ip.AddNode(op2); ip.AddNode(vres); ip.AddNode(v1); ip.AddNode(v2); ip.AddNode(v3); ValueNode iv1 = new RegisterValueNode(v1.Datatype); ip.AddNode(iv1); ip.AddEdge(v1, op1); ip.AddEdge(v2, op1); ip.AddEdge(op1, iv1); ip.AddEdge(iv1, op2); ip.AddEdge(v3, op2); ip.AddEdge(op2, vres); ip.OperandValues.Add(v1); ip.OperandValues.Add(v2); ip.OperandValues.Add(v3); ip.ResultValue = vres; Instruction i = new Instruction(mnemonic, ip); i.ExecutionUnit = exUnit; i.ResultRegisters = vresRegs; i.OperandsRegisters[0] = v1Regs; i.OperandsRegisters[1] = v2Regs; i.OperandsRegisters[2] = v3Regs; return i; }
public static OperationNode Build(QueryPlanContext context) { QueryPlanNode root = Build(context, context.Operation.GetRootSelectionSet()); var operationNode = new OperationNode(root); if (context.Deferred.Count > 0) { foreach (QueryPlanNode?deferred in BuildDeferred(context)) { operationNode.Deferred.Add(deferred); } } if (context.Streams.Count > 0) { operationNode.Streams.AddRange(context.Streams.Values); } return(operationNode); }
//Overload Compile function //this function compiles expression using a certain operation parameter and handles the parentheses private Node Compile(string exp, char op) { int counter = 0; //loop from right to left int i = exp.Length - 1; while (i >= 0) { if (exp[i] == '(') { counter++; } else if (exp[i] == ')') { counter--; } //hit correct operator if (counter == 0 && exp[i] == op) { //form the subtree with the OperationNode being the root, return the OperationNode OperationNode opNode = new OperationNode(op); opNode.Left = Compile(exp.Substring(0, i)); opNode.Right = Compile(exp.Substring(i + 1)); return opNode; } i--; } return null; }
private AccessPermissionTree BuileAccessTree(List<AccessPermission> permissions) { AccessPermissionTree accessTree = new AccessPermissionTree(); foreach (ModuleCategoryType catetype in Enum.GetValues(typeof(ModuleCategoryType))) { CategoryNode category = new CategoryNode(); category.CategoryType = catetype; List<AccessPermission> moduleList = permissions.FindAll(delegate(AccessPermission access) { return access.CategotyType == catetype; }); List<ModuleType> moduleInCategory = new List<ModuleType>(); foreach (ModuleType moduleType in Enum.GetValues(typeof(ModuleType))) { AccessPermission accesssss = moduleList.Find(delegate(AccessPermission per) { return per.ModuleType == moduleType; }); if (moduleList.Find(delegate(AccessPermission per) { return per.ModuleType == moduleType; }) != null) { moduleInCategory.Add(moduleType); } } foreach (ModuleType moduleType in moduleInCategory) { ModuleNode module = new ModuleNode(); module.Type = moduleType; foreach (AccessPermission access in moduleList) { if (access.ModuleType == moduleType) { OperationNode node = new OperationNode(); node.Id = access.OperationId; node.OperationDescription = access.OperationName; module.OperationNodes.Add(node); } } category.ModuleNodes.Add(module); } if (category.ModuleNodes.Count != 0) { accessTree.CategoryNodes.Add(category); } } return accessTree; }
public Undo(OperationNode lastOperation) { OperationId = ID; if (lastOperation != null) _lastOperation=lastOperation.Value; }
public ProgramGraph CreateUnrolledProgramGraph(int k) { ProgramGraph g = new ProgramGraph(); ValueNode[] px = new ValueNode[k]; ValueNode[] x = new ValueNode[k]; ValueNode[] py = new ValueNode[k]; ValueNode[] my = new ValueNode[k]; ValueNode[] y = new ValueNode[k]; OperationNode[] lx = new OperationNode[k]; OperationNode[] sy = new OperationNode[k]; for (int i = 0; i < k; i++) { px[i] = new FloatMemoryNode("x[" + i + "]"); lx[i] = new LoadOperationNode(); x[i] = new FloatRegisterNode(); g.AddNode(px[i]); g.AddNode(lx[i]); g.AddNode(x[i]); g.AddEdge(px[i], lx[i]); g.AddEdge(lx[i], x[i]); y[i] = new FloatRegisterNode(); py[i] = new FloatMemoryNode("y[" + i + "]"); sy[i] = new StoreOperationNode(); my[i] = new FloatMemoryNode(null); g.AddNode(y[i]); g.AddNode(py[i]); g.AddNode(sy[i]); g.AddNode(my[i]); g.AddEdge(y[i], sy[i]); g.AddEdge(py[i], sy[i]); g.AddEdge(sy[i], my[i]); } ValueNode[] x0 = new ValueNode[k + 1]; ValueNode[] x1 = new ValueNode[k + 1]; for (int i = 0; i < k + 1; i++) { x0[i] = new FloatRegisterNode(); x1[i] = new FloatRegisterNode(); g.AddNode(x0[i]); g.AddNode(x1[i]); } ValueNode px00 = new FloatMemoryNode("x0[0]"); ValueNode px10 = new FloatMemoryNode("x1[0]"); OperationNode lx00 = new LoadOperationNode(); OperationNode lx10 = new LoadOperationNode(); g.AddNode(px00); g.AddNode(px10); g.AddNode(lx00); g.AddNode(lx10); g.AddEdge(px00, lx00); g.AddEdge(lx00, x0[0]); g.AddEdge(px10, lx10); g.AddEdge(lx10, x1[0]); ValueNode px0k = new FloatMemoryNode("x0[" + k + "]"); ValueNode px1k = new FloatMemoryNode("x1[" + k + "]"); ValueNode mx0k = new FloatMemoryNode(null); ValueNode mx1k = new FloatMemoryNode(null); OperationNode sx0k = new StoreOperationNode(); OperationNode sx1k = new StoreOperationNode(); g.AddNode(px0k); g.AddNode(px1k); g.AddNode(mx0k); g.AddNode(mx1k); g.AddNode(sx0k); g.AddNode(sx1k); g.AddEdge(x0[k], sx0k); g.AddEdge(px0k, sx0k); g.AddEdge(sx0k, mx0k); g.AddEdge(x1[k], sx1k); g.AddEdge(px1k, sx1k); g.AddEdge(sx1k, mx1k); ValueNode pc0 = new FloatMemoryNode("c0"); ValueNode pc1 = new FloatMemoryNode("c1"); ValueNode pc2 = new FloatMemoryNode("c2"); ValueNode pc3 = new FloatMemoryNode("c3"); ValueNode pc4 = new FloatMemoryNode("c4"); OperationNode lc0 = new LoadOperationNode(); OperationNode lc1 = new LoadOperationNode(); OperationNode lc2 = new LoadOperationNode(); OperationNode lc3 = new LoadOperationNode(); OperationNode lc4 = new LoadOperationNode(); ValueNode c0 = new FloatRegisterNode(); ValueNode c1 = new FloatRegisterNode(); ValueNode c2 = new FloatRegisterNode(); ValueNode c3 = new FloatRegisterNode(); ValueNode c4 = new FloatRegisterNode(); g.AddNode(pc0); g.AddNode(pc1); g.AddNode(pc2); g.AddNode(pc3); g.AddNode(pc4); g.AddNode(lc0); g.AddNode(lc1); g.AddNode(lc2); g.AddNode(lc3); g.AddNode(lc4); g.AddNode(c0); g.AddNode(c1); g.AddNode(c2); g.AddNode(c3); g.AddNode(c4); g.AddEdge(pc0, lc0); g.AddEdge(lc0, c0); g.AddEdge(pc1, lc1); g.AddEdge(lc1, c1); g.AddEdge(pc2, lc2); g.AddEdge(lc2, c2); g.AddEdge(pc3, lc3); g.AddEdge(lc3, c3); g.AddEdge(pc4, lc4); g.AddEdge(lc4, c4); for (int i = 0; i < k; i++) { CreateSingleFilterLoop( g, x[i], x0[i], x1[i], c0, c1, c2, c3, c4, x0[i + 1], x1[i + 1], y[i]); } g.InitInputValues(); g.InitOutputValues(); return g; }
protected void CreateSingleLoop( ProgramGraph g, ValueNode xp, ValueNode yp, ValueNode x, ValueNode y, ValueNode c0, ValueNode c1, ValueNode c2, ValueNode xp1, ValueNode yp1, ValueNode x1, ValueNode y1) { OperationNode[] o = new OperationNode[11]; o[0] = new StoreOperationNode(); o[1] = new AddOperationNode(); o[2] = new AddOperationNode(); o[3] = new ConstOperationNode(); o[4] = new AddOperationNode(); o[5] = new MulOperationNode(); o[6] = new MulOperationNode(); o[7] = new MulOperationNode(); o[8] = new LoadOperationNode(); o[9] = new AddOperationNode(); o[10] = new ConstOperationNode(); foreach (OperationNode op in o) g.AddNode(op); ValueNode[] v = new ValueNode[9]; v[0] = new FloatMemoryNode(null); v[1] = new IntRegisterNode(); v[2] = new FloatRegisterNode(); v[3] = new FloatRegisterNode(); v[4] = new IntConstantNode(4); v[5] = new FloatRegisterNode(); v[6] = new FloatRegisterNode(); v[7] = new IntRegisterNode(); v[8] = new IntConstantNode(4); foreach (ValueNode val in v) g.AddNode(val); g.AddEdge(y1, o[0]); g.AddEdge(yp, o[0]); g.AddEdge(o[0], v[0]); g.AddEdge(yp, o[1]); g.AddEdge(v[1], o[1]); g.AddEdge(o[1], yp1); g.AddEdge(v[2], o[2]); g.AddEdge(v[3], o[2]); g.AddEdge(o[2], y1); g.AddEdge(v[4], o[3]); g.AddEdge(o[3], v[1]); g.AddEdge(v[5], o[4]); g.AddEdge(v[6], o[4]); g.AddEdge(o[4], v[2]); g.AddEdge(c2, o[5]); g.AddEdge(y, o[5]); g.AddEdge(o[5], v[3]); g.AddEdge(c1, o[6]); g.AddEdge(x, o[6]); g.AddEdge(o[6], v[5]); g.AddEdge(c0, o[7]); g.AddEdge(x1, o[7]); g.AddEdge(o[7], v[6]); g.AddEdge(xp, o[8]); g.AddEdge(o[8], x1); g.AddEdge(xp, o[9]); g.AddEdge(v[7], o[9]); g.AddEdge(o[9], xp1); g.AddEdge(v[8], o[10]); g.AddEdge(o[10], v[7]); }
protected void CreateSingleLoop( ProgramGraph g, ValueNode ap, ValueNode bp, ValueNode cp, ValueNode k0, ValueNode k1, ValueNode ap1, ValueNode bp1, ValueNode cp1) { OperationNode[] o = new OperationNode[12]; o[0] = new AddOperationNode(); o[1] = new MulOperationNode(); o[2] = new MulOperationNode(); o[3] = new LoadOperationNode(); o[4] = new AddOperationNode(); o[5] = new LoadOperationNode(); o[6] = new AddOperationNode(); o[7] = new ConstOperationNode(); o[8] = new ConstOperationNode(); o[9] = new StoreOperationNode(); o[10] = new AddOperationNode(); o[11] = new ConstOperationNode(); foreach (OperationNode op in o) g.AddNode(op); ValueNode[] v = new ValueNode[12]; v[0] = new FloatRegisterNode(); v[1] = new FloatRegisterNode(); v[2] = new FloatRegisterNode(); v[3] = new FloatRegisterNode(); v[4] = new IntRegisterNode(); v[5] = new IntRegisterNode(); v[6] = new IntConstantNode(4); v[7] = new IntConstantNode(4); v[8] = new FloatRegisterNode(); v[9] = new FloatMemoryNode(null); v[10] = new IntRegisterNode(); v[11] = new IntConstantNode(4); foreach (ValueNode val in v) g.AddNode(val); g.AddEdge(v[0], o[0]); g.AddEdge(v[1], o[0]); g.AddEdge(o[0], v[8]); g.AddEdge(v[2], o[1]); g.AddEdge(k0, o[1]); g.AddEdge(o[1], v[0]); g.AddEdge(v[3], o[2]); g.AddEdge(k1, o[2]); g.AddEdge(o[2], v[1]); g.AddEdge(ap, o[3]); g.AddEdge(o[3], v[2]); g.AddEdge(ap, o[4]); g.AddEdge(v[4], o[4]); g.AddEdge(o[4], ap1); g.AddEdge(bp, o[5]); g.AddEdge(o[5], v[3]); g.AddEdge(bp, o[6]); g.AddEdge(v[5], o[6]); g.AddEdge(o[6], bp1); g.AddEdge(v[6], o[7]); g.AddEdge(o[7], v[4]); g.AddEdge(v[7], o[8]); g.AddEdge(o[8], v[5]); g.AddEdge(v[8], o[9]); g.AddEdge(cp, o[9]); g.AddEdge(o[9], v[9]); g.AddEdge(cp, o[10]); g.AddEdge(v[10], o[10]); g.AddEdge(o[10], cp1); g.AddEdge(v[11], o[11]); g.AddEdge(o[11], v[10]); }
private static void GenerateOperation(OperationNode node, DataContext data) { Append(data, "("); GenerateExpression(node.LeftHand, data); switch (node.Type) { case OperationType.Equals: Append(data, " == "); break; case OperationType.NotEquals: Append(data, " != "); break; case OperationType.GreaterThan: Append(data, " > "); break; case OperationType.GreaterThanOrEqualTo: Append(data, " >= "); break; case OperationType.LessThan: Append(data, " < "); break; case OperationType.LessThanOrEqualTo: Append(data, " <= "); break; case OperationType.Add: Append(data, " + "); break; case OperationType.Subtract: Append(data, " - "); break; case OperationType.Multiply: Append(data, " * "); break; case OperationType.Divide: Append(data, " / "); break; case OperationType.ConditionalOr: Append(data, " || "); break; case OperationType.ConditionalAnd: Append(data, " && "); break; default: ThrowUnableToGenerateException("Operation", node); break; } GenerateExpression(node.RightHand, data); Append(data, ")"); }
protected void CreateSingleFilterLoop( ProgramGraph g, ValueNode x, ValueNode x0, ValueNode x1, ValueNode c0, ValueNode c1, ValueNode c2, ValueNode c3, ValueNode c4, ValueNode z0, ValueNode z1, ValueNode y) { OperationNode[] o = new OperationNode[13]; o[0] = new AddOperationNode(); o[1] = new MulOperationNode(); o[2] = new AddOperationNode(); o[3] = new AddOperationNode(); o[4] = new MulOperationNode(); o[5] = new AddOperationNode(); o[6] = new AddOperationNode(); o[7] = new AddOperationNode(); o[8] = new MulOperationNode(); o[9] = new MulOperationNode(); o[10] = new MulOperationNode(); o[11] = new AddOperationNode(); o[12] = new AddOperationNode(); foreach (OperationNode opNode in o) g.AddNode(opNode); ValueNode[] v = new ValueNode[10]; for (int i = 0; i < v.Length; i++) v[i] = new FloatRegisterNode(); foreach (ValueNode vNode in v) g.AddNode(vNode); g.AddEdge(x, o[0]); g.AddEdge(x0, o[0]); g.AddEdge(o[0], v[0]); g.AddEdge(c0, o[1]); g.AddEdge(v[0], o[1]); g.AddEdge(o[1], v[1]); g.AddEdge(x, o[2]); g.AddEdge(v[1], o[2]); g.AddEdge(o[2], v[2]); g.AddEdge(v[2], o[3]); g.AddEdge(x1, o[3]); g.AddEdge(o[3], v[3]); g.AddEdge(c1, o[4]); g.AddEdge(v[3], o[4]); g.AddEdge(o[4], v[4]); g.AddEdge(v[2], o[5]); g.AddEdge(v[4], o[5]); g.AddEdge(o[5], z1); g.AddEdge(v[1], o[6]); g.AddEdge(x0, o[6]); g.AddEdge(o[6], v[5]); g.AddEdge(v[4], o[7]); g.AddEdge(x1, o[7]); g.AddEdge(o[7], z0); g.AddEdge(v[5], o[8]); g.AddEdge(c2, o[8]); g.AddEdge(o[8], v[6]); g.AddEdge(z0, o[9]); g.AddEdge(c3, o[9]); g.AddEdge(o[9], v[7]); g.AddEdge(z1, o[10]); g.AddEdge(c4, o[10]); g.AddEdge(o[10], v[9]); g.AddEdge(v[6], o[11]); g.AddEdge(v[7], o[11]); g.AddEdge(o[11], v[8]); g.AddEdge(v[8], o[12]); g.AddEdge(v[9], o[12]); g.AddEdge(o[12], y); }