/// <summary> /// Updates the modules instantiated within vMod by inserting shadow clock in and chain out ports. /// </summary> /// <param name="vMod"></param> /// <param name="changeLog"></param> private void UpdateInstantiations(InserterMode mode, VerilogModule vMod, FileChangeLog changeLog) { //Propose changes in order to generate finalized change list int chainOutBit = 0; foreach (VerilogModuleInstance vmi in vMod.InstantiatedModules) { StringBuilder update = new StringBuilder();//"," + Environment.NewLine); if (mode == InserterMode.Error || mode == InserterMode.Both) { if (vmi.Type.ErrorControlWidth > 0) { String paramChange = String.Empty; if (vmi.Parameterized) { if (vmi.ParametersNamed) { paramChange = " ." + ERROR_PARAMETER + "(" + ERROR_PARAMETER + "),"; } else { paramChange = " " + ERROR_PARAMETER + ", "; } } else { paramChange = " #(." + ERROR_PARAMETER + "(" + ERROR_PARAMETER + ")) "; } changeLog.ProposeChange(vmi.ParameterList.Pos, paramChange.ToString()); update.AppendLine("\t\t." + ERROR_ENABLE + "(" + vmi.InstanceName + "_" + ERROR_ENABLE + "), // [ERROR]"); update.AppendLine("\t\t." + ERROR_CONTROL + "(" + vmi.InstanceName + "_" + ERROR_CONTROL + ") // [ERROR]"); } } if (mode == InserterMode.Shadow || mode == InserterMode.Both) { if (vmi.Type.NumChainsOut > 0) { int chainOutBitUpperLimit = (chainOutBit + vmi.Type.NumChainsOut - 1); string bitLimits = (chainOutBit == chainOutBitUpperLimit) ? ((vMod.NumChainsIn == 1) ? string.Empty : "[" + chainOutBit.ToString() + "]") : "[" + (chainOutBitUpperLimit + ":" + chainOutBit) + "]"; update.AppendLine(","); update.AppendLine("\t\t." + SHADOW_CLOCK + "(" + SHADOW_CLOCK + "), // [SHADOW]"); update.AppendLine("\t\t." + SHADOW_RESET + "(" + SHADOW_RESET + "), // [SHADOW]"); update.AppendLine("\t\t." + CAPTURE_ENABLE + "(" + CAPTURE_ENABLE + "), // [SHADOW]"); update.AppendLine("\t\t." + DUMP_ENABLE + "(" + CHAINS_DUMP_ENABLE + bitLimits + "), // [SHADOW]"); update.AppendLine("\t\t." + CHAINS_OUT + "(" + INST_CHAINS_OUT + bitLimits + "), // [SHADOW]"); update.AppendLine("\t\t." + CHAINS_OUT_DONE + "(" + INST_CHAINS_OUT_DONE + bitLimits + "), // [SHADOW]"); update.AppendLine("\t\t." + CHAINS_OUT_VALID + "(" + INST_CHAINS_OUT_VALID + bitLimits + ") // [SHADOW]"); chainOutBit += vmi.Type.NumChainsOut; } } if (update.ToString() == ("," + Environment.NewLine)) { continue; } changeLog.ProposeChange(vmi.InOutListEnd.Pos, update.ToString()); } }
/// <summary> /// Updates DFFs to support error injections /// </summary> /// <param name="vMod"></param> /// <param name="changeLog"></param> private void UpdateDffs(InserterMode mode, VerilogModule vMod, FileChangeLog changeLog) { int i = 0; foreach (DffInstance dff in vMod.LocalDffs) { if (dff.ParametersExist) { if (dff.ParametersNamed) { changeLog.ProposeChange(dff.ParameterBegin.Pos, " ." + ERROR_PARAMETER + "(" + ERROR_PARAMETER + "), "); } else { if (dff.ParamsInParens) { changeLog.ProposeChange(dff.ParameterBegin.Pos, " ." + ERROR_PARAMETER + "(" + ERROR_PARAMETER + "), .SIZE("); changeLog.ProposeChange(dff.ParameterEnd.Pos, ") "); } else { changeLog.ProposeChange(dff.ParameterBegin.Pos, "( ." + ERROR_PARAMETER + "(" + ERROR_PARAMETER + "), .SIZE("); changeLog.ProposeChange(dff.ParameterEnd.Pos, ")) "); } } } else { changeLog.ProposeChange(dff.ParameterBegin.Pos, " #( ." + ERROR_PARAMETER + "(" + ERROR_PARAMETER + ")) "); } changeLog.ProposeChange(dff.PortList.Pos, Environment.NewLine + ".err_en(lcl_err" + ((vMod.ErrorControlWidth > 1)? "[" + i + "]" : string.Empty) + "),"); i++; } }
/// <summary> /// Inserts all the inputs and outputs into the module being shadowed that are required by the shadow capture module /// </summary> /// <param name="vMod"></param> /// <param name="changeLog"></param> private void InsertLocalPorts(InserterMode mode, VerilogModule vMod, FileChangeLog changeLog) { StringBuilder inouts = new StringBuilder(Environment.NewLine); if (mode == InserterMode.Error || mode == InserterMode.Both) { inouts.AppendLine("," + Environment.NewLine + "//*****[ERROR CAPTURE MODULE INOUTS]*****"); inouts.AppendLine("\t" + ERROR_ENABLE + ", // Error injection enable"); inouts.AppendLine("\t" + ERROR_CONTROL + " // Error injection control"); } if (mode == InserterMode.Shadow || mode == InserterMode.Both) { inouts.AppendLine("," + Environment.NewLine + "//*****[SHADOW CAPTURE MODULE INOUTS]*****"); inouts.AppendLine("\t" + SHADOW_CLOCK + ", // Shadow/data clock"); inouts.AppendLine("\t" + SHADOW_RESET + ", // Shadow/data reset"); inouts.AppendLine("\t" + CAPTURE_ENABLE + ", // Capture enable"); inouts.AppendLine("\t" + DUMP_ENABLE + ", // Dump enable"); inouts.AppendLine("\t" + CHAINS_OUT + ", // Chains out"); inouts.AppendLine("\t" + CHAINS_OUT_VALID + ", // Chains out valid"); inouts.AppendLine("\t" + CHAINS_OUT_DONE + " // Chains done"); } changeLog.ProposeChange(vMod.InOutListEnd.Pos, inouts.ToString()); StringBuilder inoutDeclarations = new StringBuilder(Environment.NewLine); if ((mode == InserterMode.Error || mode == InserterMode.Both) && vMod.ErrorControlWidth > 0) { inoutDeclarations.AppendLine("parameter " + ERROR_PARAMETER + " = 1;" + Environment.NewLine); inoutDeclarations.AppendLine("\t//*****[ERROR CAPTURE MODULE INOUTS INSTANTIATIONS]*****"); inoutDeclarations.AppendLine("\tinput\t" + ERROR_ENABLE + "; // Error injection enable"); inoutDeclarations.AppendLine("\tinput\t" + ((vMod.ErrorControlWidth == 1) ? string.Empty : "[" + (vMod.ErrorControlWidth - 1) + ":0] ") + ERROR_CONTROL + "; // Error injection control"); inoutDeclarations.AppendLine(""); } if (mode == InserterMode.Shadow || mode == InserterMode.Both) { string chainsOutLimits = "[" + (vMod.NumChainsOut - 1) + ":0]"; inoutDeclarations.AppendLine("\t//*****[SHADOW CAPTURE MODULE INOUT INSTANTIATIONS]*****"); inoutDeclarations.AppendLine("\tinput\t" + SHADOW_CLOCK + "; // Shadow/data clock"); inoutDeclarations.AppendLine("\tinput\t" + SHADOW_RESET + "; // Shadow/data reset"); inoutDeclarations.AppendLine("\tinput\t" + CAPTURE_ENABLE + "; // Capture enable"); inoutDeclarations.AppendLine("\tinput\t" + chainsOutLimits + "\t" + DUMP_ENABLE + "; // Dump enable"); inoutDeclarations.AppendLine("\toutput\t" + chainsOutLimits + "\t" + CHAINS_OUT + "; // Chains out"); inoutDeclarations.AppendLine("\toutput\t" + chainsOutLimits + "\t" + CHAINS_OUT_VALID + "; // Chains out Valid"); inoutDeclarations.AppendLine("\toutput\t" + chainsOutLimits + "\t" + CHAINS_OUT_DONE + "; // Chains done"); } changeLog.ProposeChange(vMod.PostHeader.Pos, inoutDeclarations.ToString()); }
/// <summary> /// Instantiates all wires required for routing signals to/from the shadow capture module /// </summary> /// <param name="vMod"></param> /// <param name="changeLog"></param> private void InstantiateWires(InserterMode mode, VerilogModule vMod, FileChangeLog changeLog) { StringBuilder wireInst = new StringBuilder(Environment.NewLine); if (mode == InserterMode.Error || mode == InserterMode.Both) { wireInst.AppendLine("\t//*****[ERROR WIRE INSTANTIATIONS]******"); if (vMod.NumLocalDffs > 0) { wireInst.AppendLine("\twire [" + (vMod.NumLocalDffs - 1) + ":0] " + ERROR_LOCAL_CONTROL + ";"); } foreach (VerilogModuleInstance vmi in vMod.InstantiatedModules) { if (vmi.Type.ErrorControlWidth <= 0) { continue; } wireInst.AppendLine("\twire " + vmi.InstanceName + "_" + ERROR_ENABLE + ";"); wireInst.AppendLine("\twire " + ((vmi.Type.ErrorControlWidth == 0)? string.Empty : "[" + (vmi.Type.ErrorControlWidth - 1) + ":0] ") + vmi.InstanceName + "_" + ERROR_CONTROL + ";"); } changeLog.ProposeChange(vMod.PostHeader.Pos, wireInst.ToString()); wireInst.Clear(); } if (mode == InserterMode.Shadow || mode == InserterMode.Both) { if (vMod.NumChainsIn == 0) { return; } string bitLimits = (vMod.NumChainsIn == 1) ? string.Empty : "[" + (vMod.NumChainsIn - 1).ToString() + ":0] "; wireInst.AppendLine(Environment.NewLine + "//*****[SHADOW WIRE INSTANTIATIONS]*****"); wireInst.AppendLine("\twire " + bitLimits + INST_CHAINS_OUT + ";"); wireInst.AppendLine("\twire " + bitLimits + INST_CHAINS_OUT_VALID + ";"); wireInst.AppendLine("\twire " + bitLimits + INST_CHAINS_OUT_DONE + ";"); wireInst.AppendLine("\twire " + bitLimits + CHAINS_DUMP_ENABLE + ";"); wireInst.AppendLine(""); changeLog.ProposeChange(vMod.PostHeader.Pos, wireInst.ToString()); } }
public void InsertChanges(InserterMode mode, int numTopChains) { heirarchy.PopulateHeirarchy(numTopChains); Dictionary <string, FileChangeLog> projectChangeLogs = new Dictionary <string, FileChangeLog>(); foreach (VerilogModule vMod in heirarchy.FlattenedHeirarchy) { if (vMod.NumChainsOut == 0) { continue; //No changes to file required. Skip file. } string vFileName = project.GetWorkingCopyPath(vMod); FileChangeLog changeLog; if (projectChangeLogs.ContainsKey(vFileName)) { changeLog = projectChangeLogs[vFileName]; } else { changeLog = new FileChangeLog(vFileName); projectChangeLogs.Add(vFileName, changeLog); } UpdateInstantiations(mode, vMod, changeLog); if (mode == InserterMode.Error || mode == InserterMode.Both) { UpdateDffs(mode, vMod, changeLog); InstantiateLocalErrorSplitter(vMod, changeLog); InstantiateSubErrorSplitters(vMod, changeLog); } if (mode == InserterMode.Shadow || mode == InserterMode.Both) { InstantiateShadowCapture(vMod, changeLog); } InsertLocalPorts(mode, vMod, changeLog); InstantiateWires(mode, vMod, changeLog); } foreach (KeyValuePair <string, FileChangeLog> changeLogEntry in projectChangeLogs) { WriteAllChangesToFile(changeLogEntry.Value); } heirarchy.GenerateHeirarchySnapshotKey(); string snapKeyFile = Path.Combine(project.Directory, project.Name + ".snpkey"); string snapArgFile = Path.Combine(project.Directory, project.Name + ".snparg"); if (!File.Exists(snapKeyFile)) { FileStream fs = File.Create(snapKeyFile); fs.Close(); } if (!File.Exists(snapArgFile)) { FileStream fs = File.Create(snapKeyFile); fs.Close(); } XmlSerializer serializer = new XmlSerializer(typeof(List <List <DffBitRecord> >)); using (FileStream stream = File.OpenWrite(snapKeyFile)) { List <List <DffBitRecord> > exported = heirarchy.SnapshotKey.RotateExport(); serializer.Serialize(stream, exported); stream.Close(); } File.WriteAllText(snapArgFile, snapArgLog.ToString()); }