Пример #1
0
        private static void test()
        {
            /*var c = new Class1(0);
             * var list = new List<IInstruction>
             * {
             *  new RTypeInstruction() { Function = RTypeFunction.Add, Rd = 30},
             *  new ITypeInstruction() { Opcode = Opcode.AddImmediate, Rt = 30},
             *  new RTypeInstruction() { Function = RTypeFunction.JumpRegister, Rs = 31},
             *
             * };
             * c.Parse(list, 0, 8);*/

            var program      = ProgramLoader.ReadProgram(ELFReader.Load <uint>("test.axf"), false);
            var c2           = new SubCodeReader(program.TextSectionAddress);
            var startAddress = 0x100004fcu;
            var endAddress   = 0x100005e4u;
            var sc           = c2.Parse(program.Instructions, startAddress, endAddress);
            var gb           = new GraphBuilder();
            var g            = gb.Build(sc);
            var gv           = new GraphViz();

            Console.WriteLine("Plotting Graph");
            //gv.CreateGraph(g).Save("graph.svg");
            //gv.CreateSVGGraph(g, "graph");
            var gl = new GraphLinearizer();

            //var c = gl.FindCycles(g);
            //var pth = new HashSet<Node<IList<IInstruction>>>();
            //gl.SearchRec(c.ElementAt(7).Item2, c.ElementAt(7).Item1, new HashSet<Node<IList<IInstruction>>>(), pth);
            Console.WriteLine("Linearizing Graph");
            gl.Linearize(g);
            Console.WriteLine("Plotting DAG");
            //gv.CreateGraph(g).Save("DAG.svg");
            //gv.CreateSVGGraph(g, "DAG");
            Console.WriteLine("Computing WCET");


            var stateTransition = new StateTransition();
            var graphHeuristic  = new GraphHeuristic();
            var initialState    = new State();

            initialState.Cache = new Cache(5);
            initialState.Node  = g;
            graphHeuristic.ComputeHeuristic(g);
            var initialCost = stateTransition.ComputeCost(initialState);
            var aStar       = new AStar.AStarPrime();

            AStar.Node aStarResult;
            var        goalState = new State()
            {
                Node = gl.FindNodeByInstAddress(g, endAddress)
            };

            aStar.Search(stateTransition, initialState, goalState, Heuristic.ComputeHeuristic, out aStarResult, initialCost);
            var cwcet = new CachelessWCET();
            var cWCET = cwcet.CalculateWCET(g);
        }
Пример #2
0
        public void Linearize(InstNode root)
        {
            var ind = 0;
            var gv  = new GraphViz();

            while (true)
            {
                var cycles = FindCycles(root);
                if (cycles.Count == 0)
                {
                    return;
                }

                var cyclesN = new List <Tuple <Tuple <InstNode, InstNode>,
                                               ISet <InstNode> > >();
                foreach (var x in cycles)
                {
                    var set = new HashSet <InstNode>();
                    SearchRec(x.Item2, x.Item1, new HashSet <InstNode>(), set);
                    cyclesN.Add(new Tuple <Tuple <InstNode, InstNode>, ISet <InstNode> >(x, set));
                }
                var availableCycles = new List <Tuple <Tuple <InstNode, InstNode>,
                                                       ISet <InstNode> > >();
                foreach (var x in cyclesN)
                {
                    var valid = true;
                    foreach (var y in cyclesN)
                    {
                        if (x != y)
                        {
                            foreach (var e in x.Item2)
                            {
                                if (y.Item2.Contains(e))
                                {
                                    valid = false;
                                }
                            }
                        }
                    }
                    if (valid)
                    {
                        availableCycles.Add(x);
                    }
                }
                if (availableCycles.Count == 0)
                {
                    throw new InvalidOperationException("Error During Linearization");
                }

                foreach (var y in availableCycles)
                {
                    var set = y.Item2;
                    var x   = y.Item1;
                    var n1  = x.Item2;
                    var n2  = x.Item1.Clone();
                    var n3  = x.Item1;
                    if (n2.Left == n1)
                    {
                        n2.Left = null;
                        n3.Left = null;
                    }
                    if (n2.Right == n1)
                    {
                        n2.Right = null;
                        n3.Right = null;
                    }
                    var n3l = n3.Left;
                    var n3r = n3.Right;
                    n3.Left  = null;
                    n3.Right = null;
                    var lst = n1.CloneAndReturnSN(n3);
                    lst.Item2.Left  = n3l;
                    lst.Item2.Right = n3r;
                    n3.Left         = n3l;
                    n3.Right        = n3l;
                    LinearizeRec(n1, set);

                    var ccs = new CycleCountSelector(gv.CreateGraph(n1));
                    if (ccs.ShowDialog() != System.Windows.Forms.DialogResult.OK)
                    {
                        Console.WriteLine("Operation Cancelled");
                        Environment.Exit(0);
                    }


                    var N = ccs.NumberOfRepetitions;
                    //var N = 3;

                    if (N == 1)
                    {
                        n1.Left  = lst.Item1.Left;
                        n2.Right = lst.Item1.Right;
                        continue;
                    }


                    var last = new Tuple <InstNode, InstNode>(n1, n3);
                    for (int j = 2; j < N; j++)
                    {
                        var clone = last.Item1.CloneAndReturnSN(last.Item2);
                        //var clone = n1.CloneAndReturnSN(n3);
                        last.Item2.Left = clone.Item1;
                        last            = clone;
                    }
                    //last.Item2.Left = n2.Left;
                    //last.Item2.Right = n2.Right;
                    last.Item2.Left = lst.Item1;
                }
                if (cycles.Count == availableCycles.Count)
                {
                    return;
                }
            }
        }