private void ParseForModDeclarations(StringTokenizer tknzr, VerilogFile vFile) { SetupPrecompiler(); Token prevTok = null; Token currTok = tknzr.Next(); while (true) { if (currTok.Kind == TokenKind.EOF) { break; } if (prevTok == null || prevTok.Kind == TokenKind.EOL) { RunPrecompiler(tknzr, ref prevTok, ref currTok); if (currTok.Value == "module") { VerilogModule parsedModule = ParseModuleDeclaration(tknzr, vFile); AssignDffErrorIds(parsedModule); vFile.AddDeclaration(parsedModule); } } prevTok = currTok; currTok = tknzr.Next(); } }
private VerilogFile ConductParse(string filename, Token bookmark = null) { VerilogFile vFile = new VerilogFile(filename); StringTokenizer tknzr = StringTokenizer.TokenizerFromFile(filename, bookmark); ParseForModDeclarations(tknzr, vFile); return(vFile); }
public void ParseDFFLibrary(string filename) { VerilogFile dffLibrary = Parse(filename); DffImportDialog did = new DffImportDialog(); foreach (DFFModule dff in did.Import(dffLibrary)) { project.AddDffToLibrary(dff); } }
public List <DFFModule> Import(VerilogFile vFile) { inDffs = new List <DFFModule>(); foreach (KeyValuePair <string, VerilogModule> pair in vFile.DeclaredModules) { DFFModule dff = new DFFModule(pair.Value.Name, "clk", "d", "q"); inDffs.Add(dff); this.checkedListBox1.Items.Add(dff); } DialogResult dr = this.ShowDialog(); return(outDffs); }
private void LoadFiles(List <string> fileNames) { foreach (string fileName in fileNames) { VerilogFile vFile = this.parser.Parse(fileName); this.project.AddModulesToLibrary(vFile.DeclaredModules); } this.moduleLibraryDisplay.Items.Clear(); List <VerilogModule> modules = project.GetModuleList(); foreach (VerilogModule module in modules) { this.moduleLibraryDisplay.Items.Add(module); } }
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); }