Exemplo n.º 1
0
        /// <summary>
        /// Добавление нового файла в проект
        /// </summary>
        /// <param name="filePath"></param>
        /// <returns></returns>
        public override CodeFile AddCodeFile(string filePath)
        {
            LibraryDeclarativeRegion lib     = GetLibraryForFile(filePath);
            VHDL_CodeFile            newCode = new VHDL_CodeFile(filePath, lib.Identifier, this);

            files.Add(newCode);
            return(newCode);
        }
Exemplo n.º 2
0
        private static VhdlFile parse(VhdlParserSettings settings, ICharStream stream, VHDL_Library_Manager libraryManager)
        {
            RootDeclarativeRegion    rootScope    = new RootDeclarativeRegion();
            LibraryDeclarativeRegion libraryScope = new LibraryDeclarativeRegion("work");

            rootScope.Libraries.Add(libraryScope);

            return(parse(settings, stream, rootScope, libraryScope, libraryManager));
        }
Exemplo n.º 3
0
        public static void VHDLSample()
        {
            Console.WriteLine("Hello World!");

            // TODO: Implement Functionality Here
            string appBase = System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location);

            VHDL.parser.Logger loggercompile = VHDL.parser.Logger.CreateLogger(appBase, "compiler");

            VHDL_Library_Manager libraryManager = new VHDL_Library_Manager("", @"Libraries\LibraryRepository.xml", loggercompile);

            libraryManager.Logger.OnWriteEvent += new VHDL.parser.Logger.OnWriteDeleagte(Logger_OnWriteEvent);
            libraryManager.LoadData(@"Libraries");
            VhdlParserSettings       settings       = VhdlParserWrapper.DEFAULT_SETTINGS;
            RootDeclarativeRegion    rootScope      = new RootDeclarativeRegion();
            LibraryDeclarativeRegion currentLibrary = new LibraryDeclarativeRegion("work");

            rootScope.Libraries.Add(currentLibrary);
            rootScope.Libraries.Add(libraryManager.GetLibrary("STD"));

            bool success = true;

            try
            {
                Console.WriteLine("Parsing code");
                VhdlFile file = VhdlParserWrapper.parseFile("sample.vhdl", settings, rootScope, currentLibrary, libraryManager);
            }
            catch (vhdlParseException ex)
            {
                Console.WriteLine(string.Format("{0} {1}:{2} {3} {4} {5}", ex.FilePath, ex.Line, ex.CharPositionInLine, ex.OffendingSymbol.Text, ex.Message, ex.InnerException));
                Console.WriteLine("Parsing failed");
                success = false;
            }
            catch (vhdlSemanticException ex)
            {
                Console.WriteLine(ex.GetConsoleMessageTest());
                Console.WriteLine("Parsing failed");
                success = false;
            }
            catch (Exception ex)
            {
                Console.WriteLine(string.Format("{0} {1} {2} \n {3}", ex.Message, ex.InnerException, ex.Source, ex.StackTrace));
                Console.WriteLine("Parsing failed");
                success = false;
            }
            if (success)
            {
                Console.WriteLine("Parsing complete");
            }



            Console.Write("Press any key to continue . . . ");
            Console.ReadKey(true);
        }
Exemplo n.º 4
0
        /// <summary>
        /// Распарсить входной поток
        /// </summary>
        /// <param name="stream"></param>
        /// <param name="libraryScope"></param>
        /// <param name="tokenStream"></param>
        /// <param name="tree"></param>
        /// <returns></returns>
        private VhdlFile Parse(ICharStream stream, LibraryDeclarativeRegion libraryScope, out CommonTokenStream tokenStream, out IParseTree tree)
        {
            VhdlFile res = null;

            file        = null;
            tree        = null;
            tokenStream = null;
            lock (this)
            {
                try
                {
                    vhdlLexer lexer = new vhdlLexer(stream);

                    tokenStream = new CommonTokenStream(lexer);
                    vhdlParser parser = new vhdlParser(tokenStream);

                    //--------------------------------------------
                    //Optional - add listener
                    //vhdlListener listener = new vhdlListener();
                    //parser.AddParseListener(listener);
                    //--------------------------------------------
                    vhdlSemanticErrorListener vhdlSemanticErrorListener = new vhdlSemanticErrorListener(stream.SourceName);
                    parser.AddErrorListener(vhdlSemanticErrorListener);

                    tree = parser.design_file();
                    //Console.WriteLine(tree.ToStringTree(parser));
                    vhdlVisitor visitor = new vhdlVisitor(settings, rootScope, libraryScope, libraryManager)
                    {
                        FileName = stream.SourceName
                    };
                    res = visitor.Visit(tree) as VhdlFile;
                }
                catch (vhdlSemanticException ex)
                {
                    parseSemanticException = ex;
                }
                catch (vhdlParseException ex)
                {
                    parseSyntaxException = ex;
                }
                catch (Exception ex)
                {
                    parseException = ex;
                }
            }
            ShowErrorMessages();
            return(res);
        }
Exemplo n.º 5
0
        /// <summary>
        /// Обновление параметров LibraryScope
        /// </summary>
        public void UpdateLibraryScope()
        {
            if (libraryScope == null)
            {
                libraryScope = new LibraryDeclarativeRegion(name);
            }

            VhdlFile file = new VhdlFile(name);

            foreach (PackageInfo inf in packages)
            {
                file.Elements.Add(inf.Declaration);
            }

            libraryScope.Files.Add(file);
        }
Exemplo n.º 6
0
        public VHDLCompiler(string ProgramPath)
        {
            string appBase = System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location);

            VHDL.parser.Logger loggercompile = VHDL.parser.Logger.CreateLogger(appBase, "compiler");

            libraryManager = new VHDL_Library_Manager("", @"Libraries\LibraryRepository.xml", loggercompile);
            libraryManager.Logger.OnWriteEvent += new VHDL.parser.Logger.OnWriteDeleagte(Logger_OnWriteEvent);
            libraryManager.LoadData(@"Libraries");

            settings = VhdlParserWrapper.DEFAULT_SETTINGS;
            settings.AddPositionInformation = true;
            rootScope      = new RootDeclarativeRegion();
            currentLibrary = new LibraryDeclarativeRegion("work");
            rootScope.Libraries.Add(currentLibrary);
            rootScope.Libraries.Add(libraryManager.GetLibrary("STD"));
        }
Exemplo n.º 7
0
        /// <summary>
        /// Получение тела пакета по его имени и по имени библиотеки
        /// </summary>
        /// <param name="LibraryName"></param>
        /// <param name="PackageName"></param>
        /// <returns></returns>
        public PackageBody GetPackageBody(string LibraryName, string PackageName)
        {
            LibraryDeclarativeRegion library = GetLibrary(LibraryName);

            foreach (VhdlFile file in library.Files)
            {
                foreach (LibraryUnit unit in file.Elements)
                {
                    if (unit is PackageBody)
                    {
                        if ((unit as PackageBody).Package.Identifier.EqualsIdentifier(PackageName))
                        {
                            return(unit as PackageBody);
                        }
                    }
                }
            }
            return(null);
        }
Exemplo n.º 8
0
 /// <summary>
 /// Проверка наличия библиотеки
 /// </summary>
 /// <param name="tree"></param>
 /// <param name="useClause"></param>
 public bool CheckLibraryClause(ParserRuleContext tree, LibraryClause libraryClause)
 {
     foreach (string lib in libraryClause.getLibraries())
     {
         if (libraryManager.ContainsLibrary(lib) == false)
         {
             throw new VHDL.ParseError.vhdlUnknownLibraryException(tree, FileName, lib);
             return(false);
         }
         else
         {
             LibraryDeclarativeRegion libraryDecl = libraryManager.GetLibrary(lib);
             if (libraryClause.LibraryDeclarativeRegion.Contains(libraryDecl) == false)
             {
                 libraryClause.LibraryDeclarativeRegion.Add(libraryDecl);
             }
         }
     }
     return(true);
 }
Exemplo n.º 9
0
        /// <summary>
        /// Распарсить файл по адрессу filePath без создания параллельного потока
        /// </summary>
        /// <param name="filePath"></param>
        /// <param name="tokenStream"></param>
        /// <param name="tree"></param>
        /// <returns></returns>
        public VhdlFile ParseFile(string filePath, out CommonTokenStream tokenStream, out IParseTree tree)
        {
            VhdlFile file = null;

            lock (this)
            {
                if (File.Exists(filePath) == false)
                {
                    parseException = new Exception(string.Format("File {0} not found", filePath));
                    tree           = null;
                    tokenStream    = null;
                    return(null);
                }

                LibraryDeclarativeRegion libraryScope = GetLibraryForFile(filePath);
                // Start process
                ICharStream stream = new CaseInsensitiveFileStream(filePath);
                file = Parse(stream, libraryScope, out tokenStream, out tree);
            }
            return(file);
        }
Exemplo n.º 10
0
 public LibraryInfo(string name)
 {
     this.name    = name;
     packages     = new List <PackageInfo>();
     libraryScope = new LibraryDeclarativeRegion(name);
 }
Exemplo n.º 11
0
 public static VhdlFile parseFile(string fileName, VhdlParserSettings settings, RootDeclarativeRegion rootScope, LibraryDeclarativeRegion libray, VHDL_Library_Manager libraryManager)
 {
     return(parse(settings, new CaseInsensitiveFileStream(fileName), rootScope, libray, libraryManager));
 }
Exemplo n.º 12
0
        private static VhdlFile parse(VhdlParserSettings settings, ICharStream stream, RootDeclarativeRegion rootScope, LibraryDeclarativeRegion libraryScope, VHDL_Library_Manager libraryManager)
        {
            vhdlLexer lexer = new vhdlLexer(stream);

            CommonTokenStream tokens = new CommonTokenStream(lexer);
            vhdlParser        parser = new vhdlParser(tokens);

            //--------------------------------------------
            //Optional - add listener
            //vhdlListener listener = new vhdlListener();
            //parser.AddParseListener(listener);
            //--------------------------------------------
            vhdlSemanticErrorListener vhdlSemanticErrorListener = new vhdlSemanticErrorListener(stream.SourceName);

            parser.AddErrorListener(vhdlSemanticErrorListener);

            IParseTree tree = parser.design_file();
            //Console.WriteLine(tree.ToStringTree(parser));
            vhdlVisitor visitor = new vhdlVisitor(settings, rootScope, libraryScope, libraryManager)
            {
                FileName = stream.SourceName
            };
            VhdlFile res = visitor.Visit(tree) as VhdlFile;

            return(res);
        }
Exemplo n.º 13
0
        static void Main(string[] args)
        {
            try
            {
                string appBase = System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location);

                VHDL.parser.Logger loggercompile = VHDL.parser.Logger.CreateLogger(appBase, "compiler");
                VHDLRuntime.Logger loggerrun     = VHDLRuntime.Logger.CreateLogger(appBase, "run");

                VHDL_Library_Manager libraryManager = new VHDL_Library_Manager("", @"Libraries\LibraryRepository.xml", loggercompile);
                libraryManager.Logger.OnWriteEvent += new VHDL.parser.Logger.OnWriteDeleagte(Logger_OnWriteEvent);
                libraryManager.LoadData(@"Libraries");
                VhdlParserSettings       settings       = VhdlParserWrapper.DEFAULT_SETTINGS;
                RootDeclarativeRegion    rootScope      = new RootDeclarativeRegion();
                LibraryDeclarativeRegion currentLibrary = new LibraryDeclarativeRegion("work");
                rootScope.Libraries.Add(currentLibrary);
                //rootScope.getLibraries().Add(VHDL_Library_Manager.GetLibrary("STD"));

                Console.WriteLine("Parsing code");
                VhdlFile file = VhdlParserWrapper.parseFile("vhdl_tests\\simple_simulation.vhd", settings, rootScope, currentLibrary, libraryManager);
                Console.WriteLine("Parsing complete");

                foreach (LibraryUnit unit in file.Elements)
                {
                    if (unit is Architecture)
                    {
                        Architecture arch = unit as Architecture;
                        if (arch.Identifier.Equals("some_test_bench"))
                        {
                            string fileName = string.Format("{0}\\{1}.dll", appBase, arch.Identifier);
                            string vcdFile  = string.Format("{0}\\dump.vcd", appBase, arch.Identifier);


                            VHDLCompilerInterface compiler = new VHDLCompilerInterface(arch, loggercompile);
                            compiler.Compile(appBase);

                            TestRunner.LoadMyAssemblyAndRun(fileName, arch.Identifier, arch.Identifier, loggerrun, vcdFile);

                            Process proc = new Process();
                            proc.StartInfo.Arguments        = "run.log";
                            proc.StartInfo.FileName         = "notepad.exe";
                            proc.StartInfo.WorkingDirectory = Process.GetCurrentProcess().StartInfo.WorkingDirectory;
                            proc.Start();
                        }
                    }
                }
            }
            catch (InvalidOperationException ex)
            {
                Console.WriteLine(ex.Message);
                Console.WriteLine(ex.Source);
                Console.WriteLine(ex.StackTrace);
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
                Console.WriteLine(ex.Source);
                Console.WriteLine(ex.StackTrace);
            }
            catch { }
            Console.ReadKey();
        }
Exemplo n.º 14
0
 public vhdlAbstractVisitor(VhdlParserSettings settings, RootDeclarativeRegion rootScope, LibraryDeclarativeRegion libraryScope, VHDL_Library_Manager libraryManager, string fileName)
     : this(settings, rootScope, libraryScope, libraryManager)
 {
     this.fileName = fileName;
 }
Exemplo n.º 15
0
 public vhdlAbstractVisitor(VhdlParserSettings settings, RootDeclarativeRegion rootScope, LibraryDeclarativeRegion libraryScope, VHDL_Library_Manager libraryManager)
 {
     this.settings            = settings;
     this.rootScope           = rootScope;
     this.libraryScope        = libraryScope;
     this.libraryScope.Parent = rootScope;
     fileName            = string.Empty;
     this.libraryManager = libraryManager;
 }