コード例 #1
0
        //Just create one Vertex SubExpressionGraph
        public override SubExpressionGraph Visit(VariableUseNode node)
        {
            var sub_graph = new SubExpressionGraph();

            sub_graph.LastNode = node;
            return(sub_graph);
        }
コード例 #2
0
        private VariableUseNode Var(String s)
        {
            VariableUseNode _var = new VariableUseNode();

            _var.Name = s;
            return(_var);
        }
コード例 #3
0
 public override void Visit(VariableUseNode node)
 {
     Visit(node as ExpressionNode);
     if (_declToFunction[node.Declaration] != _currentFunction)
     {
         node.Declaration.NestedUse = true;
     }
     // WARNING: AbstractRecursiveVisitor traverses all edges (including non-tree)
 }
コード例 #4
0
        //Replace IfNodes and link sub_graph of childs
        public override SubExpressionGraph Visit(BlockExpressionNode node)
        {
            var sub_graph    = new SubExpressionGraph();
            var new_elements = new List <ExpressionNode>();

            VariableDefNode t = new VariableDefNode();

            t.ExpressionType = node.ExpressionType;
            t.Name           = "T" + temporary_counter;
            AtomNode _0 = new AtomNode(node.ExpressionType);

            _0.Value = "";
            t.Value  = _0;
            VariableUseNode t_use = new VariableUseNode();

            t_use.ExpressionType = node.ExpressionType;
            t_use.Declaration    = t;
            t_use.Name           = "T" + temporary_counter;

            if (!ReferenceEquals(node.Elements, null))
            {
                int counter = 0;
                foreach (var child in node.Elements)
                {
                    if (!ReferenceEquals(child, null))
                    {
                        var child_graph = child.Accept(this);
                        if (child_graph == null)
                        {
                            throw new Exception("SubGraph of child is null");
                        }
                        new_elements.Add(GetUpdatedExpressionNodeValue(child, child_graph));
                        if (counter == node.Elements.Count() - 1)
                        {
                            OperatorNode _temp_assing = new OperatorNode();
                            _temp_assing.Operator  = OperatorType.ASSIGN;
                            _temp_assing.Arguments = new List <ExpressionNode> {
                                t_use, child_graph.LastNode
                            };
                            child_graph.LastNode = _temp_assing;
                        }
                        child_graph = SubExpressionGraph.ConcatSubGraph(child_graph, SubExpressionGraph.CreateOneVertexSubGraph(child_graph.LastNode));
                        sub_graph   = SubExpressionGraph.ConcatSubGraph(sub_graph, child_graph);
                    }
                }
                node.Elements = new_elements;
            }

            sub_graph.ContainsExtracted = true;
            sub_graph.Temporary         = t_use;
            temporary_counter++;

            return(sub_graph);
        }
コード例 #5
0
            public Brep.Node Build(VariableUseNode useNode)
            {
                var definition = useNode.Declaration as VariableDefNode;

                if (definition != null)
                {
                    return(funDef.BackendFunction.AccessLocal(definition.VariableLocation));
                }
                else
                {
                    // must be a function argument
                    return(Build(useNode.Declaration));
                }
            }
コード例 #6
0
        //create cycle for while
        public override SubExpressionGraph Visit(WhileNode node)
        {
            while_stack.Add(node);

            var sub_graph = new SubExpressionGraph();

            var begin_while = SubExpressionGraph.CreateOneVertexSubGraph(new BlockExpressionNode());

            if (!ReferenceEquals(node.Condition, null))
            {
                node.Condition = ProcessSingleNode(node.Condition, ref sub_graph);
            }

            if (!ReferenceEquals(node.Body, null))
            {
                node.Body = ProcessSingleNode(node.Body, ref sub_graph);
            }

            if (node.HasElse)
            {
                node.Else = ProcessSingleNode(node.Else, ref sub_graph);
            }

            VariableDefNode t = new VariableDefNode();

            t.ExpressionType = node.ExpressionType;
            t.Name           = "T" + temporary_counter;
            AtomNode _0 = new AtomNode(node.ExpressionType);

            _0.Value = "";
            t.Value  = _0;
            VariableUseNode t_use = new VariableUseNode();

            t_use.ExpressionType = node.ExpressionType;
            t_use.Declaration    = t;
            t_use.Name           = "T" + temporary_counter;

            List <Vertex> while_graph_vertex = new List <Vertex>();

            OperatorNode assign_body = new OperatorNode();

            assign_body.Operator  = OperatorType.ASSIGN;
            assign_body.Arguments = new List <ExpressionNode> {
                t_use, node.Body
            };

            ConditionalJumpVertex condition_vertex = new ConditionalJumpVertex(null, null, node.Condition);

            while_graph_vertex.Add(condition_vertex);

            OneJumpVertex body_vertex = new OneJumpVertex(condition_vertex, assign_body);

            while_graph_vertex.Add(body_vertex);

            OneJumpVertex end_while_vertex = new OneJumpVertex(null, t_use);

            condition_vertex.TrueJump = body_vertex;
            body_vertex.Jump          = begin_while.Start;

            if (node.HasElse)
            {
                OperatorNode assign_else = new OperatorNode();
                assign_else.Operator  = OperatorType.ASSIGN;
                assign_else.Arguments = new List <ExpressionNode> {
                    t_use, node.Else
                };

                OneJumpVertex else_vertex = new OneJumpVertex(end_while_vertex, assign_else);
                while_graph_vertex.Add(else_vertex);
                condition_vertex.FalseJump = else_vertex;
            }
            else
            {
                condition_vertex.FalseJump = end_while_vertex;
            }

            while_graph_vertex.Add(end_while_vertex);

            sub_graph = SubExpressionGraph.ConcatSubGraph(sub_graph, new SubExpressionGraph(condition_vertex, while_graph_vertex, end_while_vertex, true, null));

            sub_graph.Temporary = t_use;
            temporary_counter++;

            if (while_for_loop_control.ContainsKey(LoopControlMode.LCM_BREAK) && while_for_loop_control[LoopControlMode.LCM_BREAK].ContainsKey(node))
            {
                foreach (var loop_control_vertex in while_for_loop_control[LoopControlMode.LCM_BREAK][node])
                {
                    ((OneJumpVertex)loop_control_vertex).Jump = sub_graph.End;
                }
            }
            if (while_for_loop_control.ContainsKey(LoopControlMode.LCM_CONTINUE) && while_for_loop_control[LoopControlMode.LCM_CONTINUE].ContainsKey(node))
            {
                foreach (var loop_control_vertex in while_for_loop_control[LoopControlMode.LCM_CONTINUE][node])
                {
                    ((OneJumpVertex)loop_control_vertex).Jump = sub_graph.Start;
                }
            }

            while_stack.Remove(node);

            return(sub_graph);
        }
コード例 #7
0
        //Create diamond graph with CondtionVertex, mark flag IF
        public override SubExpressionGraph Visit(IfNode node)
        {
            var sub_graph = new SubExpressionGraph();

            if (!ReferenceEquals(node.Condition, null))
            {
                node.Condition = ProcessSingleNode(node.Condition, ref sub_graph);
            }

            if (!ReferenceEquals(node.Then, null))
            {
                node.Then = ProcessSingleNode(node.Then, ref sub_graph);
            }

            if (node.HasElse)
            {
                node.Else = ProcessSingleNode(node.Else, ref sub_graph);
            }

            VariableDefNode t = new VariableDefNode();

            t.ExpressionType = node.ExpressionType;
            t.Name           = "T" + temporary_counter;
            AtomNode _0 = new AtomNode(node.ExpressionType);

            _0.Value = "";
            t.Value  = _0;
            VariableUseNode t_use = new VariableUseNode();

            t_use.ExpressionType = node.ExpressionType;
            t_use.Declaration    = t;
            t_use.Name           = "T" + temporary_counter;

            OperatorNode assign_then = new OperatorNode();

            assign_then.Operator  = OperatorType.ASSIGN;
            assign_then.Arguments = new List <ExpressionNode> {
                t_use, node.Then
            };

            OneJumpVertex         then_vertex      = new OneJumpVertex(null, assign_then);
            OneJumpVertex         end_if           = new OneJumpVertex(null, t_use);
            ConditionalJumpVertex condition_vertex = new ConditionalJumpVertex(then_vertex, end_if, node.Condition);

            var vertex_in_if = new List <Vertex> {
                condition_vertex, then_vertex
            };

            if (node.HasElse)
            {
                OperatorNode assign_else = new OperatorNode();
                assign_else.Operator  = OperatorType.ASSIGN;
                assign_else.Arguments = new List <ExpressionNode> {
                    t_use, node.Else
                };

                OneJumpVertex else_vertex = new OneJumpVertex(null, assign_else);

                condition_vertex.FalseJump = else_vertex;
                else_vertex.Jump           = end_if;

                vertex_in_if.Add(else_vertex);
            }
            else
            {
                condition_vertex.FalseJump = end_if;
            }

            vertex_in_if.Add(end_if);

            var if_sub_graph = new SubExpressionGraph(condition_vertex, vertex_in_if, end_if, true, null);

            sub_graph = SubExpressionGraph.ConcatSubGraph(sub_graph, if_sub_graph);

            sub_graph.Temporary = t_use;
            temporary_counter++;

            return(sub_graph);
        }
コード例 #8
0
        public override void Visit(IfNode node)
        {
            base.Visit(node);

            if (changed_nodes.ContainsKey(node.Condition))
            {
                node.Condition = changed_nodes[node.Condition];
            }
            if (changed_nodes.ContainsKey(node.Then))
            {
                node.Then = changed_nodes[node.Then];
            }
            if (changed_nodes.ContainsKey(node.Else))
            {
                node.Else = changed_nodes[node.Else];
            }

            VariableDefNode t = new VariableDefNode();

            t.Name = "T" + temporary_counter;
            AtomNode _0 = new AtomNode(NamedTypeNode.IntType());

            _0.Value = "0";
            t.Value  = _0;
            VariableUseNode t_use = new VariableUseNode();

            t_use.Declaration = t;
            t_use.Name        = "T" + temporary_counter;

            OperatorNode assign_then = new OperatorNode();

            assign_then.Operator  = OperatorType.ASSIGN;
            assign_then.Arguments = new List <ExpressionNode> {
                t_use, node.Then
            };
            OneJumpVertex then_vertex = new OneJumpVertex(null, assign_then);

            graph_vertex.Add(then_vertex);

            ConditionalJumpVertex condition_vertex = new ConditionalJumpVertex(then_vertex, null, node.Condition);

            graph_vertex.Add(condition_vertex);
            AddNextJump(condition_vertex);

            nodes_to_next_jmp.Add(then_vertex);

            if (node.HasElse)
            {
                OperatorNode assign_else = new OperatorNode();
                assign_else.Operator  = OperatorType.ASSIGN;
                assign_else.Arguments = new List <ExpressionNode> {
                    t_use, node.Else
                };
                OneJumpVertex else_vertex = new OneJumpVertex(null, assign_else);
                graph_vertex.Add(else_vertex);
                nodes_to_next_jmp.Add(else_vertex);
                condition_vertex.FalseJump = else_vertex;
            }
            else
            {
                nodes_to_next_jmp.Add(condition_vertex);
            }

            changed_nodes[node] = t_use;
            temporary_counter++;
        }
コード例 #9
0
 public override void Visit(VariableUseNode node)
 {
     node.Declaration = variableSymbolTable.LookUp <VariableDeclNode> (node.Name);
     base.Visit(node);
 }
コード例 #10
0
 public virtual T Visit(VariableUseNode node)
 {
     return(Visit(node as ExpressionNode));
 }
コード例 #11
0
 public virtual void Visit(VariableUseNode node)
 {
     Visit(node as ExpressionNode);
 }
コード例 #12
0
        override public void Visit(OperatorNode node)
        {
            base.Visit(node);

            switch (node.Operator)
            {
            case OperatorType.OR:
            case OperatorType.AND:
            case OperatorType.BIT_OR:
            case OperatorType.BIT_XOR:
            case OperatorType.BIT_AND:
            case OperatorType.EQUAL:
            case OperatorType.NOT_EQUAL:
            case OperatorType.LESS:
            case OperatorType.LESS_EQUAL:
            case OperatorType.GREATER:
            case OperatorType.GREATER_EQUAL:
            case OperatorType.BIT_SHIFT_UP:
            case OperatorType.BIT_SHIFT_DOWN:
            case OperatorType.PLUS:
            case OperatorType.MINUS:
            case OperatorType.MUL:
            case OperatorType.DIV:
            case OperatorType.MOD:
            case OperatorType.UNARY_PLUS:
            case OperatorType.UNARY_MINUS:
            case OperatorType.NOT:
            case OperatorType.BIT_NOT:
                var newArgs = new List <ExpressionNode>();
                foreach (var arg in node.Arguments)
                {
                    if (HasSideEffects(arg))
                    {
                        var tempDef = new VariableDefNode();
                        tempDef.Name             = "temp";
                        tempDef.Type             = arg.ExpressionType;
                        tempDef.NestedUse        = false;
                        tempDef.Value            = arg;
                        tempDef.VariableLocation = new Temporary();
                        trees.Add(tempDef);
                        var tempUse = new VariableUseNode();
                        tempUse.Name        = "temp";
                        tempUse.Declaration = tempDef;
                        newArgs.Add(tempUse);
                    }
                    else
                    {
                        newArgs.Add(arg);
                    }
                }
                node.Arguments = newArgs;
                break;

            case OperatorType.ASSIGN:
                // Do nothing. If node was a child, it would be extracted
                // and this code would not be running. Therefore,
                // node is a root. We accept side effects in roots.
                break;

            default:
                throw new NotImplementedException();
            }
        }
コード例 #13
0
 private bool HasSideEffects(VariableUseNode node)
 {
     return(false);
 }
コード例 #14
0
 //rewerite type
 public override void Visit(VariableUseNode node)
 {
     base.Visit(node);
     node.ExpressionType = node.Declaration.ExpressionType;
 }