Beispiel #1
0
        internal static void VisitSimCmd(VCDLexer lexer, IDToVarDef idToVariable, SimPass pass, BitAllocator bitAlloc)
        {
            ReadOnlyMemory <byte> declWordMem = lexer.NextWordAsMem();
            ReadOnlySpan <byte>   declWord    = declWordMem.Span;

            ReadOnlySpan <byte> endToken      = new byte[] { (byte)'$', (byte)'e', (byte)'n', (byte)'d' };
            ReadOnlySpan <byte> commentToken  = new byte[] { (byte)'$', (byte)'c', (byte)'o', (byte)'m', (byte)'m', (byte)'e', (byte)'n', (byte)'t' };
            ReadOnlySpan <byte> dumpAllToken  = new byte[] { (byte)'$', (byte)'d', (byte)'u', (byte)'m', (byte)'p', (byte)'a', (byte)'l', (byte)'l' };
            ReadOnlySpan <byte> dumpOffToken  = new byte[] { (byte)'$', (byte)'d', (byte)'u', (byte)'m', (byte)'p', (byte)'o', (byte)'f', (byte)'f' };
            ReadOnlySpan <byte> dumpOnToken   = new byte[] { (byte)'$', (byte)'d', (byte)'u', (byte)'m', (byte)'p', (byte)'o', (byte)'n' };
            ReadOnlySpan <byte> dumpVarsToken = new byte[] { (byte)'$', (byte)'d', (byte)'u', (byte)'m', (byte)'p', (byte)'v', (byte)'a', (byte)'r', (byte)'s' };
            ReadOnlySpan <byte> hashtagToken  = new byte[] { (byte)'#' };

            //It may be the case that it's first discovered now that
            // the end of the file has been reached.
            if (declWord.Length == 0)
            {
                if (lexer.IsWordsRemaining())
                {
                    throw new Exception("Invalid simulation command.");
                }

                return;
            }

            if (declWord.SequenceEqual(commentToken))
            {
                string text = lexer.NextUntil(endToken).ToCharString();

                lexer.ExpectNextWord(endToken);
                pass.SimCmd = new Comment(text);
            }
            else if (declWord.SequenceEqual(dumpAllToken))
            {
                pass.SimCmd = new DumpAll(VisitValueChangeStream(lexer, idToVariable, pass, bitAlloc));
            }
            else if (declWord.SequenceEqual(dumpOffToken))
            {
                pass.SimCmd = new DumpOff(VisitValueChangeStream(lexer, idToVariable, pass, bitAlloc));
            }
            else if (declWord.SequenceEqual(dumpOnToken))
            {
                pass.SimCmd = new DumpOn(VisitValueChangeStream(lexer, idToVariable, pass, bitAlloc));
            }
            else if (declWord.SequenceEqual(dumpVarsToken))
            {
                pass.SimCmd = new DumpVars(VisitValueChangeStream(lexer, idToVariable, pass, bitAlloc));
            }
            else if (declWord.StartsWith(hashtagToken))
            {
                pass.SimCmd = VisitSimTime(declWord);
            }
            else
            {
                VisitValueChange(lexer, declWordMem, idToVariable, pass, bitAlloc);
            }
        }
Beispiel #2
0
        internal static IDeclCmd?VisitDeclCmd(VCDLexer lexer, IDToVarDef idToVariable, Stack <Scope> scopes)
        {
            ReadOnlySpan <byte> declWord = lexer.NextWord();
            Span <char>         chars    = stackalloc char[declWord.Length];

            declWord.CopyToCharArray(chars);

            ReadOnlySpan <byte> endToken   = new byte[] { (byte)'$', (byte)'e', (byte)'n', (byte)'d' };
            ReadOnlySpan <byte> dollarSign = new byte[] { (byte)'$' };

            if (chars.SequenceEqual("$comment"))
            {
                string text = lexer.NextUntil(endToken).ToCharString();

                lexer.ExpectNextWord(endToken);
                return(new Comment(text));
            }
            else if (chars.SequenceEqual("$date"))
            {
                string text = lexer.NextUntil(endToken).ToCharString();

                lexer.ExpectNextWord(endToken);
                return(new Date(text));
            }
            else if (chars.SequenceEqual("$scope"))
            {
                ScopeType type = VisitScopeType(lexer);
                string    id   = lexer.NextWord().ToCharString();

                Scope scope = new Scope(type, id);
                scopes.Push(scope);

                lexer.ExpectNextWord(endToken);
                return(scope);
            }
            else if (chars.SequenceEqual("$timescale"))
            {
                int      scale = VisitTimeNumber(lexer);
                TimeUnit unit  = VisitTimeUnit(lexer);

                lexer.ExpectNextWord(endToken);
                return(new TimeScale(scale, unit));
            }
            else if (chars.SequenceEqual("$upscope"))
            {
                scopes.Pop();

                lexer.ExpectNextWord(endToken);
                return(new UpScope());
            }
            else if (chars.SequenceEqual("$var"))
            {
                VarType type      = VisitVarType(lexer);
                int     size      = VisitSize(lexer);
                string  id        = lexer.NextWord().ToCharString();
                string  reference = lexer.NextWord().ToCharString();

                VarDef variable = new VarDef(type, size, id, reference, scopes.Reverse().ToArray());
                idToVariable.AddVariable(variable);

                //Skip this stuff because it's not currently supported
                char nextChar = lexer.PeekNextChar();
                if (nextChar == '[')
                {
                    ReadOnlySpan <byte> endBracket = new byte[] { (byte)']' };
                    lexer.NextUntil(endBracket);
                    lexer.SkipChar();
                }

                lexer.ExpectNextWord(endToken);
                return(variable);
            }
            else if (chars.SequenceEqual("$version"))
            {
                string versionTxt       = lexer.NextUntil(dollarSign).ToCharString();
                string systemTaskString = string.Empty;

                ReadOnlySpan <byte> systemTask = lexer.PeekNextWord().Span;
                if (systemTask.StartsWith(dollarSign) && !systemTask.SequenceEqual(endToken))
                {
                    lexer.SkipWord(systemTask);
                    systemTaskString = systemTask.ToCharString();
                }

                lexer.ExpectNextWord(endToken);
                return(new Version(versionTxt, systemTaskString));
            }
            else if (chars.SequenceEqual("$enddefinitions"))
            {
                lexer.ExpectNextWord(endToken);
                return(null);
            }
            else
            {
                throw new Exception($"Invalid declaration command: {declWord.ToCharString()}\nBuffer: {lexer.BufferToString()}");
            }
        }