コード例 #1
0
        public void TestGreibachNormalForm()
        {
            Assert.IsFalse(grammar1.InGreibachNormalForm());
            Assert.IsFalse(grammar2.InGreibachNormalForm());
            Assert.IsFalse(grammar3.InGreibachNormalForm());
            Assert.IsTrue(grammar1.ToGreibachNormalForm().InGreibachNormalForm());
            Assert.IsTrue(grammar2.ToGreibachNormalForm().InGreibachNormalForm());
            CFG grammar3Greibach = grammar3.ToGreibachNormalForm();

            Assert.IsTrue(grammar3Greibach.InGreibachNormalForm());
            Assert.IsTrue(derives(grammar3Greibach, ""));
            Assert.IsTrue(derives(grammar3Greibach, "()"));
            Assert.IsTrue(derives(grammar3Greibach, "()()"));
            Assert.IsTrue(derives(grammar3Greibach, "(())"));
            Assert.IsTrue(derives(grammar3Greibach, "(()())"));
            Assert.IsTrue(derives(grammar3Greibach, "()(()(()))(())"));
            Assert.IsFalse(derives(grammar3Greibach, "("));
            Assert.IsFalse(derives(grammar3Greibach, ")"));
            Assert.IsFalse(derives(grammar3Greibach, "())"));
            Assert.IsFalse(derives(grammar3Greibach, "(()()"));
            Assert.IsFalse(derives(grammar3Greibach, "((())))"));
            Assert.IsFalse(derives(grammar3Greibach, "(()(())"));
            Assert.IsFalse(derives(grammar3Greibach, "()(()((()))(())))"));
            Assert.IsTrue(CFGBuilder.Start("A")
                          .Derive("A").To("a")
                          .Derive("A").ToEpsilon()
                          .Build().InGreibachNormalForm());
            Assert.IsFalse(CFGBuilder.Start("A")
                           .Derive("A").To("a", "A")
                           .Derive("A").ToEpsilon()
                           .Build().InGreibachNormalForm());
        }
コード例 #2
0
        private void UnFinished(ItemSet itemSet, int status, Item item)
        {
            char nextChar = item.Production.Right[item.Index];

            if (nextChar == System.Configuration.ConfigurationManager.AppSettings["Empty"][0])
            {
                return;
            }
            ItemSet nextSet = itemSet.Go(nextChar);

            nextSet.Closure(CFG, First);
            if (!InItemSetMap(nextSet))
            {
                ItemSetMap.Add(nextSet, ItemSetMap.Count);
                _ItemSetMap.Add(_ItemSetMap.Count, nextSet);
            }
            if (CFG.isVn(nextChar))
            {
                Table.add(new TableIndex(status, nextChar), new TableItem('G', ItemSetMap[nextSet]));
            }
            else
            {
                Table.add(new TableIndex(status, nextChar), new TableItem('S', ItemSetMap[nextSet]));
            }
        }
コード例 #3
0
 void init()
 {
     if (!TCA_Active)
     {
         return;
     }
     updateCFG();
     VSL = new VesselWrapper(this);
     EnableTCA(VSL.Engines.All.Count > 0 ||
               VSL.Engines.RCS.Count > 0 ||
               VSL.Torque.Wheels.Count > 0);
     if (!TCA_Active)
     {
         VSL = null; return;
     }
     VSL.Init();
     TCAModulesDatabase.InitModules(this);
     VSL.ConnectAutopilotOutput();//should follow module initialization
     vessel.OnPreAutopilotUpdate  += OnPreAutopilotUpdate;
     vessel.OnPostAutopilotUpdate += OnPostAutopilotUpdate;
     TCAGui.Reinitialize(this);
     StartCoroutine(updateUnpackDistance());
     Actions["onActionUpdate"].active = true;
     Actions["ToggleTCA"].actionGroup = CFG.ActionGroup;
     CFG.Resume(this);
 }
コード例 #4
0
    void Start()
    {
        var evsys = GameObject.FindObjectOfType <EventSystem>();

        if (!evsys)
        {
            Debug.LogError("UnityEvent System not found in scene, manually add it.");
            Debug.Break();
        }
        GameObject prefab = Resources.Load <GameObject>("BeastConsole/BeastConsole");

        consoleRoot = GameObject.Instantiate(prefab);
        consoleRoot.transform.SetParent(transform);
        SmartConsole.options        = Options;
        SmartConsole.entryTemplate  = Resources.Load <GameObject>("BeastConsole/ConsoleEntry");
        SmartConsole.consoleContent = consoleRoot.transform.FindDeepChild("Content").gameObject;
        SmartConsole.consoleRoot    = consoleRoot.transform.FindDeepChild("Root").GetComponent <RectTransform>();
        SmartConsole.inputField     = consoleRoot.transform.FindDeepChild("InputField").GetComponent <InputField>();
        SmartConsole.scrollBar      = consoleRoot.transform.FindDeepChild("Scrollbar Vertical").GetComponent <Scrollbar>();
        fps_display = consoleRoot.transform.FindDeepChild("fps_display").gameObject;

        CFG.Initialize();

        CFG.showfps.OnChanged += x => { fps_display.SetActive(x); CFG.minFPS.Set(120); CFG.maxFPS.Set(0); };
        CFG.showfps.Set(ShowFps);
        consoleRoot.AddComponent <SmartConsole>();

        StartCoroutine(TrackFPS());
    }
コード例 #5
0
        public void setCFG(CFG <BasicBlock, BasicEdge> cfg)
        {
            Debug.Assert(cfg != null);
            Debug.Assert(this.cfg == null);

            this.cfg = cfg;
        }
コード例 #6
0
        public DB()
        {
            String db = CFG.getDataBase();

            cn = new OleDbConnection(connStr);
            cn.Open();
        }
コード例 #7
0
        public void ManeuverCallback(Multiplexer.Command cmd)
        {
            switch (cmd)
            {
            case Multiplexer.Command.Resume:
            case Multiplexer.Command.On:
                if (!TCAScenario.HavePatchedConics)
                {
                    Status("yellow", "WARNING: maneuver nodes are not yet available. Upgrade the Tracking Station.");
                    CFG.AP1.Off();
                    return;
                }
                if (!VSL.HasManeuverNode)
                {
                    CFG.AP1.Off(); return;
                }
                VSL.Controls.StopWarp();
                CFG.AT.On(Attitude.ManeuverNode);
                Node = Solver.maneuverNodes[0];
                if (VSL.Engines.MaxDeltaV < (float)Node.DeltaV.magnitude)
                {
                    Status("yellow", "WARNING: there may be not enough propellant for the maneuver");
                }
                THR.Throttle = 0;
                CFG.DisableVSC();
                break;

            case Multiplexer.Command.Off:
                TimeWarp.SetRate(0, false);
                CFG.AT.On(Attitude.KillRotation);
                reset();
                break;
            }
        }
コード例 #8
0
        public void UpdateState()
        {
            //update onPlanet state
            var on_planet = vessel.OnPlanet();
            var in_orbit  = vessel.InOrbit();

            if (on_planet != OnPlanet)
            {
                CFG.EnginesProfiles.OnPlanetChanged(on_planet);
                if (!on_planet)
                {
                    if (CFG.BlockThrottle)
                    {
                        var THR = TCA.GetModule <ThrottleControl>();
                        if (THR != null)
                        {
                            THR.Throttle = 0f;
                        }
                    }
                    CFG.DisableVSC();
                    CFG.Nav.Off();
                    CFG.HF.Off();
                    if (IsActiveVessel && TCAGui.Instance.ORB != null)
                    {
                        TCAGui.Instance.ActiveTab = TCAGui.Instance.ORB;
                    }
                }
            }
            OnPlanet       = on_planet;
            InOrbit        = in_orbit;
            IsActiveVessel = vessel != null && vessel == FlightGlobals.ActiveVessel;
        }
コード例 #9
0
 /// <summary>
 /// Constructs a new phi binding allocator.
 /// </summary>
 /// <param name="parent">The parent code generator.</param>
 /// <param name="cfg">The CFG to use.</param>
 public PhiBindingAllocator(CLCodeGenerator parent, CFG cfg)
 {
     phiMapping = new Dictionary <BasicBlock, List <Variable> >(cfg.Count);
     Parent     = parent;
     CFG        = cfg;
     Dominators = Dominators.Create(cfg);
 }
コード例 #10
0
        ////////////////////////////////////////////////////////////////////////////////////////////////
        private static IEnumerable <StatementId> getRelevant(CFG <BasicBlock, BasicEdge> cfg, StatementId target)
        {
            var result = new Dictionary <string, StatementId>();

            var toMark = new Queue <StatementId>();

            foreach (var p in target.predecessors)
            {
                toMark.Enqueue(p.Item2);
            }
            while (toMark.Count > 0)
            {
                StatementId si = toMark.Dequeue();
                if (!result.ContainsKey(si.ToString()))
                {
                    if (si.statement is PredicateStatement)
                    {
                        result.Add(si.ToString(), si);
                    }
                    foreach (var p in si.predecessors)
                    {
                        toMark.Enqueue(p.Item2);
                    }
                }
            }
            return(result.Values);
        }
コード例 #11
0
        public void ManeuverCallback(Multiplexer.Command cmd)
        {
            switch (cmd)
            {
            case Multiplexer.Command.Resume:
            case Multiplexer.Command.On:
                ManeuverStage = Stage.WAITING;
                if (!TCAScenario.HavePatchedConics)
                {
                    Status("yellow", "WARNING: maneuver nodes are not yet available. Upgrade the Tracking Station.");
                    CFG.AP1.Off();
                    return;
                }
                if (!VSL.HasManeuverNode)
                {
                    CFG.AP1.Off(); return;
                }
                VSL.Controls.StopWarp();
                CFG.AT.On(Attitude.ManeuverNode);
                update_maneuver_node();
                THR.Throttle = 0;
                CFG.DisableVSC();
                break;

            case Multiplexer.Command.Off:
                VSL.Controls.StopWarp();
                if (!CFG.WarpToNode && TimeWarp.CurrentRateIndex > 0)
                {
                    TimeWarp.SetRate(0, false);
                }
                CFG.AT.On(Attitude.KillRotation);
                Reset();
                break;
            }
        }
コード例 #12
0
        public void Parser_MiniPL_LL1ParseTableGenerationTest()
        {
            CFG        grammar    = MiniPL.GetInstance().Grammar;
            ParseTable parseTable = grammar.CreateLL1ParseTable();

            Assert.AreNotEqual(null, parseTable);
        }
コード例 #13
0
        private void EnumerateUsages()
        {
            foreach (KeyValuePair <long, ICollection <long> > nodeVariablesPair in Usages)
            {
                long uNodeId = nodeVariablesPair.Key;

                foreach (long variable in nodeVariablesPair.Value)
                {
                    long usage = (long)(UsagesCount++);

                    AppHelper.TakeValueByKey(
                        NodeToUsesSet,
                        uNodeId,
                        () => new List <long>())
                    .Add(usage);

                    if (!CFG.IsSinkNode(uNodeId))
                    {
                        Ensure.That(NodeToVarMap.ContainsKey(uNodeId)).IsTrue();
                    }

                    UseToNodeMap[usage] = uNodeId;
                }
            }
        }
コード例 #14
0
 void onVesselModify(Vessel vsl)
 {
     if (vsl == null || vsl != vessel)
     {
         return;
     }
     //this.Log("onVesselModify: vsl.id {}, old.id {}", vsl.id,
     //VSL != null && VSL.vessel != null? VSL.vessel.id.ToString() : "null");//debug
     AllModules.ForEach(m => m.SaveToConfig());
     check_priority();
     if (GroupMaster)
     {
         change_GID();
     }
     EnableTCA(TCA_Active);
     if (!TCA_Active)
     {
         reset();
     }
     else if (VSL == null || VSL.vessel == null || vsl.id != VSL.vessel.id)
     {
         reset();
         if (CFG != null)
         {
             CFG = CFG.Clone <VesselConfig>();
         }
         init();
     }
     else
     {
         VSL.Engines.ForceUpdateParts = true;
         StartCoroutine(updateUnpackDistance());
     }
 }
コード例 #15
0
        private static bool MergeChain(
            Method.Builder builder,
            CFG.Node rootNode,
            CFG cfg,
            HashSet <CFG.Node> mergedNodes)
        {
            if (rootNode.NumSuccessors != 1)
            {
                return(false);
            }

            var  rootBlockBuilder = builder[rootNode.Block];
            var  successors       = rootNode.Successors;
            bool result           = false;

            do
            {
                var nextBlock = successors[0];

                // We cannot merge jump targets in div. control flow
                if (nextBlock.NumPredecessors > 1)
                {
                    break;
                }

                mergedNodes.Add(nextBlock);
                successors = nextBlock.Successors;
                rootBlockBuilder.MergeBlock(nextBlock.Block);
                result = true;
            }while (successors.Count == 1);

            return(result);
        }
コード例 #16
0
 public override void Draw()
 {
     GUILayout.BeginHorizontal();
     if (CFG.SelectedMacro != null && CFG.MacroIsActive)
     {
         GUILayout.Label(new GUIContent("Macro: " + CFG.SelectedMacro.Title, "The macro is executing..."),
                         Styles.warning, GUILayout.ExpandWidth(true));
         CFG.MacroIsActive &= !GUILayout.Button("Pause", Styles.enabled_button, GUILayout.Width(70));
         if (GUILayout.Button("Stop", Styles.danger_button, GUILayout.ExpandWidth(false)))
         {
             CFG.StopMacro();
         }
         GUILayout.Label("Edit", Styles.inactive_button, GUILayout.ExpandWidth(false));
     }
     else if (CFG.SelectedMacro != null)
     {
         if (GUILayout.Button(new GUIContent("Macro: " + CFG.SelectedMacro.Title, "Select a macro from databases"),
                              Styles.normal_button, GUILayout.ExpandWidth(true)))
         {
             selecting_macro = !selecting_macro;
         }
         CFG.MacroIsActive |= GUILayout.Button(CFG.SelectedMacro.Active? "Resume" : "Execute",
                                               Styles.active_button, GUILayout.Width(70));
         if (GUILayout.Button("Stop", CFG.SelectedMacro.Active?
                              Styles.danger_button : Styles.inactive_button, GUILayout.ExpandWidth(false)))
         {
             CFG.SelectedMacro.Rewind();
         }
         if (GUILayout.Button("Edit", Styles.active_button, GUILayout.ExpandWidth(false)))
         {
             TCAMacroEditor.Edit(CFG);
         }
     }
     else
     {
         if (GUILayout.Button("Select Macro", Styles.normal_button, GUILayout.ExpandWidth(true)))
         {
             selecting_macro = !selecting_macro;
         }
         if (GUILayout.Button("New Macro", Styles.open_button, GUILayout.ExpandWidth(false)))
         {
             TCAMacroEditor.Edit(CFG);
         }
     }
     GUILayout.EndHorizontal();
     if (selecting_macro)
     {
         TCAMacro macro = null;
         if (TCAMacroEditor.DrawMacroSelector(CFG, out macro))
         {
             if (macro != null)
             {
                 CFG.SelectedMacro = macro.GetCopy() as TCAMacro;
                 CFG.MacroIsActive = false;
             }
             selecting_macro = false;
         }
     }
 }
コード例 #17
0
ファイル: havlak.cs プロジェクト: elizarov/kostya-benchmarks
 public BasicBlockEdge(CFG cfg, int fromName, int toName)
 {
     From = cfg.CreateNode(fromName);
     To   = cfg.CreateNode(toName);
     From.OutEdges.Add(To);
     To.InEdges.Add(From);
     cfg.AddEdge(this);
 }
コード例 #18
0
        public static void EnterNewSubMenu(DbgMenuItem menu)
        {
            CFG.Save();

            menu.RequestTextRefresh();
            DbgMenuStack.Push(CurrentMenu);
            CurrentMenu = menu;
        }
コード例 #19
0
 /// <summary>
 /// Creates a new if infos instance.
 /// </summary>
 /// <param name="cfg">The current CFG.</param>
 /// <returns>The created info instance.</returns>
 public static IfInfos Create(CFG cfg)
 {
     if (cfg == null)
     {
         throw new ArgumentNullException(nameof(cfg));
     }
     return(Create(Dominators.Create(cfg)));
 }
コード例 #20
0
ファイル: havlak.cs プロジェクト: ZombineDev/benchmarks
 public BasicBlockEdge(CFG cfg, int fromName, int toName)
 {
     From = cfg.CreateNode(fromName);
     To = cfg.CreateNode(toName);
     From.OutEdges.Add(To);
     To.InEdges.Add(From);
     cfg.AddEdge(this);
 }
コード例 #21
0
 public override void OnSave(ConfigNode node)
 {
     if ((enabled || HighLogic.LoadedSceneIsEditor) && CFG != null)
     {
         AllModules.ForEach(m => m.SaveToConfig());
         CFG.Save(node.AddNode(VesselConfig.NODE_NAME));
     }
     base.OnSave(node);
 }
コード例 #22
0
        public List <CFG> CreateControlFlowGraphForDisplay(string code)
        {
            CFG                  cfg;
            List <CFG>           CFGs        = new List <CFG>();
            List <Nodes>         nodes       = new List <Nodes>();
            List <List <Nodes> > methodNodes = new List <List <Nodes> >();
            List <Edges>         edges       = new List <Edges>();
            List <List <Edges> > methodEdges = new List <List <Edges> >();

            char[] alpha = "ABCDEFGHIJKLMNOPQRSTUVWXYZ".ToCharArray();
            //var nodesWithLinks = CreateControlFlowGraph(code);
            var nodesWithLinksByMethod = CreateControlFlowGraph(code);

            foreach (var method in nodesWithLinksByMethod)
            {
                foreach (var node in method.node)
                {
                    if (node.nodeDecision != null)
                    {
                        nodes.Add(new Nodes(alpha[node.nodeNumber].ToString(), node.nodeDecision));
                    }
                    else if (node.nodeOperation != null)
                    {
                        StringBuilder sb = new StringBuilder();
                        foreach (var operations in node.nodeOperation)
                        {
                            sb.Append(operations);
                        }

                        nodes.Add(new Nodes(alpha[node.nodeNumber].ToString(), sb.ToString()));
                    }
                }
                methodNodes.Add(nodes);
                nodes = new List <Nodes>();
            }
            foreach (var method in nodesWithLinksByMethod)
            {
                foreach (var node in method.node)
                {
                    foreach (var linkedNode in node.linkedNodes)
                    {
                        StringBuilder sb = new StringBuilder();
                        sb.Append(alpha[node.nodeNumber].ToString());
                        sb.Append(alpha[linkedNode].ToString());
                        edges.Add(new Edges(sb.ToString(), alpha[node.nodeNumber].ToString(), alpha[linkedNode].ToString(), "Jest połączony z"));
                    }
                }
                methodEdges.Add(edges);
                edges = new List <Edges>();
            }
            for (int index = 0; index < methodNodes.Count; index++)
            {
                cfg = new CFG(nodesWithLinksByMethod[index].methodName, methodNodes[index], methodEdges[index]);
                CFGs.Add(cfg);
            }
            return(CFGs);
        }
コード例 #23
0
        public static void GoBack()
        {
            CFG.Save();

            if (DbgMenuStack.Count > 0)
            {
                CurrentMenu = DbgMenuStack.Pop();
            }
        }
コード例 #24
0
 public override void OnSave(ConfigNode node)
 {
     if (GroupMaster && CFG != null)
     {
         AllModules.ForEach(m => m.SaveToConfig());
         CFG.SaveInto(node);
     }
     base.OnSave(node);
 }
コード例 #25
0
        ////////////////////////////////////////////////////////////////////////////////////////////////
        public static CFG <BasicBlock, BasicEdge> getFlatCFG(CFG <BasicBlock, BasicEdge> cfg, StatementId target)
        {
/*            Console.WriteLine("Slicing for [{0}] {1}: {2}",
 *              target.basicBlock.statements[0].preState.equalityAnalyzer.pathCondition.ToString(),
 *              target.ToString(),
 *              target.statement.ToString()
 *          );*/
            var targetA = target.statement as Assert;
            var result  = new CFG <BasicBlock, BasicEdge>();

            int n = 0;

            foreach (var bb in cfg.nodes)
            {
                foreach (var s in bb.statements)
                {
                    n++;
                }
            }


            IEnumerable <StatementId> relevant = getRelevant(cfg, target);

            Console.WriteLine("[{0}] Statements: {1}, relevant : {2}", target.ToString(), n, relevant.Count());
            Debug.Assert(n >= relevant.Count());

            BasicBlock block = result.lookupOrAddNode("start");

            PropositionalFormula pathCondition           = target.preStates.equalityAnalyzer.pathCondition;
            Expression           pathConditionExpression = PF2E(
                target.basicBlock.getPreState(0).equalityAnalyzer.conditionVariableNames,
                pathCondition
                );


            PropositionalFormula notPathCondition = !pathCondition;

//            Console.WriteLine("!{0} == {1}", pathCondition.ToString(), notPathCondition.ToString());

            foreach (var si in relevant)
            {
                addAssumptions(block, pathCondition, notPathCondition, si);
            }

//            Console.WriteLine("Assuming path condition [{0}] {1}", pathCondition.ToString(), pathConditionExpression.ToString());
            block.appendStatement(
                new Assume(pathConditionExpression)
                );

            block.appendStatement(new Assert(targetA.expression, targetA.message));
            block.setControlStatement(new Block(block));
            result.setStartNode(block.label);
            result.setEndNode(block.label);

            return(result);
        }
コード例 #26
0
        public Main()
        {
            InitializeComponent();
            IDictionary <string, string> configResult = CFG.init();

            txtSourceDir.Text = configResult["sourceDir"];
            txtOutputDir.Text = configResult["outputDir"];

            myThis = this;
        }
コード例 #27
0
        public BasicBlockEdge(CFG cfg, int fromName, int toName)
        {
            from = cfg.createNode(fromName);
            to   = cfg.createNode(toName);

            from.addOutEdge(to);
            to.addInEdge(from);

            cfg.addEdge(this);
        }
コード例 #28
0
        public BasicBlockEdge(CFG cfg, int fromName, int toName)
        {
            from = cfg.createNode(fromName);
            to = cfg.createNode(toName);

            from.addOutEdge(to);
            to.addInEdge(from);

            cfg.addEdge(this);
        }
コード例 #29
0
        void wbActivate(Excel.Workbook Wb)
        {
            string shName = CFG.getMasterSheet();

            Excel.Worksheet sh = Q1XLS.getSheet(shName);
            if (sh != null)
            {
                // Ocultar la opcion de menu
            }
        }
コード例 #30
0
 public override void OnSave(ConfigNode node)
 {
     if (GroupMaster && CFG != null)
     {
         AllModules.ForEach(m => m.SaveToConfig());
         CFG.SaveInto(node);
         //this.Log("OnSave: GroupMaster: {}", this);//debug
     }
     base.OnSave(node);
 }
コード例 #31
0
ファイル: PDAToCFG.cs プロジェクト: arjen0203/AutomataReader
        public void AddType1AndType2Transitions(Automata automata, CFG cfg)
        {
            foreach (Node fromNode in automata.nodes)
            {
                foreach (Node toNode in automata.nodes)
                {
                    CFGVariable transition = GetOrCreateNewTransition(fromNode, toNode, cfg.AllTransitions);

                    //type 1 transitions
                    if (fromNode == toNode)
                    {
                        transition.ToVariablesOrLetters.Add(new List <ILetterOrVariable>()
                        {
                            GetOrCreateNewSymbol('_', cfg)
                        });
                    }

                    //type 2 transitions
                    foreach (Node betweenNode in automata.nodes)
                    {
                        if (betweenNode != fromNode && betweenNode != toNode)
                        {
                            transition.ToVariablesOrLetters.Add(new List <ILetterOrVariable>()
                            {
                                GetOrCreateNewTransition(fromNode, betweenNode, cfg.AllTransitions),
                                GetOrCreateNewTransition(betweenNode, toNode, cfg.AllTransitions)
                            });
                        }
                    }
                }
                //type 3 transitions
                foreach (Connection conn in fromNode.Connections)
                {
                    if (conn.PushStack != '_')
                    {
                        foreach (Node secondConnNode in automata.nodes)
                        {
                            foreach (Connection secondConn in secondConnNode.Connections)
                            {
                                if (secondConn.PopStack == conn.PushStack)
                                {
                                    CFGVariable type3Transition = GetOrCreateNewTransition(fromNode, secondConn.ToNode, cfg.AllTransitions);
                                    type3Transition.ToVariablesOrLetters.Add(new List <ILetterOrVariable>()
                                    {
                                        GetOrCreateNewSymbol(conn.Symbol, cfg),
                                        GetOrCreateNewTransition(conn.ToNode, secondConnNode, cfg.AllTransitions),
                                        GetOrCreateNewSymbol(secondConn.Symbol, cfg),
                                    });
                                }
                            }
                        }
                    }
                }
            }
        }
コード例 #32
0
 void reset()
 {
     if (VSL != null)
     {
         VSL.Reset();
         AllModules.ForEach(m => m.Reset());
         CFG.ClearCallbacks();
     }
     DeleteModules();
     VSL = null;
 }
コード例 #33
0
ファイル: CFGRepo.cs プロジェクト: thanhphung901/ketoan.app
 public virtual void Create(CFG user)
 {
     try
     {
         this.db.CFGs.InsertOnSubmit(user);
         db.SubmitChanges();
     }
     catch (Exception e)
     {
         throw new Exception(e.Message);
     }
 }
コード例 #34
0
ファイル: CFGRepo.cs プロジェクト: thanhphung901/ketoan.app
 public virtual void Remove(CFG user)
 {
     try
     {
         db.CFGs.DeleteOnSubmit(user);
         db.SubmitChanges();
     }
     catch (Exception e)
     {
         throw new Exception(e.Message);
     }
 }
コード例 #35
0
ファイル: CFGRepo.cs プロジェクト: thanhphung901/ketoan.app
 public virtual void Update(CFG user)
 {
     try
     {
         CFG userOld = this.GetById(user.ID);
         userOld = user;
         db.SubmitChanges();
     }
     catch (Exception e)
     {
         throw new Exception(e.Message);
     }
 }
コード例 #36
0
ファイル: ACFG.cs プロジェクト: radiopaedia/uploader-agent
 public static CFG GetConfigData()
 {
     CFG cfg = new CFG();
     cfg.ConnectionString = ConfigurationManager.ConnectionStrings["cn1"].ToString();
     if (!string.IsNullOrEmpty(cfg.ConnectionString))
     {
         APetaPoco.SetConnectionString("cn1");
         cfg.SiteApi = GetSiteApiDetails();
         var bm = APetaPoco.PpRetrieveList<Node>("PACS");
         if (bm.Success)
         {
             cfg.Nodes = (List<Node>)bm.Data;
         }
     }
     return cfg;
 }
コード例 #37
0
ファイル: havlak.cs プロジェクト: ZombineDev/benchmarks
 public HavlakLoopFinder(CFG cfg, LSG lsg)
 {
     this.cfg = cfg;
     this.lsg = lsg;
 }
コード例 #38
0
ファイル: GraphRenderer.cs プロジェクト: sidecut/xaeios
 public CFGRenderer(CFG graph, MethodCompileInfo compileInfo)
 {
     Graph = graph;
     MethodCompileInfo = compileInfo;
 }
コード例 #39
0
ファイル: CecilFrontEnd.cs プロジェクト: sidecut/xaeios
        public void BuildCFG(MethodCompileInfo compileInfo)
        {
            if (Compiler.Options.Verbocity > 0)
            {
                Console.WriteLine("CecilFrontEnd: " + compileInfo.Method);
            }
            _methodCompileInfo = compileInfo;

            _methodDefinition = compileInfo.Method;
            _body = _methodDefinition.Body;
            _cfg = new CFG();

            _instructionMap = new Dictionary<Instruction, CFGNodeCluster>();
            _handlerStarts = new Dictionary<Instruction, ExceptionHandler>();
            Dictionary<Instruction, ExceptionHandler> finallyStarts = new Dictionary<Instruction, ExceptionHandler>();
            _instructionsWithMultiplePredecessors = new Set<Instruction>();
            _stackAlignmentNodes = new Set<CFGNode>();
            Set<Instruction> hasPredecessor = new Set<Instruction>();

            // find instructions with multiple predecessors
            foreach (Instruction instr in _body.Instructions)
            {
                switch (instr.OpCode.FlowControl)
                {
                    case Mono.Cecil.Cil.FlowControl.Next:
                        {
                            if (hasPredecessor.Contains(instr.Next))
                            {
                                _instructionsWithMultiplePredecessors.Add(instr.Next);
                            }
                            else
                            {
                                hasPredecessor.Add(instr.Next);
                            }
                            break;
                        }
                    case Mono.Cecil.Cil.FlowControl.Branch:
                        {
                            if (hasPredecessor.Contains((Instruction)instr.Operand))
                            {
                                _instructionsWithMultiplePredecessors.Add((Instruction)instr.Operand);
                            }
                            else
                            {
                                hasPredecessor.Add((Instruction)instr.Operand);
                            }
                            break;
                        }
                    case Mono.Cecil.Cil.FlowControl.Cond_Branch:
                        {
                            if (hasPredecessor.Contains(instr.Next))
                            {
                                _instructionsWithMultiplePredecessors.Add(instr.Next);
                            }
                            else
                            {
                                hasPredecessor.Add(instr.Next);
                            }

                            Instruction branchTarget = instr.Operand as Instruction;
                            if (branchTarget != null)
                            {
                                if (hasPredecessor.Contains(branchTarget))
                                {
                                    _instructionsWithMultiplePredecessors.Add(branchTarget);
                                }
                                else
                                {
                                    hasPredecessor.Add(branchTarget);
                                }
                            }
                            else
                            {
                                Instruction[] switchTargets = instr.Operand as Instruction[];
                                if (switchTargets != null)
                                {
                                    throw new NotImplementedException("Switch is not yet supported");
                                }
                                else
                                {
                                    throw new CompilerException("Unable to follow conditional branch flow");
                                }
                            }
                            break;
                        }
                    case Mono.Cecil.Cil.FlowControl.Call:
                        {
                            if (hasPredecessor.Contains(instr.Next))
                            {
                                _instructionsWithMultiplePredecessors.Add(instr.Next);
                            }
                            else
                            {
                                hasPredecessor.Add(instr.Next);
                            }
                            break;
                        }
                    case Mono.Cecil.Cil.FlowControl.Return:
                        {
                            break;
                        }
                    case Mono.Cecil.Cil.FlowControl.Throw:
                        {
                            break;
                        }
                    default:
                        {
                            throw new CompilerException("Invalid FlowControl");
                        }
                }
            }

            // find beginnings of filter/catch/finally clauses
            foreach (ExceptionHandler handler in _body.ExceptionHandlers)
            {
                switch (handler.Type)
                {
                    case ExceptionHandlerType.Catch:
                        {
                            _handlerStarts.Add(handler.HandlerStart, handler);
                            break;
                        }
                    case ExceptionHandlerType.Fault:
                        {
                            throw new NotImplementedException();
                        }
                    case ExceptionHandlerType.Filter:
                        {
                            _handlerStarts.Add(handler.FilterStart, handler);
                            break;
                        }
                    case ExceptionHandlerType.Finally:
                        {
                            finallyStarts.Add(handler.HandlerStart, handler);
                            break;
                        }
                    default:
                        {
                            throw new CompilerException("Invalid exception handler type: " + handler.Type);
                        }
                }
            }

            if (DebugSettings.FrontEndGraph)
            {
                new XaeiO.Compiler.Helpers.CFGRenderer(_cfg, _methodCompileInfo).Render("frontend-initial.png");
            }

            // start at the first instruction and follow the control path to build the CFG
            // most of the work is done here
            FollowControlFlowPath(new Stack<IExpression>(), _body.Instructions[0]);

            if (DebugSettings.FrontEndGraph)
            {
                new XaeiO.Compiler.Helpers.CFGRenderer(_cfg, _methodCompileInfo).Render("frontend-follow-root.png");
            }

            // add left over instructions to the CFG - these are typically catch/finally clauses that aren't explicitly branched to in IL code
            foreach (Instruction instr in _body.Instructions)
            {
                FollowControlFlowPath(new Stack<IExpression>(), instr);
            }

            if (DebugSettings.FrontEndGraph)
            {
                new XaeiO.Compiler.Helpers.CFGRenderer(_cfg, _methodCompileInfo).Render("frontend-follow-remainder.png");
            }

            // set up TryBlockInfos
            Dictionary<CFGNode, TryBlockInfo> tryBlockInfoMap = new Dictionary<CFGNode,TryBlockInfo>();

            // set up handlers - we also set up the associated TryBlockInfos here and add them to the MethodCompileInfo
            foreach (KeyValuePair<Instruction, ExceptionHandler> handlerStart in _handlerStarts)
            {
                CFGNode tryStartNode = GetMappedCFGNodeCluster(handlerStart.Value.TryStart).Start;

                TryBlockInfo tryBlockInfo;
                if (!tryBlockInfoMap.TryGetValue(tryStartNode, out tryBlockInfo))
                {
                    tryBlockInfo = new TryBlockInfo();
                    tryBlockInfo.TryBlock = new CFGNodeCluster();
                    tryBlockInfo.TryBlock.Start = tryStartNode;
                    tryBlockInfo.TryBlock.End = GetMappedCFGNodeCluster(handlerStart.Value.TryEnd.Previous).End;

                    _methodCompileInfo.TryBlockInfos.Add(tryBlockInfo);

                    tryBlockInfoMap[tryStartNode] = tryBlockInfo;
                }

                // add the handler to the tryBlockInfo
                tryBlockInfo.Handlers.Add(
                    new CFGNodeCluster(
                        GetMappedCFGNodeCluster(handlerStart.Value.HandlerStart),
                        GetMappedCFGNodeCluster(handlerStart.Value.HandlerEnd.Previous)
                    ),
                    handlerStart.Value
                );
            }

            // set up finally blocks - we also implicity set up the associated TryBlockInfos here (if they haven't already been set up by a handler)
            foreach (KeyValuePair<Instruction, ExceptionHandler> finallyStart in finallyStarts)
            {
                CFGNode tryStartNode = GetMappedCFGNodeCluster(finallyStart.Value.TryStart).Start;

                TryBlockInfo tryBlockInfo;
                if (!tryBlockInfoMap.TryGetValue(tryStartNode, out tryBlockInfo))
                {

                    tryBlockInfo = new TryBlockInfo();
                    tryBlockInfo.TryBlock = new CFGNodeCluster();
                    tryBlockInfo.TryBlock.Start = tryStartNode;
                    tryBlockInfo.TryBlock.End = GetMappedCFGNodeCluster(finallyStart.Value.TryEnd.Previous).End;

                    _methodCompileInfo.TryBlockInfos.Add(tryBlockInfo);

                    tryBlockInfoMap[tryStartNode] = tryBlockInfo;
                }

                tryBlockInfo.FinallyBlock = new CFGNodeCluster(
                    GetMappedCFGNodeCluster(finallyStart.Value.HandlerStart),
                    GetMappedCFGNodeCluster(finallyStart.Value.HandlerEnd.Previous)
                );
            }

            // add branch edges
            foreach (Instruction instr in _body.Instructions)
            {
                CFGNodeCluster cluster = GetMappedCFGNodeCluster(instr);

                switch (instr.OpCode.FlowControl)
                {
                    case Mono.Cecil.Cil.FlowControl.Next:
                        {
                            cluster.End.FlowControl = FlowControl.Next;
                            AddEdge(cluster.End, GetMappedCFGNodeCluster(instr.Next).Start);
                            break;
                        }
                    case Mono.Cecil.Cil.FlowControl.Branch:
                        {
                            cluster.End.FlowControl = FlowControl.Branch;
                            AddEdge(cluster.End, GetMappedCFGNodeCluster((Instruction)instr.Operand).Start);
                            break;
                        }
                    case Mono.Cecil.Cil.FlowControl.Cond_Branch:
                        {
                            CFGNode current = cluster.End;
                            Debug.Assert(cluster.End.BasicBlock.Statements.Count == 1);
                            ConditionalBranchExpressionStatement conditionalBranchExpressionStatement = (ConditionalBranchExpressionStatement)cluster.End.BasicBlock.Statements[0];
                            cluster.End.FlowControl = FlowControl.ConditionalBranch;
                            CFGEdge falseEdge = AddEdge(cluster.End, GetMappedCFGNodeCluster(instr.Next).Start);
                            falseEdge.BranchCondition = new BranchCondition(BranchConditionType.False);
                            falseEdge.BranchCondition.Data = conditionalBranchExpressionStatement;
                            CFGEdge trueEdge = AddEdge(cluster.End, GetMappedCFGNodeCluster((Instruction)instr.Operand).Start);
                            trueEdge.BranchCondition = new BranchCondition(BranchConditionType.True);
                            trueEdge.BranchCondition.Data = conditionalBranchExpressionStatement;
                            break;
                        }
                    case Mono.Cecil.Cil.FlowControl.Call:
                        {
                            cluster.End.FlowControl = FlowControl.Call;
                            AddEdge(cluster.End, GetMappedCFGNodeCluster(instr.Next).Start);
                            break;
                        }
                    case Mono.Cecil.Cil.FlowControl.Return:
                        {
                            cluster.End.FlowControl = FlowControl.Return;
                            break;
                        }
                    case Mono.Cecil.Cil.FlowControl.Throw:
                        {
                            cluster.End.FlowControl = FlowControl.Throw;
                            break;
                        }
                    default:
                        {
                            throw new CompilerException("Invalid FlowControl");
                        }
                }
            }

            if (DebugSettings.FrontEndGraph)
            {
                new XaeiO.Compiler.Helpers.CFGRenderer(_cfg, _methodCompileInfo).Render("frontend-final.png");
            }
            _cfg.Root = GetMappedCFGNodeCluster(_body.Instructions[0]).Start;
            _methodCompileInfo.CFG = _cfg;
        }
コード例 #40
0
ファイル: havlak.cs プロジェクト: ZombineDev/benchmarks
 int FindHavlakLoops(CFG cfg)
 {
     var lsg = new LSG();
     return FindHavlakLoops(cfg, lsg);
 }
コード例 #41
0
ファイル: havlak.cs プロジェクト: ZombineDev/benchmarks
 int FindHavlakLoops(CFG cfg, LSG lsg)
 {
     var h = new HavlakLoopFinder(cfg, lsg);
     return h.FindLoops();
 }
コード例 #42
0
ファイル: CFGRepo.cs プロジェクト: thanhphung901/ketoan.app
 public virtual int Delete(CFG user)
 {
     try
     {
         //user.IsDelete = true;
         db.SubmitChanges();
         return 0;
     }
     catch (Exception e)
     {
         throw new Exception(e.Message);
     }
 }