public SnapshotKey Generate(String instanceName) { Dictionary <int, SnapshotKey.ChainKey> key = new Dictionary <int, SnapshotKey.ChainKey>(); if (this.numChainsOut == 0) { return(new SnapshotKey(key, 0, 0)); } int chainLength = (this.numDffBits / this.numChainsOut); int extraBits = this.numDffBits - chainLength * this.numChainsOut; for (int i = 0; i < this.numDffBits; i++) { bool extraBit = i >= numDffBits - extraBits; int chain = extraBit ? numChainsOut - 1 : i / chainLength; int cycle = i - chain * chainLength; if (!key.ContainsKey(chain)) { key.Add(chain, new SnapshotKey.ChainKey(extraBit ? chainLength + extraBits : chainLength)); } key[chain][cycle] = GetBitEntry(instanceName, i); } SnapshotKey snapshotKey = new SnapshotKey(key, this.numChainsOut, chainLength + extraBits); List <SnapshotKey> childKeys = new List <SnapshotKey>(); for (int i = 0; i < vMod.InstantiatedModules.Count; i++) { VerilogModuleInstance vmi = vMod.InstantiatedModules[i]; childKeys.Add(vmi.Type.GenerateSnapshotKey(instanceName + "/" + vmi.InstanceName)); } snapshotKey.AppendChildKeys(childKeys); return(snapshotKey); }
public void AddModulesToLibrary(Dictionary <string, VerilogModule> modules) { foreach (KeyValuePair <string, VerilogModule> kvp in modules) { if (!this.moduleLibrary.ContainsKey(kvp.Key)) { // Extract Module from dictionary and add to library VerilogModule vMod = kvp.Value; this.moduleLibrary.Add(vMod.Name, vMod); // Add possible instances contained in the module to the library foreach (KeyValuePair <string, List <PossibleInstance> > kvpLPI in vMod.PossibleInstances) { foreach (PossibleInstance pi in kvpLPI.Value) { if (!this.possibleInstancesLibrary.ContainsKey(pi.TypeName)) { //If it's the first possible instance of its type, create a new list before adding the PossibleInstance to it possibleInstancesLibrary.Add(pi.TypeName, new List <PossibleInstance>()); } // Already other possible instances of the same type, add pi to list of instances possibleInstancesLibrary[pi.TypeName].Add(pi); } // Check if any possibleInstances are defined by this module if (this.possibleInstancesLibrary.ContainsKey(vMod.Name)) { // If so, replace PossibleInstances with VerilogModuleInstances List <PossibleInstance> piList = possibleInstancesLibrary[vMod.Name]; for (int i = 0; i < piList.Count; i++) { PossibleInstance pi = piList[i]; StringTokenizer tknzr = StringTokenizer.TokenizerFromFile(pi.Filename, pi.Bookmark); VerilogModuleInstance vmi = parser.ParseModuleInstance(pi.ParentModule, tknzr, pi.Bookmark, vMod); pi.ParentModule.AddModuleInstance(vmi); //this.AddModulesToLibrary(this.parser.Reparse(piList[i]).DeclaredModules); piList.RemoveAt(i); if (piList.Count == 0) { possibleInstancesLibrary.Remove(vMod.Name); } } } } } else { // Reparsing: updating VerilogModule definitions to contain more module instantiations this.moduleLibrary[kvp.Key] = kvp.Value; } } }
/// <summary> /// Replaces all PossibleInstances with real instances of the VerilogModule type. /// Used after the type has been found. /// </summary> /// <param name="vMod"></param> public void ReplacePossibleInstances(VerilogModule vMod) { if (!this.possibleInstances.ContainsKey(vMod.Name)) { return; } List <PossibleInstance> lpi = this.possibleInstances[vMod.Name]; foreach (PossibleInstance pInst in lpi) { VerilogModuleInstance vmi = new VerilogModuleInstance(pInst.ParentModule, vMod, pInst.InstanceName, pInst.InOutListEnd); vmi.Parameterized = pInst.paramsExist; vmi.ParametersNamed = pInst.paramsNamed; vmi.ParameterList = pInst.paramList; this.moduleInstances.Add(vmi); } this.possibleInstances.Remove(vMod.Name); }
/// <summary> /// Adds ModuleInstance to the parent's definition. Also, if a definition to a PossibleInstance is found, /// the PossibleInstance is removed and replaced with the ModuleInstance provided. /// </summary> /// <param name="module"></param> public void AddModuleInstance(VerilogModuleInstance module) { if (this.possibleInstances.ContainsKey(module.Type.Name)) { List <PossibleInstance> lpi = this.possibleInstances[module.Type.Name]; for (int i = 0; i < lpi.Count; i++) { PossibleInstance pi = lpi[i]; if (pi.InstanceName == module.InstanceName) { this.possibleInstances[module.Type.Name].Remove(pi); break; } } if (this.possibleInstances[module.Type.Name].Count == 0) { this.possibleInstances.Remove(module.Type.Name); } } this.moduleInstances.Add(module); }
public VerilogModuleInstance ParseModuleInstance(VerilogModule parent, StringTokenizer tknzr, Token possibleParamList, VerilogModule modInstType) { string instName; Token paramListBegin = possibleParamList;//tknzr.Next(); bool paramExists = false; bool paramsNamed = false; string word = tknzr.Next().Value; if (word == "#") { // Run through parameter lists until parens all closed paramExists = true; //paramListBegin = tknzr.Next(); // after "#(" int parenPairs = 1; while (parenPairs > 0) { word = tknzr.Next().Value; if (word.Contains(".")) { paramsNamed = true; } if (word == "(") { parenPairs++; } else if (word == ")") { parenPairs--; } } instName = tknzr.Next().Value; } else { instName = word; } if (instName.Contains("st4_rrobin") || parent.Name == "lsu_rrobin_picker2") { Console.Write("pOOp"); } Token currTok = tknzr.Next(); Token prevTok = currTok; Token twoPrevTok = currTok; while (currTok.Value != ";") { // Run through in/out list to end of instantiation twoPrevTok = prevTok; // At ')' prevTok = currTok; // At ';' currTok = tknzr.Next(); // After ';' } VerilogModuleInstance vModInst = modInstType.Instantiate(parent, instName, twoPrevTok); vModInst.ParameterList = paramListBegin; vModInst.Parameterized = paramExists; vModInst.ParametersNamed = paramsNamed; return(vModInst); }
private VerilogModule ParseModuleDeclaration(StringTokenizer tknzr, VerilogFile vFile) { #region Are the ports even needed? Besides knowing where to insert the shadow chain ports /* * List<string> inPorts = new List<string>(); * List<string> outPorts = new List<string>(); * List<string> inoutPorts = new List<string>(); * Token currToken = null; * Token prevToken = new Token(TokenKind.Unknown, "", 0, 0, 0); * while (true) { * if (currToken == null) { * tknzr.Next(); * } * currToken = tknzr.Next(); * if (currToken.Kind == TokenKind.EOF) { * break; * } else if (currToken.Value == ";" && prevToken.Value == ")") { * break; * } else if (currToken.Value == "input" && prevToken.Kind == TokenKind.EOL) { * * } * prevToken = currToken; * } */ #endregion Token prevTok = tknzr.Next(); Token twoPrevTok = prevTok; Token currTok = tknzr.Next(); VerilogModule vMod = new VerilogModule(vFile.FileName, prevTok.Value); bool headerParsed = false; while (currTok.Value != "endmodule" && currTok.Kind != TokenKind.EOF) { if (prevTok.Kind == TokenKind.EOL) { if (!RunPrecompiler(tknzr, ref prevTok, ref currTok)) { if (currTok.Value == "parameter") { // PARAMETER FOUND ParseParameter(tknzr, vMod.Parameters); } else if (this.project.IsDff(currTok.Value)) { // DFF INSTANCE FOUND DffInstance dffInst = ParseDffInstance(tknzr, currTok, project.GetDffType(currTok.Value)); if (dffInst == null) { throw new InvalidDataException("DFF Library was unable to instantiate from type retrieved from project."); } vMod.AddDffInstance(dffInst); } else if (this.project.IsModule(currTok.Value)) { // MODULE INSTANCE FOUND VerilogModuleInstance vModInst = ParseModuleInstance(vMod, tknzr, currTok, project.GetModule(currTok.Value)); if (vModInst == null) { throw new InvalidDataException("Error instantiating module from type retrieved from project."); } vMod.AddModuleInstance(vModInst); } else if (headerParsed && !this.project.IsKeyword(currTok.Value) && currTok.Kind == TokenKind.Word) { // POSSIBLE MODULE, NOT YET PARSED /* OPTIMZATION: * TODO: Change tokenizer to ignore everything between certain keywords and ';', * EX: "assign blah = blah blah blah;" in case there is weird indenting for * readibility. This will minimize the number of false Possibles. * */ if (currTok.Value == "lsu_dc_parity_gen") { Console.Write("!"); } StringTokenizer tempTknzr = new StringTokenizer(tknzr); // Perform deep copy to leave tknzr untouched Token nameTok = tempTknzr.Next(); bool paramExist = false; bool paramNamed = false; Token paramList = null; /*if (nameTok.Value == "#") { * paramsExist = true; * tempTknzr.Next();// ( * tempTknzr.Next();// Number * tempTknzr.Next();// ) * nameTok = tempTknzr.Next(); * }*/ if (nameTok.Value == "#") { // Run through parameter lists until parens all closed paramExist = true; paramList = tempTknzr.Next(); // after "#(" if (paramList.Value == "(") { int parenPairs = 1; while (parenPairs > 0) { nameTok = tempTknzr.Next(); if (nameTok.Value.Contains(".")) { paramNamed = true; } if (nameTok.Value == "(") { parenPairs++; } else if (nameTok.Value == ")") { parenPairs--; } } } nameTok = tempTknzr.Next(); } else { paramList = currTok; } Token tempCurrTok = tempTknzr.Next(); Token tempPrevTok = tempCurrTok; Token tempTwoPrevTok = tempCurrTok; while (tempCurrTok.Value != ";") { // Run through in/out list to end of instantiation tempTwoPrevTok = tempPrevTok; // At ')' tempPrevTok = tempCurrTok; // At ';' tempCurrTok = tempTknzr.Next(); // After ';' } vMod.AddPossibleInstance(currTok, nameTok.Value, tempTwoPrevTok, paramExist, paramNamed, paramList); } } } twoPrevTok = prevTok; prevTok = currTok; currTok = tknzr.Next(); if (!headerParsed && currTok.Value == ";" /*&& prevTok.Value == ")"*/) { vMod.InOutListEnd = twoPrevTok; vMod.PostHeader = tknzr.Next(); twoPrevTok = prevTok; prevTok = (currTok.Value == ")")? currTok : prevTok; currTok = vMod.PostHeader; headerParsed = true; } } vMod.PrevEndModule = prevTok; return(vMod); }