예제 #1
0
 public void AddDffInstance(DffInstance dff)
 {
     if (dff.IsParameterized)
     {
         if (parameters.ContainsKey(dff.Parameter))
         {
             dff.Size = parameters[dff.Parameter];
         }
         else
         {
             try {
                 dff.Size = EvaluateComplexParam(dff.Parameter);
             } catch {
                 // ABORT EVALUATION: assign default width
                 dff.Size = 1;
                 //throw new Exception("The string '" + dff.Parameter + "' could not be interpreted to a defined parameter.");
             }
         }
     }
     this.localDffs.Add(dff);
 }
예제 #2
0
        private DffInstance ParseDffInstance(StringTokenizer tknzr, Token possibleParameter, DFFModule dffType)
        {
            DffInstance dff       = new DffInstance(dffType);
            Token       currToken = tknzr.Next();

            dff.ParameterBegin  = possibleParameter;
            dff.ParametersExist = false;
            dff.ParametersNamed = false;
            dff.ParamsInParens  = false;
            if (currToken.Value == "#")
            {
                dff.ParametersExist = true;
                dff.ParameterBegin  = currToken;
                currToken           = tknzr.Next();
                if (currToken.Value == "(")
                {
                    dff.ParamsInParens = true;
                    dff.ParameterBegin = currToken;
                    Token  tempParamList;
                    string paramValue = tknzr.ParseToCloseParenthesis(out tempParamList);
                    dff.ParameterList = tempParamList;
                    dff.ParameterEnd  = tempParamList;
                    try {
                        dff.Size = Convert.ToInt32(paramValue);
                    } catch (FormatException) {
                        if (paramValue.StartsWith("`"))
                        {
                            // TODO: Deal with `DEFINE'd values
                            dff.Size = 1;
                        }
                        else if (paramValue.StartsWith("."))
                        {
                            dff.ParametersNamed = true;
                        }
                        else
                        {
                            dff.ParametersExist = true;
                            dff.IsParameterized = true;
                            dff.Parameter       = paramValue;
                            //throw new InvalidDataException("Wah. I don't get it. '" + currToken.Value + "' isn't a number.");
                        }
                    }
                }
                else
                {
                    dff.ParameterEnd = currToken;
                    try {
                        dff.Size = Convert.ToInt32(currToken.Value); // In case they use the weird '#12' notation instead of '#(12)'
                    } catch (FormatException) {
                        if (currToken.Value == "`")
                        {
                            // TODO: Deal with `DEFINE'd values
                            dff.Size = 1;
                        }
                        else
                        {
                            throw new InvalidDataException("Wah. I don't get it. '" + currToken.Value + "' isn't a number.");
                        }
                    }
                }

                //tknzr.Next();
                currToken        = tknzr.Next();
                dff.InstanceName = currToken.Value;
            }
            else
            {
                dff.Size         = 1;
                dff.InstanceName = currToken.Value;
            }

            while (currToken.Value != "(")
            {
                currToken = tknzr.Next();
            }
            //currToken = tknzr.Next();
            dff.PortList = currToken;

            while (dff.ClockPort == null || dff.DPort == null || dff.QPort == null)
            {
                currToken = tknzr.Next();
                string word = currToken.Value;
                if (word == ";")
                {
                    break;
                }
                if (word == ".")
                {
                    currToken = tknzr.Next();
                    switch (currToken.Value)
                    {
                    case "clk": {
                        tknzr.Next();
                        Token tempToken;
                        dff.ClockPort = tknzr.ParseToCloseParenthesis(out tempToken);
                        break;
                    }

                    case "q": {
                        tknzr.Next();
                        Token tempToken;
                        dff.QPort = tknzr.ParseToCloseParenthesis(out tempToken);
                        break;
                    }

                    case "din": {
                        tknzr.Next();
                        Token tempToken;
                        dff.DPort = tknzr.ParseToCloseParenthesis(out tempToken);
                        break;
                    }
                    }
                }
            }
            while (currToken.Value != ";" && currToken.Kind != TokenKind.EOF)
            {
                currToken = tknzr.Next();
            }
            return(dff);
        }
예제 #3
0
        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);
        }