예제 #1
0
파일: Location.cs 프로젝트: cnduru/SW10
        public Location(Location caller)
        {
            id = caller.id + "a";
            y = caller.y + Constants.LabelOffsetY * 2;
            x = Constants.LabelOffsetX * 10;
            Label = new Label{
                content = "1", 
                kind = "exponentialrate", 
                y = y,
                x = caller.x + Constants.LabelOffsetX * 10 - 70               
            };

        }
예제 #2
0
파일: Location.cs 프로젝트: cnduru/SW10
 public Location(string na, int xc, int yc)
 {
     name = na;
     x = xc;
     y = yc;
     Label = new Label{
         content = "1", 
         kind = "exponentialrate", 
         y = y,
         x = xc + Constants.LabelOffsetX * 10 - 70               
     };
     id = "nId" + nextID;
     nextID++;
 }
예제 #3
0
파일: UppaalModel.cs 프로젝트: cnduru/SW10
        public void rewriteInstructionFault(string path)
        {
            ByteCodeInstructions insts = new ByteCodeInstructions();

            foreach (var tem in templates)
            {
                foreach (var loc in tem.Locations)
                {
                    if(loc.pc == null)
                    {
                        continue;
                    }

                    foreach (var l2 in tem.Locations)
                    {
                        if (loc.id != l2.id)
                        {
                            foreach (var edge in tem.Transitions)
                            {
                                if (edge.source.id == loc.id && edge.target.id == l2.id)
                                {
                                    edge.grds.content += " && faultAtId != " + loc.Guid;
                                }
                            }
                        }
                    }
              
                    // get instruction name and resolve to byte code instruction
                    int index = loc.name.IndexOf("_");
                    string inst = loc.name.Replace("__", "_");//.Substring(loc.name.IndexOf("_") + 1);
                    inst = Regex.Replace(inst, @"pc\d*_", "");
                    inst = inst.Replace("\n", "");
                    string instNotSpecial = Regex.Replace(inst, @"_\d*", "");

                    BytecodeInstruction bci = insts.instructionToBytecode(inst);
                    BytecodeInstruction bciNotSpecial = insts.instructionToBytecode(instNotSpecial);

                    // for handling special case in instruction, e.g. iconst_0 vs. ifeq 7
                    if(bciNotSpecial != null)
                    {
                        // special case, overwrite bci
                        bci = bciNotSpecial;
                    }

                    var tempTrans = new List<Transition>();

                    if(bci == null || bci.relatedInstruction.mnemonic == "") // should we use "" or null for non-valid instruction?
                    {   
                        // make transition to error state if invalid instruction
                        var x = tem.idToLocation(Constants.errorLocId);
                        var labs = new List<Label>()
                        {
                            new Label() 
                            {
                                content = string.Format("faultAtId == {0}", loc.Guid),
                                kind = "guard"
                            }
                         };   

                        Transition errorTransition = new Transition(loc, x, labs);
                        tempTrans.Add(errorTransition);
                    }

                    if (bci != null && index != -1)
                    {

                        foreach (var edge in tem.Transitions)
                        {   
                            // for inst fault edges
                            if (edge.source.id == loc.id && !edge.source.id.Contains("-") && !edge.target.id.Contains("-"))
                            {
                                var a = bci.relatedInstruction;

                                var labs = a.getLabels();

                                // add guard to distribute probability equally among fault and valid edge
                                Label probLbl = new Label() {content = "faultAtId == " + loc.Guid, kind = "guard", x = loc.x, y = loc.y };
                                labs.Add(probLbl);

                                int lx = 50, lx2 = 90, ly = 100;
                                Transition tt = new Transition(edge.source, edge.target, labs);

                                List<Transition.Nail> nails = new List<Transition.Nail>();
                                Transition.Nail nail1 = new Transition.Nail { x = loc.x - lx, y = loc.y - ly };
                                Transition.Nail nail2 = new Transition.Nail { x = loc.x - lx2, y = loc.y - ly };
                                nails.Add(nail1);
                                nails.Add(nail2);
                                tt.nails = nails;

                                tempTrans.Add(tt);
                            }
                        }
                    }

                    tem.Transitions.AddRange(tempTrans);
                }
            }

            // add inst fault template
            XElement instFaultTemplateXML = XElement.Parse(XMLProvider.getInstructionFaultTemplate());
            XMLHandler xhl = new XMLHandler();
            Template instFaultTemplate = xhl.getTemplate(instFaultTemplateXML);
            instFaultTemplate.Locations[1].Committed = true;

            // define number range for fault number
            Label selectFaultIdLabel = new Label(){content = string.Format("i:int[0,{0}]", XMLHandler.idCount), kind = "select", x = -110, y = -127};
            instFaultTemplate.Transitions[0].labels.Add(selectFaultIdLabel);

            // todo: generalize this
            globalDeclarations += "\nint faultAtId;\n";

            templates.Add(instFaultTemplate);


            Save(path);

        }
예제 #4
0
파일: XMLHandler.cs 프로젝트: cnduru/SW10
        public Template getTemplate(XElement xel)
        {
            Template t = new Template(xel);
            t.InitialLocation.id = xel.Element("init").Attribute("ref").Value;

            // store name object from XML
            t.name = (string)xel.Element("name");

            // store information about locations from UPPAAL model in objects from XML
            foreach (var locs in xel.Descendants("location"))
            {
                Location l = new Location();

                l.id = (string)locs.Attribute("id");
                l.name = (string)locs.Element("name");
                l.Guid = idCount.ToString();
                var tr = locs.Element("urgent");
                l.Urgent = tr != null;
                idCount++;

                XElement xele = locs.Element("label");
                if (xele != null)
                {
                    int xCoord = Convert.ToInt32(xele.Attribute("x").Value);
                    int yCoord = Convert.ToInt32(xele.Attribute("y").Value);

                    Label invariant = new Label { kind = xele.Attribute("kind").Value, content = (string)xele.Value, x = xCoord, y = yCoord };
                    l.Label = invariant;
                }

                try
                {
                    // load pc number
                    Regex regex = new Regex(@"pc(\d+)");
                    Match match = regex.Match(l.name);

                    if (match.Success)
                    {
                        l.pc = match.Value.Replace("pc", "");
                    }
                }
                catch (Exception ex)
                {
                    // yeah.. this should probably be handled more eloquently..
                    l.pc = "None";
                } //TODO fix fault template

                l.x = Convert.ToInt32(locs.Attribute("x").Value);
                l.y = Convert.ToInt32(locs.Attribute("y").Value);

                t.Locations.Add(l);
            }

            // store information about transitions from UPPAAL model in objects from XML
            List<Transition> transitions = new List<Transition>();

            foreach (var trans in xel.Descendants("transition"))
            {
                Transition srcDstPair = new Transition();

                srcDstPair.source.id = (string)trans.Element("source").Attribute("ref");
                srcDstPair.target.id = (string)trans.Element("target").Attribute("ref");

                // add guards
                srcDstPair.grds = getGuards(trans);

                // add selections
                srcDstPair.sels = getSelections(trans);

                // add updates
                srcDstPair.asms = getAssignments(trans);

                // add synchronizations
                srcDstPair.syncs = getSyncs(trans);

                // add nails
                srcDstPair.nails = getNails(trans);

                transitions.Add(srcDstPair);
            }

            t.Transitions = transitions;

            return t;
        }
예제 #5
0
파일: Location.cs 프로젝트: cnduru/SW10
        private void parseInst(int count, string instLine){

            /*if(instLine.Contains("try"))
            {
                instLine = "exception catch";
            }*/

            inst = new Instruction(instLine);
            
            name = "pc" + instLine.Replace("(", "").Replace(")", "").Replace("<", "").Replace(">", "")
                .Replace(",", "").Replace(" ", "_").Replace(".", "_").Replace(":", "_")
                .Replace("__", "_").Replace("-","");
            Label = new Label{
                content = "t <= " + Constants.instTime, 
                kind = "invariant", 
                y = y,
                x = -70               
            };
        }
예제 #6
0
파일: Location.cs 프로젝트: cnduru/SW10
 private void parseCall(string instLine)
 {
     inst = new Instruction();
     name = new Regex(" [a-zA-Z]+ \\(").Match(instLine)
         .ToString().Replace(" ","").Replace("(","");
     Label = new Label{
         content = "1", 
         kind = "exponentialrate", 
         y = y,
         x = -70               
     };
 }