private void OkButton_Click(object sender, RoutedEventArgs e) { Debug.WriteLine("OK: " + targetSystemTree.SelectedItem); SystemDef sd = (SystemDef)((TreeViewItem)targetSystemTree.SelectedItem).Tag; AppSettings.Global.SetString(AppSettings.NEWP_SELECTED_SYSTEM, sd.Name); DialogResult = true; }
/// <summary> /// /// </summary> /// <param name="type"></param> /// <param name="vars"></param> /// <param name="allAllModules"></param> /// <param name="rewardStructs"></param> /// <param name="system"></param> /// <param name="initExp">give null if not exists</param> public Modules(ModelType type, List <VarDeclaration> vars, List <Module> allAllModules, List <RewardStruct> rewardStructs, SystemDef system, Expression initExp) { modelType = type; GlobalVars = vars; AllModules = allAllModules; this.rewardStructs = rewardStructs; systemDef = system; init = initExp; }
private void TargetSystemTree_SelectedItemChanged(object sender, RoutedPropertyChangedEventArgs <object> e) { Debug.WriteLine("Now selected: " + targetSystemTree.SelectedItem); SystemDef sd = (SystemDef)((TreeViewItem)targetSystemTree.SelectedItem).Tag; if (sd == null) { systemDescr.Text = string.Empty; } else { systemDescr.Text = sd.GetSummaryString(); } UpdateOKEnabled(); }
public Modules(ModelType type, List <VarDeclaration> vars, FormulaList formulae, LabelList labels, ConstantList constants, List <Module> allAllModules, List <RewardStruct> rewardStructs, Expression initExp) { modelType = type; GlobalVars = vars; formulaList = formulae; labelList = labels; constantList = constants; AllModules = allAllModules; this.rewardStructs = rewardStructs; init = initExp; List <SystemDef> sys = new List <SystemDef>(); foreach (var module in AllModules) { sys.Add(new SingleModuleSystem(module.Name)); } systemDef = new FullParallelSystem(sys); }
private SystemDDs EncodeSystemDefRec(SystemDef system, List <int> currentAvailStartBits) { if (system is SingleModuleSystem) { return(EncodeSingleModule(system as SingleModuleSystem, currentAvailStartBits)); } else if (system is InterleaveSystem) { return(EncodeInterelave(system as InterleaveSystem, currentAvailStartBits)); } else if (system is ParallelSystem) { return(EncodeParallel(system as ParallelSystem, currentAvailStartBits)); } else if (system is FullParallelSystem) { return(EncodeFullParallelSystem(system as FullParallelSystem, currentAvailStartBits)); } else { throw new Exception("Invalide system!"); } }
public ParallelSystem(SystemDef s1, SystemDef s2, List <string> actions) { system1 = s1; system2 = s2; syncActions = actions; }
private void EncodeSystemDef(SystemDef system) { List <int> currentAvailStartBits = new List <int>(); for (int i = 0; i < synchs.Count; i++) { currentAvailStartBits.Add(0); } SystemDDs sysDDs = EncodeSystemDefRec(system, currentAvailStartBits); // for the nondeterministic case, add extra mtbdd variables to encode nondeterminism if (modules.modelType == ModelType.MDP) { int max = sysDDs.ind.max; for (int i = 0; i < synchs.Count; i++) { if (sysDDs.synchs[i].max > max) { max = sysDDs.synchs[i].max; } } //update max sysDDs.ind.max = max; for (int i = 0; i < synchs.Count; i++) { sysDDs.synchs[i].max = max; } //TODO Different from Prism // now add in new mtbdd variables to distinguish between actions //index 0 for empty label CUDDNode tmp = CUDD.Matrix.SetVectorElement(CUDD.Constant(0), allSynchVars, 0, 1); sysDDs.ind.trans = CUDD.Function.Times(tmp, sysDDs.ind.trans); // synchronous bits //1... for other labels for (int i = 0; i < synchs.Count; i++) { tmp = CUDD.Matrix.SetVectorElement(CUDD.Constant(0), allSynchVars, i + 1, 1); sysDDs.synchs[i].trans = CUDD.Function.Times(tmp, sysDDs.synchs[i].trans); } } ComputeRewards(sysDDs); // now, for all model types, transition matrix can be built by summing over all actions // also build transition rewards at the same time CUDD.Ref(sysDDs.ind.trans); trans = sysDDs.ind.trans; int numRewardStructs = modules.rewardStructs.Count; for (int j = 0; j < numRewardStructs; j++) { CUDD.Ref(sysDDs.ind.rewards[j]); transRewards.Add(sysDDs.ind.rewards[j]); } for (int i = 0; i < synchs.Count; i++) { CUDD.Ref(sysDDs.synchs[i].trans); trans = CUDD.Function.Plus(trans, sysDDs.synchs[i].trans); for (int j = 0; j < numRewardStructs; j++) { CUDD.Ref(sysDDs.synchs[i].rewards[j]); transRewards[j] = CUDD.Function.Plus(transRewards[j], sysDDs.synchs[i].rewards[j]); } } // For D/CTMCs, final rewards are scaled by dividing by total prob/rate for each transition // (when individual transition rewards are computed, they are multiplied by individual probs/rates). // Need to do this (for D/CTMCs) because transition prob/rate can be the sum of values from // several different actions; this gives us the "expected" reward for each transition. // (Note, for MDPs, nondeterministic choices are always kept separate so this never occurs.) if (modules.modelType != ModelType.MDP) { int numberOfRewardStructs = modules.rewardStructs.Count; for (int j = 0; j < numberOfRewardStructs; j++) { CUDD.Ref(trans); transRewards[j] = CUDD.Function.Divide(transRewards[j], trans); } } // sysDDs.Deref(); }
private bool GenerateDataAndProject() { // Sum up the segment lengths to get the total project size. int totalLen = 0; foreach (SegmentMapEntry ent in mSegmentMap) { if (ent == null) { continue; } totalLen += ent.Segment.Length; } Debug.WriteLine("Total length of loaded binary is " + totalLen); byte[] data = new byte[totalLen]; // Create the project object. DisasmProject proj = new DisasmProject(); proj.Initialize(data.Length); // Try to get the Apple IIgs system definition. This is fragile, because it // relies on the name in the JSON file, but it's optional. (If the default CPU // type stops being 65816, we should be sure to set that here.) try { // TODO(maybe): encapsulate this somewhere else string sysDefsPath = RuntimeDataAccess.GetPathName("SystemDefs.json"); SystemDefSet sds = SystemDefSet.ReadFile(sysDefsPath); SystemDef sd = sds.FindEntryByName(IIGS_SYSTEM_DEF); if (sd != null) { proj.ApplySystemDef(sd); } else { Debug.WriteLine("Unable to find Apple IIgs system definition"); } } catch (Exception) { // never mind Debug.WriteLine("Failed to apply Apple IIgs system definition"); } ChangeSet cs = new ChangeSet(mSegmentMap.Count * 2); AddHeaderComment(proj, cs); UndoableChange uc; // Load the segments, and add entries to the project. int bufOffset = 0; foreach (SegmentMapEntry ent in mSegmentMap) { if (ent == null) { continue; } if (ent.Segment.Kind == OmfSegment.SegmentKind.JumpTable) { if (!RelocJumpTable(ent, data, bufOffset, cs)) { // Could treat this as non-fatal, but it really ought to work. Debug.WriteLine("Jump Table reloc failed"); return(false); } } else { // Perform relocation. if (!RelocSegment(ent, data, bufOffset)) { return(false); } } // Add one or more address entries. (Normally one, but data segments // can straddle multiple pages.) AddAddressEntries(proj, ent, bufOffset, cs); if ((mFlags & Flags.AddNotes) != 0) { // Add a comment identifying the segment and its attributes. string segCmt = string.Format(Res.Strings.OMF_SEG_COMMENT_FMT, ent.Segment.SegNum, ent.Segment.Kind, ent.Segment.Attrs, ent.Segment.SegName); uc = UndoableChange.CreateLongCommentChange(bufOffset, null, new MultiLineComment(segCmt)); cs.Add(uc); // Add a note identifying the segment. string segNote = string.Format(Res.Strings.OMF_SEG_NOTE_FMT, ent.Segment.SegNum, mFormatter.FormatAddress(ent.Address, true), ent.Segment.SegName); uc = UndoableChange.CreateNoteChange(bufOffset, null, new MultiLineComment(segNote)); cs.Add(uc); } bufOffset += ent.Segment.Length; } proj.PrepForNew(data, "new_proj"); foreach (KeyValuePair <int, DisasmProject.RelocData> kvp in mRelocData) { proj.RelocList.Add(kvp.Key, kvp.Value); } // Enable "use reloc" in the analysis parameters. ProjectProperties newProps = new ProjectProperties(proj.ProjectProps); newProps.AnalysisParams.UseRelocData = true; uc = UndoableChange.CreateProjectPropertiesChange(proj.ProjectProps, newProps); cs.Add(uc); // TODO(someday): by default we apply a code start tag to offset 0 of the first // segment. The placement should take the segment's ENTRY into account. Debug.WriteLine("Applying " + cs.Count + " changes"); proj.ApplyChanges(cs, false, out _); mLoadedData = data; mNewProject = proj; return(true); }